/
validate.go
38 lines (34 loc) · 969 Bytes
/
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
package directrequest
import (
"github.com/pelletier/go-toml"
"github.com/pkg/errors"
"github.com/GoPlugin/Plugin/core/services/job"
"github.com/GoPlugin/Plugin/core/services/keystore/keys/ethkey"
)
type DirectRequestToml struct {
ContractAddress ethkey.EIP55Address `toml:"contractAddress"`
}
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}
if jb.Type != job.DirectRequest {
return jb, errors.Errorf("unsupported type %s", jb.Type)
}
if jb.SchemaVersion != uint32(1) {
return jb, errors.Errorf("the only supported schema version is currently 1, got %v", jb.SchemaVersion)
}
return jb, nil
}