utils.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 DebugApiName:
  19. apis[i] = NewDebugApi(xeth, eth, codec)
  20. case EthApiName:
  21. apis[i] = NewEthApi(xeth, codec)
  22. case MinerApiName:
  23. apis[i] = NewMinerApi(eth, codec)
  24. case NetApiName:
  25. apis[i] = NewNetApi(xeth, eth, codec)
  26. case Web3ApiName:
  27. apis[i] = NewWeb3(xeth, codec)
  28. default:
  29. return nil, fmt.Errorf("Unknown API '%s'", name)
  30. }
  31. }
  32. return apis, nil
  33. }
  34. func Javascript(name string) string {
  35. switch strings.ToLower(strings.TrimSpace(name)) {
  36. case DebugApiName:
  37. return Debug_JS
  38. case MinerApiName:
  39. return Miner_JS
  40. case NetApiName:
  41. return Net_JS
  42. }
  43. return ""
  44. }