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