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