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