-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
validate.go
55 lines (49 loc) · 1.55 KB
/
validate.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
package ocrbootstrap
import (
"github.com/pelletier/go-toml"
"github.com/pkg/errors"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon"
)
// ValidatedBootstrapSpecToml validates a bootstrap spec that came from TOML
func ValidatedBootstrapSpecToml(tomlString string) (jb job.Job, err error) {
var spec job.BootstrapSpec
tree, err := toml.Load(tomlString)
if err != nil {
return jb, errors.Wrap(err, "toml error on load")
}
// Note this validates all the fields which implement an UnmarshalText
err = tree.Unmarshal(&spec)
if err != nil {
return jb, errors.Wrap(err, "toml unmarshal error on spec")
}
err = tree.Unmarshal(&jb)
if err != nil {
return jb, errors.Wrap(err, "toml unmarshal error on job")
}
jb.BootstrapSpec = &spec
if jb.Type != job.Bootstrap {
return jb, errors.Errorf("the only supported type is currently 'bootstrap', got %s", jb.Type)
}
expected, notExpected := ocrcommon.CloneSet(params), ocrcommon.CloneSet(nonBootstrapParams)
if err := ocrcommon.ValidateExplicitlySetKeys(tree, expected, notExpected, "bootstrap"); err != nil {
return jb, err
}
return jb, nil
}
// Parameters that must be explicitly set by the operator.
var (
params = map[string]struct{}{
"type": {},
"schemaVersion": {},
"contractID": {},
"relay": {},
"relayConfig": {},
}
// Parameters that should not be set
nonBootstrapParams = map[string]struct{}{
"isBootstrapPeer": {},
"juelsPerFeeCoinSource": {},
"observationSource": {},
}
)