web3ext.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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: 'setGlobalRegistrar',
  226. call: 'admin_setGlobalRegistrar',
  227. params: 2
  228. }),
  229. new web3._extend.Method({
  230. name: 'setHashReg',
  231. call: 'admin_setHashReg',
  232. params: 2
  233. }),
  234. new web3._extend.Method({
  235. name: 'setUrlHint',
  236. call: 'admin_setUrlHint',
  237. params: 2
  238. }),
  239. new web3._extend.Method({
  240. name: 'saveInfo',
  241. call: 'admin_saveInfo',
  242. params: 2
  243. }),
  244. new web3._extend.Method({
  245. name: 'register',
  246. call: 'admin_register',
  247. params: 3
  248. }),
  249. new web3._extend.Method({
  250. name: 'registerUrl',
  251. call: 'admin_registerUrl',
  252. params: 3
  253. }),
  254. new web3._extend.Method({
  255. name: 'httpGet',
  256. call: 'admin_httpGet',
  257. params: 2
  258. })
  259. ],
  260. properties:
  261. [
  262. new web3._extend.Property({
  263. name: 'nodeInfo',
  264. getter: 'admin_nodeInfo'
  265. }),
  266. new web3._extend.Property({
  267. name: 'peers',
  268. getter: 'admin_peers'
  269. }),
  270. new web3._extend.Property({
  271. name: 'datadir',
  272. getter: 'admin_datadir'
  273. })
  274. ]
  275. });
  276. `
  277. const Debug_JS = `
  278. web3._extend({
  279. property: 'debug',
  280. methods:
  281. [
  282. new web3._extend.Method({
  283. name: 'printBlock',
  284. call: 'debug_printBlock',
  285. params: 1
  286. }),
  287. new web3._extend.Method({
  288. name: 'getBlockRlp',
  289. call: 'debug_getBlockRlp',
  290. params: 1
  291. }),
  292. new web3._extend.Method({
  293. name: 'setHead',
  294. call: 'debug_setHead',
  295. params: 1
  296. }),
  297. new web3._extend.Method({
  298. name: 'traceBlock',
  299. call: 'debug_traceBlock',
  300. params: 1
  301. }),
  302. new web3._extend.Method({
  303. name: 'traceBlockByFile',
  304. call: 'debug_traceBlockByFile',
  305. params: 1
  306. }),
  307. new web3._extend.Method({
  308. name: 'traceBlockByNumber',
  309. call: 'debug_traceBlockByNumber',
  310. params: 1
  311. }),
  312. new web3._extend.Method({
  313. name: 'traceBlockByHash',
  314. call: 'debug_traceBlockByHash',
  315. params: 1
  316. }),
  317. new web3._extend.Method({
  318. name: 'seedHash',
  319. call: 'debug_seedHash',
  320. params: 1
  321. }),
  322. new web3._extend.Method({
  323. name: 'dumpBlock',
  324. call: 'debug_dumpBlock',
  325. params: 1
  326. }),
  327. new web3._extend.Method({
  328. name: 'chaindbProperty',
  329. call: 'debug_chaindbProperty',
  330. params: 1,
  331. outputFormatter: console.log
  332. }),
  333. new web3._extend.Method({
  334. name: 'chaindbCompact',
  335. call: 'debug_chaindbCompact',
  336. }),
  337. new web3._extend.Method({
  338. name: 'metrics',
  339. call: 'debug_metrics',
  340. params: 1
  341. }),
  342. new web3._extend.Method({
  343. name: 'verbosity',
  344. call: 'debug_verbosity',
  345. params: 1
  346. }),
  347. new web3._extend.Method({
  348. name: 'vmodule',
  349. call: 'debug_vmodule',
  350. params: 1
  351. }),
  352. new web3._extend.Method({
  353. name: 'backtraceAt',
  354. call: 'debug_backtraceAt',
  355. params: 1,
  356. }),
  357. new web3._extend.Method({
  358. name: 'stacks',
  359. call: 'debug_stacks',
  360. params: 0,
  361. outputFormatter: console.log
  362. }),
  363. new web3._extend.Method({
  364. name: 'memStats',
  365. call: 'debug_memStats',
  366. params: 0,
  367. }),
  368. new web3._extend.Method({
  369. name: 'gcStats',
  370. call: 'debug_gcStats',
  371. params: 0,
  372. }),
  373. new web3._extend.Method({
  374. name: 'cpuProfile',
  375. call: 'debug_cpuProfile',
  376. params: 2
  377. }),
  378. new web3._extend.Method({
  379. name: 'startCPUProfile',
  380. call: 'debug_startCPUProfile',
  381. params: 1
  382. }),
  383. new web3._extend.Method({
  384. name: 'stopCPUProfile',
  385. call: 'debug_stopCPUProfile',
  386. params: 0
  387. }),
  388. new web3._extend.Method({
  389. name: 'goTrace',
  390. call: 'debug_goTrace',
  391. params: 2
  392. }),
  393. new web3._extend.Method({
  394. name: 'startGoTrace',
  395. call: 'debug_startGoTrace',
  396. params: 1
  397. }),
  398. new web3._extend.Method({
  399. name: 'stopGoTrace',
  400. call: 'debug_stopGoTrace',
  401. params: 0
  402. }),
  403. new web3._extend.Method({
  404. name: 'blockProfile',
  405. call: 'debug_blockProfile',
  406. params: 2
  407. }),
  408. new web3._extend.Method({
  409. name: 'setBlockProfileRate',
  410. call: 'debug_setBlockProfileRate',
  411. params: 1
  412. }),
  413. new web3._extend.Method({
  414. name: 'writeBlockProfile',
  415. call: 'debug_writeBlockProfile',
  416. params: 1
  417. }),
  418. new web3._extend.Method({
  419. name: 'writeMemProfile',
  420. call: 'debug_writeMemProfile',
  421. params: 1
  422. }),
  423. new web3._extend.Method({
  424. name: 'traceTransaction',
  425. call: 'debug_traceTransaction',
  426. params: 2,
  427. inputFormatter: [null, null]
  428. })
  429. ],
  430. properties: []
  431. });
  432. `
  433. const Eth_JS = `
  434. web3._extend({
  435. property: 'eth',
  436. methods:
  437. [
  438. new web3._extend.Method({
  439. name: 'sign',
  440. call: 'eth_sign',
  441. params: 2,
  442. inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
  443. }),
  444. new web3._extend.Method({
  445. name: 'resend',
  446. call: 'eth_resend',
  447. params: 3,
  448. inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
  449. }),
  450. new web3._extend.Method({
  451. name: 'getNatSpec',
  452. call: 'eth_getNatSpec',
  453. params: 1,
  454. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  455. }),
  456. new web3._extend.Method({
  457. name: 'signTransaction',
  458. call: 'eth_signTransaction',
  459. params: 1,
  460. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  461. }),
  462. new web3._extend.Method({
  463. name: 'submitTransaction',
  464. call: 'eth_submitTransaction',
  465. params: 1,
  466. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  467. }),
  468. new web3._extend.Method({
  469. name: 'getRawTransaction',
  470. call: 'eth_getRawTransactionByHash',
  471. params: 1
  472. }),
  473. new web3._extend.Method({
  474. name: 'getRawTransactionFromBlock',
  475. call: function(args) {
  476. return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
  477. },
  478. params: 2,
  479. inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
  480. })
  481. ],
  482. properties:
  483. [
  484. new web3._extend.Property({
  485. name: 'pendingTransactions',
  486. getter: 'eth_pendingTransactions',
  487. outputFormatter: function(txs) {
  488. var formatted = [];
  489. for (var i = 0; i < txs.length; i++) {
  490. formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
  491. formatted[i].blockHash = null;
  492. }
  493. return formatted;
  494. }
  495. })
  496. ]
  497. });
  498. `
  499. const Miner_JS = `
  500. web3._extend({
  501. property: 'miner',
  502. methods:
  503. [
  504. new web3._extend.Method({
  505. name: 'start',
  506. call: 'miner_start',
  507. params: 1,
  508. inputFormatter: [null]
  509. }),
  510. new web3._extend.Method({
  511. name: 'stop',
  512. call: 'miner_stop'
  513. }),
  514. new web3._extend.Method({
  515. name: 'setEtherbase',
  516. call: 'miner_setEtherbase',
  517. params: 1,
  518. inputFormatter: [web3._extend.formatters.inputAddressFormatter]
  519. }),
  520. new web3._extend.Method({
  521. name: 'setExtra',
  522. call: 'miner_setExtra',
  523. params: 1
  524. }),
  525. new web3._extend.Method({
  526. name: 'setGasPrice',
  527. call: 'miner_setGasPrice',
  528. params: 1,
  529. inputFormatter: [web3._extend.utils.fromDecimal]
  530. }),
  531. new web3._extend.Method({
  532. name: 'startAutoDAG',
  533. call: 'miner_startAutoDAG',
  534. params: 0
  535. }),
  536. new web3._extend.Method({
  537. name: 'stopAutoDAG',
  538. call: 'miner_stopAutoDAG',
  539. params: 0
  540. }),
  541. new web3._extend.Method({
  542. name: 'makeDAG',
  543. call: 'miner_makeDAG',
  544. params: 1,
  545. inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter]
  546. })
  547. ],
  548. properties: []
  549. });
  550. `
  551. const Net_JS = `
  552. web3._extend({
  553. property: 'net',
  554. methods: [],
  555. properties:
  556. [
  557. new web3._extend.Property({
  558. name: 'version',
  559. getter: 'net_version'
  560. })
  561. ]
  562. });
  563. `
  564. const Personal_JS = `
  565. web3._extend({
  566. property: 'personal',
  567. methods:
  568. [
  569. new web3._extend.Method({
  570. name: 'importRawKey',
  571. call: 'personal_importRawKey',
  572. params: 2
  573. }),
  574. new web3._extend.Method({
  575. name: 'sendTransaction',
  576. call: 'personal_sendTransaction',
  577. params: 2,
  578. inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
  579. }),
  580. new web3._extend.Method({
  581. name: 'sign',
  582. call: 'personal_sign',
  583. params: 3,
  584. inputFormatter: [null, web3._extend.formatters.inputAddressFormatter, null]
  585. }),
  586. new web3._extend.Method({
  587. name: 'ecRecover',
  588. call: 'personal_ecRecover',
  589. params: 2
  590. })
  591. ]
  592. })
  593. `
  594. const RPC_JS = `
  595. web3._extend({
  596. property: 'rpc',
  597. methods: [],
  598. properties:
  599. [
  600. new web3._extend.Property({
  601. name: 'modules',
  602. getter: 'rpc_modules'
  603. })
  604. ]
  605. });
  606. `
  607. const Shh_JS = `
  608. web3._extend({
  609. property: 'shh',
  610. methods: [],
  611. properties:
  612. [
  613. new web3._extend.Property({
  614. name: 'version',
  615. getter: 'shh_version',
  616. outputFormatter: web3._extend.utils.toDecimal
  617. })
  618. ]
  619. });
  620. `
  621. const TxPool_JS = `
  622. web3._extend({
  623. property: 'txpool',
  624. methods: [],
  625. properties:
  626. [
  627. new web3._extend.Property({
  628. name: 'content',
  629. getter: 'txpool_content'
  630. }),
  631. new web3._extend.Property({
  632. name: 'inspect',
  633. getter: 'txpool_inspect'
  634. }),
  635. new web3._extend.Property({
  636. name: 'status',
  637. getter: 'txpool_status',
  638. outputFormatter: function(status) {
  639. status.pending = web3._extend.utils.toDecimal(status.pending);
  640. status.queued = web3._extend.utils.toDecimal(status.queued);
  641. return status;
  642. }
  643. })
  644. ]
  645. });
  646. `