github.com/wzbox/go-ethereum@v1.9.2/internal/web3ext/web3ext.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // package web3ext contains geth specific web3.js extensions. 18 package web3ext 19 20 var Modules = map[string]string{ 21 "accounting": AccountingJs, 22 "admin": AdminJs, 23 "chequebook": ChequebookJs, 24 "clique": CliqueJs, 25 "ethash": EthashJs, 26 "debug": DebugJs, 27 "eth": EthJs, 28 "miner": MinerJs, 29 "net": NetJs, 30 "personal": PersonalJs, 31 "rpc": RpcJs, 32 "shh": ShhJs, 33 "swarmfs": SwarmfsJs, 34 "txpool": TxpoolJs, 35 "les": LESJs, 36 } 37 38 const ChequebookJs = ` 39 web3._extend({ 40 property: 'chequebook', 41 methods: [ 42 new web3._extend.Method({ 43 name: 'deposit', 44 call: 'chequebook_deposit', 45 params: 1, 46 inputFormatter: [null] 47 }), 48 new web3._extend.Property({ 49 name: 'balance', 50 getter: 'chequebook_balance', 51 outputFormatter: web3._extend.utils.toDecimal 52 }), 53 new web3._extend.Method({ 54 name: 'cash', 55 call: 'chequebook_cash', 56 params: 1, 57 inputFormatter: [null] 58 }), 59 new web3._extend.Method({ 60 name: 'issue', 61 call: 'chequebook_issue', 62 params: 2, 63 inputFormatter: [null, null] 64 }), 65 ] 66 }); 67 ` 68 69 const CliqueJs = ` 70 web3._extend({ 71 property: 'clique', 72 methods: [ 73 new web3._extend.Method({ 74 name: 'getSnapshot', 75 call: 'clique_getSnapshot', 76 params: 1, 77 inputFormatter: [null] 78 }), 79 new web3._extend.Method({ 80 name: 'getSnapshotAtHash', 81 call: 'clique_getSnapshotAtHash', 82 params: 1 83 }), 84 new web3._extend.Method({ 85 name: 'getSigners', 86 call: 'clique_getSigners', 87 params: 1, 88 inputFormatter: [null] 89 }), 90 new web3._extend.Method({ 91 name: 'getSignersAtHash', 92 call: 'clique_getSignersAtHash', 93 params: 1 94 }), 95 new web3._extend.Method({ 96 name: 'propose', 97 call: 'clique_propose', 98 params: 2 99 }), 100 new web3._extend.Method({ 101 name: 'discard', 102 call: 'clique_discard', 103 params: 1 104 }), 105 ], 106 properties: [ 107 new web3._extend.Property({ 108 name: 'proposals', 109 getter: 'clique_proposals' 110 }), 111 ] 112 }); 113 ` 114 115 const EthashJs = ` 116 web3._extend({ 117 property: 'ethash', 118 methods: [ 119 new web3._extend.Method({ 120 name: 'getWork', 121 call: 'ethash_getWork', 122 params: 0 123 }), 124 new web3._extend.Method({ 125 name: 'getHashrate', 126 call: 'ethash_getHashrate', 127 params: 0 128 }), 129 new web3._extend.Method({ 130 name: 'submitWork', 131 call: 'ethash_submitWork', 132 params: 3, 133 }), 134 new web3._extend.Method({ 135 name: 'submitHashRate', 136 call: 'ethash_submitHashRate', 137 params: 2, 138 }), 139 ] 140 }); 141 ` 142 143 const AdminJs = ` 144 web3._extend({ 145 property: 'admin', 146 methods: [ 147 new web3._extend.Method({ 148 name: 'addPeer', 149 call: 'admin_addPeer', 150 params: 1 151 }), 152 new web3._extend.Method({ 153 name: 'removePeer', 154 call: 'admin_removePeer', 155 params: 1 156 }), 157 new web3._extend.Method({ 158 name: 'addTrustedPeer', 159 call: 'admin_addTrustedPeer', 160 params: 1 161 }), 162 new web3._extend.Method({ 163 name: 'removeTrustedPeer', 164 call: 'admin_removeTrustedPeer', 165 params: 1 166 }), 167 new web3._extend.Method({ 168 name: 'exportChain', 169 call: 'admin_exportChain', 170 params: 1, 171 inputFormatter: [null] 172 }), 173 new web3._extend.Method({ 174 name: 'importChain', 175 call: 'admin_importChain', 176 params: 1 177 }), 178 new web3._extend.Method({ 179 name: 'sleepBlocks', 180 call: 'admin_sleepBlocks', 181 params: 2 182 }), 183 new web3._extend.Method({ 184 name: 'startRPC', 185 call: 'admin_startRPC', 186 params: 4, 187 inputFormatter: [null, null, null, null] 188 }), 189 new web3._extend.Method({ 190 name: 'stopRPC', 191 call: 'admin_stopRPC' 192 }), 193 new web3._extend.Method({ 194 name: 'startWS', 195 call: 'admin_startWS', 196 params: 4, 197 inputFormatter: [null, null, null, null] 198 }), 199 new web3._extend.Method({ 200 name: 'stopWS', 201 call: 'admin_stopWS' 202 }), 203 ], 204 properties: [ 205 new web3._extend.Property({ 206 name: 'nodeInfo', 207 getter: 'admin_nodeInfo' 208 }), 209 new web3._extend.Property({ 210 name: 'peers', 211 getter: 'admin_peers' 212 }), 213 new web3._extend.Property({ 214 name: 'datadir', 215 getter: 'admin_datadir' 216 }), 217 ] 218 }); 219 ` 220 221 const DebugJs = ` 222 web3._extend({ 223 property: 'debug', 224 methods: [ 225 new web3._extend.Method({ 226 name: 'printBlock', 227 call: 'debug_printBlock', 228 params: 1 229 }), 230 new web3._extend.Method({ 231 name: 'getBlockRlp', 232 call: 'debug_getBlockRlp', 233 params: 1 234 }), 235 new web3._extend.Method({ 236 name: 'testSignCliqueBlock', 237 call: 'debug_testSignCliqueBlock', 238 params: 2, 239 inputFormatters: [web3._extend.formatters.inputAddressFormatter, null], 240 }), 241 new web3._extend.Method({ 242 name: 'setHead', 243 call: 'debug_setHead', 244 params: 1 245 }), 246 new web3._extend.Method({ 247 name: 'seedHash', 248 call: 'debug_seedHash', 249 params: 1 250 }), 251 new web3._extend.Method({ 252 name: 'dumpBlock', 253 call: 'debug_dumpBlock', 254 params: 1 255 }), 256 new web3._extend.Method({ 257 name: 'chaindbProperty', 258 call: 'debug_chaindbProperty', 259 params: 1, 260 outputFormatter: console.log 261 }), 262 new web3._extend.Method({ 263 name: 'chaindbCompact', 264 call: 'debug_chaindbCompact', 265 }), 266 new web3._extend.Method({ 267 name: 'verbosity', 268 call: 'debug_verbosity', 269 params: 1 270 }), 271 new web3._extend.Method({ 272 name: 'vmodule', 273 call: 'debug_vmodule', 274 params: 1 275 }), 276 new web3._extend.Method({ 277 name: 'backtraceAt', 278 call: 'debug_backtraceAt', 279 params: 1, 280 }), 281 new web3._extend.Method({ 282 name: 'stacks', 283 call: 'debug_stacks', 284 params: 0, 285 outputFormatter: console.log 286 }), 287 new web3._extend.Method({ 288 name: 'freeOSMemory', 289 call: 'debug_freeOSMemory', 290 params: 0, 291 }), 292 new web3._extend.Method({ 293 name: 'setGCPercent', 294 call: 'debug_setGCPercent', 295 params: 1, 296 }), 297 new web3._extend.Method({ 298 name: 'memStats', 299 call: 'debug_memStats', 300 params: 0, 301 }), 302 new web3._extend.Method({ 303 name: 'gcStats', 304 call: 'debug_gcStats', 305 params: 0, 306 }), 307 new web3._extend.Method({ 308 name: 'cpuProfile', 309 call: 'debug_cpuProfile', 310 params: 2 311 }), 312 new web3._extend.Method({ 313 name: 'startCPUProfile', 314 call: 'debug_startCPUProfile', 315 params: 1 316 }), 317 new web3._extend.Method({ 318 name: 'stopCPUProfile', 319 call: 'debug_stopCPUProfile', 320 params: 0 321 }), 322 new web3._extend.Method({ 323 name: 'goTrace', 324 call: 'debug_goTrace', 325 params: 2 326 }), 327 new web3._extend.Method({ 328 name: 'startGoTrace', 329 call: 'debug_startGoTrace', 330 params: 1 331 }), 332 new web3._extend.Method({ 333 name: 'stopGoTrace', 334 call: 'debug_stopGoTrace', 335 params: 0 336 }), 337 new web3._extend.Method({ 338 name: 'blockProfile', 339 call: 'debug_blockProfile', 340 params: 2 341 }), 342 new web3._extend.Method({ 343 name: 'setBlockProfileRate', 344 call: 'debug_setBlockProfileRate', 345 params: 1 346 }), 347 new web3._extend.Method({ 348 name: 'writeBlockProfile', 349 call: 'debug_writeBlockProfile', 350 params: 1 351 }), 352 new web3._extend.Method({ 353 name: 'mutexProfile', 354 call: 'debug_mutexProfile', 355 params: 2 356 }), 357 new web3._extend.Method({ 358 name: 'setMutexProfileFraction', 359 call: 'debug_setMutexProfileFraction', 360 params: 1 361 }), 362 new web3._extend.Method({ 363 name: 'writeMutexProfile', 364 call: 'debug_writeMutexProfile', 365 params: 1 366 }), 367 new web3._extend.Method({ 368 name: 'writeMemProfile', 369 call: 'debug_writeMemProfile', 370 params: 1 371 }), 372 new web3._extend.Method({ 373 name: 'traceBlock', 374 call: 'debug_traceBlock', 375 params: 2, 376 inputFormatter: [null, null] 377 }), 378 new web3._extend.Method({ 379 name: 'traceBlockFromFile', 380 call: 'debug_traceBlockFromFile', 381 params: 2, 382 inputFormatter: [null, null] 383 }), 384 new web3._extend.Method({ 385 name: 'traceBadBlock', 386 call: 'debug_traceBadBlock', 387 params: 1, 388 inputFormatter: [null] 389 }), 390 new web3._extend.Method({ 391 name: 'standardTraceBadBlockToFile', 392 call: 'debug_standardTraceBadBlockToFile', 393 params: 2, 394 inputFormatter: [null, null] 395 }), 396 new web3._extend.Method({ 397 name: 'standardTraceBlockToFile', 398 call: 'debug_standardTraceBlockToFile', 399 params: 2, 400 inputFormatter: [null, null] 401 }), 402 new web3._extend.Method({ 403 name: 'traceBlockByNumber', 404 call: 'debug_traceBlockByNumber', 405 params: 2, 406 inputFormatter: [null, null] 407 }), 408 new web3._extend.Method({ 409 name: 'traceBlockByHash', 410 call: 'debug_traceBlockByHash', 411 params: 2, 412 inputFormatter: [null, null] 413 }), 414 new web3._extend.Method({ 415 name: 'traceTransaction', 416 call: 'debug_traceTransaction', 417 params: 2, 418 inputFormatter: [null, null] 419 }), 420 new web3._extend.Method({ 421 name: 'preimage', 422 call: 'debug_preimage', 423 params: 1, 424 inputFormatter: [null] 425 }), 426 new web3._extend.Method({ 427 name: 'getBadBlocks', 428 call: 'debug_getBadBlocks', 429 params: 0, 430 }), 431 new web3._extend.Method({ 432 name: 'storageRangeAt', 433 call: 'debug_storageRangeAt', 434 params: 5, 435 }), 436 new web3._extend.Method({ 437 name: 'getModifiedAccountsByNumber', 438 call: 'debug_getModifiedAccountsByNumber', 439 params: 2, 440 inputFormatter: [null, null], 441 }), 442 new web3._extend.Method({ 443 name: 'getModifiedAccountsByHash', 444 call: 'debug_getModifiedAccountsByHash', 445 params: 2, 446 inputFormatter:[null, null], 447 }), 448 ], 449 properties: [] 450 }); 451 ` 452 453 const EthJs = ` 454 web3._extend({ 455 property: 'eth', 456 methods: [ 457 new web3._extend.Method({ 458 name: 'chainId', 459 call: 'eth_chainId', 460 params: 0 461 }), 462 new web3._extend.Method({ 463 name: 'sign', 464 call: 'eth_sign', 465 params: 2, 466 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null] 467 }), 468 new web3._extend.Method({ 469 name: 'resend', 470 call: 'eth_resend', 471 params: 3, 472 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal] 473 }), 474 new web3._extend.Method({ 475 name: 'signTransaction', 476 call: 'eth_signTransaction', 477 params: 1, 478 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 479 }), 480 new web3._extend.Method({ 481 name: 'submitTransaction', 482 call: 'eth_submitTransaction', 483 params: 1, 484 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 485 }), 486 new web3._extend.Method({ 487 name: 'getHeaderByNumber', 488 call: 'eth_getHeaderByNumber', 489 params: 1 490 }), 491 new web3._extend.Method({ 492 name: 'getHeaderByHash', 493 call: 'eth_getHeaderByHash', 494 params: 1 495 }), 496 new web3._extend.Method({ 497 name: 'getBlockByNumber', 498 call: 'eth_getBlockByNumber', 499 params: 2 500 }), 501 new web3._extend.Method({ 502 name: 'getBlockByHash', 503 call: 'eth_getBlockByHash', 504 params: 2 505 }), 506 new web3._extend.Method({ 507 name: 'getRawTransaction', 508 call: 'eth_getRawTransactionByHash', 509 params: 1 510 }), 511 new web3._extend.Method({ 512 name: 'getRawTransactionFromBlock', 513 call: function(args) { 514 return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex'; 515 }, 516 params: 2, 517 inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] 518 }), 519 new web3._extend.Method({ 520 name: 'getProof', 521 call: 'eth_getProof', 522 params: 3, 523 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null, web3._extend.formatters.inputBlockNumberFormatter] 524 }), 525 ], 526 properties: [ 527 new web3._extend.Property({ 528 name: 'pendingTransactions', 529 getter: 'eth_pendingTransactions', 530 outputFormatter: function(txs) { 531 var formatted = []; 532 for (var i = 0; i < txs.length; i++) { 533 formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i])); 534 formatted[i].blockHash = null; 535 } 536 return formatted; 537 } 538 }), 539 ] 540 }); 541 ` 542 543 const MinerJs = ` 544 web3._extend({ 545 property: 'miner', 546 methods: [ 547 new web3._extend.Method({ 548 name: 'start', 549 call: 'miner_start', 550 params: 1, 551 inputFormatter: [null] 552 }), 553 new web3._extend.Method({ 554 name: 'stop', 555 call: 'miner_stop' 556 }), 557 new web3._extend.Method({ 558 name: 'setEtherbase', 559 call: 'miner_setEtherbase', 560 params: 1, 561 inputFormatter: [web3._extend.formatters.inputAddressFormatter] 562 }), 563 new web3._extend.Method({ 564 name: 'setExtra', 565 call: 'miner_setExtra', 566 params: 1 567 }), 568 new web3._extend.Method({ 569 name: 'setGasPrice', 570 call: 'miner_setGasPrice', 571 params: 1, 572 inputFormatter: [web3._extend.utils.fromDecimal] 573 }), 574 new web3._extend.Method({ 575 name: 'setRecommitInterval', 576 call: 'miner_setRecommitInterval', 577 params: 1, 578 }), 579 new web3._extend.Method({ 580 name: 'getHashrate', 581 call: 'miner_getHashrate' 582 }), 583 ], 584 properties: [] 585 }); 586 ` 587 588 const NetJs = ` 589 web3._extend({ 590 property: 'net', 591 methods: [], 592 properties: [ 593 new web3._extend.Property({ 594 name: 'version', 595 getter: 'net_version' 596 }), 597 ] 598 }); 599 ` 600 601 const PersonalJs = ` 602 web3._extend({ 603 property: 'personal', 604 methods: [ 605 new web3._extend.Method({ 606 name: 'importRawKey', 607 call: 'personal_importRawKey', 608 params: 2 609 }), 610 new web3._extend.Method({ 611 name: 'sign', 612 call: 'personal_sign', 613 params: 3, 614 inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null] 615 }), 616 new web3._extend.Method({ 617 name: 'ecRecover', 618 call: 'personal_ecRecover', 619 params: 2 620 }), 621 new web3._extend.Method({ 622 name: 'openWallet', 623 call: 'personal_openWallet', 624 params: 2 625 }), 626 new web3._extend.Method({ 627 name: 'deriveAccount', 628 call: 'personal_deriveAccount', 629 params: 3 630 }), 631 new web3._extend.Method({ 632 name: 'signTransaction', 633 call: 'personal_signTransaction', 634 params: 2, 635 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null] 636 }), 637 new web3._extend.Method({ 638 name: 'unpair', 639 call: 'personal_unpair', 640 params: 2 641 }), 642 new web3._extend.Method({ 643 name: 'initializeWallet', 644 call: 'personal_initializeWallet', 645 params: 1 646 }) 647 ], 648 properties: [ 649 new web3._extend.Property({ 650 name: 'listWallets', 651 getter: 'personal_listWallets' 652 }), 653 ] 654 }) 655 ` 656 657 const RpcJs = ` 658 web3._extend({ 659 property: 'rpc', 660 methods: [], 661 properties: [ 662 new web3._extend.Property({ 663 name: 'modules', 664 getter: 'rpc_modules' 665 }), 666 ] 667 }); 668 ` 669 670 const ShhJs = ` 671 web3._extend({ 672 property: 'shh', 673 methods: [ 674 ], 675 properties: 676 [ 677 new web3._extend.Property({ 678 name: 'version', 679 getter: 'shh_version', 680 outputFormatter: web3._extend.utils.toDecimal 681 }), 682 new web3._extend.Property({ 683 name: 'info', 684 getter: 'shh_info' 685 }), 686 ] 687 }); 688 ` 689 690 const SwarmfsJs = ` 691 web3._extend({ 692 property: 'swarmfs', 693 methods: 694 [ 695 new web3._extend.Method({ 696 name: 'mount', 697 call: 'swarmfs_mount', 698 params: 2 699 }), 700 new web3._extend.Method({ 701 name: 'unmount', 702 call: 'swarmfs_unmount', 703 params: 1 704 }), 705 new web3._extend.Method({ 706 name: 'listmounts', 707 call: 'swarmfs_listmounts', 708 params: 0 709 }), 710 ] 711 }); 712 ` 713 714 const TxpoolJs = ` 715 web3._extend({ 716 property: 'txpool', 717 methods: [], 718 properties: 719 [ 720 new web3._extend.Property({ 721 name: 'content', 722 getter: 'txpool_content' 723 }), 724 new web3._extend.Property({ 725 name: 'inspect', 726 getter: 'txpool_inspect' 727 }), 728 new web3._extend.Property({ 729 name: 'status', 730 getter: 'txpool_status', 731 outputFormatter: function(status) { 732 status.pending = web3._extend.utils.toDecimal(status.pending); 733 status.queued = web3._extend.utils.toDecimal(status.queued); 734 return status; 735 } 736 }), 737 ] 738 }); 739 ` 740 741 const AccountingJs = ` 742 web3._extend({ 743 property: 'accounting', 744 methods: [ 745 new web3._extend.Property({ 746 name: 'balance', 747 getter: 'account_balance' 748 }), 749 new web3._extend.Property({ 750 name: 'balanceCredit', 751 getter: 'account_balanceCredit' 752 }), 753 new web3._extend.Property({ 754 name: 'balanceDebit', 755 getter: 'account_balanceDebit' 756 }), 757 new web3._extend.Property({ 758 name: 'bytesCredit', 759 getter: 'account_bytesCredit' 760 }), 761 new web3._extend.Property({ 762 name: 'bytesDebit', 763 getter: 'account_bytesDebit' 764 }), 765 new web3._extend.Property({ 766 name: 'msgCredit', 767 getter: 'account_msgCredit' 768 }), 769 new web3._extend.Property({ 770 name: 'msgDebit', 771 getter: 'account_msgDebit' 772 }), 773 new web3._extend.Property({ 774 name: 'peerDrops', 775 getter: 'account_peerDrops' 776 }), 777 new web3._extend.Property({ 778 name: 'selfDrops', 779 getter: 'account_selfDrops' 780 }), 781 ] 782 }); 783 ` 784 785 const LESJs = ` 786 web3._extend({ 787 property: 'les', 788 methods: 789 [ 790 new web3._extend.Method({ 791 name: 'getCheckpoint', 792 call: 'les_getCheckpoint', 793 params: 1 794 }), 795 ], 796 properties: 797 [ 798 new web3._extend.Property({ 799 name: 'latestCheckpoint', 800 getter: 'les_latestCheckpoint' 801 }), 802 new web3._extend.Property({ 803 name: 'checkpointContractAddress', 804 getter: 'les_getCheckpointContractAddress' 805 }), 806 ] 807 }); 808 `