-
Notifications
You must be signed in to change notification settings - Fork 28
/
params.go
72 lines (58 loc) · 1.77 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
package types
import (
"fmt"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var maxTotalBypassMinFeeMsgGasUsage = 2_000_000
// DefaultParams returns default parameters
func DefaultParams() Params {
return Params{
MinimumGasPrices: sdk.DecCoins(nil),
BypassMinFeeMsgTypes: []string{},
MaxTotalBypassMinFeeMsgGasUsage: uint64(maxTotalBypassMinFeeMsgGasUsage),
}
}
// Validate performs basic validation.
func (p Params) Validate() error {
return validateMinimumGasPrices(p.MinimumGasPrices)
}
// this requires the fee non-negative
func validateMinimumGasPrices(i interface{}) error {
v, ok := i.(sdk.DecCoins)
if !ok {
return errorsmod.Wrapf(sdkerrors.ErrInvalidType, "type: %T, expected sdk.DecCoins", i)
}
dec := DecCoins(v)
return dec.Validate()
}
type DecCoins sdk.DecCoins
// Validate checks that the DecCoins are sorted, have non-negtive amount, with a valid and unique
// denomination (i.e no duplicates). Otherwise, it returns an error.
func (coins DecCoins) Validate() error {
if len(coins) == 0 {
return nil
}
lowDenom := ""
seenDenoms := make(map[string]bool)
for i, coin := range coins {
if seenDenoms[coin.Denom] {
return fmt.Errorf("duplicate denomination %s", coin.Denom)
}
if err := sdk.ValidateDenom(coin.Denom); err != nil {
return err
}
// skip the denom order check for the first denom in the coins list
if i != 0 && coin.Denom <= lowDenom {
return fmt.Errorf("denomination %s is not sorted", coin.Denom)
}
if coin.IsNegative() {
return fmt.Errorf("coin %s amount is negative", coin.Amount)
}
// we compare each coin against the last denom
lowDenom = coin.Denom
seenDenoms[coin.Denom] = true
}
return nil
}