utils.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // Parse a comma separated API string to individual api's
  10. func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.Ethereum) ([]EthereumApi, error) {
  11. if len(strings.TrimSpace(apistr)) == 0 {
  12. return nil, fmt.Errorf("Empty apistr provided")
  13. }
  14. names := strings.Split(apistr, ",")
  15. apis := make([]EthereumApi, len(names))
  16. for i, name := range names {
  17. switch strings.ToLower(strings.TrimSpace(name)) {
  18. case AdminApiName:
  19. apis[i] = NewAdminApi(xeth, eth, codec)
  20. case DebugApiName:
  21. apis[i] = NewDebugApi(xeth, eth, codec)
  22. case EthApiName:
  23. apis[i] = NewEthApi(xeth, codec)
  24. case MinerApiName:
  25. apis[i] = NewMinerApi(eth, codec)
  26. case NetApiName:
  27. apis[i] = NewNetApi(xeth, eth, codec)
  28. case PersonalApiName:
  29. apis[i] = NewPersonalApi(xeth, eth, codec)
  30. case Web3ApiName:
  31. apis[i] = NewWeb3Api(xeth, codec)
  32. default:
  33. return nil, fmt.Errorf("Unknown API '%s'", name)
  34. }
  35. }
  36. return apis, nil
  37. }
  38. func Javascript(name string) string {
  39. switch strings.ToLower(strings.TrimSpace(name)) {
  40. case AdminApiName:
  41. return Admin_JS
  42. case DebugApiName:
  43. return Debug_JS
  44. case MinerApiName:
  45. return Miner_JS
  46. case NetApiName:
  47. return Net_JS
  48. case PersonalApiName:
  49. return Personal_JS
  50. }
  51. return ""
  52. }