/
validate.go
50 lines (45 loc) · 1.57 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
package directrequest
import (
"github.com/pelletier/go-toml"
"github.com/pkg/errors"
"github.com/smartcontractkit/chainlink/core/assets"
"github.com/smartcontractkit/chainlink/core/null"
"github.com/smartcontractkit/chainlink/core/services/job"
"github.com/smartcontractkit/chainlink/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/core/store/models"
"github.com/smartcontractkit/chainlink/core/utils"
)
type DirectRequestToml struct {
ContractAddress ethkey.EIP55Address `toml:"contractAddress"`
Requesters models.AddressCollection `toml:"requesters"`
MinContractPayment *assets.Link `toml:"minContractPaymentLinkJuels"`
EVMChainID *utils.Big `toml:"evmChainID"`
MinIncomingConfirmations null.Uint32 `toml:"minIncomingConfirmations"`
}
func ValidatedDirectRequestSpec(tomlString string) (job.Job, error) {
var jb = job.Job{}
tree, err := toml.Load(tomlString)
if err != nil {
return jb, err
}
err = tree.Unmarshal(&jb)
if err != nil {
return jb, err
}
var spec DirectRequestToml
err = tree.Unmarshal(&spec)
if err != nil {
return jb, err
}
jb.DirectRequestSpec = &job.DirectRequestSpec{
ContractAddress: spec.ContractAddress,
Requesters: spec.Requesters,
MinContractPayment: spec.MinContractPayment,
EVMChainID: spec.EVMChainID,
MinIncomingConfirmations: spec.MinIncomingConfirmations,
}
if jb.Type != job.DirectRequest {
return jb, errors.Errorf("unsupported type %s", jb.Type)
}
return jb, nil
}