-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathflags.go
35 lines (26 loc) · 907 Bytes
/
flags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package xchain
import (
"strconv"
"github.com/omni-network/omni/lib/errors"
"github.com/spf13/pflag"
)
type RPCEndpoints map[string]string
func (e RPCEndpoints) ByNameOrID(name string, chainID uint64) (string, error) {
if val := e[name]; val != "" {
return val, nil
} else if val := e[strconv.FormatUint(chainID, 10)]; val != "" {
return val, nil
}
return "", errors.New("no rpc endpoint for chain", "chain_name", name, "chain_id", chainID)
}
func (e RPCEndpoints) Keys() []string {
keys := make([]string, 0, len(e))
for k := range e {
keys = append(keys, k)
}
return keys
}
// BindFlags binds the xchain evm rpc flag.
func BindFlags(flags *pflag.FlagSet, endpoints *RPCEndpoints) {
flags.StringToStringVar((*map[string]string)(endpoints), "xchain-evm-rpc-endpoints", *endpoints, "Cross-chain EVM RPC endpoints. e.g. \"ethereum=http://geth:8545,optimism=https://optimism.io\"")
}