web3ext.go 13 KB

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