-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations_validation.go
48 lines (38 loc) · 1.04 KB
/
operations_validation.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
package mcms
import (
"encoding/json"
"fmt"
"math/big"
cselectors "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/mcms/sdk"
"github.com/smartcontractkit/mcms/sdk/evm"
"github.com/smartcontractkit/mcms/types"
)
func ValidateAdditionalFields(additionalFields json.RawMessage, csel types.ChainSelector) error {
chainFamily, err := types.GetChainSelectorFamily(csel)
if err != nil {
return err
}
var validator sdk.Validator
switch chainFamily {
case cselectors.FamilyEVM:
// Unmarshal and validate for EVM
fields := evm.AdditionalFields{
Value: big.NewInt(0),
}
if len(additionalFields) != 0 {
if err := json.Unmarshal(additionalFields, &fields); err != nil {
return fmt.Errorf("failed to unmarshal EVM additional fields: %w", err)
}
}
validator = fields
case cselectors.FamilySolana:
fields := evm.AdditionalFields{Value: big.NewInt(0)}
validator = fields
}
// Call Validate on the chain-specific struct
if err := validator.Validate(); err != nil {
return err
}
return nil
}