github.com/reapchain/go-reapchain@v0.2.15-0.20210609012950-9735c110c705/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 "admin": Admin_JS, 22 "chequebook": Chequebook_JS, 23 "clique": Clique_JS, 24 "debug": Debug_JS, 25 "eth": Eth_JS, 26 "miner": Miner_JS, 27 "net": Net_JS, 28 "personal": Personal_JS, 29 "rpc": RPC_JS, 30 "shh": Shh_JS, 31 "swarmfs": SWARMFS_JS, 32 "txpool": TxPool_JS, 33 "istanbul": Istanbul_JS, 34 "PoDC": PoDC_JS, 35 } 36 const Chequebook_JS = ` 37 web3._extend({ 38 property: 'chequebook', 39 methods: 40 [ 41 new web3._extend.Method({ 42 name: 'deposit', 43 call: 'chequebook_deposit', 44 params: 1, 45 inputFormatter: [null] 46 }), 47 new web3._extend.Property({ 48 name: 'balance', 49 getter: 'chequebook_balance', 50 outputFormatter: web3._extend.utils.toDecimal 51 }), 52 new web3._extend.Method({ 53 name: 'cash', 54 call: 'chequebook_cash', 55 params: 1, 56 inputFormatter: [null] 57 }), 58 new web3._extend.Method({ 59 name: 'issue', 60 call: 'chequebook_issue', 61 params: 2, 62 inputFormatter: [null, null] 63 }), 64 ] 65 }); 66 ` 67 68 const Clique_JS = ` 69 web3._extend({ 70 property: 'clique', 71 methods: 72 [ 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 [ 108 new web3._extend.Property({ 109 name: 'proposals', 110 getter: 'clique_proposals' 111 }), 112 ] 113 }); 114 ` 115 116 const Admin_JS = ` 117 web3._extend({ 118 property: 'admin', 119 methods: 120 [ 121 new web3._extend.Method({ 122 name: 'addPeer', 123 call: 'admin_addPeer', 124 params: 1 125 }), 126 new web3._extend.Method({ 127 name: 'removePeer', 128 call: 'admin_removePeer', 129 params: 1 130 }), 131 new web3._extend.Method({ 132 name: 'exportChain', 133 call: 'admin_exportChain', 134 params: 1, 135 inputFormatter: [null] 136 }), 137 new web3._extend.Method({ 138 name: 'importChain', 139 call: 'admin_importChain', 140 params: 1 141 }), 142 new web3._extend.Method({ 143 name: 'sleepBlocks', 144 call: 'admin_sleepBlocks', 145 params: 2 146 }), 147 new web3._extend.Method({ 148 name: 'startRPC', 149 call: 'admin_startRPC', 150 params: 4, 151 inputFormatter: [null, null, null, null] 152 }), 153 new web3._extend.Method({ 154 name: 'stopRPC', 155 call: 'admin_stopRPC' 156 }), 157 new web3._extend.Method({ 158 name: 'startWS', 159 call: 'admin_startWS', 160 params: 4, 161 inputFormatter: [null, null, null, null] 162 }), 163 new web3._extend.Method({ 164 name: 'stopWS', 165 call: 'admin_stopWS' 166 }) 167 ], 168 properties: 169 [ 170 new web3._extend.Property({ 171 name: 'nodeInfo', 172 getter: 'admin_nodeInfo' 173 }), 174 new web3._extend.Property({ 175 name: 'peers', 176 getter: 'admin_peers' 177 }), 178 new web3._extend.Property({ 179 name: 'datadir', 180 getter: 'admin_datadir' 181 }) 182 ] 183 }); 184 ` 185 186 const Debug_JS = ` 187 web3._extend({ 188 property: 'debug', 189 methods: 190 [ 191 new web3._extend.Method({ 192 name: 'printBlock', 193 call: 'debug_printBlock', 194 params: 1 195 }), 196 new web3._extend.Method({ 197 name: 'getBlockRlp', 198 call: 'debug_getBlockRlp', 199 params: 1 200 }), 201 new web3._extend.Method({ 202 name: 'setHead', 203 call: 'debug_setHead', 204 params: 1 205 }), 206 new web3._extend.Method({ 207 name: 'traceBlock', 208 call: 'debug_traceBlock', 209 params: 1 210 }), 211 new web3._extend.Method({ 212 name: 'traceBlockByFile', 213 call: 'debug_traceBlockByFile', 214 params: 1 215 }), 216 new web3._extend.Method({ 217 name: 'traceBlockByNumber', 218 call: 'debug_traceBlockByNumber', 219 params: 1 220 }), 221 new web3._extend.Method({ 222 name: 'traceBlockByHash', 223 call: 'debug_traceBlockByHash', 224 params: 1 225 }), 226 new web3._extend.Method({ 227 name: 'seedHash', 228 call: 'debug_seedHash', 229 params: 1 230 }), 231 new web3._extend.Method({ 232 name: 'dumpBlock', 233 call: 'debug_dumpBlock', 234 params: 1 235 }), 236 new web3._extend.Method({ 237 name: 'chaindbProperty', 238 call: 'debug_chaindbProperty', 239 params: 1, 240 outputFormatter: console.log 241 }), 242 new web3._extend.Method({ 243 name: 'chaindbCompact', 244 call: 'debug_chaindbCompact', 245 }), 246 new web3._extend.Method({ 247 name: 'metrics', 248 call: 'debug_metrics', 249 params: 1 250 }), 251 new web3._extend.Method({ 252 name: 'verbosity', 253 call: 'debug_verbosity', 254 params: 1 255 }), 256 new web3._extend.Method({ 257 name: 'vmodule', 258 call: 'debug_vmodule', 259 params: 1 260 }), 261 new web3._extend.Method({ 262 name: 'backtraceAt', 263 call: 'debug_backtraceAt', 264 params: 1, 265 }), 266 new web3._extend.Method({ 267 name: 'stacks', 268 call: 'debug_stacks', 269 params: 0, 270 outputFormatter: console.log 271 }), 272 new web3._extend.Method({ 273 name: 'memStats', 274 call: 'debug_memStats', 275 params: 0, 276 }), 277 new web3._extend.Method({ 278 name: 'gcStats', 279 call: 'debug_gcStats', 280 params: 0, 281 }), 282 new web3._extend.Method({ 283 name: 'cpuProfile', 284 call: 'debug_cpuProfile', 285 params: 2 286 }), 287 new web3._extend.Method({ 288 name: 'startCPUProfile', 289 call: 'debug_startCPUProfile', 290 params: 1 291 }), 292 new web3._extend.Method({ 293 name: 'stopCPUProfile', 294 call: 'debug_stopCPUProfile', 295 params: 0 296 }), 297 new web3._extend.Method({ 298 name: 'goTrace', 299 call: 'debug_goTrace', 300 params: 2 301 }), 302 new web3._extend.Method({ 303 name: 'startGoTrace', 304 call: 'debug_startGoTrace', 305 params: 1 306 }), 307 new web3._extend.Method({ 308 name: 'stopGoTrace', 309 call: 'debug_stopGoTrace', 310 params: 0 311 }), 312 new web3._extend.Method({ 313 name: 'blockProfile', 314 call: 'debug_blockProfile', 315 params: 2 316 }), 317 new web3._extend.Method({ 318 name: 'setBlockProfileRate', 319 call: 'debug_setBlockProfileRate', 320 params: 1 321 }), 322 new web3._extend.Method({ 323 name: 'writeBlockProfile', 324 call: 'debug_writeBlockProfile', 325 params: 1 326 }), 327 new web3._extend.Method({ 328 name: 'writeMemProfile', 329 call: 'debug_writeMemProfile', 330 params: 1 331 }), 332 new web3._extend.Method({ 333 name: 'traceTransaction', 334 call: 'debug_traceTransaction', 335 params: 2, 336 inputFormatter: [null, null] 337 }), 338 new web3._extend.Method({ 339 name: 'preimage', 340 call: 'debug_preimage', 341 params: 1, 342 inputFormatter: [null] 343 }), 344 new web3._extend.Method({ 345 name: 'getBadBlocks', 346 call: 'debug_getBadBlocks', 347 params: 0, 348 }), 349 new web3._extend.Method({ 350 name: 'storageRangeAt', 351 call: 'debug_storageRangeAt', 352 params: 5, 353 }), 354 ], 355 properties: [] 356 }); 357 ` 358 359 const Eth_JS = ` 360 web3._extend({ 361 property: 'eth', 362 methods: 363 [ 364 new web3._extend.Method({ 365 name: 'sign', 366 call: 'eth_sign', 367 params: 2, 368 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null] 369 }), 370 new web3._extend.Method({ 371 name: 'resend', 372 call: 'eth_resend', 373 params: 3, 374 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal] 375 }), 376 new web3._extend.Method({ 377 name: 'signTransaction', 378 call: 'eth_signTransaction', 379 params: 1, 380 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 381 }), 382 new web3._extend.Method({ 383 name: 'submitTransaction', 384 call: 'eth_submitTransaction', 385 params: 1, 386 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 387 }), 388 new web3._extend.Method({ 389 name: 'getRawTransaction', 390 call: 'eth_getRawTransactionByHash', 391 params: 1 392 }), 393 new web3._extend.Method({ 394 name: 'getRawTransactionFromBlock', 395 call: function(args) { 396 return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex'; 397 }, 398 params: 2, 399 inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] 400 }) 401 ], 402 properties: 403 [ 404 new web3._extend.Property({ 405 name: 'pendingTransactions', 406 getter: 'eth_pendingTransactions', 407 outputFormatter: function(txs) { 408 var formatted = []; 409 for (var i = 0; i < txs.length; i++) { 410 formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i])); 411 formatted[i].blockHash = null; 412 } 413 return formatted; 414 } 415 }) 416 ] 417 }); 418 ` 419 420 const Miner_JS = ` 421 web3._extend({ 422 property: 'miner', 423 methods: 424 [ 425 new web3._extend.Method({ 426 name: 'start', 427 call: 'miner_start', 428 params: 1, 429 inputFormatter: [null] 430 }), 431 new web3._extend.Method({ 432 name: 'stop', 433 call: 'miner_stop' 434 }), 435 new web3._extend.Method({ 436 name: 'setEtherbase', 437 call: 'miner_setEtherbase', 438 params: 1, 439 inputFormatter: [web3._extend.formatters.inputAddressFormatter] 440 }), 441 new web3._extend.Method({ 442 name: 'setExtra', 443 call: 'miner_setExtra', 444 params: 1 445 }), 446 new web3._extend.Method({ 447 name: 'setGasPrice', 448 call: 'miner_setGasPrice', 449 params: 1, 450 inputFormatter: [web3._extend.utils.fromDecimal] 451 }), 452 new web3._extend.Method({ 453 name: 'getHashrate', 454 call: 'miner_getHashrate' 455 }) 456 ], 457 properties: [] 458 }); 459 ` 460 461 const Net_JS = ` 462 web3._extend({ 463 property: 'net', 464 methods: [], 465 properties: 466 [ 467 new web3._extend.Property({ 468 name: 'version', 469 getter: 'net_version' 470 }) 471 ] 472 }); 473 ` 474 475 const Personal_JS = ` 476 web3._extend({ 477 property: 'personal', 478 methods: 479 [ 480 new web3._extend.Method({ 481 name: 'importRawKey', 482 call: 'personal_importRawKey', 483 params: 2 484 }), 485 new web3._extend.Method({ 486 name: 'sign', 487 call: 'personal_sign', 488 params: 3, 489 inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null] 490 }), 491 new web3._extend.Method({ 492 name: 'ecRecover', 493 call: 'personal_ecRecover', 494 params: 2 495 }), 496 new web3._extend.Method({ 497 name: 'signTransaction', 498 call: 'personal_signTransaction', 499 params: 2, 500 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null] 501 }), 502 new web3._extend.Method({ 503 name: 'deriveAccount', 504 call: 'personal_deriveAccount', 505 params: 3 506 }), 507 new web3._extend.Method({ 508 name: 'pubkeyHash', 509 call: 'personal_pubkeyHash', 510 params: 2 511 }) 512 ], 513 properties: 514 [ 515 new web3._extend.Property({ 516 name: 'listWallets', 517 getter: 'personal_listWallets' 518 }) 519 ] 520 }) 521 ` 522 523 const RPC_JS = ` 524 web3._extend({ 525 property: 'rpc', 526 methods: [], 527 properties: 528 [ 529 new web3._extend.Property({ 530 name: 'modules', 531 getter: 'rpc_modules' 532 }) 533 ] 534 }); 535 ` 536 537 const Shh_JS = ` 538 web3._extend({ 539 property: 'shh', 540 methods: [ 541 new web3._extend.Method({ 542 name: 'info', 543 call: 'shh_info' 544 }), 545 new web3._extend.Method({ 546 name: 'setMaxMessageLength', 547 call: 'shh_setMaxMessageLength', 548 params: 1 549 }), 550 new web3._extend.Method({ 551 name: 'setMinimumPoW', 552 call: 'shh_setMinimumPoW', 553 params: 1 554 }), 555 new web3._extend.Method({ 556 name: 'allowP2PMessagesFromPeer', 557 call: 'shh_allowP2PMessagesFromPeer', 558 params: 1 559 }), 560 new web3._extend.Method({ 561 name: 'hasKeyPair', 562 call: 'shh_hasKeyPair', 563 params: 1 564 }), 565 new web3._extend.Method({ 566 name: 'deleteKeyPair', 567 call: 'shh_deleteKeyPair', 568 params: 1 569 }), 570 new web3._extend.Method({ 571 name: 'newKeyPair', 572 call: 'shh_newKeyPair' 573 }), 574 new web3._extend.Method({ 575 name: 'getPublicKey', 576 call: 'shh_getPublicKey', 577 params: 1 578 }), 579 new web3._extend.Method({ 580 name: 'getPrivateKey', 581 call: 'shh_getPrivateKey', 582 params: 1 583 }), 584 new web3._extend.Method({ 585 name: 'generateSymmetricKey', 586 call: 'shh_generateSymmetricKey', 587 }), 588 new web3._extend.Method({ 589 name: 'addSymmetricKeyDirect', 590 call: 'shh_addSymmetricKeyDirect', 591 params: 1 592 }), 593 new web3._extend.Method({ 594 name: 'addSymmetricKeyFromPassword', 595 call: 'shh_addSymmetricKeyFromPassword', 596 params: 1 597 }), 598 new web3._extend.Method({ 599 name: 'hasSymmetricKey', 600 call: 'shh_hasSymmetricKey', 601 params: 1 602 }), 603 new web3._extend.Method({ 604 name: 'getSymmetricKey', 605 call: 'shh_getSymmetricKey', 606 params: 1 607 }), 608 new web3._extend.Method({ 609 name: 'deleteSymmetricKey', 610 call: 'shh_deleteSymmetricKey', 611 params: 1 612 }), 613 new web3._extend.Method({ 614 name: 'subscribe', 615 call: 'shh_subscribe', 616 params: 1 617 }), 618 new web3._extend.Method({ 619 name: 'unsubscribe', 620 call: 'shh_unsubscribe', 621 params: 1 622 }), 623 new web3._extend.Method({ 624 name: 'getNewSubscriptionMessages', 625 call: 'shh_getNewSubscriptionMessages', 626 params: 1 627 }), 628 new web3._extend.Method({ 629 name: 'getFloatingMessages', 630 call: 'shh_getFloatingMessages', 631 params: 1 632 }), 633 new web3._extend.Method({ 634 name: 'post', 635 call: 'shh_post', 636 params: 1 637 }) 638 ], 639 properties: 640 [ 641 new web3._extend.Property({ 642 name: 'version', 643 getter: 'shh_version', 644 outputFormatter: web3._extend.utils.toDecimal 645 }) 646 ] 647 }); 648 ` 649 650 const SWARMFS_JS = ` 651 web3._extend({ 652 property: 'swarmfs', 653 methods: 654 [ 655 new web3._extend.Method({ 656 name: 'mount', 657 call: 'swarmfs_mount', 658 params: 2 659 }), 660 new web3._extend.Method({ 661 name: 'unmount', 662 call: 'swarmfs_unmount', 663 params: 1 664 }), 665 new web3._extend.Method({ 666 name: 'listmounts', 667 call: 'swarmfs_listmounts', 668 params: 0 669 }) 670 ] 671 }); 672 ` 673 674 const TxPool_JS = ` 675 web3._extend({ 676 property: 'txpool', 677 methods: [], 678 properties: 679 [ 680 new web3._extend.Property({ 681 name: 'content', 682 getter: 'txpool_content' 683 }), 684 new web3._extend.Property({ 685 name: 'inspect', 686 getter: 'txpool_inspect' 687 }), 688 new web3._extend.Property({ 689 name: 'status', 690 getter: 'txpool_status', 691 outputFormatter: function(status) { 692 status.pending = web3._extend.utils.toDecimal(status.pending); 693 status.queued = web3._extend.utils.toDecimal(status.queued); 694 return status; 695 } 696 }) 697 ] 698 }); 699 ` 700 701 const Istanbul_JS = ` 702 web3._extend({ 703 property: 'istanbul', 704 methods: 705 [ 706 new web3._extend.Method({ 707 name: 'getSnapshot', 708 call: 'istanbul_getSnapshot', 709 params: 1, 710 inputFormatter: [null] 711 }), 712 new web3._extend.Method({ 713 name: 'getSnapshotAtHash', 714 call: 'istanbul_getSnapshotAtHash', 715 params: 1 716 }), 717 new web3._extend.Method({ 718 name: 'getValidators', 719 call: 'istanbul_getValidators', 720 params: 1, 721 inputFormatter: [null] 722 }), 723 new web3._extend.Method({ 724 name: 'getValidatorsAtHash', 725 call: 'istanbul_getValidatorsAtHash', 726 params: 1 727 }), 728 new web3._extend.Method({ 729 name: 'propose', 730 call: 'istanbul_propose', 731 params: 2 732 }), 733 new web3._extend.Method({ 734 name: 'discard', 735 call: 'istanbul_discard', 736 params: 1 737 }) 738 ], 739 properties: 740 [ 741 new web3._extend.Property({ 742 name: 'candidates', 743 getter: 'istanbul_candidates' 744 }), 745 ] 746 }); 747 ` 748 749 const PoDC_JS = ` 750 web3._extend({ 751 property: 'PoDC', 752 methods: 753 [ 754 new web3._extend.Method({ 755 name: 'getSnapshot', 756 call: 'PoDC_getSnapshot', 757 params: 1, 758 inputFormatter: [null] 759 }), 760 new web3._extend.Method({ 761 name: 'getSnapshotAtHash', 762 call: 'PoDC_getSnapshotAtHash', 763 params: 1 764 }), 765 new web3._extend.Method({ 766 name: 'getValidators', 767 call: 'PoDC_getValidators', 768 params: 1, 769 inputFormatter: [null] 770 }), 771 new web3._extend.Method({ 772 name: 'getValidatorsAtHash', 773 call: 'PoDC_getValidatorsAtHash', 774 params: 1 775 }), 776 new web3._extend.Method({ 777 name: 'propose', 778 call: 'PoDC_propose', 779 params: 2 780 }), 781 new web3._extend.Method({ 782 name: 'discard', 783 call: 'PoDC_discard', 784 params: 1 785 }) 786 ], 787 properties: 788 [ 789 new web3._extend.Property({ 790 name: 'candidates', 791 getter: 'PoDC_candidates' 792 }), 793 ] 794 }); 795 `