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