github.com/zjj1991/quorum@v0.0.0-20190524123704-ae4b0a1e1a19/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 "ethash": Ethash_JS, 25 "debug": Debug_JS, 26 "eth": Eth_JS, 27 "miner": Miner_JS, 28 "net": Net_JS, 29 "personal": Personal_JS, 30 "rpc": RPC_JS, 31 "shh": Shh_JS, 32 "swarmfs": SWARMFS_JS, 33 "txpool": TxPool_JS, 34 "raft": Raft_JS, 35 "istanbul": Istanbul_JS, 36 } 37 38 const Chequebook_JS = ` 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 Clique_JS = ` 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 Ethash_JS = ` 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 Admin_JS = ` 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 Debug_JS = ` 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: 'setHead', 237 call: 'debug_setHead', 238 params: 1 239 }), 240 new web3._extend.Method({ 241 name: 'seedHash', 242 call: 'debug_seedHash', 243 params: 1 244 }), 245 new web3._extend.Method({ 246 name: 'dumpBlock', 247 call: 'debug_dumpBlock', 248 params: 1 249 }), 250 new web3._extend.Method({ 251 name: 'chaindbProperty', 252 call: 'debug_chaindbProperty', 253 params: 1, 254 outputFormatter: console.log 255 }), 256 new web3._extend.Method({ 257 name: 'chaindbCompact', 258 call: 'debug_chaindbCompact', 259 }), 260 new web3._extend.Method({ 261 name: 'metrics', 262 call: 'debug_metrics', 263 params: 1 264 }), 265 new web3._extend.Method({ 266 name: 'verbosity', 267 call: 'debug_verbosity', 268 params: 1 269 }), 270 new web3._extend.Method({ 271 name: 'vmodule', 272 call: 'debug_vmodule', 273 params: 1 274 }), 275 new web3._extend.Method({ 276 name: 'backtraceAt', 277 call: 'debug_backtraceAt', 278 params: 1, 279 }), 280 new web3._extend.Method({ 281 name: 'stacks', 282 call: 'debug_stacks', 283 params: 0, 284 outputFormatter: console.log 285 }), 286 new web3._extend.Method({ 287 name: 'freeOSMemory', 288 call: 'debug_freeOSMemory', 289 params: 0, 290 }), 291 new web3._extend.Method({ 292 name: 'setGCPercent', 293 call: 'debug_setGCPercent', 294 params: 1, 295 }), 296 new web3._extend.Method({ 297 name: 'memStats', 298 call: 'debug_memStats', 299 params: 0, 300 }), 301 new web3._extend.Method({ 302 name: 'gcStats', 303 call: 'debug_gcStats', 304 params: 0, 305 }), 306 new web3._extend.Method({ 307 name: 'cpuProfile', 308 call: 'debug_cpuProfile', 309 params: 2 310 }), 311 new web3._extend.Method({ 312 name: 'startCPUProfile', 313 call: 'debug_startCPUProfile', 314 params: 1 315 }), 316 new web3._extend.Method({ 317 name: 'stopCPUProfile', 318 call: 'debug_stopCPUProfile', 319 params: 0 320 }), 321 new web3._extend.Method({ 322 name: 'goTrace', 323 call: 'debug_goTrace', 324 params: 2 325 }), 326 new web3._extend.Method({ 327 name: 'startGoTrace', 328 call: 'debug_startGoTrace', 329 params: 1 330 }), 331 new web3._extend.Method({ 332 name: 'stopGoTrace', 333 call: 'debug_stopGoTrace', 334 params: 0 335 }), 336 new web3._extend.Method({ 337 name: 'blockProfile', 338 call: 'debug_blockProfile', 339 params: 2 340 }), 341 new web3._extend.Method({ 342 name: 'setBlockProfileRate', 343 call: 'debug_setBlockProfileRate', 344 params: 1 345 }), 346 new web3._extend.Method({ 347 name: 'writeBlockProfile', 348 call: 'debug_writeBlockProfile', 349 params: 1 350 }), 351 new web3._extend.Method({ 352 name: 'mutexProfile', 353 call: 'debug_mutexProfile', 354 params: 2 355 }), 356 new web3._extend.Method({ 357 name: 'setMutexProfileFraction', 358 call: 'debug_setMutexProfileFraction', 359 params: 1 360 }), 361 new web3._extend.Method({ 362 name: 'writeMutexProfile', 363 call: 'debug_writeMutexProfile', 364 params: 1 365 }), 366 new web3._extend.Method({ 367 name: 'writeMemProfile', 368 call: 'debug_writeMemProfile', 369 params: 1 370 }), 371 new web3._extend.Method({ 372 name: 'traceBlock', 373 call: 'debug_traceBlock', 374 params: 2, 375 inputFormatter: [null, null] 376 }), 377 new web3._extend.Method({ 378 name: 'traceBlockFromFile', 379 call: 'debug_traceBlockFromFile', 380 params: 2, 381 inputFormatter: [null, null] 382 }), 383 new web3._extend.Method({ 384 name: 'traceBadBlock', 385 call: 'debug_traceBadBlock', 386 params: 1, 387 inputFormatter: [null] 388 }), 389 new web3._extend.Method({ 390 name: 'traceBlockByNumber', 391 call: 'debug_traceBlockByNumber', 392 params: 2, 393 inputFormatter: [null, null] 394 }), 395 new web3._extend.Method({ 396 name: 'traceBlockByHash', 397 call: 'debug_traceBlockByHash', 398 params: 2, 399 inputFormatter: [null, null] 400 }), 401 new web3._extend.Method({ 402 name: 'traceTransaction', 403 call: 'debug_traceTransaction', 404 params: 2, 405 inputFormatter: [null, null] 406 }), 407 new web3._extend.Method({ 408 name: 'preimage', 409 call: 'debug_preimage', 410 params: 1, 411 inputFormatter: [null] 412 }), 413 new web3._extend.Method({ 414 name: 'getBadBlocks', 415 call: 'debug_getBadBlocks', 416 params: 0, 417 }), 418 new web3._extend.Method({ 419 name: 'storageRangeAt', 420 call: 'debug_storageRangeAt', 421 params: 5, 422 }), 423 new web3._extend.Method({ 424 name: 'getModifiedAccountsByNumber', 425 call: 'debug_getModifiedAccountsByNumber', 426 params: 2, 427 inputFormatter: [null, null], 428 }), 429 new web3._extend.Method({ 430 name: 'getModifiedAccountsByHash', 431 call: 'debug_getModifiedAccountsByHash', 432 params: 2, 433 inputFormatter:[null, null], 434 }), 435 ], 436 properties: [] 437 }); 438 ` 439 440 const Eth_JS = ` 441 web3._extend({ 442 property: 'eth', 443 methods: [ 444 new web3._extend.Method({ 445 name: 'sendRawPrivateTransaction', 446 call: 'eth_sendRawPrivateTransaction', 447 params: 2, 448 inputFormatter: [null, null] 449 }), 450 new web3._extend.Method({ 451 name: 'chainId', 452 call: 'eth_chainId', 453 params: 0 454 }), 455 new web3._extend.Method({ 456 name: 'sign', 457 call: 'eth_sign', 458 params: 2, 459 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null] 460 }), 461 new web3._extend.Method({ 462 name: 'resend', 463 call: 'eth_resend', 464 params: 3, 465 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal] 466 }), 467 new web3._extend.Method({ 468 name: 'signTransaction', 469 call: 'eth_signTransaction', 470 params: 1, 471 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 472 }), 473 new web3._extend.Method({ 474 name: 'submitTransaction', 475 call: 'eth_submitTransaction', 476 params: 1, 477 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 478 }), 479 new web3._extend.Method({ 480 name: 'getRawTransaction', 481 call: 'eth_getRawTransactionByHash', 482 params: 1 483 }), 484 new web3._extend.Method({ 485 name: 'getRawTransactionFromBlock', 486 call: function(args) { 487 return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex'; 488 }, 489 params: 2, 490 inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] 491 }), 492 new web3._extend.Method({ 493 name: 'getProof', 494 call: 'eth_getProof', 495 params: 3, 496 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null, web3._extend.formatters.inputBlockNumberFormatter] 497 }), 498 new web3._extend.Method({ 499 name: 'storageRoot', 500 call: 'eth_storageRoot', 501 params: 2, 502 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null] 503 }) 504 ], 505 properties: [ 506 new web3._extend.Property({ 507 name: 'pendingTransactions', 508 getter: 'eth_pendingTransactions', 509 outputFormatter: function(txs) { 510 var formatted = []; 511 for (var i = 0; i < txs.length; i++) { 512 formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i])); 513 formatted[i].blockHash = null; 514 } 515 return formatted; 516 } 517 }), 518 ] 519 }); 520 ` 521 522 const Miner_JS = ` 523 web3._extend({ 524 property: 'miner', 525 methods: [ 526 new web3._extend.Method({ 527 name: 'start', 528 call: 'miner_start', 529 params: 1, 530 inputFormatter: [null] 531 }), 532 new web3._extend.Method({ 533 name: 'stop', 534 call: 'miner_stop' 535 }), 536 new web3._extend.Method({ 537 name: 'setEtherbase', 538 call: 'miner_setEtherbase', 539 params: 1, 540 inputFormatter: [web3._extend.formatters.inputAddressFormatter] 541 }), 542 new web3._extend.Method({ 543 name: 'setExtra', 544 call: 'miner_setExtra', 545 params: 1 546 }), 547 new web3._extend.Method({ 548 name: 'setGasPrice', 549 call: 'miner_setGasPrice', 550 params: 1, 551 inputFormatter: [web3._extend.utils.fromDecimal] 552 }), 553 new web3._extend.Method({ 554 name: 'setRecommitInterval', 555 call: 'miner_setRecommitInterval', 556 params: 1, 557 }), 558 new web3._extend.Method({ 559 name: 'getHashrate', 560 call: 'miner_getHashrate' 561 }), 562 ], 563 properties: [] 564 }); 565 ` 566 567 const Net_JS = ` 568 web3._extend({ 569 property: 'net', 570 methods: [], 571 properties: [ 572 new web3._extend.Property({ 573 name: 'version', 574 getter: 'net_version' 575 }), 576 ] 577 }); 578 ` 579 580 const Personal_JS = ` 581 web3._extend({ 582 property: 'personal', 583 methods: [ 584 new web3._extend.Method({ 585 name: 'importRawKey', 586 call: 'personal_importRawKey', 587 params: 2 588 }), 589 new web3._extend.Method({ 590 name: 'sign', 591 call: 'personal_sign', 592 params: 3, 593 inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null] 594 }), 595 new web3._extend.Method({ 596 name: 'ecRecover', 597 call: 'personal_ecRecover', 598 params: 2 599 }), 600 new web3._extend.Method({ 601 name: 'openWallet', 602 call: 'personal_openWallet', 603 params: 2 604 }), 605 new web3._extend.Method({ 606 name: 'deriveAccount', 607 call: 'personal_deriveAccount', 608 params: 3 609 }), 610 new web3._extend.Method({ 611 name: 'signTransaction', 612 call: 'personal_signTransaction', 613 params: 2, 614 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null] 615 }), 616 ], 617 properties: [ 618 new web3._extend.Property({ 619 name: 'listWallets', 620 getter: 'personal_listWallets' 621 }), 622 ] 623 }) 624 ` 625 626 const RPC_JS = ` 627 web3._extend({ 628 property: 'rpc', 629 methods: [], 630 properties: [ 631 new web3._extend.Property({ 632 name: 'modules', 633 getter: 'rpc_modules' 634 }), 635 ] 636 }); 637 ` 638 639 const Shh_JS = ` 640 web3._extend({ 641 property: 'shh', 642 methods: [ 643 ], 644 properties: 645 [ 646 new web3._extend.Property({ 647 name: 'version', 648 getter: 'shh_version', 649 outputFormatter: web3._extend.utils.toDecimal 650 }), 651 new web3._extend.Property({ 652 name: 'info', 653 getter: 'shh_info' 654 }), 655 ] 656 }); 657 ` 658 659 const SWARMFS_JS = ` 660 web3._extend({ 661 property: 'swarmfs', 662 methods: 663 [ 664 new web3._extend.Method({ 665 name: 'mount', 666 call: 'swarmfs_mount', 667 params: 2 668 }), 669 new web3._extend.Method({ 670 name: 'unmount', 671 call: 'swarmfs_unmount', 672 params: 1 673 }), 674 new web3._extend.Method({ 675 name: 'listmounts', 676 call: 'swarmfs_listmounts', 677 params: 0 678 }), 679 ] 680 }); 681 ` 682 683 const TxPool_JS = ` 684 web3._extend({ 685 property: 'txpool', 686 methods: [], 687 properties: 688 [ 689 new web3._extend.Property({ 690 name: 'content', 691 getter: 'txpool_content' 692 }), 693 new web3._extend.Property({ 694 name: 'inspect', 695 getter: 'txpool_inspect' 696 }), 697 new web3._extend.Property({ 698 name: 'status', 699 getter: 'txpool_status', 700 outputFormatter: function(status) { 701 status.pending = web3._extend.utils.toDecimal(status.pending); 702 status.queued = web3._extend.utils.toDecimal(status.queued); 703 return status; 704 } 705 }), 706 ] 707 }); 708 ` 709 710 const Raft_JS = ` 711 web3._extend({ 712 property: 'raft', 713 methods: 714 [ 715 ], 716 properties: 717 [ 718 new web3._extend.Property({ 719 name: 'role', 720 getter: 'raft_role' 721 }), 722 new web3._extend.Method({ 723 name: 'addPeer', 724 call: 'raft_addPeer', 725 params: 1 726 }), 727 new web3._extend.Method({ 728 name: 'removePeer', 729 call: 'raft_removePeer', 730 params: 1 731 }), 732 new web3._extend.Property({ 733 name: 'leader', 734 getter: 'raft_leader' 735 }), 736 new web3._extend.Property({ 737 name: 'cluster', 738 getter: 'raft_cluster' 739 }), 740 ] 741 }) 742 ` 743 744 const Istanbul_JS = ` 745 web3._extend({ 746 property: 'istanbul', 747 methods: 748 [ 749 new web3._extend.Method({ 750 name: 'getSnapshot', 751 call: 'istanbul_getSnapshot', 752 params: 1, 753 inputFormatter: [null] 754 }), 755 new web3._extend.Method({ 756 name: 'getSnapshotAtHash', 757 call: 'istanbul_getSnapshotAtHash', 758 params: 1 759 }), 760 new web3._extend.Method({ 761 name: 'getValidators', 762 call: 'istanbul_getValidators', 763 params: 1, 764 inputFormatter: [null] 765 }), 766 new web3._extend.Method({ 767 name: 'getValidatorsAtHash', 768 call: 'istanbul_getValidatorsAtHash', 769 params: 1 770 }), 771 new web3._extend.Method({ 772 name: 'propose', 773 call: 'istanbul_propose', 774 params: 2 775 }), 776 new web3._extend.Method({ 777 name: 'discard', 778 call: 'istanbul_discard', 779 params: 1 780 }) 781 ], 782 properties: 783 [ 784 new web3._extend.Property({ 785 name: 'candidates', 786 getter: 'istanbul_candidates' 787 }), 788 ] 789 }); 790 `