web3ext.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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. [
  37. new web3._extend.Method({
  38. name: 'deposit',
  39. call: 'chequebook_deposit',
  40. params: 1,
  41. inputFormatter: [null]
  42. }),
  43. new web3._extend.Property({
  44. name: 'balance',
  45. getter: 'chequebook_balance',
  46. outputFormatter: web3._extend.utils.toDecimal
  47. }),
  48. new web3._extend.Method({
  49. name: 'cash',
  50. call: 'chequebook_cash',
  51. params: 1,
  52. inputFormatter: [null]
  53. }),
  54. new web3._extend.Method({
  55. name: 'issue',
  56. call: 'chequebook_issue',
  57. params: 2,
  58. inputFormatter: [null, null]
  59. }),
  60. ]
  61. });
  62. `
  63. const Clique_JS = `
  64. web3._extend({
  65. property: 'clique',
  66. methods:
  67. [
  68. new web3._extend.Method({
  69. name: 'getSnapshot',
  70. call: 'clique_getSnapshot',
  71. params: 1,
  72. inputFormatter: [null]
  73. }),
  74. new web3._extend.Method({
  75. name: 'getSnapshotAtHash',
  76. call: 'clique_getSnapshotAtHash',
  77. params: 1
  78. }),
  79. new web3._extend.Method({
  80. name: 'getSigners',
  81. call: 'clique_getSigners',
  82. params: 1,
  83. inputFormatter: [null]
  84. }),
  85. new web3._extend.Method({
  86. name: 'getSignersAtHash',
  87. call: 'clique_getSignersAtHash',
  88. params: 1
  89. }),
  90. new web3._extend.Method({
  91. name: 'propose',
  92. call: 'clique_propose',
  93. params: 2
  94. }),
  95. new web3._extend.Method({
  96. name: 'discard',
  97. call: 'clique_discard',
  98. params: 1
  99. })
  100. ],
  101. properties:
  102. [
  103. new web3._extend.Property({
  104. name: 'proposals',
  105. getter: 'clique_proposals'
  106. }),
  107. ]
  108. });
  109. `
  110. const Admin_JS = `
  111. web3._extend({
  112. property: 'admin',
  113. methods:
  114. [
  115. new web3._extend.Method({
  116. name: 'addPeer',
  117. call: 'admin_addPeer',
  118. params: 1
  119. }),
  120. new web3._extend.Method({
  121. name: 'removePeer',
  122. call: 'admin_removePeer',
  123. params: 1
  124. }),
  125. new web3._extend.Method({
  126. name: 'exportChain',
  127. call: 'admin_exportChain',
  128. params: 1,
  129. inputFormatter: [null]
  130. }),
  131. new web3._extend.Method({
  132. name: 'importChain',
  133. call: 'admin_importChain',
  134. params: 1
  135. }),
  136. new web3._extend.Method({
  137. name: 'sleepBlocks',
  138. call: 'admin_sleepBlocks',
  139. params: 2
  140. }),
  141. new web3._extend.Method({
  142. name: 'startRPC',
  143. call: 'admin_startRPC',
  144. params: 4,
  145. inputFormatter: [null, null, null, null]
  146. }),
  147. new web3._extend.Method({
  148. name: 'stopRPC',
  149. call: 'admin_stopRPC'
  150. }),
  151. new web3._extend.Method({
  152. name: 'startWS',
  153. call: 'admin_startWS',
  154. params: 4,
  155. inputFormatter: [null, null, null, null]
  156. }),
  157. new web3._extend.Method({
  158. name: 'stopWS',
  159. call: 'admin_stopWS'
  160. })
  161. ],
  162. properties:
  163. [
  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. const Debug_JS = `
  180. web3._extend({
  181. property: 'debug',
  182. methods:
  183. [
  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: 'traceBlock',
  201. call: 'debug_traceBlock',
  202. params: 1
  203. }),
  204. new web3._extend.Method({
  205. name: 'traceBlockByFile',
  206. call: 'debug_traceBlockByFile',
  207. params: 1
  208. }),
  209. new web3._extend.Method({
  210. name: 'traceBlockByNumber',
  211. call: 'debug_traceBlockByNumber',
  212. params: 1
  213. }),
  214. new web3._extend.Method({
  215. name: 'traceBlockByHash',
  216. call: 'debug_traceBlockByHash',
  217. params: 1
  218. }),
  219. new web3._extend.Method({
  220. name: 'seedHash',
  221. call: 'debug_seedHash',
  222. params: 1
  223. }),
  224. new web3._extend.Method({
  225. name: 'dumpBlock',
  226. call: 'debug_dumpBlock',
  227. params: 1
  228. }),
  229. new web3._extend.Method({
  230. name: 'chaindbProperty',
  231. call: 'debug_chaindbProperty',
  232. params: 1,
  233. outputFormatter: console.log
  234. }),
  235. new web3._extend.Method({
  236. name: 'chaindbCompact',
  237. call: 'debug_chaindbCompact',
  238. }),
  239. new web3._extend.Method({
  240. name: 'metrics',
  241. call: 'debug_metrics',
  242. params: 1
  243. }),
  244. new web3._extend.Method({
  245. name: 'verbosity',
  246. call: 'debug_verbosity',
  247. params: 1
  248. }),
  249. new web3._extend.Method({
  250. name: 'vmodule',
  251. call: 'debug_vmodule',
  252. params: 1
  253. }),
  254. new web3._extend.Method({
  255. name: 'backtraceAt',
  256. call: 'debug_backtraceAt',
  257. params: 1,
  258. }),
  259. new web3._extend.Method({
  260. name: 'stacks',
  261. call: 'debug_stacks',
  262. params: 0,
  263. outputFormatter: console.log
  264. }),
  265. new web3._extend.Method({
  266. name: 'memStats',
  267. call: 'debug_memStats',
  268. params: 0,
  269. }),
  270. new web3._extend.Method({
  271. name: 'gcStats',
  272. call: 'debug_gcStats',
  273. params: 0,
  274. }),
  275. new web3._extend.Method({
  276. name: 'cpuProfile',
  277. call: 'debug_cpuProfile',
  278. params: 2
  279. }),
  280. new web3._extend.Method({
  281. name: 'startCPUProfile',
  282. call: 'debug_startCPUProfile',
  283. params: 1
  284. }),
  285. new web3._extend.Method({
  286. name: 'stopCPUProfile',
  287. call: 'debug_stopCPUProfile',
  288. params: 0
  289. }),
  290. new web3._extend.Method({
  291. name: 'goTrace',
  292. call: 'debug_goTrace',
  293. params: 2
  294. }),
  295. new web3._extend.Method({
  296. name: 'startGoTrace',
  297. call: 'debug_startGoTrace',
  298. params: 1
  299. }),
  300. new web3._extend.Method({
  301. name: 'stopGoTrace',
  302. call: 'debug_stopGoTrace',
  303. params: 0
  304. }),
  305. new web3._extend.Method({
  306. name: 'blockProfile',
  307. call: 'debug_blockProfile',
  308. params: 2
  309. }),
  310. new web3._extend.Method({
  311. name: 'setBlockProfileRate',
  312. call: 'debug_setBlockProfileRate',
  313. params: 1
  314. }),
  315. new web3._extend.Method({
  316. name: 'writeBlockProfile',
  317. call: 'debug_writeBlockProfile',
  318. params: 1
  319. }),
  320. new web3._extend.Method({
  321. name: 'writeMemProfile',
  322. call: 'debug_writeMemProfile',
  323. params: 1
  324. }),
  325. new web3._extend.Method({
  326. name: 'traceTransaction',
  327. call: 'debug_traceTransaction',
  328. params: 2,
  329. inputFormatter: [null, null]
  330. }),
  331. new web3._extend.Method({
  332. name: 'preimage',
  333. call: 'debug_preimage',
  334. params: 1,
  335. inputFormatter: [null]
  336. }),
  337. new web3._extend.Method({
  338. name: 'getBadBlocks',
  339. call: 'debug_getBadBlocks',
  340. params: 0,
  341. }),
  342. new web3._extend.Method({
  343. name: 'storageRangeAt',
  344. call: 'debug_storageRangeAt',
  345. params: 5,
  346. }),
  347. ],
  348. properties: []
  349. });
  350. `
  351. const Eth_JS = `
  352. web3._extend({
  353. property: 'eth',
  354. methods:
  355. [
  356. new web3._extend.Method({
  357. name: 'sign',
  358. call: 'eth_sign',
  359. params: 2,
  360. inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
  361. }),
  362. new web3._extend.Method({
  363. name: 'resend',
  364. call: 'eth_resend',
  365. params: 3,
  366. inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
  367. }),
  368. new web3._extend.Method({
  369. name: 'signTransaction',
  370. call: 'eth_signTransaction',
  371. params: 1,
  372. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  373. }),
  374. new web3._extend.Method({
  375. name: 'submitTransaction',
  376. call: 'eth_submitTransaction',
  377. params: 1,
  378. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  379. }),
  380. new web3._extend.Method({
  381. name: 'getRawTransaction',
  382. call: 'eth_getRawTransactionByHash',
  383. params: 1
  384. }),
  385. new web3._extend.Method({
  386. name: 'getRawTransactionFromBlock',
  387. call: function(args) {
  388. return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
  389. },
  390. params: 2,
  391. inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
  392. })
  393. ],
  394. properties:
  395. [
  396. new web3._extend.Property({
  397. name: 'pendingTransactions',
  398. getter: 'eth_pendingTransactions',
  399. outputFormatter: function(txs) {
  400. var formatted = [];
  401. for (var i = 0; i < txs.length; i++) {
  402. formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
  403. formatted[i].blockHash = null;
  404. }
  405. return formatted;
  406. }
  407. })
  408. ]
  409. });
  410. `
  411. const Miner_JS = `
  412. web3._extend({
  413. property: 'miner',
  414. methods:
  415. [
  416. new web3._extend.Method({
  417. name: 'start',
  418. call: 'miner_start',
  419. params: 1,
  420. inputFormatter: [null]
  421. }),
  422. new web3._extend.Method({
  423. name: 'stop',
  424. call: 'miner_stop'
  425. }),
  426. new web3._extend.Method({
  427. name: 'setEtherbase',
  428. call: 'miner_setEtherbase',
  429. params: 1,
  430. inputFormatter: [web3._extend.formatters.inputAddressFormatter]
  431. }),
  432. new web3._extend.Method({
  433. name: 'setExtra',
  434. call: 'miner_setExtra',
  435. params: 1
  436. }),
  437. new web3._extend.Method({
  438. name: 'setGasPrice',
  439. call: 'miner_setGasPrice',
  440. params: 1,
  441. inputFormatter: [web3._extend.utils.fromDecimal]
  442. }),
  443. new web3._extend.Method({
  444. name: 'getHashrate',
  445. call: 'miner_getHashrate'
  446. })
  447. ],
  448. properties: []
  449. });
  450. `
  451. const Net_JS = `
  452. web3._extend({
  453. property: 'net',
  454. methods: [],
  455. properties:
  456. [
  457. new web3._extend.Property({
  458. name: 'version',
  459. getter: 'net_version'
  460. })
  461. ]
  462. });
  463. `
  464. const Personal_JS = `
  465. web3._extend({
  466. property: 'personal',
  467. methods:
  468. [
  469. new web3._extend.Method({
  470. name: 'importRawKey',
  471. call: 'personal_importRawKey',
  472. params: 2
  473. }),
  474. new web3._extend.Method({
  475. name: 'sign',
  476. call: 'personal_sign',
  477. params: 3,
  478. inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
  479. }),
  480. new web3._extend.Method({
  481. name: 'ecRecover',
  482. call: 'personal_ecRecover',
  483. params: 2
  484. }),
  485. new web3._extend.Method({
  486. name: 'deriveAccount',
  487. call: 'personal_deriveAccount',
  488. params: 3
  489. })
  490. ],
  491. properties:
  492. [
  493. new web3._extend.Property({
  494. name: 'listWallets',
  495. getter: 'personal_listWallets'
  496. })
  497. ]
  498. })
  499. `
  500. const RPC_JS = `
  501. web3._extend({
  502. property: 'rpc',
  503. methods: [],
  504. properties:
  505. [
  506. new web3._extend.Property({
  507. name: 'modules',
  508. getter: 'rpc_modules'
  509. })
  510. ]
  511. });
  512. `
  513. const Shh_JS = `
  514. web3._extend({
  515. property: 'shh',
  516. methods: [
  517. new web3._extend.Method({
  518. name: 'setMaxMessageLength',
  519. call: 'shh_setMaxMessageLength',
  520. params: 1
  521. }),
  522. new web3._extend.Method({
  523. name: 'setMinimumPoW',
  524. call: 'shh_setMinimumPoW',
  525. params: 1
  526. }),
  527. new web3._extend.Method({
  528. name: 'markTrustedPeer',
  529. call: 'shh_markTrustedPeer',
  530. params: 1
  531. }),
  532. new web3._extend.Method({
  533. name: 'hasKeyPair',
  534. call: 'shh_hasKeyPair',
  535. params: 1
  536. }),
  537. new web3._extend.Method({
  538. name: 'deleteKeyPair',
  539. call: 'shh_deleteKeyPair',
  540. params: 1
  541. }),
  542. new web3._extend.Method({
  543. name: 'newKeyPair',
  544. call: 'shh_newKeyPair'
  545. }),
  546. new web3._extend.Method({
  547. name: 'getPublicKey',
  548. call: 'shh_getPublicKey',
  549. params: 1
  550. }),
  551. new web3._extend.Method({
  552. name: 'getPrivateKey',
  553. call: 'shh_getPrivateKey',
  554. params: 1
  555. }),
  556. new web3._extend.Method({
  557. name: 'newSymKey',
  558. call: 'shh_newSymKey',
  559. }),
  560. new web3._extend.Method({
  561. name: 'addSymKey',
  562. call: 'shh_addSymKey',
  563. params: 1
  564. }),
  565. new web3._extend.Method({
  566. name: 'generateSymKeyFromPassword',
  567. call: 'shh_generateSymKeyFromPassword',
  568. params: 1
  569. }),
  570. new web3._extend.Method({
  571. name: 'hasSymKey',
  572. call: 'shh_hasSymKey',
  573. params: 1
  574. }),
  575. new web3._extend.Method({
  576. name: 'getSymKey',
  577. call: 'shh_getSymKey',
  578. params: 1
  579. }),
  580. new web3._extend.Method({
  581. name: 'deleteSymKey',
  582. call: 'shh_deleteSymKey',
  583. params: 1
  584. }),
  585. new web3._extend.Method({
  586. name: 'subscribe',
  587. call: 'shh_subscribe',
  588. params: 2
  589. }),
  590. new web3._extend.Method({
  591. name: 'unsubscribe',
  592. call: 'shh_unsubscribe',
  593. params: 1
  594. }),
  595. new web3._extend.Method({
  596. name: 'post',
  597. call: 'shh_post',
  598. params: 1
  599. }),
  600. new web3._extend.Method({
  601. name: 'publicKey',
  602. call: 'shh_getPublicKey',
  603. params: 1
  604. }),
  605. new web3._extend.Method({
  606. name: 'getFilterMessages',
  607. call: 'shh_getFilterMessages',
  608. params: 1
  609. }),
  610. new web3._extend.Method({
  611. name: 'deleteMessageFilter',
  612. call: 'shh_deleteMessageFilter',
  613. params: 1
  614. }),
  615. new web3._extend.Method({
  616. name: 'newMessageFilter',
  617. call: 'shh_newMessageFilter',
  618. params: 1
  619. })
  620. ],
  621. properties:
  622. [
  623. new web3._extend.Property({
  624. name: 'version',
  625. getter: 'shh_version',
  626. outputFormatter: web3._extend.utils.toDecimal
  627. }),
  628. new web3._extend.Property({
  629. name: 'info',
  630. getter: 'shh_info'
  631. }),
  632. ]
  633. });
  634. `
  635. const SWARMFS_JS = `
  636. web3._extend({
  637. property: 'swarmfs',
  638. methods:
  639. [
  640. new web3._extend.Method({
  641. name: 'mount',
  642. call: 'swarmfs_mount',
  643. params: 2
  644. }),
  645. new web3._extend.Method({
  646. name: 'unmount',
  647. call: 'swarmfs_unmount',
  648. params: 1
  649. }),
  650. new web3._extend.Method({
  651. name: 'listmounts',
  652. call: 'swarmfs_listmounts',
  653. params: 0
  654. })
  655. ]
  656. });
  657. `
  658. const TxPool_JS = `
  659. web3._extend({
  660. property: 'txpool',
  661. methods: [],
  662. properties:
  663. [
  664. new web3._extend.Property({
  665. name: 'content',
  666. getter: 'txpool_content'
  667. }),
  668. new web3._extend.Property({
  669. name: 'inspect',
  670. getter: 'txpool_inspect'
  671. }),
  672. new web3._extend.Property({
  673. name: 'status',
  674. getter: 'txpool_status',
  675. outputFormatter: function(status) {
  676. status.pending = web3._extend.utils.toDecimal(status.pending);
  677. status.queued = web3._extend.utils.toDecimal(status.queued);
  678. return status;
  679. }
  680. })
  681. ]
  682. });
  683. `