github.com/aerth/aquachain@v1.4.1/internal/web3ext/web3ext.go (about) 1 // Copyright 2015 The aquachain Authors 2 // This file is part of the aquachain library. 3 // 4 // The aquachain 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 aquachain 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 aquachain library. If not, see <http://www.gnu.org/licenses/>. 16 17 // package web3ext contains aquachain 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 "aqua": Aqua_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: 'seedHash', 201 call: 'debug_seedHash', 202 params: 1 203 }), 204 new web3._extend.Method({ 205 name: 'dumpBlock', 206 call: 'debug_dumpBlock', 207 params: 1 208 }), 209 new web3._extend.Method({ 210 name: 'chaindbProperty', 211 call: 'debug_chaindbProperty', 212 params: 1, 213 outputFormatter: console.log 214 }), 215 new web3._extend.Method({ 216 name: 'chaindbCompact', 217 call: 'debug_chaindbCompact', 218 }), 219 new web3._extend.Method({ 220 name: 'metrics', 221 call: 'debug_metrics', 222 params: 1 223 }), 224 new web3._extend.Method({ 225 name: 'verbosity', 226 call: 'debug_verbosity', 227 params: 1 228 }), 229 new web3._extend.Method({ 230 name: 'vmodule', 231 call: 'debug_vmodule', 232 params: 1 233 }), 234 new web3._extend.Method({ 235 name: 'backtraceAt', 236 call: 'debug_backtraceAt', 237 params: 1, 238 }), 239 new web3._extend.Method({ 240 name: 'stacks', 241 call: 'debug_stacks', 242 params: 0, 243 outputFormatter: console.log 244 }), 245 new web3._extend.Method({ 246 name: 'freeOSMemory', 247 call: 'debug_freeOSMemory', 248 params: 0, 249 }), 250 new web3._extend.Method({ 251 name: 'setGCPercent', 252 call: 'debug_setGCPercent', 253 params: 1, 254 }), 255 new web3._extend.Method({ 256 name: 'memStats', 257 call: 'debug_memStats', 258 params: 0, 259 }), 260 new web3._extend.Method({ 261 name: 'gcStats', 262 call: 'debug_gcStats', 263 params: 0, 264 }), 265 new web3._extend.Method({ 266 name: 'cpuProfile', 267 call: 'debug_cpuProfile', 268 params: 2 269 }), 270 new web3._extend.Method({ 271 name: 'startCPUProfile', 272 call: 'debug_startCPUProfile', 273 params: 1 274 }), 275 new web3._extend.Method({ 276 name: 'stopCPUProfile', 277 call: 'debug_stopCPUProfile', 278 params: 0 279 }), 280 new web3._extend.Method({ 281 name: 'goTrace', 282 call: 'debug_goTrace', 283 params: 2 284 }), 285 new web3._extend.Method({ 286 name: 'startGoTrace', 287 call: 'debug_startGoTrace', 288 params: 1 289 }), 290 new web3._extend.Method({ 291 name: 'stopGoTrace', 292 call: 'debug_stopGoTrace', 293 params: 0 294 }), 295 new web3._extend.Method({ 296 name: 'blockProfile', 297 call: 'debug_blockProfile', 298 params: 2 299 }), 300 new web3._extend.Method({ 301 name: 'setBlockProfileRate', 302 call: 'debug_setBlockProfileRate', 303 params: 1 304 }), 305 new web3._extend.Method({ 306 name: 'writeBlockProfile', 307 call: 'debug_writeBlockProfile', 308 params: 1 309 }), 310 new web3._extend.Method({ 311 name: 'writeMemProfile', 312 call: 'debug_writeMemProfile', 313 params: 1 314 }), 315 new web3._extend.Method({ 316 name: 'traceBlock', 317 call: 'debug_traceBlock', 318 params: 2, 319 inputFormatter: [null, null] 320 }), 321 new web3._extend.Method({ 322 name: 'traceBlockFromFile', 323 call: 'debug_traceBlockFromFile', 324 params: 2, 325 inputFormatter: [null, null] 326 }), 327 new web3._extend.Method({ 328 name: 'traceBlockByNumber', 329 call: 'debug_traceBlockByNumber', 330 params: 2, 331 inputFormatter: [null, null] 332 }), 333 new web3._extend.Method({ 334 name: 'traceBlockByHash', 335 call: 'debug_traceBlockByHash', 336 params: 2, 337 inputFormatter: [null, null] 338 }), 339 new web3._extend.Method({ 340 name: 'traceTransaction', 341 call: 'debug_traceTransaction', 342 params: 2, 343 inputFormatter: [null, null] 344 }), 345 new web3._extend.Method({ 346 name: 'preimage', 347 call: 'debug_preimage', 348 params: 1, 349 inputFormatter: [null] 350 }), 351 new web3._extend.Method({ 352 name: 'getBadBlocks', 353 call: 'debug_getBadBlocks', 354 params: 0, 355 }), 356 new web3._extend.Method({ 357 name: 'storageRangeAt', 358 call: 'debug_storageRangeAt', 359 params: 5, 360 }), 361 new web3._extend.Method({ 362 name: 'getModifiedAccountsByNumber', 363 call: 'debug_getModifiedAccountsByNumber', 364 params: 2, 365 inputFormatter: [null, null], 366 }), 367 new web3._extend.Method({ 368 name: 'getModifiedAccountsByHash', 369 call: 'debug_getModifiedAccountsByHash', 370 params: 2, 371 inputFormatter:[null, null], 372 }), 373 ], 374 properties: [] 375 }); 376 ` 377 378 const Aqua_JS = ` 379 web3._extend({ 380 property: 'aqua', 381 methods: [ 382 new web3._extend.Method({ 383 name: 'sign', 384 call: 'aqua_sign', 385 params: 2, 386 inputFormatter: [web3._extend.formatters.inputAddressFormatter, null] 387 }), 388 new web3._extend.Method({ 389 name: 'resend', 390 call: 'aqua_resend', 391 params: 3, 392 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal] 393 }), 394 new web3._extend.Method({ 395 name: 'signTransaction', 396 call: 'aqua_signTransaction', 397 params: 1, 398 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 399 }), 400 new web3._extend.Method({ 401 name: 'submitTransaction', 402 call: 'aqua_submitTransaction', 403 params: 1, 404 inputFormatter: [web3._extend.formatters.inputTransactionFormatter] 405 }), 406 new web3._extend.Method({ 407 name: 'getRawTransaction', 408 call: 'aqua_getRawTransactionByHash', 409 params: 1 410 }), 411 new web3._extend.Method({ 412 name: 'getRawTransactionFromBlock', 413 call: function(args) { 414 return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'aqua_getRawTransactionByBlockHashAndIndex' : 'aqua_getRawTransactionByBlockNumberAndIndex'; 415 }, 416 params: 2, 417 inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] 418 }), 419 ], 420 properties: [ 421 new web3._extend.Property({ 422 name: 'pendingTransactions', 423 getter: 'aqua_pendingTransactions', 424 outputFormatter: function(txs) { 425 var formatted = []; 426 for (var i = 0; i < txs.length; i++) { 427 formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i])); 428 formatted[i].blockHash = null; 429 } 430 return formatted; 431 } 432 }), 433 ] 434 }); 435 ` 436 437 const Miner_JS = ` 438 web3._extend({ 439 property: 'miner', 440 methods: [ 441 new web3._extend.Method({ 442 name: 'start', 443 call: 'miner_start', 444 params: 1, 445 inputFormatter: [null] 446 }), 447 new web3._extend.Method({ 448 name: 'stop', 449 call: 'miner_stop' 450 }), 451 new web3._extend.Method({ 452 name: 'setAquabase', 453 call: 'miner_setAquabase', 454 params: 1, 455 inputFormatter: [web3._extend.formatters.inputAddressFormatter] 456 }), 457 new web3._extend.Method({ 458 name: 'setExtra', 459 call: 'miner_setExtra', 460 params: 1 461 }), 462 new web3._extend.Method({ 463 name: 'setGasPrice', 464 call: 'miner_setGasPrice', 465 params: 1, 466 inputFormatter: [web3._extend.utils.fromDecimal] 467 }), 468 new web3._extend.Method({ 469 name: 'getHashrate', 470 call: 'miner_getHashrate' 471 }), 472 ], 473 properties: [] 474 }); 475 ` 476 477 const Net_JS = ` 478 web3._extend({ 479 property: 'net', 480 methods: [], 481 properties: [ 482 new web3._extend.Property({ 483 name: 'version', 484 getter: 'net_version' 485 }), 486 ] 487 }); 488 ` 489 490 const Personal_JS = ` 491 web3._extend({ 492 property: 'personal', 493 methods: [ 494 new web3._extend.Method({ 495 name: 'importRawKey', 496 call: 'personal_importRawKey', 497 params: 2 498 }), 499 new web3._extend.Method({ 500 name: 'sign', 501 call: 'personal_sign', 502 params: 3, 503 inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null] 504 }), 505 new web3._extend.Method({ 506 name: 'ecRecover', 507 call: 'personal_ecRecover', 508 params: 2 509 }), 510 new web3._extend.Method({ 511 name: 'openWallet', 512 call: 'personal_openWallet', 513 params: 2 514 }), 515 new web3._extend.Method({ 516 name: 'deriveAccount', 517 call: 'personal_deriveAccount', 518 params: 3 519 }), 520 new web3._extend.Method({ 521 name: 'signTransaction', 522 call: 'personal_signTransaction', 523 params: 2, 524 inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null] 525 }), 526 ], 527 properties: [ 528 new web3._extend.Property({ 529 name: 'listWallets', 530 getter: 'personal_listWallets' 531 }), 532 ] 533 }) 534 ` 535 536 const RPC_JS = ` 537 web3._extend({ 538 property: 'rpc', 539 methods: [], 540 properties: [ 541 new web3._extend.Property({ 542 name: 'modules', 543 getter: 'rpc_modules' 544 }), 545 ] 546 }); 547 ` 548 549 const Shh_JS = ` 550 web3._extend({ 551 property: 'shh', 552 methods: [ 553 ], 554 properties: 555 [ 556 new web3._extend.Property({ 557 name: 'version', 558 getter: 'shh_version', 559 outputFormatter: web3._extend.utils.toDecimal 560 }), 561 new web3._extend.Property({ 562 name: 'info', 563 getter: 'shh_info' 564 }), 565 ] 566 }); 567 ` 568 569 const SWARMFS_JS = ` 570 web3._extend({ 571 property: 'swarmfs', 572 methods: 573 [ 574 new web3._extend.Method({ 575 name: 'mount', 576 call: 'swarmfs_mount', 577 params: 2 578 }), 579 new web3._extend.Method({ 580 name: 'unmount', 581 call: 'swarmfs_unmount', 582 params: 1 583 }), 584 new web3._extend.Method({ 585 name: 'listmounts', 586 call: 'swarmfs_listmounts', 587 params: 0 588 }), 589 ] 590 }); 591 ` 592 593 const TxPool_JS = ` 594 web3._extend({ 595 property: 'txpool', 596 methods: [], 597 properties: 598 [ 599 new web3._extend.Property({ 600 name: 'content', 601 getter: 'txpool_content' 602 }), 603 new web3._extend.Property({ 604 name: 'inspect', 605 getter: 'txpool_inspect' 606 }), 607 new web3._extend.Property({ 608 name: 'status', 609 getter: 'txpool_status', 610 outputFormatter: function(status) { 611 status.pending = web3._extend.utils.toDecimal(status.pending); 612 status.queued = web3._extend.utils.toDecimal(status.queued); 613 return status; 614 } 615 }), 616 ] 617 }); 618 `