web3ext.go 12.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

17 18
// package web3ext contains geth specific web3.js extensions.
package web3ext
19

20
var Modules = map[string]string{
21 22
	"admin":      Admin_JS,
	"chequebook": Chequebook_JS,
23
	"clique":     Clique_JS,
24 25 26 27 28 29 30
	"debug":      Debug_JS,
	"eth":        Eth_JS,
	"miner":      Miner_JS,
	"net":        Net_JS,
	"personal":   Personal_JS,
	"rpc":        RPC_JS,
	"shh":        Shh_JS,
31
	"swarmfs":    SWARMFS_JS,
32
	"txpool":     TxPool_JS,
33
}
34

35 36
const Chequebook_JS = `
web3._extend({
37 38 39 40 41 42 43 44 45
	property: 'chequebook',
	methods: [
		new web3._extend.Method({
			name: 'deposit',
			call: 'chequebook_deposit',
			params: 1,
			inputFormatter: [null]
		}),
		new web3._extend.Property({
46 47
			name: 'balance',
			getter: 'chequebook_balance',
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
			outputFormatter: web3._extend.utils.toDecimal
		}),
		new web3._extend.Method({
			name: 'cash',
			call: 'chequebook_cash',
			params: 1,
			inputFormatter: [null]
		}),
		new web3._extend.Method({
			name: 'issue',
			call: 'chequebook_issue',
			params: 2,
			inputFormatter: [null, null]
		}),
	]
63 64 65
});
`

66 67
const Clique_JS = `
web3._extend({
68 69
	property: 'clique',
	methods: [
70 71 72 73
		new web3._extend.Method({
			name: 'getSnapshot',
			call: 'clique_getSnapshot',
			params: 1,
74
			inputFormatter: [null]
75
		}),
76 77 78 79 80
		new web3._extend.Method({
			name: 'getSnapshotAtHash',
			call: 'clique_getSnapshotAtHash',
			params: 1
		}),
81 82 83 84 85 86
		new web3._extend.Method({
			name: 'getSigners',
			call: 'clique_getSigners',
			params: 1,
			inputFormatter: [null]
		}),
87 88 89 90 91
		new web3._extend.Method({
			name: 'getSignersAtHash',
			call: 'clique_getSignersAtHash',
			params: 1
		}),
92 93 94 95 96 97 98 99 100
		new web3._extend.Method({
			name: 'propose',
			call: 'clique_propose',
			params: 2
		}),
		new web3._extend.Method({
			name: 'discard',
			call: 'clique_discard',
			params: 1
101 102 103
		}),
	],
	properties: [
104 105 106 107 108 109 110 111
		new web3._extend.Property({
			name: 'proposals',
			getter: 'clique_proposals'
		}),
	]
});
`

112 113 114
const Admin_JS = `
web3._extend({
	property: 'admin',
115
	methods: [
116 117 118 119 120
		new web3._extend.Method({
			name: 'addPeer',
			call: 'admin_addPeer',
			params: 1
		}),
121 122 123 124 125
		new web3._extend.Method({
			name: 'removePeer',
			call: 'admin_removePeer',
			params: 1
		}),
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
		new web3._extend.Method({
			name: 'exportChain',
			call: 'admin_exportChain',
			params: 1,
			inputFormatter: [null]
		}),
		new web3._extend.Method({
			name: 'importChain',
			call: 'admin_importChain',
			params: 1
		}),
		new web3._extend.Method({
			name: 'sleepBlocks',
			call: 'admin_sleepBlocks',
			params: 2
		}),
		new web3._extend.Method({
			name: 'startRPC',
			call: 'admin_startRPC',
145 146
			params: 4,
			inputFormatter: [null, null, null, null]
147 148 149
		}),
		new web3._extend.Method({
			name: 'stopRPC',
150
			call: 'admin_stopRPC'
151 152 153 154
		}),
		new web3._extend.Method({
			name: 'startWS',
			call: 'admin_startWS',
155 156
			params: 4,
			inputFormatter: [null, null, null, null]
157 158 159
		}),
		new web3._extend.Method({
			name: 'stopWS',
160
			call: 'admin_stopWS'
161
		}),
162
	],
163
	properties: [
164 165 166 167 168 169 170 171 172 173 174
		new web3._extend.Property({
			name: 'nodeInfo',
			getter: 'admin_nodeInfo'
		}),
		new web3._extend.Property({
			name: 'peers',
			getter: 'admin_peers'
		}),
		new web3._extend.Property({
			name: 'datadir',
			getter: 'admin_datadir'
175
		}),
176 177 178 179 180 181 182
	]
});
`

