web3ext.go 9.8 KB

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