web3ext.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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: 'writeMemProfile',
  306. call: 'debug_writeMemProfile',
  307. params: 1
  308. }),
  309. new web3._extend.Method({
  310. name: 'traceBlock',
  311. call: 'debug_traceBlock',
  312. params: 2,
  313. inputFormatter: [null, null]
  314. }),
  315. new web3._extend.Method({
  316. name: 'traceBlockFromFile',
  317. call: 'debug_traceBlockFromFile',
  318. params: 2,
  319. inputFormatter: [null, null]
  320. }),
  321. new web3._extend.Method({
  322. name: 'traceBlockByNumber',
  323. call: 'debug_traceBlockByNumber',
  324. params: 2,
  325. inputFormatter: [null, null]
  326. }),
  327. new web3._extend.Method({
  328. name: 'traceBlockByHash',
  329. call: 'debug_traceBlockByHash',
  330. params: 2,
  331. inputFormatter: [null, null]
  332. }),
  333. new web3._extend.Method({
  334. name: 'traceTransaction',
  335. call: 'debug_traceTransaction',
  336. params: 2,
  337. inputFormatter: [null, null]
  338. }),
  339. new web3._extend.Method({
  340. name: 'preimage',
  341. call: 'debug_preimage',
  342. params: 1,
  343. inputFormatter: [null]
  344. }),
  345. new web3._extend.Method({
  346. name: 'getBadBlocks',
  347. call: 'debug_getBadBlocks',
  348. params: 0,
  349. }),
  350. new web3._extend.Method({
  351. name: 'storageRangeAt',
  352. call: 'debug_storageRangeAt',
  353. params: 5,
  354. }),
  355. new web3._extend.Method({
  356. name: 'getModifiedAccountsByNumber',
  357. call: 'debug_getModifiedAccountsByNumber',
  358. params: 2,
  359. inputFormatter: [null, null],
  360. }),
  361. new web3._extend.Method({
  362. name: 'getModifiedAccountsByHash',
  363. call: 'debug_getModifiedAccountsByHash',
  364. params: 2,
  365. inputFormatter:[null, null],
  366. }),
  367. ],
  368. properties: []
  369. });
  370. `
  371. const Eth_JS = `
  372. web3._extend({
  373. property: 'eth',
  374. methods: [
  375. new web3._extend.Method({
  376. name: 'sign',
  377. call: 'eth_sign',
  378. params: 2,
  379. inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
  380. }),
  381. new web3._extend.Method({
  382. name: 'resend',
  383. call: 'eth_resend',
  384. params: 3,
  385. inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
  386. }),
  387. new web3._extend.Method({
  388. name: 'signTransaction',
  389. call: 'eth_signTransaction',
  390. params: 1,
  391. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  392. }),
  393. new web3._extend.Method({
  394. name: 'submitTransaction',
  395. call: 'eth_submitTransaction',
  396. params: 1,
  397. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  398. }),
  399. new web3._extend.Method({
  400. name: 'getRawTransaction',
  401. call: 'eth_getRawTransactionByHash',
  402. params: 1
  403. }),
  404. new web3._extend.Method({
  405. name: 'getRawTransactionFromBlock',
  406. call: function(args) {
  407. return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
  408. },
  409. params: 2,
  410. inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
  411. }),
  412. ],
  413. properties: [
  414. new web3._extend.Property({
  415. name: 'pendingTransactions',
  416. getter: 'eth_pendingTransactions',
  417. outputFormatter: function(txs) {
  418. var formatted = [];
  419. for (var i = 0; i < txs.length; i++) {
  420. formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
  421. formatted[i].blockHash = null;
  422. }
  423. return formatted;
  424. }
  425. }),
  426. ]
  427. });
  428. `
  429. const Miner_JS = `
  430. web3._extend({
  431. property: 'miner',
  432. methods: [
  433. new web3._extend.Method({
  434. name: 'start',
  435. call: 'miner_start',
  436. params: 1,
  437. inputFormatter: [null]
  438. }),
  439. new web3._extend.Method({
  440. name: 'stop',
  441. call: 'miner_stop'
  442. }),
  443. new web3._extend.Method({
  444. name: 'setEtherbase',
  445. call: 'miner_setEtherbase',
  446. params: 1,
  447. inputFormatter: [web3._extend.formatters.inputAddressFormatter]
  448. }),
  449. new web3._extend.Method({
  450. name: 'setExtra',
  451. call: 'miner_setExtra',
  452. params: 1
  453. }),
  454. new web3._extend.Method({
  455. name: 'setGasPrice',
  456. call: 'miner_setGasPrice',
  457. params: 1,
  458. inputFormatter: [web3._extend.utils.fromDecimal]
  459. }),
  460. new web3._extend.Method({
  461. name: 'getHashrate',
  462. call: 'miner_getHashrate'
  463. }),
  464. ],
  465. properties: []
  466. });
  467. `
  468. const Net_JS = `
  469. web3._extend({
  470. property: 'net',
  471. methods: [],
  472. properties: [
  473. new web3._extend.Property({
  474. name: 'version',
  475. getter: 'net_version'
  476. }),
  477. ]
  478. });
  479. `
  480. const Personal_JS = `
  481. web3._extend({
  482. property: 'personal',
  483. methods: [
  484. new web3._extend.Method({
  485. name: 'importRawKey',
  486. call: 'personal_importRawKey',
  487. params: 2
  488. }),
  489. new web3._extend.Method({
  490. name: 'sign',
  491. call: 'personal_sign',
  492. params: 3,
  493. inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
  494. }),
  495. new web3._extend.Method({
  496. name: 'ecRecover',
  497. call: 'personal_ecRecover',
  498. params: 2
  499. }),
  500. new web3._extend.Method({
  501. name: 'openWallet',
  502. call: 'personal_openWallet',
  503. params: 2
  504. }),
  505. new web3._extend.Method({
  506. name: 'deriveAccount',
  507. call: 'personal_deriveAccount',
  508. params: 3
  509. }),
  510. new web3._extend.Method({
  511. name: 'signTransaction',
  512. call: 'personal_signTransaction',
  513. params: 2,
  514. inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
  515. }),
  516. ],
  517. properties: [
  518. new web3._extend.Property({
  519. name: 'listWallets',
  520. getter: 'personal_listWallets'
  521. }),
  522. ]
  523. })
  524. `
  525. const RPC_JS = `
  526. web3._extend({
  527. property: 'rpc',
  528. methods: [],
  529. properties: [
  530. new web3._extend.Property({
  531. name: 'modules',
  532. getter: 'rpc_modules'
  533. }),
  534. ]
  535. });
  536. `
  537. const Shh_JS = `
  538. web3._extend({
  539. property: 'shh',
  540. methods: [
  541. ],
  542. properties:
  543. [
  544. new web3._extend.Property({
  545. name: 'version',
  546. getter: 'shh_version',
  547. outputFormatter: web3._extend.utils.toDecimal
  548. }),
  549. new web3._extend.Property({
  550. name: 'info',
  551. getter: 'shh_info'
  552. }),
  553. ]
  554. });
  555. `
  556. const SWARMFS_JS = `
  557. web3._extend({
  558. property: 'swarmfs',
  559. methods:
  560. [
  561. new web3._extend.Method({
  562. name: 'mount',
  563. call: 'swarmfs_mount',
  564. params: 2
  565. }),
  566. new web3._extend.Method({
  567. name: 'unmount',
  568. call: 'swarmfs_unmount',
  569. params: 1
  570. }),
  571. new web3._extend.Method({
  572. name: 'listmounts',
  573. call: 'swarmfs_listmounts',
  574. params: 0
  575. }),
  576. ]
  577. });
  578. `
  579. const TxPool_JS = `
  580. web3._extend({
  581. property: 'txpool',
  582. methods: [],
  583. properties:
  584. [
  585. new web3._extend.Property({
  586. name: 'content',
  587. getter: 'txpool_content'
  588. }),
  589. new web3._extend.Property({
  590. name: 'inspect',
  591. getter: 'txpool_inspect'
  592. }),
  593. new web3._extend.Property({
  594. name: 'status',
  595. getter: 'txpool_status',
  596. outputFormatter: function(status) {
  597. status.pending = web3._extend.utils.toDecimal(status.pending);
  598. status.queued = web3._extend.utils.toDecimal(status.queued);
  599. return status;
  600. }
  601. }),
  602. ]
  603. });
  604. `