github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/internal/web3ext/web3ext.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 // package web3ext contains geth specific web3.js extensions. 13 package web3ext 14 15 var Modules = map[string]string{ 16 "admin": Admin_JS, 17 "chequebook": Chequebook_JS, 18 "clique": Clique_JS, 19 "debug": Debug_JS, 20 "eth": Eth_JS, 21 "miner": Miner_JS, 22 "net": Net_JS, 23 "personal": Personal_JS, 24 "rpc": RPC_JS, 25 "shh": Shh_JS, 26 "swarmfs": SWARMFS_JS, 27 "txpool": TxPool_JS, 28 } 29 30 const Chequebook_JS = ` 31 web3._extend({ 32 property: 'chequebook', 33 methods: [ 34 new web3._extend.Method({ 35 name: 'deposit', 36 call: 'chequebook_deposit', 37 params: 1, 38 inputFormatter: [null] 39 }), 40 new web3._extend.Property({ 41 name: 'balance', 42 getter: 'chequebook_balance', 43 outputFormatter: web3._extend.utils.toDecimal 44 }), 45 new web3._extend.Method({ 46 name: 'cash', 47 call: 'chequebook_cash', 48 params: 1, 49 inputFormatter: [null] 50 }), 51 new web3._extend.Method({ 52 name: 'issue', 53 call: 'chequebook_issue', 54 params: 2, 55 inputFormatter: [null, null] 56 }), 57 ] 58 }); 59 ` 60 61 const Clique_JS = ` 62 web3._extend({ 63 property: 'clique', 64 methods: [ 65 new web3._extend.Method({ 66 name: 'getSnapshot', 67 call: 'clique_getSnapshot', 68 params: 1, 69 inputFormatter: [null] 70 }), 71 new web3._extend.Method({ 72 name: 'getSnapshotAtHash', 73 call: 'clique_getSnapshotAtHash', 74 params: 1 75 }), 76 new web3._extend.Method({ 77 name: 'getSigners', 78 call: 'clique_getSigners', 79 params: 1, 80 inputFormatter: [null] 81 }), 82 new web3._extend.Method({ 83 name: 'getSignersAtHash', 84 call: 'clique_getSignersAtHash', 85 params: 1 86 }), 87 new web3._extend.Method({ 88 name: 'propose', 89 call: 'clique_propose', 90 params: 2 91 }), 92 new web3._extend.Method({ 93 name: 'discard', 94 call: 'clique_discard', 95 params: 1 96 }), 97 ], 98 properties: [ 99 new web3._extend.Property({ 100 name: 'proposals', 101 getter: 'clique_proposals' 102 }), 103 ] 104 }); 105 ` 106 107 const Admin_JS = ` 108 web3._extend({ 109 property: 'admin', 110 methods: [ 111 new web3._extend.Method({ 112 name: 'addPeer', 113 call: 'admin_addPeer', 114 params: 1 115 }), 116 new web3._extend.Method({ 117 name: 'removePeer', 118 call: 'admin_removePeer', 119 params: 1 120 }), 121 new web3._extend.Method({ 122 name: 'exportChain', 123 call: 'admin_exportChain', 124 params: 1, 125 inputFormatter: [null] 126 }), 127 new web3._extend.Method({ 128 name: 'importChain', 129 call: 'admin_importChain', 130 params: 1 131 }), 132 new web3._extend.Method({ 133 name: 'sleepBlocks', 134 call: 'admin_sleepBlocks', 135 params: 2 136 }), 137 new web3._extend.Method({ 138 name: 'startRPC', 139 call: 'admin_startRPC', 140 params: 4, 141 inputFormatter: [null, null, null, null] 142 }), 143 new web3._extend.Method({ 144 name: 'stopRPC', 145 call: 'admin_stopRPC' 146 }), 147 new web3._extend.Method({ 148 name: 'startWS', 149 call: 'admin_startWS', 150 params: 4, 151 inputFormatter: [null, null, null, null] 152 }), 153 new web3._extend.Method({ 154 name: 'stopWS', 155 call: 'admin_stopWS' 156 }), 157 ], 158 properties: [ 159 new web3._extend.Property({ 160 name: 'nodeInfo', 161 getter: 'admin_nodeInfo' 162 }), 163 new web3._extend.Property({ 164 name: 'peers', 165 getter: 'admin_peers' 166 }), 167 new web3._extend.Property({ 168 name: 'datadir', 169 getter: 'admin_datadir' 170 }), 171 ] 172 }); 173 ` 174 175 const Debug_JS = ` 176 web3._extend({ 177 property: 'debug', 178 methods: [ 179 new web3._extend.Method({ 180 name: 'printBlock', 181 call: 'debug_printBlock', 182 params: 1 183 }), 184 new web3._extend.Method({ 185 name: 'getBlockRlp', 186 call: 'debug_getBlockRlp', 187 params: 1 188 }), 189 new web3._extend.Method({ 190 name: 'setHead', 191 call: 'debug_setHead', 192 params: 1 193 }), 194 new web3._extend.Method({ 195 name: 'seedHash', 196 call: 'debug_seedHash', 197 params: 1 198 }), 199 new web3._extend.Method({ 200 name: 'dumpBlock', 201 call: 'debug_dumpBlock', 202 params: 1 203 }), 204 new web3._extend.Method({ 205 name: 'chaindbProperty', 206 call: 'debug_chaindbProperty', 207 params: 1, 208 outputFormatter: console.log 209 }), 210 new web3._extend.Method({ 211 name: 'chaindbCompact', 212 call: 'debug_chaindbCompact', 213 }), 214 new web3._extend.Method({ 215 name: 'metrics', 216 call: 'debug_metrics', 217 params: 1 218 }), 219 new web3._extend.Method({ 220 name: 'verbosity', 221 call: 'debug_verbosity', 222 params: 1 223 }), 224 new web3._extend.Method({ 225 name: 'vmodule', 226 call: 'debug_vmodule', 227 params: 1 228 }), 229 new web3._extend.Method({ 230 name: 'backtraceAt', 231 call: 'debug_backtraceAt', 232 params: 1, 233 }), 234 new web3._extend.Method({ 235 name: 'stacks', 236 call: 'debug_stacks', 237 params: 0, 238 outputFormatter: console.log 239 }), 240 new web3._extend.Method({ 241 name: 'freeOSMemory', 242 call: 'debug_freeOSMemory', 243 params: 0, 244 }), 245 new web3._extend.Method({ 246 name: 'setGCPercent', 247 call: 'debug_setGCPercent', 248 params: 1, 249 }), 250 new web3._extend.Method({ 251 name: 'memStats', 252 call: 'debug_memStats', 253 params: 0, 254 }), 255 new web3._extend.Method({ 256 name: 'gcStats', 257 call: 'debug_gcStats', 258 params: 0, 259 }), 260 new web3._extend.Method({ 261 name: 'cpuProfile', 262 call: 'debug_cpuProfile', 263 params: 2 264 }), 265 new web3._extend.Method({ 266 name: 'startCPUProfile', 267 call: 'debug_startCPUProfile', 268 params: 1 269 }), 270 new web3._extend.Method({ 271 name: 'stopCPUProfile', 272 call: 'debug_stopCPUProfile', 273 params: 0 274 }), 275 new web3._extend.Method({ 276 name: 'goTrace', 277 call: 'debug_goTrace', 278 params: 2 279 }), 280 new web3._extend.Method({ 281 name: 'startGoTrace', 282 call: 'debug_startGoTrace', 283 params: 1 284 }), 285 new web3._extend.Method({ 286 name: 'stopGoTrace', 287 call: 'debug_stopGoTrace', 288 params: 0 289 }), 290 new web3._extend.Method({ 291 name: 'blockProfile', 292 call: 'debug_blockProfile', 293 params: 2 294 }), 295 new web3._extend.Method({ 296 name: 'setBlockProfileRate', 297 call: 'debug_setBlockProfileRate', 298 params: 1 299 }), 300 new web3._extend.Method({ 301 name: 'writeBlockProfile', 302 call: 'debug_writeBlockProfile', 303 params: 1 304 }), 305 new web3._extend.Method({ 306 name: 'writeMemProfile', 307 call: 'debug_writeMemProfile', 308 params: 1 309 }), 310 new web3._extend.Method({ 311 name: 'traceBlock', 312 call: 'debug_traceBlock', 313 params: 2, 314 inputFormatter: [null, null] 315 }), 316 new web3._extend.Method({ 317 name: 'traceBlockFromFile', 318 call: 'debug_traceBlockFromFile', 319 params: 2, 320 inputFormatter: [null, null] 321 }), 322 new web3._extend.Method({ 323 name: 'traceBlockByNumber', 324 call: 'debug_traceBlockByNumber', 325 params: 2, 326 inputFormatter: [null, null] 327 }), 328 new web3._extend.Method({ 329 name: 'traceBlockByHash', 330 call: 'debug_traceBlockByHash', 331 params: 2, 332 inputFormatter: [null, null] 333 }), 334 new web3._extend.Method({ 335 name: 'traceTransaction', 336 call: 'debug_traceTransaction', 337 params: 2, 338 inputFormatter: [null, null] 339 }), 340 new web3._extend.Method({ 341 name: 'preimage', 342 call: 'debug_preimage', 343 params: 1, 344 inputFormatter: [null] 345 }), 346 new web3._extend.Method({ 347 name: 'getBadBlocks', 348 call: 'debug_getBadBlocks', 349 params: 0, 350 }), 351 new web3._extend.Method({ 352 name: 'storageRangeAt', 353 call: 'debug_storageRangeAt', 354 params: 5, 355 }), 356 new web3._extend.Method({ 357 name: 'getModifiedAccountsByNumber', 358 call: 'debug_getModifiedAccountsByNumber', 359 params: 2, 360 inputFormatter: [null, null], 361 }), 362 new web3._extend.Method({ 363 name: 'getModifiedAccountsByHash', 364 call: 'debug_getModifiedAccountsByHash', 365 params: 2, 366 inputFormatter:[null, null], 367 }), 368 ], 369 properties: [] 370 }); 371 ` 372 373 const Eth_JS = ` 374 web3._extend({ 375 property: 'eth', 376 methods: [ 377 new web3._extend.Method({ 378 name: 'sign', 379 call: 'eth_sign', 380 params: 2, 381 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null] 382 }), 383 new web3._extend.Method({ 384 name: 'resend', 385 call: 'eth_resend', 386 params: 3, 387 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal] 388 }), 389 new web3._extend.Method({ 390 name: 'signTransaction', 391 call: 'eth_signTransaction', 392 params: 1, 393 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 394 }), 395 new web3._extend.Method({ 396 name: 'submitTransaction', 397 call: 'eth_submitTransaction', 398 params: 1, 399 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 400 }), 401 new web3._extend.Method({ 402 name: 'getRawTransaction', 403 call: 'eth_getRawTransactionByHash', 404 params: 1 405 }), 406 new web3._extend.Method({ 407 name: 'getRawTransactionFromBlock', 408 call: function(args) { 409 return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex'; 410 }, 411 params: 2, 412 inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] 413 }), 414 ], 415 properties: [ 416 new web3._extend.Property({ 417 name: 'pendingTransactions', 418 getter: 'eth_pendingTransactions', 419 outputFormatter: function(txs) { 420 var formatted = []; 421 for (var i = 0; i < txs.length; i++) { 422 formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i])); 423 formatted[i].blockHash = null; 424 } 425 return formatted; 426 } 427 }), 428 ] 429 }); 430 ` 431 432 const Miner_JS = ` 433 web3._extend({ 434 property: 'miner', 435 methods: [ 436 new web3._extend.Method({ 437 name: 'start', 438 call: 'miner_start', 439 params: 1, 440 inputFormatter: [null] 441 }), 442 new web3._extend.Method({ 443 name: 'stop', 444 call: 'miner_stop' 445 }), 446 new web3._extend.Method({ 447 name: 'setEtherbase', 448 call: 'miner_setEtherbase', 449 params: 1, 450 inputFormatter: [web3._extend.formatters.inputAddressFormatter] 451 }), 452 new web3._extend.Method({ 453 name: 'setExtra', 454 call: 'miner_setExtra', 455 params: 1 456 }), 457 new web3._extend.Method({ 458 name: 'setGasPrice', 459 call: 'miner_setGasPrice', 460 params: 1, 461 inputFormatter: [web3._extend.utils.fromDecimal] 462 }), 463 new web3._extend.Method({ 464 name: 'getHashrate', 465 call: 'miner_getHashrate' 466 }), 467 ], 468 properties: [] 469 }); 470 ` 471 472 const Net_JS = ` 473 web3._extend({ 474 property: 'net', 475 methods: [], 476 properties: [ 477 new web3._extend.Property({ 478 name: 'version', 479 getter: 'net_version' 480 }), 481 ] 482 }); 483 ` 484 485 const Personal_JS = ` 486 web3._extend({ 487 property: 'personal', 488 methods: [ 489 new web3._extend.Method({ 490 name: 'importRawKey', 491 call: 'personal_importRawKey', 492 params: 2 493 }), 494 new web3._extend.Method({ 495 name: 'sign', 496 call: 'personal_sign', 497 params: 3, 498 inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null] 499 }), 500 new web3._extend.Method({ 501 name: 'ecRecover', 502 call: 'personal_ecRecover', 503 params: 2 504 }), 505 new web3._extend.Method({ 506 name: 'openWallet', 507 call: 'personal_openWallet', 508 params: 2 509 }), 510 new web3._extend.Method({ 511 name: 'deriveAccount', 512 call: 'personal_deriveAccount', 513 params: 3 514 }), 515 new web3._extend.Method({ 516 name: 'signTransaction', 517 call: 'personal_signTransaction', 518 params: 2, 519 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null] 520 }), 521 ], 522 properties: [ 523 new web3._extend.Property({ 524 name: 'listWallets', 525 getter: 'personal_listWallets' 526 }), 527 ] 528 }) 529 ` 530 531 const RPC_JS = ` 532 web3._extend({ 533 property: 'rpc', 534 methods: [], 535 properties: [ 536 new web3._extend.Property({ 537 name: 'modules', 538 getter: 'rpc_modules' 539 }), 540 ] 541 }); 542 ` 543 544 const Shh_JS = ` 545 web3._extend({ 546 property: 'shh', 547 methods: [ 548 ], 549 properties: 550 [ 551 new web3._extend.Property({ 552 name: 'version', 553 getter: 'shh_version', 554 outputFormatter: web3._extend.utils.toDecimal 555 }), 556 new web3._extend.Property({ 557 name: 'info', 558 getter: 'shh_info' 559 }), 560 ] 561 }); 562 ` 563 564 const SWARMFS_JS = ` 565 web3._extend({ 566 property: 'swarmfs', 567 methods: 568 [ 569 new web3._extend.Method({ 570 name: 'mount', 571 call: 'swarmfs_mount', 572 params: 2 573 }), 574 new web3._extend.Method({ 575 name: 'unmount', 576 call: 'swarmfs_unmount', 577 params: 1 578 }), 579 new web3._extend.Method({ 580 name: 'listmounts', 581 call: 'swarmfs_listmounts', 582 params: 0 583 }), 584 ] 585 }); 586 ` 587 588 const TxPool_JS = ` 589 web3._extend({ 590 property: 'txpool', 591 methods: [], 592 properties: 593 [ 594 new web3._extend.Property({ 595 name: 'content', 596 getter: 'txpool_content' 597 }), 598 new web3._extend.Property({ 599 name: 'inspect', 600 getter: 'txpool_inspect' 601 }), 602 new web3._extend.Property({ 603 name: 'status', 604 getter: 'txpool_status', 605 outputFormatter: function(status) { 606 status.pending = web3._extend.utils.toDecimal(status.pending); 607 status.queued = web3._extend.utils.toDecimal(status.queued); 608 return status; 609 } 610 }), 611 ] 612 }); 613 `