-
Notifications
You must be signed in to change notification settings - Fork 169
/
params.go
48 lines (40 loc) · 1.11 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
package incentive
import (
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// DefaultParams returns a default set of parameters.
func DefaultParams() Params {
return Params{
MaxUnbondings: 10,
UnbondingDuration: 0,
EmergencyUnbondFee: sdk.MustNewDecFromStr("0.01"),
}
}
// validate a set of params
func (p Params) Validate() error {
if err := validateMaxUnbondings(p.MaxUnbondings); err != nil {
return err
}
if err := validateUnbondingDuration(p.UnbondingDuration); err != nil {
return err
}
return validateEmergencyUnbondFee(p.EmergencyUnbondFee)
}
func validateUnbondingDuration(v int64) error {
// non-negative durations, including zero (instant unbond), are allowed
if v < 0 {
return fmt.Errorf("invalid unbonding duration: %d", v)
}
return nil
}
func validateEmergencyUnbondFee(v sdk.Dec) error {
if v.IsNil() || v.IsNegative() || v.GTE(sdk.OneDec()) {
return fmt.Errorf("invalid emergency unbonding fee: %s, valid values: [0, 1)", v)
}
return nil
}
func validateMaxUnbondings(_ uint32) error {
// max unbondings can be any positive number, or zero for unlimited
return nil
}