const Debug_JS = `
web3._extend({
	property: 'debug',
183
	methods: [
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
		new web3._extend.Method({
			name: 'printBlock',
			call: 'debug_printBlock',
			params: 1
		}),
		new web3._extend.Method({
			name: 'getBlockRlp',
			call: 'debug_getBlockRlp',
			params: 1
		}),
		new web3._extend.Method({
			name: 'setHead',
			call: 'debug_setHead',
			params: 1
		}),
		new web3._extend.Method({
200 201
			name: 'traceBlock',
			call: 'debug_traceBlock',
202
			params: 1
203 204
		}),
		new web3._extend.Method({
205 206
			name: 'traceBlockFromFile',
			call: 'debug_traceBlockFromFile',
207
			params: 1
208 209 210 211
		}),
		new web3._extend.Method({
			name: 'traceBlockByNumber',
			call: 'debug_traceBlockByNumber',
212
			params: 1
213 214 215 216
		}),
		new web3._extend.Method({
			name: 'traceBlockByHash',
			call: 'debug_traceBlockByHash',
217
			params: 1
218 219 220 221 222 223 224 225 226 227 228
		}),
		new web3._extend.Method({
			name: 'seedHash',
			call: 'debug_seedHash',
			params: 1
		}),
		new web3._extend.Method({
			name: 'dumpBlock',
			call: 'debug_dumpBlock',
			params: 1
		}),
229 230 231 232 233 234
		new web3._extend.Method({
			name: 'chaindbProperty',
			call: 'debug_chaindbProperty',
			params: 1,
			outputFormatter: console.log
		}),
235 236 237 238
		new web3._extend.Method({
			name: 'chaindbCompact',
			call: 'debug_chaindbCompact',
		}),
239 240 241 242
		new web3._extend.Method({
			name: 'metrics',
			call: 'debug_metrics',
			params: 1
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
		}),
		new web3._extend.Method({
			name: 'verbosity',
			call: 'debug_verbosity',
			params: 1
		}),
		new web3._extend.Method({
			name: 'vmodule',
			call: 'debug_vmodule',
			params: 1
		}),
		new web3._extend.Method({
			name: 'backtraceAt',
			call: 'debug_backtraceAt',
			params: 1,
		}),
		new web3._extend.Method({
			name: 'stacks',
			call: 'debug_stacks',
			params: 0,
			outputFormatter: console.log
		}),
265 266 267 268 269
		new web3._extend.Method({
			name: 'freeOSMemory',
			call: 'debug_freeOSMemory',
			params: 0,
		}),
270 271 272 273 274
		new web3._extend.Method({
			name: 'setGCPercent',
			call: 'debug_setGCPercent',
			params: 1,
		}),
275 276 277 278 279 280 281 282 283 284
		new web3._extend.Method({
			name: 'memStats',
			call: 'debug_memStats',
			params: 0,
		}),
		new web3._extend.Method({
			name: 'gcStats',
			call: 'debug_gcStats',
			params: 0,
		}),
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
		new web3._extend.Method({
			name: 'cpuProfile',
			call: 'debug_cpuProfile',
			params: 2
		}),
		new web3._extend.Method({
			name: 'startCPUProfile',
			call: 'debug_startCPUProfile',
			params: 1
		}),
		new web3._extend.Method({
			name: 'stopCPUProfile',
			call: 'debug_stopCPUProfile',
			params: 0
		}),
		new web3._extend.Method({
301 302
			name: 'goTrace',
			call: 'debug_goTrace',
303 304 305
			params: 2
		}),
		new web3._extend.Method({
306 307
			name: 'startGoTrace',
			call: 'debug_startGoTrace',
308 309 310
			params: 1
		}),
		new web3._extend.Method({
311 312
			name: 'stopGoTrace',
			call: 'debug_stopGoTrace',
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
			params: 0
		}),
		new web3._extend.Method({
			name: 'blockProfile',
			call: 'debug_blockProfile',
			params: 2
		}),
		new web3._extend.Method({
			name: 'setBlockProfileRate',
			call: 'debug_setBlockProfileRate',
			params: 1
		}),
		new web3._extend.Method({
			name: 'writeBlockProfile',
			call: 'debug_writeBlockProfile',
			params: 1
		}),
		new web3._extend.Method({
			name: 'writeMemProfile',
			call: 'debug_writeMemProfile',
			params: 1
		}),
335
		new web3._extend.Method({
336 337
			name: 'traceTransaction',
			call: 'debug_traceTransaction',
338 339
			params: 2,
			inputFormatter: [null, null]
340 341 342 343 344 345
		}),
		new web3._extend.Method({
			name: 'preimage',
			call: 'debug_preimage',
			params: 1,
			inputFormatter: [null]
346 347 348 349 350 351
		}),
		new web3._extend.Method({
			name: 'getBadBlocks',
			call: 'debug_getBadBlocks',
			params: 0,
		}),
352 353 354 355 356
		new web3._extend.Method({
			name: 'storageRangeAt',
			call: 'debug_storageRangeAt',
			params: 5,
		}),
357 358 359 360 361 362 363 364 365 366 367 368
		new web3._extend.Method({
			name: 'getModifiedAccountsByNumber',
			call: 'debug_getModifiedAccountsByNumber',
			params: 2,
			inputFormatter: [null, null],
		}),
		new web3._extend.Method({
			name: 'getModifiedAccountsByHash',
			call: 'debug_getModifiedAccountsByHash',
			params: 2,
			inputFormatter:[null, null],
		}),
369
	],
370
	properties: []
371 372 373
});
`

