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