web3ext.go 13 KB

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