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