github.com/gmax0/go-ethereum@v1.9.7/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: 'fillTransaction', 488 call: 'eth_fillTransaction', 489 params: 1, 490 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 491 }), 492 new web3._extend.Method({ 493 name: 'getHeaderByNumber', 494 call: 'eth_getHeaderByNumber', 495 params: 1 496 }), 497 new web3._extend.Method({ 498 name: 'getHeaderByHash', 499 call: 'eth_getHeaderByHash', 500 params: 1 501 }), 502 new web3._extend.Method({ 503 name: 'getBlockByNumber', 504 call: 'eth_getBlockByNumber', 505 params: 2 506 }), 507 new web3._extend.Method({ 508 name: 'getBlockByHash', 509 call: 'eth_getBlockByHash', 510 params: 2 511 }), 512 new web3._extend.Method({ 513 name: 'getRawTransaction', 514 call: 'eth_getRawTransactionByHash', 515 params: 1 516 }), 517 new web3._extend.Method({ 518 name: 'getRawTransactionFromBlock', 519 call: function(args) { 520 return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex'; 521 }, 522 params: 2, 523 inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] 524 }), 525 new web3._extend.Method({ 526 name: 'getProof', 527 call: 'eth_getProof', 528 params: 3, 529 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null, web3._extend.formatters.inputBlockNumberFormatter] 530 }), 531 ], 532 properties: [ 533 new web3._extend.Property({ 534 name: 'pendingTransactions', 535 getter: 'eth_pendingTransactions', 536 outputFormatter: function(txs) { 537 var formatted = []; 538 for (var i = 0; i < txs.length; i++) { 539 formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i])); 540 formatted[i].blockHash = null; 541 } 542 return formatted; 543 } 544 }), 545 ] 546 }); 547 ` 548 549 const MinerJs = ` 550 web3._extend({ 551 property: 'miner', 552 methods: [ 553 new web3._extend.Method({ 554 name: 'start', 555 call: 'miner_start', 556 params: 1, 557 inputFormatter: [null] 558 }), 559 new web3._extend.Method({ 560 name: 'stop', 561 call: 'miner_stop' 562 }), 563 new web3._extend.Method({ 564 name: 'setEtherbase', 565 call: 'miner_setEtherbase', 566 params: 1, 567 inputFormatter: [web3._extend.formatters.inputAddressFormatter] 568 }), 569 new web3._extend.Method({ 570 name: 'setExtra', 571 call: 'miner_setExtra', 572 params: 1 573 }), 574 new web3._extend.Method({ 575 name: 'setGasPrice', 576 call: 'miner_setGasPrice', 577 params: 1, 578 inputFormatter: [web3._extend.utils.fromDecimal] 579 }), 580 new web3._extend.Method({ 581 name: 'setRecommitInterval', 582 call: 'miner_setRecommitInterval', 583 params: 1, 584 }), 585 new web3._extend.Method({ 586 name: 'getHashrate', 587 call: 'miner_getHashrate' 588 }), 589 ], 590 properties: [] 591 }); 592 ` 593 594 const NetJs = ` 595 web3._extend({ 596 property: 'net', 597 methods: [], 598 properties: [ 599 new web3._extend.Property({ 600 name: 'version', 601 getter: 'net_version' 602 }), 603 ] 604 }); 605 ` 606 607 const PersonalJs = ` 608 web3._extend({ 609 property: 'personal', 610 methods: [ 611 new web3._extend.Method({ 612 name: 'importRawKey', 613 call: 'personal_importRawKey', 614 params: 2 615 }), 616 new web3._extend.Method({ 617 name: 'sign', 618 call: 'personal_sign', 619 params: 3, 620 inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null] 621 }), 622 new web3._extend.Method({ 623 name: 'ecRecover', 624 call: 'personal_ecRecover', 625 params: 2 626 }), 627 new web3._extend.Method({ 628 name: 'openWallet', 629 call: 'personal_openWallet', 630 params: 2 631 }), 632 new web3._extend.Method({ 633 name: 'deriveAccount', 634 call: 'personal_deriveAccount', 635 params: 3 636 }), 637 new web3._extend.Method({ 638 name: 'signTransaction', 639 call: 'personal_signTransaction', 640 params: 2, 641 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null] 642 }), 643 new web3._extend.Method({ 644 name: 'unpair', 645 call: 'personal_unpair', 646 params: 2 647 }), 648 new web3._extend.Method({ 649 name: 'initializeWallet', 650 call: 'personal_initializeWallet', 651 params: 1 652 }) 653 ], 654 properties: [ 655 new web3._extend.Property({ 656 name: 'listWallets', 657 getter: 'personal_listWallets' 658 }), 659 ] 660 }) 661 ` 662 663 const RpcJs = ` 664 web3._extend({ 665 property: 'rpc', 666 methods: [], 667 properties: [ 668 new web3._extend.Property({ 669 name: 'modules', 670 getter: 'rpc_modules' 671 }), 672 ] 673 }); 674 ` 675 676 const ShhJs = ` 677 web3._extend({ 678 property: 'shh', 679 methods: [ 680 ], 681 properties: 682 [ 683 new web3._extend.Property({ 684 name: 'version', 685 getter: 'shh_version', 686 outputFormatter: web3._extend.utils.toDecimal 687 }), 688 new web3._extend.Property({ 689 name: 'info', 690 getter: 'shh_info' 691 }), 692 ] 693 }); 694 ` 695 696 const SwarmfsJs = ` 697 web3._extend({ 698 property: 'swarmfs', 699 methods: 700 [ 701 new web3._extend.Method({ 702 name: 'mount', 703 call: 'swarmfs_mount', 704 params: 2 705 }), 706 new web3._extend.Method({ 707 name: 'unmount', 708 call: 'swarmfs_unmount', 709 params: 1 710 }), 711 new web3._extend.Method({ 712 name: 'listmounts', 713 call: 'swarmfs_listmounts', 714 params: 0 715 }), 716 ] 717 }); 718 ` 719 720 const TxpoolJs = ` 721 web3._extend({ 722 property: 'txpool', 723 methods: [], 724 properties: 725 [ 726 new web3._extend.Property({ 727 name: 'content', 728 getter: 'txpool_content' 729 }), 730 new web3._extend.Property({ 731 name: 'inspect', 732 getter: 'txpool_inspect' 733 }), 734 new web3._extend.Property({ 735 name: 'status', 736 getter: 'txpool_status', 737 outputFormatter: function(status) { 738 status.pending = web3._extend.utils.toDecimal(status.pending); 739 status.queued = web3._extend.utils.toDecimal(status.queued); 740 return status; 741 } 742 }), 743 ] 744 }); 745 ` 746 747 const AccountingJs = ` 748 web3._extend({ 749 property: 'accounting', 750 methods: [ 751 new web3._extend.Property({ 752 name: 'balance', 753 getter: 'account_balance' 754 }), 755 new web3._extend.Property({ 756 name: 'balanceCredit', 757 getter: 'account_balanceCredit' 758 }), 759 new web3._extend.Property({ 760 name: 'balanceDebit', 761 getter: 'account_balanceDebit' 762 }), 763 new web3._extend.Property({ 764 name: 'bytesCredit', 765 getter: 'account_bytesCredit' 766 }), 767 new web3._extend.Property({ 768 name: 'bytesDebit', 769 getter: 'account_bytesDebit' 770 }), 771 new web3._extend.Property({ 772 name: 'msgCredit', 773 getter: 'account_msgCredit' 774 }), 775 new web3._extend.Property({ 776 name: 'msgDebit', 777 getter: 'account_msgDebit' 778 }), 779 new web3._extend.Property({ 780 name: 'peerDrops', 781 getter: 'account_peerDrops' 782 }), 783 new web3._extend.Property({ 784 name: 'selfDrops', 785 getter: 'account_selfDrops' 786 }), 787 ] 788 }); 789 ` 790 791 const LESJs = ` 792 web3._extend({ 793 property: 'les', 794 methods: 795 [ 796 new web3._extend.Method({ 797 name: 'getCheckpoint', 798 call: 'les_getCheckpoint', 799 params: 1 800 }), 801 ], 802 properties: 803 [ 804 new web3._extend.Property({ 805 name: 'latestCheckpoint', 806 getter: 'les_latestCheckpoint' 807 }), 808 new web3._extend.Property({ 809 name: 'checkpointContractAddress', 810 getter: 'les_getCheckpointContractAddress' 811 }), 812 ] 813 }); 814 `