web3ext.go 10 KB

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