javascript.go 9.5 KB

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