-
Notifications
You must be signed in to change notification settings - Fork 20
/
params.go
63 lines (49 loc) · 1.36 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
package types
import (
"fmt"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/params/subspace"
)
const (
DefaultParamspace = ModuleName
)
var (
DefaultRewardsBlockInterval int64 = 483840 // average block time is 5s, 17280 blocks a day, 28 days
)
var (
KeyRewardsBlockInterval = []byte("RewardsBlockInterval")
)
type Params struct {
RewardsBlockInterval int64 `json:"rewards_block_interval" yaml:"rewards_block_interval"`
}
// ParamKeyTable for token module
func ParamKeyTable() subspace.KeyTable {
return subspace.NewKeyTable().RegisterParamSet(&Params{})
}
func (p *Params) ParamSetPairs() subspace.ParamSetPairs {
return subspace.ParamSetPairs{
params.NewParamSetPair(KeyRewardsBlockInterval, &p.RewardsBlockInterval, validateRewardsBlockInterval),
}
}
// DefaultParams returns a default set of parameters.
func DefaultParams() Params {
return Params{
RewardsBlockInterval: DefaultRewardsBlockInterval,
}
}
func validateRewardsBlockInterval(i interface{}) error {
v, ok := i.(int64)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v < 1 {
return fmt.Errorf("invalid value: should be greater then 0")
}
return nil
}
func (p Params) Validate() error {
if err := validateRewardsBlockInterval(p.RewardsBlockInterval); err != nil {
return fmt.Errorf("invalid rewards_block_interval: %w", err)
}
return nil
}