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