web3ext.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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: 'metrics',
  335. call: 'debug_metrics',
  336. params: 1
  337. }),
  338. new web3._extend.Method({
  339. name: 'verbosity',
  340. call: 'debug_verbosity',
  341. params: 1
  342. }),
  343. new web3._extend.Method({
  344. name: 'vmodule',
  345. call: 'debug_vmodule',
  346. params: 1
  347. }),
  348. new web3._extend.Method({
  349. name: 'backtraceAt',
  350. call: 'debug_backtraceAt',
  351. params: 1,
  352. }),
  353. new web3._extend.Method({
  354. name: 'stacks',
  355. call: 'debug_stacks',
  356. params: 0,
  357. outputFormatter: console.log
  358. }),
  359. new web3._extend.Method({
  360. name: 'memStats',
  361. call: 'debug_memStats',
  362. params: 0,
  363. }),
  364. new web3._extend.Method({
  365. name: 'gcStats',
  366. call: 'debug_gcStats',
  367. params: 0,
  368. }),
  369. new web3._extend.Method({
  370. name: 'cpuProfile',
  371. call: 'debug_cpuProfile',
  372. params: 2
  373. }),
  374. new web3._extend.Method({
  375. name: 'startCPUProfile',
  376. call: 'debug_startCPUProfile',
  377. params: 1
  378. }),
  379. new web3._extend.Method({
  380. name: 'stopCPUProfile',
  381. call: 'debug_stopCPUProfile',
  382. params: 0
  383. }),
  384. new web3._extend.Method({
  385. name: 'goTrace',
  386. call: 'debug_goTrace',
  387. params: 2
  388. }),
  389. new web3._extend.Method({
  390. name: 'startGoTrace',
  391. call: 'debug_startGoTrace',
  392. params: 1
  393. }),
  394. new web3._extend.Method({
  395. name: 'stopGoTrace',
  396. call: 'debug_stopGoTrace',
  397. params: 0
  398. }),
  399. new web3._extend.Method({
  400. name: 'blockProfile',
  401. call: 'debug_blockProfile',
  402. params: 2
  403. }),
  404. new web3._extend.Method({
  405. name: 'setBlockProfileRate',
  406. call: 'debug_setBlockProfileRate',
  407. params: 1
  408. }),
  409. new web3._extend.Method({
  410. name: 'writeBlockProfile',
  411. call: 'debug_writeBlockProfile',
  412. params: 1
  413. }),
  414. new web3._extend.Method({
  415. name: 'writeMemProfile',
  416. call: 'debug_writeMemProfile',
  417. params: 1
  418. }),
  419. new web3._extend.Method({
  420. name: 'traceTransaction',
  421. call: 'debug_traceTransaction',
  422. params: 2,
  423. inputFormatter: [null, null]
  424. })
  425. ],
  426. properties: []
  427. });
  428. `
  429. const Eth_JS = `
  430. web3._extend({
  431. property: 'eth',
  432. methods:
  433. [
  434. new web3._extend.Method({
  435. name: 'sign',
  436. call: 'eth_sign',
  437. params: 2,
  438. inputFormatter: [web3._extend.formatters.inputAddressFormatter, null]
  439. }),
  440. new web3._extend.Method({
  441. name: 'resend',
  442. call: 'eth_resend',
  443. params: 3,
  444. inputFormatter: [web3._extend.formatters.inputTransactionFormatter, web3._extend.utils.fromDecimal, web3._extend.utils.fromDecimal]
  445. }),
  446. new web3._extend.Method({
  447. name: 'getNatSpec',
  448. call: 'eth_getNatSpec',
  449. params: 1,
  450. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  451. }),
  452. new web3._extend.Method({
  453. name: 'signTransaction',
  454. call: 'eth_signTransaction',
  455. params: 1,
  456. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  457. }),
  458. new web3._extend.Method({
  459. name: 'submitTransaction',
  460. call: 'eth_submitTransaction',
  461. params: 1,
  462. inputFormatter: [web3._extend.formatters.inputTransactionFormatter]
  463. }),
  464. new web3._extend.Method({
  465. name: 'getRawTransaction',
  466. call: 'eth_getRawTransactionByHash',
  467. params: 1
  468. }),
  469. new web3._extend.Method({
  470. name: 'getRawTransactionFromBlock',
  471. call: function(args) {
  472. return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getRawTransactionByBlockHashAndIndex' : 'eth_getRawTransactionByBlockNumberAndIndex';
  473. },
  474. params: 2,
  475. inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
  476. })
  477. ],
  478. properties:
  479. [
  480. new web3._extend.Property({
  481. name: 'pendingTransactions',
  482. getter: 'eth_pendingTransactions',
  483. outputFormatter: function(txs) {
  484. var formatted = [];
  485. for (var i = 0; i < txs.length; i++) {
  486. formatted.push(web3._extend.formatters.outputTransactionFormatter(txs[i]));
  487. formatted[i].blockHash = null;
  488. }
  489. return formatted;
  490. }
  491. })
  492. ]
  493. });
  494. `
  495. const Miner_JS = `
  496. web3._extend({
  497. property: 'miner',
  498. methods:
  499. [
  500. new web3._extend.Method({
  501. name: 'start',
  502. call: 'miner_start',
  503. params: 1,
  504. inputFormatter: [null]
  505. }),
  506. new web3._extend.Method({
  507. name: 'stop',
  508. call: 'miner_stop'
  509. }),
  510. new web3._extend.Method({
  511. name: 'setEtherbase',
  512. call: 'miner_setEtherbase',
  513. params: 1,
  514. inputFormatter: [web3._extend.formatters.inputAddressFormatter]
  515. }),
  516. new web3._extend.Method({
  517. name: 'setExtra',
  518. call: 'miner_setExtra',
  519. params: 1
  520. }),
  521. new web3._extend.Method({
  522. name: 'setGasPrice',
  523. call: 'miner_setGasPrice',
  524. params: 1,
  525. inputFormatter: [web3._extend.utils.fromDecimal]
  526. }),
  527. new web3._extend.Method({
  528. name: 'startAutoDAG',
  529. call: 'miner_startAutoDAG',
  530. params: 0
  531. }),
  532. new web3._extend.Method({
  533. name: 'stopAutoDAG',
  534. call: 'miner_stopAutoDAG',
  535. params: 0
  536. }),
  537. new web3._extend.Method({
  538. name: 'makeDAG',
  539. call: 'miner_makeDAG',
  540. params: 1,
  541. inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter]
  542. })
  543. ],
  544. properties: []
  545. });
  546. `
  547. const Net_JS = `
  548. web3._extend({
  549. property: 'net',
  550. methods: [],
  551. properties:
  552. [
  553. new web3._extend.Property({
  554. name: 'version',
  555. getter: 'net_version'
  556. })
  557. ]
  558. });
  559. `
  560. const Personal_JS = `
  561. web3._extend({
  562. property: 'personal',
  563. methods:
  564. [
  565. new web3._extend.Method({
  566. name: 'importRawKey',
  567. call: 'personal_importRawKey',
  568. params: 2
  569. }),
  570. new web3._extend.Method({
  571. name: 'sendTransaction',
  572. call: 'personal_sendTransaction',
  573. params: 2,
  574. inputFormatter: [web3._extend.formatters.inputTransactionFormatter, null]
  575. })
  576. ]
  577. });
  578. `
  579. const RPC_JS = `
  580. web3._extend({
  581. property: 'rpc',
  582. methods: [],
  583. properties:
  584. [
  585. new web3._extend.Property({
  586. name: 'modules',
  587. getter: 'rpc_modules'
  588. })
  589. ]
  590. });
  591. `
  592. const Shh_JS = `
  593. web3._extend({
  594. property: 'shh',
  595. methods: [],
  596. properties:
  597. [
  598. new web3._extend.Property({
  599. name: 'version',
  600. getter: 'shh_version',
  601. outputFormatter: web3._extend.utils.toDecimal
  602. })
  603. ]
  604. });
  605. `
  606. const TxPool_JS = `
  607. web3._extend({
  608. property: 'txpool',
  609. methods: [],
  610. properties:
  611. [
  612. new web3._extend.Property({
  613. name: 'content',
  614. getter: 'txpool_content'
  615. }),
  616. new web3._extend.Property({
  617. name: 'inspect',
  618. getter: 'txpool_inspect'
  619. }),
  620. new web3._extend.Property({
  621. name: 'status',
  622. getter: 'txpool_status',
  623. outputFormatter: function(status) {
  624. status.pending = web3._extend.utils.toDecimal(status.pending);
  625. status.queued = web3._extend.utils.toDecimal(status.queued);
  626. return status;
  627. }
  628. })
  629. ]
  630. });
  631. `