-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
common.go
38 lines (30 loc) · 940 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("chain id does not match any local chains")
ErrEmptyChainID = errors.New("chainID is empty")
ErrInvalidChainID = errors.New("invalid chain id")
ErrMultipleChains = errors.New("more than one chain available, you must specify chain id parameter")
)
func getChain(legacyChains evm.LegacyChainContainer, chainIDstr string) (chain evm.Chain, err error) {
if chainIDstr != "" && chainIDstr != "<nil>" {
// evm keys are expected to be parsable as a big int
_, ok := big.NewInt(0).SetString(chainIDstr, 10)
if !ok {
return nil, ErrInvalidChainID
}
chain, err = legacyChains.Get(chainIDstr)
if err != nil {
return nil, ErrMissingChainID
}
return chain, nil
}
if legacyChains.Len() > 1 {
return nil, ErrMultipleChains
}
return nil, ErrEmptyChainID
}