utils.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package api
  2. import (
  3. "strings"
  4. "fmt"
  5. "github.com/ethereum/go-ethereum/eth"
  6. "github.com/ethereum/go-ethereum/rpc/codec"
  7. "github.com/ethereum/go-ethereum/xeth"
  8. )
  9. var (
  10. // Mapping between the different methods each api supports
  11. AutoCompletion = map[string][]string{
  12. "admin": []string{
  13. "addPeer",
  14. "peers",
  15. "nodeInfo",
  16. "exportChain",
  17. "importChain",
  18. "verbosity",
  19. "chainSyncStatus",
  20. "setSolc",
  21. "datadir",
  22. },
  23. "debug": []string{
  24. "dumpBlock",
  25. "getBlockRlp",
  26. "printBlock",
  27. "processBlock",
  28. "seedHash",
  29. "setHead",
  30. },
  31. "eth": []string{
  32. "accounts",
  33. "blockNumber",
  34. "getBalance",
  35. "protocolVersion",
  36. "coinbase",
  37. "mining",
  38. "gasPrice",
  39. "getStorage",
  40. "storageAt",
  41. "getStorageAt",
  42. "getTransactionCount",
  43. "getBlockTransactionCountByHash",
  44. "getBlockTransactionCountByNumber",
  45. "getUncleCountByBlockHash",
  46. "getUncleCountByBlockNumber",
  47. "getData",
  48. "getCode",
  49. "sign",
  50. "sendRawTransaction",
  51. "sendTransaction",
  52. "transact",
  53. "estimateGas",
  54. "call",
  55. "flush",
  56. "getBlockByHash",
  57. "getBlockByNumber",
  58. "getTransactionByHash",
  59. "getTransactionByBlockHashAndIndex",
  60. "getUncleByBlockHashAndIndex",
  61. "getUncleByBlockNumberAndIndex",
  62. "getCompilers",
  63. "compileSolidity",
  64. "newFilter",
  65. "newBlockFilter",
  66. "newPendingTransactionFilter",
  67. "uninstallFilter",
  68. "getFilterChanges",
  69. "getFilterLogs",
  70. "getLogs",
  71. "hashrate",
  72. "getWork",
  73. "submitWork",
  74. },
  75. "miner": []string{
  76. "hashrate",
  77. "makeDAG",
  78. "setExtra",
  79. "setGasPrice",
  80. "startAutoDAG",
  81. "start",
  82. "stopAutoDAG",
  83. "stop",
  84. },
  85. "net": []string{
  86. "peerCount",
  87. "listening",
  88. },
  89. "personal": []string{
  90. "listAccounts",
  91. "newAccount",
  92. "deleteAccount",
  93. "unlockAccount",
  94. },
  95. "shh": []string{
  96. "version",
  97. "post",
  98. "hasIdentity",
  99. "newIdentity",
  100. "newFilter",
  101. "uninstallFilter",
  102. "getFilterChanges",
  103. },
  104. "txpool": []string{
  105. "status",
  106. },
  107. "web3": []string{
  108. "sha3",
  109. "version",
  110. "fromWei",
  111. "toWei",
  112. "toHex",
  113. "toAscii",
  114. "fromAscii",
  115. "toBigNumber",
  116. "isAddress",
  117. },
  118. }
  119. )
  120. // Parse a comma separated API string to individual api's
  121. func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.Ethereum) ([]EthereumApi, error) {
  122. if len(strings.TrimSpace(apistr)) == 0 {
  123. return nil, fmt.Errorf("Empty apistr provided")
  124. }
  125. names := strings.Split(apistr, ",")
  126. apis := make([]EthereumApi, len(names))
  127. for i, name := range names {
  128. switch strings.ToLower(strings.TrimSpace(name)) {
  129. case AdminApiName:
  130. apis[i] = NewAdminApi(xeth, eth, codec)
  131. case DebugApiName:
  132. apis[i] = NewDebugApi(xeth, eth, codec)
  133. case EthApiName:
  134. apis[i] = NewEthApi(xeth, codec)
  135. case MinerApiName:
  136. apis[i] = NewMinerApi(eth, codec)
  137. case NetApiName:
  138. apis[i] = NewNetApi(xeth, eth, codec)
  139. case ShhApiName:
  140. apis[i] = NewShhApi(xeth, eth, codec)
  141. case TxPoolApiName:
  142. apis[i] = NewTxPoolApi(xeth, eth, codec)
  143. case PersonalApiName:
  144. apis[i] = NewPersonalApi(xeth, eth, codec)
  145. case Web3ApiName:
  146. apis[i] = NewWeb3Api(xeth, codec)
  147. default:
  148. return nil, fmt.Errorf("Unknown API '%s'", name)
  149. }
  150. }
  151. return apis, nil
  152. }
  153. func Javascript(name string) string {
  154. switch strings.ToLower(strings.TrimSpace(name)) {
  155. case AdminApiName:
  156. return Admin_JS
  157. case DebugApiName:
  158. return Debug_JS
  159. case MinerApiName:
  160. return Miner_JS
  161. case NetApiName:
  162. return Net_JS
  163. case ShhApiName:
  164. return Shh_JS
  165. case TxPoolApiName:
  166. return TxPool_JS
  167. case PersonalApiName:
  168. return Personal_JS
  169. }
  170. return ""
  171. }