-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
common.go
38 lines (32 loc) · 860 Bytes
/
common.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
36
37
38
package web
import (
"math/big"
"github.com/pkg/errors"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm"
)
var (
ErrMissingChainID = errors.New("evmChainID does not match any local chains")
ErrInvalidChainID = errors.New("invalid evmChainID")
ErrMultipleChains = errors.New("more than one chain available, you must specify evmChainID parameter")
)
func getChain(cs evm.ChainSet, chainIDstr string) (chain evm.Chain, err error) {
if chainIDstr != "" && chainIDstr != "<nil>" {
chainID, ok := big.NewInt(0).SetString(chainIDstr, 10)
if !ok {
return nil, ErrInvalidChainID
}
chain, err = cs.Get(chainID)
if err != nil {
return nil, ErrMissingChainID
}
return chain, nil
}
if cs.ChainCount() > 1 {
return nil, ErrMultipleChains
}
chain, err = cs.Default()
if err != nil {
return nil, err
}
return chain, nil
}