github.com/etherbanking/go-etherbanking@v1.7.1-0.20181009210156-cf649bca5aba/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 gebc 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 } 34 35 const Chequebook_JS = ` 36 web3._extend({ 37 property: 'chequebook', 38 methods: [ 39 new web3._extend.Method({ 40 name: 'deposit', 41 call: 'chequebook_deposit', 42 params: 1, 43 inputFormatter: [null] 44 }), 45 new web3._extend.Property({ 46 name: 'balance', 47 getter: 'chequebook_balance', 48 outputFormatter: web3._extend.utils.toDecimal 49 }), 50 new web3._extend.Method({ 51 name: 'cash', 52 call: 'chequebook_cash', 53 params: 1, 54 inputFormatter: [null] 55 }), 56 new web3._extend.Method({ 57 name: 'issue', 58 call: 'chequebook_issue', 59 params: 2, 60 inputFormatter: [null, null] 61 }), 62 ] 63 }); 64 ` 65 66 const Clique_JS = ` 67 web3._extend({ 68 property: 'clique', 69 methods: [ 70 new web3._extend.Method({ 71 name: 'getSnapshot', 72 call: 'clique_getSnapshot', 73 params: 1, 74 inputFormatter: [null] 75 }), 76 new web3._extend.Method({ 77 name: 'getSnapshotAtHash', 78 call: 'clique_getSnapshotAtHash', 79 params: 1 80 }), 81 new web3._extend.Method({ 82 name: 'getSigners', 83 call: 'clique_getSigners', 84 params: 1, 85 inputFormatter: [null] 86 }), 87 new web3._extend.Method({ 88 name: 'getSignersAtHash', 89 call: 'clique_getSignersAtHash', 90 params: 1 91 }), 92 new web3._extend.Method({ 93 name: 'propose', 94 call: 'clique_propose', 95 params: 2 96 }), 97 new web3._extend.Method({ 98 name: 'discard', 99 call: 'clique_discard', 100 params: 1 101 }), 102 ], 103 properties: [ 104 new web3._extend.Property({ 105 name: 'proposals', 106 getter: 'clique_proposals' 107 }), 108 ] 109 }); 110 ` 111 112 const Admin_JS = ` 113 web3._extend({ 114 property: 'admin', 115 methods: [ 116 new web3._extend.Method({ 117 name: 'addPeer', 118 call: 'admin_addPeer', 119 params: 1 120 }), 121 new web3._extend.Method({ 122 name: 'removePeer', 123 call: 'admin_removePeer', 124 params: 1 125 }), 126 new web3._extend.Method({ 127 name: 'exportChain', 128 call: 'admin_exportChain', 129 params: 1, 130 inputFormatter: [null] 131 }), 132 new web3._extend.Method({ 133 name: 'importChain', 134 call: 'admin_importChain', 135 params: 1 136 }), 137 new web3._extend.Method({ 138 name: 'sleepBlocks', 139 call: 'admin_sleepBlocks', 140 params: 2 141 }), 142 new web3._extend.Method({ 143 name: 'startRPC', 144 call: 'admin_startRPC', 145 params: 4, 146 inputFormatter: [null, null, null, null] 147 }), 148 new web3._extend.Method({ 149 name: 'stopRPC', 150 call: 'admin_stopRPC' 151 }), 152 new web3._extend.Method({ 153 name: 'startWS', 154 call: 'admin_startWS', 155 params: 4, 156 inputFormatter: [null, null, null, null] 157 }), 158 new web3._extend.Method({ 159 name: 'stopWS', 160 call: 'admin_stopWS' 161 }), 162 ], 163 properties: [ 164 new web3._extend.Property({ 165 name: 'nodeInfo', 166 getter: 'admin_nodeInfo' 167 }), 168 new web3._extend.Property({ 169 name: 'peers', 170 getter: 'admin_peers' 171 }), 172 new web3._extend.Property({ 173 name: 'datadir', 174 getter: 'admin_datadir' 175 }), 176 ] 177 }); 178 ` 179 180 const Debug_JS = ` 181 web3._extend({ 182 property: 'debug', 183 methods: [ 184 new web3._extend.Method({ 185 name: 'printBlock', 186 call: 'debug_printBlock', 187 params: 1 188 }), 189 new web3._extend.Method({ 190 name: 'getBlockRlp', 191 call: 'debug_getBlockRlp', 192 params: 1 193 }), 194 new web3._extend.Method({ 195 name: 'setHead', 196 call: 'debug_setHead', 197 params: 1 198 }), 199 new web3._extend.Method({ 200 name: 'traceBlock', 201 call: 'debug_traceBlock', 202 params: 1 203 }), 204 new web3._extend.Method({ 205 name: 'traceBlockFromFile', 206 call: 'debug_traceBlockFromFile', 207 params: 1 208 }), 209 new web3._extend.Method({ 210 name: 'traceBlockByNumber', 211 call: 'debug_traceBlockByNumber', 212 params: 1 213 }), 214 new web3._extend.Method({ 215 name: 'traceBlockByHash', 216 call: 'debug_traceBlockByHash', 217 params: 1 218 }), 219 new web3._extend.Method({ 220 name: 'seedHash', 221 call: 'debug_seedHash', 222 params: 1 223 }), 224 new web3._extend.Method({ 225 name: 'dumpBlock', 226 call: 'debug_dumpBlock', 227 params: 1 228 }), 229 new web3._extend.Method({ 230 name: 'chaindbProperty', 231 call: 'debug_chaindbProperty', 232 params: 1, 233 outputFormatter: console.log 234 }), 235 new web3._extend.Method({ 236 name: 'chaindbCompact', 237 call: 'debug_chaindbCompact', 238 }), 239 new web3._extend.Method({ 240 name: 'metrics', 241 call: 'debug_metrics', 242 params: 1 243 }), 244 new web3._extend.Method({ 245 name: 'verbosity', 246 call: 'debug_verbosity', 247 params: 1 248 }), 249 new web3._extend.Method({ 250 name: 'vmodule', 251 call: 'debug_vmodule', 252 params: 1 253 }), 254 new web3._extend.Method({ 255 name: 'backtraceAt', 256 call: 'debug_backtraceAt', 257 params: 1, 258 }), 259 new web3._extend.Method({ 260 name: 'stacks', 261 call: 'debug_stacks', 262 params: 0, 263 outputFormatter: console.log 264 }), 265 new web3._extend.Method({ 266 name: 'freeOSMemory', 267 call: 'debug_freeOSMemory', 268 params: 0, 269 }), 270 new web3._extend.Method({ 271 name: 'setGCPercent', 272 call: 'debug_setGCPercent', 273 params: 1, 274 }), 275 new web3._extend.Method({ 276 name: 'memStats', 277 call: 'debug_memStats', 278 params: 0, 279 }), 280 new web3._extend.Method({ 281 name: 'gcStats', 282 call: 'debug_gcStats', 283 params: 0, 284 }), 285 new web3._extend.Method({ 286 name: 'cpuProfile', 287 call: 'debug_cpuProfile', 288 params: 2 289 }), 290 new web3._extend.Method({ 291 name: 'startCPUProfile', 292 call: 'debug_startCPUProfile', 293 params: 1 294 }), 295 new web3._extend.Method({ 296 name: 'stopCPUProfile', 297 call: 'debug_stopCPUProfile', 298 params: 0 299 }), 300 new web3._extend.Method({ 301 name: 'goTrace', 302 call: 'debug_goTrace', 303 params: 2 304 }), 305 new web3._extend.Method({ 306 name: 'startGoTrace', 307 call: 'debug_startGoTrace', 308 params: 1 309 }), 310 new web3._extend.Method({ 311 name: 'stopGoTrace', 312 call: 'debug_stopGoTrace', 313 params: 0 314 }), 315 new web3._extend.Method({ 316 name: 'blockProfile', 317 call: 'debug_blockProfile', 318 params: 2 319 }), 320 new web3._extend.Method({ 321 name: 'setBlockProfileRate', 322 call: 'debug_setBlockProfileRate', 323 params: 1 324 }), 325 new web3._extend.Method({ 326 name: 'writeBlockProfile', 327 call: 'debug_writeBlockProfile', 328 params: 1 329 }), 330 new web3._extend.Method({ 331 name: 'writeMemProfile', 332 call: 'debug_writeMemProfile', 333 params: 1 334 }), 335 new web3._extend.Method({ 336 name: 'traceTransaction', 337 call: 'debug_traceTransaction', 338 params: 2, 339 inputFormatter: [null, null] 340 }), 341 new web3._extend.Method({ 342 name: 'preimage', 343 call: 'debug_preimage', 344 params: 1, 345 inputFormatter: [null] 346 }), 347 new web3._extend.Method({ 348 name: 'getBadBlocks', 349 call: 'debug_getBadBlocks', 350 params: 0, 351 }), 352 new web3._extend.Method({ 353 name: 'storageRangeAt', 354 call: 'debug_storageRangeAt', 355 params: 5, 356 }), 357 ], 358 properties: [] 359 }); 360 ` 361 362 const Eth_JS = ` 363 web3._extend({ 364 property: 'eth', 365 methods: [ 366 new web3._extend.Method({ 367 name: 'sign', 368 call: 'eth_sign', 369 params: 2, 370 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null] 371 }), 372 new web3._extend.Method({ 373 name: 'resend', 374 call: 'eth_resend', 375 params: 3, 376 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal] 377 }), 378 new web3._extend.Method({ 379 name: 'signTransaction', 380 call: 'eth_signTransaction', 381 params: 1, 382 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 383 }), 384 new web3._extend.Method({ 385 name: 'submitTransaction', 386 call: 'eth_submitTransaction', 387 params: 1, 388 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 389 }), 390 new web3._extend.Method({ 391 name: 'getRawTransaction', 392 call: 'eth_getRawTransactionByHash', 393 params: 1 394 }), 395 new web3._extend.Method({ 396 name: 'getRawTransactionFromBlock', 397 call: function(args) { 398 return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex'; 399 }, 400 params: 2, 401 inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] 402 }), 403 ], 404 properties: [ 405 new web3._extend.Property({ 406 name: 'pendingTransactions', 407 getter: 'eth_pendingTransactions', 408 outputFormatter: function(txs) { 409 var formatted = []; 410 for (var i = 0; i < txs.length; i++) { 411 formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i])); 412 formatted[i].blockHash = null; 413 } 414 return formatted; 415 } 416 }), 417 ] 418 }); 419 ` 420 421 const Miner_JS = ` 422 web3._extend({ 423 property: 'miner', 424 methods: [ 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 new web3._extend.Property({ 467 name: 'version', 468 getter: 'net_version' 469 }), 470 ] 471 }); 472 ` 473 474 const Personal_JS = ` 475 web3._extend({ 476 property: 'personal', 477 methods: [ 478 new web3._extend.Method({ 479 name: 'importRawKey', 480 call: 'personal_importRawKey', 481 params: 2 482 }), 483 new web3._extend.Method({ 484 name: 'sign', 485 call: 'personal_sign', 486 params: 3, 487 inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null] 488 }), 489 new web3._extend.Method({ 490 name: 'ecRecover', 491 call: 'personal_ecRecover', 492 params: 2 493 }), 494 new web3._extend.Method({ 495 name: 'openWallet', 496 call: 'personal_openWallet', 497 params: 2 498 }), 499 new web3._extend.Method({ 500 name: 'deriveAccount', 501 call: 'personal_deriveAccount', 502 params: 3 503 }), 504 ], 505 properties: [ 506 new web3._extend.Property({ 507 name: 'listWallets', 508 getter: 'personal_listWallets' 509 }), 510 ] 511 }) 512 ` 513 514 const RPC_JS = ` 515 web3._extend({ 516 property: 'rpc', 517 methods: [], 518 properties: [ 519 new web3._extend.Property({ 520 name: 'modules', 521 getter: 'rpc_modules' 522 }), 523 ] 524 }); 525 ` 526 527 const Shh_JS = ` 528 web3._extend({ 529 property: 'shh', 530 methods: [ 531 new web3._extend.Method({ 532 name: 'setMaxMessageLength', 533 call: 'shh_setMaxMessageLength', 534 params: 1 535 }), 536 new web3._extend.Method({ 537 name: 'setMinimumPoW', 538 call: 'shh_setMinimumPoW', 539 params: 1 540 }), 541 new web3._extend.Method({ 542 name: 'markTrustedPeer', 543 call: 'shh_markTrustedPeer', 544 params: 1 545 }), 546 new web3._extend.Method({ 547 name: 'hasKeyPair', 548 call: 'shh_hasKeyPair', 549 params: 1 550 }), 551 new web3._extend.Method({ 552 name: 'deleteKeyPair', 553 call: 'shh_deleteKeyPair', 554 params: 1 555 }), 556 new web3._extend.Method({ 557 name: 'newKeyPair', 558 call: 'shh_newKeyPair' 559 }), 560 new web3._extend.Method({ 561 name: 'getPublicKey', 562 call: 'shh_getPublicKey', 563 params: 1 564 }), 565 new web3._extend.Method({ 566 name: 'getPrivateKey', 567 call: 'shh_getPrivateKey', 568 params: 1 569 }), 570 new web3._extend.Method({ 571 name: 'newSymKey', 572 call: 'shh_newSymKey', 573 }), 574 new web3._extend.Method({ 575 name: 'addSymKey', 576 call: 'shh_addSymKey', 577 params: 1 578 }), 579 new web3._extend.Method({ 580 name: 'generateSymKeyFromPassword', 581 call: 'shh_generateSymKeyFromPassword', 582 params: 1 583 }), 584 new web3._extend.Method({ 585 name: 'hasSymKey', 586 call: 'shh_hasSymKey', 587 params: 1 588 }), 589 new web3._extend.Method({ 590 name: 'getSymKey', 591 call: 'shh_getSymKey', 592 params: 1 593 }), 594 new web3._extend.Method({ 595 name: 'deleteSymKey', 596 call: 'shh_deleteSymKey', 597 params: 1 598 }), 599 new web3._extend.Method({ 600 name: 'subscribe', 601 call: 'shh_subscribe', 602 params: 2 603 }), 604 new web3._extend.Method({ 605 name: 'unsubscribe', 606 call: 'shh_unsubscribe', 607 params: 1 608 }), 609 new web3._extend.Method({ 610 name: 'post', 611 call: 'shh_post', 612 params: 1 613 }), 614 new web3._extend.Method({ 615 name: 'publicKey', 616 call: 'shh_getPublicKey', 617 params: 1 618 }), 619 new web3._extend.Method({ 620 name: 'getFilterMessages', 621 call: 'shh_getFilterMessages', 622 params: 1 623 }), 624 new web3._extend.Method({ 625 name: 'deleteMessageFilter', 626 call: 'shh_deleteMessageFilter', 627 params: 1 628 }), 629 new web3._extend.Method({ 630 name: 'newMessageFilter', 631 call: 'shh_newMessageFilter', 632 params: 1 633 }), 634 ], 635 properties: 636 [ 637 new web3._extend.Property({ 638 name: 'version', 639 getter: 'shh_version', 640 outputFormatter: web3._extend.utils.toDecimal 641 }), 642 new web3._extend.Property({ 643 name: 'info', 644 getter: 'shh_info' 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 `