web3ext.go 9.9 KB

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