-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
config.go
40 lines (34 loc) · 1.02 KB
/
config.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
package ocrcommon
import (
"github.com/pkg/errors"
"github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/chainlink/v2/common/config"
)
type Config interface {
ChainType() config.ChainType
}
func ParseBootstrapPeers(peers []string) (bootstrapPeers []commontypes.BootstrapperLocator, err error) {
for _, bs := range peers {
var bsl commontypes.BootstrapperLocator
err = bsl.UnmarshalText([]byte(bs))
if err != nil {
return nil, err
}
bootstrapPeers = append(bootstrapPeers, bsl)
}
return
}
// GetValidatedBootstrapPeers will error unless at least one valid bootstrap peer is found
func GetValidatedBootstrapPeers(specPeers []string, configPeers []commontypes.BootstrapperLocator) ([]commontypes.BootstrapperLocator, error) {
bootstrapPeers, err := ParseBootstrapPeers(specPeers)
if err != nil {
return nil, err
}
if len(bootstrapPeers) == 0 {
if len(configPeers) == 0 {
return nil, errors.New("no bootstrappers found")
}
return configPeers, nil
}
return bootstrapPeers, nil
}