github.com/puppeth/go-ethereum@v0.8.6-0.20171014130046-e9295163aa25/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 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 ], 532 properties: 533 [ 534 new web3._extend.Property({ 535 name: 'version', 536 getter: 'shh_version', 537 outputFormatter: web3._extend.utils.toDecimal 538 }), 539 new web3._extend.Property({ 540 name: 'info', 541 getter: 'shh_info' 542 }), 543 ] 544 }); 545 ` 546 547 const SWARMFS_JS = ` 548 web3._extend({ 549 property: 'swarmfs', 550 methods: 551 [ 552 new web3._extend.Method({ 553 name: 'mount', 554 call: 'swarmfs_mount', 555 params: 2 556 }), 557 new web3._extend.Method({ 558 name: 'unmount', 559 call: 'swarmfs_unmount', 560 params: 1 561 }), 562 new web3._extend.Method({ 563 name: 'listmounts', 564 call: 'swarmfs_listmounts', 565 params: 0 566 }), 567 ] 568 }); 569 ` 570 571 const TxPool_JS = ` 572 web3._extend({ 573 property: 'txpool', 574 methods: [], 575 properties: 576 [ 577 new web3._extend.Property({ 578 name: 'content', 579 getter: 'txpool_content' 580 }), 581 new web3._extend.Property({ 582 name: 'inspect', 583 getter: 'txpool_inspect' 584 }), 585 new web3._extend.Property({ 586 name: 'status', 587 getter: 'txpool_status', 588 outputFormatter: function(status) { 589 status.pending = web3._extend.utils.toDecimal(status.pending); 590 status.queued = web3._extend.utils.toDecimal(status.queued); 591 return status; 592 } 593 }), 594 ] 595 }); 596 `