web3ext.go 11 KB

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