utils.go 799 B

12345678910111213141516171819202122232425262728293031323334
  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 EthApiName:
  19. apis[i] = NewEthApi(xeth, codec)
  20. case Web3ApiName:
  21. apis[i] = NewWeb3(xeth, codec)
  22. default:
  23. return nil, fmt.Errorf("Unknown API '%s'", name)
  24. }
  25. }
  26. return apis, nil
  27. }