-
Notifications
You must be signed in to change notification settings - Fork 42
/
params.go
145 lines (112 loc) · 3.41 KB
/
params.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
var ParamStoreKeyFeeParams = []byte("feeparams")
// ParamKeyTable returns the key declaration for parameters
func ParamKeyTable() paramstypes.KeyTable {
return paramstypes.NewKeyTable(
paramstypes.NewParamSetPair(ParamStoreKeyFeeParams, FeeParams{}, validateFeeParams),
)
}
// DefaultFeeParams returns default cheqd module tx fee parameters
func DefaultFeeParams() *FeeParams {
return &FeeParams{
Image: sdk.NewCoin(BaseMinimalDenom, sdk.NewInt(DefaultCreateResourceImageFee)),
Json: sdk.NewCoin(BaseMinimalDenom, sdk.NewInt(DefaultCreateResourceJSONFee)),
Default: sdk.NewCoin(BaseMinimalDenom, sdk.NewInt(DefaultCreateResourceDefaultFee)),
BurnFactor: sdk.MustNewDecFromStr(DefaultBurnFactor),
}
}
// ValidateBasic performs basic validation of cheqd module tx fee parameters
func (tfp *FeeParams) ValidateBasic() error {
if !tfp.Image.IsPositive() || tfp.Image.Denom != BaseMinimalDenom {
return fmt.Errorf("invalid create resource image tx fee: %s", tfp.Image)
}
if !tfp.Json.IsPositive() || tfp.Json.Denom != BaseMinimalDenom {
return fmt.Errorf("invalid create resource json tx fee: %s", tfp.Json)
}
if !tfp.Json.IsPositive() || tfp.Json.Denom != BaseMinimalDenom {
return fmt.Errorf("invalid create resource default tx fee: %s", tfp.Json)
}
if !tfp.BurnFactor.IsPositive() || tfp.BurnFactor.GTE(sdk.OneDec()) {
return fmt.Errorf("invalid burn factor: %s", tfp.BurnFactor)
}
return nil
}
func validateImage(i interface{}) error {
v, ok := i.(sdk.Coin)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("create resource image msg fee param must not be nil")
}
if !v.IsPositive() {
return fmt.Errorf("create resource image msg fee param must be positive coin: %s", v)
}
return nil
}
func validateJSON(i interface{}) error {
v, ok := i.(sdk.Coin)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("create resource json msg fee param must not be nil")
}
if !v.IsPositive() {
return fmt.Errorf("create resource json msg fee param must be positive coin: %s", v)
}
return nil
}
func validateDefault(i interface{}) error {
v, ok := i.(sdk.Coin)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("create resource default msg fee param must not be nil")
}
if !v.IsPositive() {
return fmt.Errorf("create resource default msg fee param must be positive coin: %s", v)
}
return nil
}
func validateBurnFactor(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.IsNil() {
return fmt.Errorf("burn factor must not be nil")
}
if v.IsNegative() {
return fmt.Errorf("burn factor must not be negative: %s", v)
}
if v.GTE(sdk.OneDec()) {
return fmt.Errorf("burn factor must be less than 1: %s", v)
}
return nil
}
func validateFeeParams(i interface{}) error {
v, ok := i.(FeeParams)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if err := validateImage(v.Image); err != nil {
return err
}
if err := validateJSON(v.Json); err != nil {
return err
}
if err := validateDefault(v.Default); err != nil {
return err
}
if err := validateBurnFactor(v.BurnFactor); err != nil {
return err
}
return v.ValidateBasic()
}