374 375 376
const Eth_JS = `
web3._extend({
	property: 'eth',
377
	methods: [
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
		new web3._extend.Method({
			name: 'sign',
			call: 'eth_sign',
			params: 2,
			inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
		}),
		new web3._extend.Method({
			name: 'resend',
			call: 'eth_resend',
			params: 3,
			inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
		}),
		new web3._extend.Method({
			name: 'signTransaction',
			call: 'eth_signTransaction',
			params: 1,
			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
		}),
		new web3._extend.Method({
			name: 'submitTransaction',
			call: 'eth_submitTransaction',
			params: 1,
			inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
401 402 403 404 405 406 407 408 409 410 411 412 413
		}),
		new web3._extend.Method({
			name: 'getRawTransaction',
			call: 'eth_getRawTransactionByHash',
			params: 1
		}),
		new web3._extend.Method({
			name: 'getRawTransactionFromBlock',
			call: function(args) {
				return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
			},
			params: 2,
			inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
414
		}),
415
	],
416
	properties: [
417 418 419 420 421 422 423 424 425 426 427
		new web3._extend.Property({
			name: 'pendingTransactions',
			getter: 'eth_pendingTransactions',
			outputFormatter: function(txs) {
				var formatted = [];
				for (var i = 0; i < txs.length; i++) {
					formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
					formatted[i].blockHash = null;
				}
				return formatted;
			}
428
		}),
429 430 431 432
	]
});
`

