-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
util.go
73 lines (60 loc) · 2.09 KB
/
util.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package job
import (
"fmt"
"math/big"
"github.com/pkg/errors"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm"
)
var (
ErrNoChainFromSpec = fmt.Errorf("could not get chain from spec")
ErrNoSendingKeysFromSpec = fmt.Errorf("could not get sending keys from spec")
)
// EVMChainForJob parses the job spec and retrieves the evm chain found.
func EVMChainForBootstrapJob(job *Job, set evm.ChainSet) (evm.Chain, error) {
chainIDInterface, ok := job.BootstrapSpec.RelayConfig["chainID"]
if !ok {
return nil, fmt.Errorf("%w: chainID must be provided in relay config", ErrNoChainFromSpec)
}
chainID := chainIDInterface.(int64)
chain, err := set.Get(big.NewInt(chainID))
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrNoChainFromSpec, err)
}
return chain, nil
}
// EVMChainForJob parses the job spec and retrieves the evm chain found.
func EVMChainForJob(job *Job, set evm.ChainSet) (evm.Chain, error) {
chainIDInterface, ok := job.OCR2OracleSpec.RelayConfig["chainID"]
if !ok {
return nil, fmt.Errorf("%w: chainID must be provided in relay config", ErrNoChainFromSpec)
}
chainID := chainIDInterface.(int64)
chain, err := set.Get(big.NewInt(chainID))
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrNoChainFromSpec, err)
}
return chain, nil
}
// SendingKeysForJob parses the job spec and retrieves the sending keys found.
func SendingKeysForJob(job *Job) ([]string, error) {
sendingKeysInterface, ok := job.OCR2OracleSpec.RelayConfig["sendingKeys"]
if !ok {
return nil, fmt.Errorf("%w: sendingKeys must be provided in relay config", ErrNoSendingKeysFromSpec)
}
sendingKeysInterfaceSlice, ok := sendingKeysInterface.([]interface{})
if !ok {
return nil, errors.New("sending keys should be an array")
}
var sendingKeys []string
for _, sendingKeyInterface := range sendingKeysInterfaceSlice {
sendingKey, ok := sendingKeyInterface.(string)
if !ok {
return nil, errors.New("sending keys are of wrong type")
}
sendingKeys = append(sendingKeys, sendingKey)
}
if len(sendingKeys) == 0 {
return nil, errors.New("sending keys are empty")
}
return sendingKeys, nil
}