web3ext.go 12 KB

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