433 434 435
const Miner_JS = `
web3._extend({
	property: 'miner',
436
	methods: [
437 438 439
		new web3._extend.Method({
			name: 'start',
			call: 'miner_start',
440 441
			params: 1,
			inputFormatter: [null]
442 443 444
		}),
		new web3._extend.Method({
			name: 'stop',
445
			call: 'miner_stop'
446 447 448 449 450
		}),
		new web3._extend.Method({
			name: 'setEtherbase',
			call: 'miner_setEtherbase',
			params: 1,
451
			inputFormatter: [web3._extend.formatters.inputAddressFormatter]
452 453 454 455 456 457 458 459 460 461
		}),
		new web3._extend.Method({
			name: 'setExtra',
			call: 'miner_setExtra',
			params: 1
		}),
		new web3._extend.Method({
			name: 'setGasPrice',
			call: 'miner_setGasPrice',
			params: 1,
462
			inputFormatter: [web3._extend.utils.fromDecimal]
463 464
		}),
		new web3._extend.Method({
465 466
			name: 'getHashrate',
			call: 'miner_getHashrate'
467
		}),
468
	],
469
	properties: []
470 471 472
});
`

473 474 475 476
const Net_JS = `
web3._extend({
	property: 'net',
	methods: [],
477
	properties: [
478 479 480
		new web3._extend.Property({
			name: 'version',
			getter: 'net_version'
481
		}),
482 483 484 485 486 487 488
	]
});
`

const Personal_JS = `
web3._extend({
	property: 'personal',
489
	methods: [
490 491 492 493
		new web3._extend.Method({
			name: 'importRawKey',
			call: 'personal_importRawKey',
			params: 2
494
		}),
495 496 497 498 499 500 501 502 503 504
		new web3._extend.Method({
			name: 'sign',
			call: 'personal_sign',
			params: 3,
			inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
		}),
		new web3._extend.Method({
			name: 'ecRecover',
			call: 'personal_ecRecover',
			params: 2
505
		}),
506 507 508 509 510
		new web3._extend.Method({
			name: 'openWallet',
			call: 'personal_openWallet',
			params: 2
		}),
511 512 513 514
		new web3._extend.Method({
			name: 'deriveAccount',
			call: 'personal_deriveAccount',
			params: 3
515
		}),
516
	],
517
	properties: [
518 519 520
		new web3._extend.Property({
			name: 'listWallets',
			getter: 'personal_listWallets'
521
		}),
522
	]
523
})
524 525 526 527 528 529
`

const RPC_JS = `
web3._extend({
	property: 'rpc',
	methods: [],
530
	properties: [
531 532 533
		new web3._extend.Property({
			name: 'modules',
			getter: 'rpc_modules'
534
		}),
535 536 537 538
	]
});
`

539 540 541
const Shh_JS = `
web3._extend({
	property: 'shh',
542 543
	methods: [
	],
544 545 546 547
	properties:
	[
		new web3._extend.Property({
			name: 'version',
548 549
			getter: 'shh_version',
			outputFormatter: web3._extend.utils.toDecimal
550 551 552 553 554
		}),
		new web3._extend.Property({
			name: 'info',
			getter: 'shh_info'
		}),
555 556 557
	]
});
`
558

559 560
const SWARMFS_JS = `
web3._extend({
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
	property: 'swarmfs',
	methods:
	[
		new web3._extend.Method({
			name: 'mount',
			call: 'swarmfs_mount',
			params: 2
		}),
		new web3._extend.Method({
			name: 'unmount',
			call: 'swarmfs_unmount',
			params: 1
		}),
		new web3._extend.Method({
			name: 'listmounts',
			call: 'swarmfs_listmounts',
			params: 0
578
		}),
579
	]
580 581
});
`
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604

const TxPool_JS = `
web3._extend({
	property: 'txpool',
	methods: [],
	properties:
	[
		new web3._extend.Property({
			name: 'content',
			getter: 'txpool_content'
		}),
		new web3._extend.Property({
			name: 'inspect',
			getter: 'txpool_inspect'
		}),
		new web3._extend.Property({
			name: 'status',
			getter: 'txpool_status',
			outputFormatter: function(status) {
				status.pending = web3._extend.utils.toDecimal(status.pending);
				status.queued = web3._extend.utils.toDecimal(status.queued);
				return status;
			}
605
		}),
606 607 608
	]
});
`