-
Notifications
You must be signed in to change notification settings - Fork 46
/
genesis.go
107 lines (89 loc) · 3.05 KB
/
genesis.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package types
import (
"bytes"
"fmt"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/ethereum/go-ethereum/common"
)
// DefaultParamspace defines the default auth module parameter subspace
const (
// todo: implement oracle constants as params
DefaultParamspace = ModuleName
)
var (
// Ensure that params implements the proper interface
// nolint: exhaustruct
_ paramtypes.ParamSet = &Params{}
ParamsStoreKeyVerifiedNativeDexAddress = "VerifiedNativeDexAddress"
ParamsStoreKeyVerifiedCrocPolicyAddress = "VerifiedCrocPolicyAddress"
)
// ValidateBasic validates genesis state by looping through the params and
// calling their validation functions
func (s GenesisState) ValidateBasic() error {
if err := s.Params.ValidateBasic(); err != nil {
return sdkerrors.Wrap(err, "params")
}
return nil
}
// DefaultGenesis returns empty genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
Params: *DefaultParams(),
}
}
// DefaultParams returns a copy of the default params
func DefaultParams() *Params {
return &Params{
VerifiedNativeDexAddress: common.BytesToAddress([]byte{0x0}).String(),
VerifiedCrocPolicyAddress: common.BytesToAddress([]byte{0x0}).String(),
}
}
// ValidateBasic checks that the parameters have valid values.
func (p Params) ValidateBasic() error {
if err := validateVerifiedNativeDexAddress(p.VerifiedNativeDexAddress); err != nil {
return sdkerrors.Wrap(err, "VerifiedNativeDexAddress")
}
if err := validateVerifiedCrocPolicyAddress(p.VerifiedCrocPolicyAddress); err != nil {
return sdkerrors.Wrap(err, "VerifiedCrocPolicyAddress")
}
return nil
}
// ParamKeyTable for auth module
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(DefaultParams())
}
// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
// pairs of auth module's parameters.
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair([]byte(ParamsStoreKeyVerifiedNativeDexAddress), &p.VerifiedNativeDexAddress, validateVerifiedNativeDexAddress),
paramtypes.NewParamSetPair([]byte(ParamsStoreKeyVerifiedCrocPolicyAddress), &p.VerifiedCrocPolicyAddress, validateVerifiedCrocPolicyAddress),
}
}
// Equal returns a boolean determining if two Params types are identical.
func (p Params) Equal(p2 Params) bool {
bz1 := ModuleCdc.MustMarshalLengthPrefixed(&p)
bz2 := ModuleCdc.MustMarshalLengthPrefixed(&p2)
return bytes.Equal(bz1, bz2)
}
func validateVerifiedNativeDexAddress(i interface{}) error {
v, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if !common.IsHexAddress(v) {
return sdkerrors.Wrap(ErrInvalidEvmAddress, "invalid address")
}
return nil
}
func validateVerifiedCrocPolicyAddress(i interface{}) error {
v, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if !common.IsHexAddress(v) {
return sdkerrors.Wrap(ErrInvalidEvmAddress, "invalid address")
}
return nil
}