github.com/devfans/go-ethereum@v1.5.10-0.20170326212234-7419d0c38291/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 "debug": Debug_JS, 24 "eth": Eth_JS, 25 "miner": Miner_JS, 26 "net": Net_JS, 27 "personal": Personal_JS, 28 "rpc": RPC_JS, 29 "shh": Shh_JS, 30 "swarmfs": SWARMFS_JS, 31 "txpool": TxPool_JS, 32 33 } 34 35 36 const Chequebook_JS = ` 37 web3._extend({ 38 property: 'chequebook', 39 methods: 40 [ 41 new web3._extend.Method({ 42 name: 'deposit', 43 call: 'chequebook_deposit', 44 params: 1, 45 inputFormatter: [null] 46 }), 47 new web3._extend.Property({ 48 name: 'balance', 49 getter: 'chequebook_balance', 50 outputFormatter: web3._extend.utils.toDecimal 51 }), 52 new web3._extend.Method({ 53 name: 'cash', 54 call: 'chequebook_cash', 55 params: 1, 56 inputFormatter: [null] 57 }), 58 new web3._extend.Method({ 59 name: 'issue', 60 call: 'chequebook_issue', 61 params: 2, 62 inputFormatter: [null, null] 63 }), 64 ] 65 }); 66 ` 67 68 const Admin_JS = ` 69 web3._extend({ 70 property: 'admin', 71 methods: 72 [ 73 new web3._extend.Method({ 74 name: 'addPeer', 75 call: 'admin_addPeer', 76 params: 1 77 }), 78 new web3._extend.Method({ 79 name: 'removePeer', 80 call: 'admin_removePeer', 81 params: 1 82 }), 83 new web3._extend.Method({ 84 name: 'exportChain', 85 call: 'admin_exportChain', 86 params: 1, 87 inputFormatter: [null] 88 }), 89 new web3._extend.Method({ 90 name: 'importChain', 91 call: 'admin_importChain', 92 params: 1 93 }), 94 new web3._extend.Method({ 95 name: 'sleepBlocks', 96 call: 'admin_sleepBlocks', 97 params: 2 98 }), 99 new web3._extend.Method({ 100 name: 'setSolc', 101 call: 'admin_setSolc', 102 params: 1 103 }), 104 new web3._extend.Method({ 105 name: 'startRPC', 106 call: 'admin_startRPC', 107 params: 4, 108 inputFormatter: [null, null, null, null] 109 }), 110 new web3._extend.Method({ 111 name: 'stopRPC', 112 call: 'admin_stopRPC' 113 }), 114 new web3._extend.Method({ 115 name: 'startWS', 116 call: 'admin_startWS', 117 params: 4, 118 inputFormatter: [null, null, null, null] 119 }), 120 new web3._extend.Method({ 121 name: 'stopWS', 122 call: 'admin_stopWS' 123 }) 124 ], 125 properties: 126 [ 127 new web3._extend.Property({ 128 name: 'nodeInfo', 129 getter: 'admin_nodeInfo' 130 }), 131 new web3._extend.Property({ 132 name: 'peers', 133 getter: 'admin_peers' 134 }), 135 new web3._extend.Property({ 136 name: 'datadir', 137 getter: 'admin_datadir' 138 }) 139 ] 140 }); 141 ` 142 143 const Debug_JS = ` 144 web3._extend({ 145 property: 'debug', 146 methods: 147 [ 148 new web3._extend.Method({ 149 name: 'printBlock', 150 call: 'debug_printBlock', 151 params: 1 152 }), 153 new web3._extend.Method({ 154 name: 'getBlockRlp', 155 call: 'debug_getBlockRlp', 156 params: 1 157 }), 158 new web3._extend.Method({ 159 name: 'setHead', 160 call: 'debug_setHead', 161 params: 1 162 }), 163 new web3._extend.Method({ 164 name: 'traceBlock', 165 call: 'debug_traceBlock', 166 params: 1 167 }), 168 new web3._extend.Method({ 169 name: 'traceBlockByFile', 170 call: 'debug_traceBlockByFile', 171 params: 1 172 }), 173 new web3._extend.Method({ 174 name: 'traceBlockByNumber', 175 call: 'debug_traceBlockByNumber', 176 params: 1 177 }), 178 new web3._extend.Method({ 179 name: 'traceBlockByHash', 180 call: 'debug_traceBlockByHash', 181 params: 1 182 }), 183 new web3._extend.Method({ 184 name: 'seedHash', 185 call: 'debug_seedHash', 186 params: 1 187 }), 188 new web3._extend.Method({ 189 name: 'dumpBlock', 190 call: 'debug_dumpBlock', 191 params: 1 192 }), 193 new web3._extend.Method({ 194 name: 'chaindbProperty', 195 call: 'debug_chaindbProperty', 196 params: 1, 197 outputFormatter: console.log 198 }), 199 new web3._extend.Method({ 200 name: 'chaindbCompact', 201 call: 'debug_chaindbCompact', 202 }), 203 new web3._extend.Method({ 204 name: 'metrics', 205 call: 'debug_metrics', 206 params: 1 207 }), 208 new web3._extend.Method({ 209 name: 'verbosity', 210 call: 'debug_verbosity', 211 params: 1 212 }), 213 new web3._extend.Method({ 214 name: 'vmodule', 215 call: 'debug_vmodule', 216 params: 1 217 }), 218 new web3._extend.Method({ 219 name: 'backtraceAt', 220 call: 'debug_backtraceAt', 221 params: 1, 222 }), 223 new web3._extend.Method({ 224 name: 'stacks', 225 call: 'debug_stacks', 226 params: 0, 227 outputFormatter: console.log 228 }), 229 new web3._extend.Method({ 230 name: 'memStats', 231 call: 'debug_memStats', 232 params: 0, 233 }), 234 new web3._extend.Method({ 235 name: 'gcStats', 236 call: 'debug_gcStats', 237 params: 0, 238 }), 239 new web3._extend.Method({ 240 name: 'cpuProfile', 241 call: 'debug_cpuProfile', 242 params: 2 243 }), 244 new web3._extend.Method({ 245 name: 'startCPUProfile', 246 call: 'debug_startCPUProfile', 247 params: 1 248 }), 249 new web3._extend.Method({ 250 name: 'stopCPUProfile', 251 call: 'debug_stopCPUProfile', 252 params: 0 253 }), 254 new web3._extend.Method({ 255 name: 'goTrace', 256 call: 'debug_goTrace', 257 params: 2 258 }), 259 new web3._extend.Method({ 260 name: 'startGoTrace', 261 call: 'debug_startGoTrace', 262 params: 1 263 }), 264 new web3._extend.Method({ 265 name: 'stopGoTrace', 266 call: 'debug_stopGoTrace', 267 params: 0 268 }), 269 new web3._extend.Method({ 270 name: 'blockProfile', 271 call: 'debug_blockProfile', 272 params: 2 273 }), 274 new web3._extend.Method({ 275 name: 'setBlockProfileRate', 276 call: 'debug_setBlockProfileRate', 277 params: 1 278 }), 279 new web3._extend.Method({ 280 name: 'writeBlockProfile', 281 call: 'debug_writeBlockProfile', 282 params: 1 283 }), 284 new web3._extend.Method({ 285 name: 'writeMemProfile', 286 call: 'debug_writeMemProfile', 287 params: 1 288 }), 289 new web3._extend.Method({ 290 name: 'traceTransaction', 291 call: 'debug_traceTransaction', 292 params: 2, 293 inputFormatter: [null, null] 294 }), 295 new web3._extend.Method({ 296 name: 'preimage', 297 call: 'debug_preimage', 298 params: 1, 299 inputFormatter: [null] 300 }), 301 new web3._extend.Method({ 302 name: 'getBadBlocks', 303 call: 'debug_getBadBlocks', 304 params: 0, 305 }), 306 ], 307 properties: [] 308 }); 309 ` 310 311 const Eth_JS = ` 312 web3._extend({ 313 property: 'eth', 314 methods: 315 [ 316 new web3._extend.Method({ 317 name: 'sign', 318 call: 'eth_sign', 319 params: 2, 320 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null] 321 }), 322 new web3._extend.Method({ 323 name: 'resend', 324 call: 'eth_resend', 325 params: 3, 326 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal] 327 }), 328 new web3._extend.Method({ 329 name: 'signTransaction', 330 call: 'eth_signTransaction', 331 params: 1, 332 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 333 }), 334 new web3._extend.Method({ 335 name: 'submitTransaction', 336 call: 'eth_submitTransaction', 337 params: 1, 338 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 339 }), 340 new web3._extend.Method({ 341 name: 'getRawTransaction', 342 call: 'eth_getRawTransactionByHash', 343 params: 1 344 }), 345 new web3._extend.Method({ 346 name: 'getRawTransactionFromBlock', 347 call: function(args) { 348 return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex'; 349 }, 350 params: 2, 351 inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] 352 }) 353 ], 354 properties: 355 [ 356 new web3._extend.Property({ 357 name: 'pendingTransactions', 358 getter: 'eth_pendingTransactions', 359 outputFormatter: function(txs) { 360 var formatted = []; 361 for (var i = 0; i < txs.length; i++) { 362 formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i])); 363 formatted[i].blockHash = null; 364 } 365 return formatted; 366 } 367 }) 368 ] 369 }); 370 ` 371 372 const Miner_JS = ` 373 web3._extend({ 374 property: 'miner', 375 methods: 376 [ 377 new web3._extend.Method({ 378 name: 'start', 379 call: 'miner_start', 380 params: 1, 381 inputFormatter: [null] 382 }), 383 new web3._extend.Method({ 384 name: 'stop', 385 call: 'miner_stop' 386 }), 387 new web3._extend.Method({ 388 name: 'setEtherbase', 389 call: 'miner_setEtherbase', 390 params: 1, 391 inputFormatter: [web3._extend.formatters.inputAddressFormatter] 392 }), 393 new web3._extend.Method({ 394 name: 'setExtra', 395 call: 'miner_setExtra', 396 params: 1 397 }), 398 new web3._extend.Method({ 399 name: 'setGasPrice', 400 call: 'miner_setGasPrice', 401 params: 1, 402 inputFormatter: [web3._extend.utils.fromDecimal] 403 }), 404 new web3._extend.Method({ 405 name: 'getHashrate', 406 call: 'miner_getHashrate' 407 }) 408 ], 409 properties: [] 410 }); 411 ` 412 413 const Net_JS = ` 414 web3._extend({ 415 property: 'net', 416 methods: [], 417 properties: 418 [ 419 new web3._extend.Property({ 420 name: 'version', 421 getter: 'net_version' 422 }) 423 ] 424 }); 425 ` 426 427 const Personal_JS = ` 428 web3._extend({ 429 property: 'personal', 430 methods: 431 [ 432 new web3._extend.Method({ 433 name: 'importRawKey', 434 call: 'personal_importRawKey', 435 params: 2 436 }), 437 new web3._extend.Method({ 438 name: 'sign', 439 call: 'personal_sign', 440 params: 3, 441 inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null] 442 }), 443 new web3._extend.Method({ 444 name: 'ecRecover', 445 call: 'personal_ecRecover', 446 params: 2 447 }), 448 new web3._extend.Method({ 449 name: 'deriveAccount', 450 call: 'personal_deriveAccount', 451 params: 3 452 }) 453 ], 454 properties: 455 [ 456 new web3._extend.Property({ 457 name: 'listWallets', 458 getter: 'personal_listWallets' 459 }) 460 ] 461 }) 462 ` 463 464 const RPC_JS = ` 465 web3._extend({ 466 property: 'rpc', 467 methods: [], 468 properties: 469 [ 470 new web3._extend.Property({ 471 name: 'modules', 472 getter: 'rpc_modules' 473 }) 474 ] 475 }); 476 ` 477 478 const Shh_JS = ` 479 web3._extend({ 480 property: 'shh', 481 methods: [], 482 properties: 483 [ 484 new web3._extend.Property({ 485 name: 'version', 486 getter: 'shh_version', 487 outputFormatter: web3._extend.utils.toDecimal 488 }) 489 ] 490 }); 491 ` 492 const SWARMFS_JS = ` 493 web3._extend({ 494 property: 'swarmfs', 495 methods: 496 [ 497 new web3._extend.Method({ 498 name: 'mount', 499 call: 'swarmfs_mount', 500 params: 2, 501 inputFormatter: [null,null] 502 }), 503 new web3._extend.Method({ 504 name: 'unmount', 505 call: 'swarmfs_unmount', 506 params: 1, 507 inputFormatter: [null] 508 }), 509 new web3._extend.Method({ 510 name: 'listmounts', 511 call: 'swarmfs_listmounts', 512 params: 0, 513 inputFormatter: [] 514 }) 515 ] 516 }); 517 ` 518 519 const TxPool_JS = ` 520 web3._extend({ 521 property: 'txpool', 522 methods: [], 523 properties: 524 [ 525 new web3._extend.Property({ 526 name: 'content', 527 getter: 'txpool_content' 528 }), 529 new web3._extend.Property({ 530 name: 'inspect', 531 getter: 'txpool_inspect' 532 }), 533 new web3._extend.Property({ 534 name: 'status', 535 getter: 'txpool_status', 536 outputFormatter: function(status) { 537 status.pending = web3._extend.utils.toDecimal(status.pending); 538 status.queued = web3._extend.utils.toDecimal(status.queued); 539 return status; 540 } 541 }) 542 ] 543 }); 544 `