-
Notifications
You must be signed in to change notification settings - Fork 8
/
params.go
61 lines (50 loc) · 1.57 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
package types
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
// validator params default values
const (
// DefaultHistorical entries is 100. Apps that don't use IBC can ignore this
// value by not adding the staking module to the application module manager's
// SetOrderBeginBlockers.
DefaultHistoricalEntries uint32 = 100
)
var (
KeyHistoricalEntries = []byte("HistoricalEntries")
)
var _ paramtypes.ParamSet = (*Params)(nil)
// NewParams creates a new Params instance
func NewParams(historicalEntries uint32) Params {
return Params{HistoricalEntries: historicalEntries}
}
// Implements params.ParamSet
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyHistoricalEntries, &p.HistoricalEntries, validateHistoricalEntries),
}
}
// DefaultParams returns a default set of parameters.
func DefaultParams() Params {
return NewParams(DefaultHistoricalEntries)
}
// unmarshal the current staking params value from store key or panic
func MustUnmarshalParams(cdc *codec.LegacyAmino, value []byte) Params {
params, err := UnmarshalParams(cdc, value)
if err != nil {
panic(err)
}
return params
}
// unmarshal the current staking params value from store key
func UnmarshalParams(cdc *codec.LegacyAmino, value []byte) (params Params, err error) {
err = cdc.Unmarshal(value, ¶ms)
return
}
func validateHistoricalEntries(i interface{}) error {
if _, ok := i.(uint32); !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}