web3ext.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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: 'traceBlock',
  195. call: 'debug_traceBlock',
  196. params: 1
  197. }),
  198. new web3._extend.Method({
  199. name: 'traceBlockFromFile',
  200. call: 'debug_traceBlockFromFile',
  201. params: 1
  202. }),
  203. new web3._extend.Method({
  204. name: 'traceBlockByNumber',
  205. call: 'debug_traceBlockByNumber',
  206. params: 1
  207. }),
  208. new web3._extend.Method({
  209. name: 'traceBlockByHash',
  210. call: 'debug_traceBlockByHash',
  211. params: 1
  212. }),
  213. new web3._extend.Method({
  214. name: 'seedHash',
  215. call: 'debug_seedHash',
  216. params: 1
  217. }),
  218. new web3._extend.Method({
  219. name: 'dumpBlock',
  220. call: 'debug_dumpBlock',
  221. params: 1
  222. }),
  223. new web3._extend.Method({
  224. name: 'chaindbProperty',
  225. call: 'debug_chaindbProperty',
  226. params: 1,
  227. outputFormatter: console.log
  228. }),
  229. new web3._extend.Method({
  230. name: 'chaindbCompact',
  231. call: 'debug_chaindbCompact',
  232. }),
  233. new web3._extend.Method({
  234. name: 'metrics',
  235. call: 'debug_metrics',
  236. params: 1
  237. }),
  238. new web3._extend.Method({
  239. name: 'verbosity',
  240. call: 'debug_verbosity',
  241. params: 1
  242. }),
  243. new web3._extend.Method({
  244. name: 'vmodule',
  245. call: 'debug_vmodule',
  246. params: 1
  247. }),
  248. new web3._extend.Method({
  249. name: 'backtraceAt',
  250. call: 'debug_backtraceAt',
  251. params: 1,
  252. }),
  253. new web3._extend.Method({
  254. name: 'stacks',
  255. call: 'debug_stacks',
  256. params: 0,
  257. outputFormatter: console.log
  258. }),
  259. new web3._extend.Method({
  260. name: 'freeOSMemory',
  261. call: 'debug_freeOSMemory',
  262. params: 0,
  263. }),
  264. new web3._extend.Method({
  265. name: 'setGCPercent',
  266. call: 'debug_setGCPercent',
  267. params: 1,
  268. }),
  269. new web3._extend.Method({
  270. name: 'memStats',
  271. call: 'debug_memStats',
  272. params: 0,
  273. }),
  274. new web3._extend.Method({
  275. name: 'gcStats',
  276. call: 'debug_gcStats',
  277. params: 0,
  278. }),
  279. new web3._extend.Method({
  280. name: 'cpuProfile',
  281. call: 'debug_cpuProfile',
  282. params: 2
  283. }),
  284. new web3._extend.Method({
  285. name: 'startCPUProfile',
  286. call: 'debug_startCPUProfile',
  287. params: 1
  288. }),
  289. new web3._extend.Method({
  290. name: 'stopCPUProfile',
  291. call: 'debug_stopCPUProfile',
  292. params: 0
  293. }),
  294. new web3._extend.Method({
  295. name: 'goTrace',
  296. call: 'debug_goTrace',
  297. params: 2
  298. }),
  299. new web3._extend.Method({
  300. name: 'startGoTrace',
  301. call: 'debug_startGoTrace',
  302. params: 1
  303. }),
  304. new web3._extend.Method({
  305. name: 'stopGoTrace',
  306. call: 'debug_stopGoTrace',
  307. params: 0
  308. }),
  309. new web3._extend.Method({
  310. name: 'blockProfile',
  311. call: 'debug_blockProfile',
  312. params: 2
  313. }),
  314. new web3._extend.Method({
  315. name: 'setBlockProfileRate',
  316. call: 'debug_setBlockProfileRate',
  317. params: 1
  318. }),
  319. new web3._extend.Method({
  320. name: 'writeBlockProfile',
  321. call: 'debug_writeBlockProfile',
  322. params: 1
  323. }),
  324. new web3._extend.Method({
  325. name: 'writeMemProfile',
  326. call: 'debug_writeMemProfile',
  327. params: 1
  328. }),
  329. new web3._extend.Method({
  330. name: 'traceTransaction',
  331. call: 'debug_traceTransaction',
  332. params: 2,
  333. inputFormatter: [null, null]
  334. }),
  335. new web3._extend.Method({
  336. name: 'preimage',
  337. call: 'debug_preimage',
  338. params: 1,
  339. inputFormatter: [null]
  340. }),
  341. new web3._extend.Method({
  342. name: 'getBadBlocks',
  343. call: 'debug_getBadBlocks',
  344. params: 0,
  345. }),
  346. new web3._extend.Method({
  347. name: 'storageRangeAt',
  348. call: 'debug_storageRangeAt',
  349. params: 5,
  350. }),
  351. ],
  352. properties: []
  353. });
  354. `
  355. const Eth_JS = `
  356. web3._extend({
  357. property: 'eth',
  358. methods: [
  359. new web3._extend.Method({
  360. name: 'sign',
  361. call: 'eth_sign',
  362. params: 2,
  363. inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
  364. }),
  365. new web3._extend.Method({
  366. name: 'resend',
  367. call: 'eth_resend',
  368. params: 3,
  369. inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
  370. }),
  371. new web3._extend.Method({
  372. name: 'signTransaction',
  373. call: 'eth_signTransaction',
  374. params: 1,
  375. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  376. }),
  377. new web3._extend.Method({
  378. name: 'submitTransaction',
  379. call: 'eth_submitTransaction',
  380. params: 1,
  381. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  382. }),
  383. new web3._extend.Method({
  384. name: 'getRawTransaction',
  385. call: 'eth_getRawTransactionByHash',
  386. params: 1
  387. }),
  388. new web3._extend.Method({
  389. name: 'getRawTransactionFromBlock',
  390. call: function(args) {
  391. return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
  392. },
  393. params: 2,
  394. inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
  395. }),
  396. ],
  397. properties: [
  398. new web3._extend.Property({
  399. name: 'pendingTransactions',
  400. getter: 'eth_pendingTransactions',
  401. outputFormatter: function(txs) {
  402. var formatted = [];
  403. for (var i = 0; i < txs.length; i++) {
  404. formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
  405. formatted[i].blockHash = null;
  406. }
  407. return formatted;
  408. }
  409. }),
  410. ]
  411. });
  412. `
  413. const Miner_JS = `
  414. web3._extend({
  415. property: 'miner',
  416. methods: [
  417. new web3._extend.Method({
  418. name: 'start',
  419. call: 'miner_start',
  420. params: 1,
  421. inputFormatter: [null]
  422. }),
  423. new web3._extend.Method({
  424. name: 'stop',
  425. call: 'miner_stop'
  426. }),
  427. new web3._extend.Method({
  428. name: 'setEtherbase',
  429. call: 'miner_setEtherbase',
  430. params: 1,
  431. inputFormatter: [web3._extend.formatters.inputAddressFormatter]
  432. }),
  433. new web3._extend.Method({
  434. name: 'setExtra',
  435. call: 'miner_setExtra',
  436. params: 1
  437. }),
  438. new web3._extend.Method({
  439. name: 'setGasPrice',
  440. call: 'miner_setGasPrice',
  441. params: 1,
  442. inputFormatter: [web3._extend.utils.fromDecimal]
  443. }),
  444. new web3._extend.Method({
  445. name: 'getHashrate',
  446. call: 'miner_getHashrate'
  447. }),
  448. ],
  449. properties: []
  450. });
  451. `
  452. const Net_JS = `
  453. web3._extend({
  454. property: 'net',
  455. methods: [],
  456. properties: [
  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. new web3._extend.Method({
  469. name: 'importRawKey',
  470. call: 'personal_importRawKey',
  471. params: 2
  472. }),
  473. new web3._extend.Method({
  474. name: 'sign',
  475. call: 'personal_sign',
  476. params: 3,
  477. inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
  478. }),
  479. new web3._extend.Method({
  480. name: 'ecRecover',
  481. call: 'personal_ecRecover',
  482. params: 2
  483. }),
  484. new web3._extend.Method({
  485. name: 'openWallet',
  486. call: 'personal_openWallet',
  487. params: 2
  488. }),
  489. new web3._extend.Method({
  490. name: 'deriveAccount',
  491. call: 'personal_deriveAccount',
  492. params: 3
  493. }),
  494. ],
  495. properties: [
  496. new web3._extend.Property({
  497. name: 'listWallets',
  498. getter: 'personal_listWallets'
  499. }),
  500. ]
  501. })
  502. `
  503. const RPC_JS = `
  504. web3._extend({
  505. property: 'rpc',
  506. methods: [],
  507. properties: [
  508. new web3._extend.Property({
  509. name: 'modules',
  510. getter: 'rpc_modules'
  511. }),
  512. ]
  513. });
  514. `
  515. const Shh_JS = `
  516. web3._extend({
  517. property: 'shh',
  518. methods: [
  519. ],
  520. properties:
  521. [
  522. new web3._extend.Property({
  523. name: 'version',
  524. getter: 'shh_version',
  525. outputFormatter: web3._extend.utils.toDecimal
  526. }),
  527. new web3._extend.Property({
  528. name: 'info',
  529. getter: 'shh_info'
  530. }),
  531. ]
  532. });
  533. `
  534. const SWARMFS_JS = `
  535. web3._extend({
  536. property: 'swarmfs',
  537. methods:
  538. [
  539. new web3._extend.Method({
  540. name: 'mount',
  541. call: 'swarmfs_mount',
  542. params: 2
  543. }),
  544. new web3._extend.Method({
  545. name: 'unmount',
  546. call: 'swarmfs_unmount',
  547. params: 1
  548. }),
  549. new web3._extend.Method({
  550. name: 'listmounts',
  551. call: 'swarmfs_listmounts',
  552. params: 0
  553. }),
  554. ]
  555. });
  556. `
  557. const TxPool_JS = `
  558. web3._extend({
  559. property: 'txpool',
  560. methods: [],
  561. properties:
  562. [
  563. new web3._extend.Property({
  564. name: 'content',
  565. getter: 'txpool_content'
  566. }),
  567. new web3._extend.Property({
  568. name: 'inspect',
  569. getter: 'txpool_inspect'
  570. }),
  571. new web3._extend.Property({
  572. name: 'status',
  573. getter: 'txpool_status',
  574. outputFormatter: function(status) {
  575. status.pending = web3._extend.utils.toDecimal(status.pending);
  576. status.queued = web3._extend.utils.toDecimal(status.queued);
  577. return status;
  578. }
  579. }),
  580. ]
  581. });
  582. `