-
Notifications
You must be signed in to change notification settings - Fork 3
/
params.go
136 lines (112 loc) · 3.97 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
package types
import (
"fmt"
"gopkg.in/yaml.v2"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
// Parameter store keys
var (
KeyPrivatePlanCreationFee = []byte("PrivatePlanCreationFee")
KeyNextEpochDays = []byte("NextEpochDays")
KeyFarmingFeeCollector = []byte("FarmingFeeCollector")
KeyDelayedStakingGasFee = []byte("DelayedStakingGasFee")
DefaultPrivatePlanCreationFee = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100_000_000)))
DefaultCurrentEpochDays = uint32(1)
DefaultNextEpochDays = uint32(1)
DefaultFarmingFeeCollector = sdk.AccAddress(address.Module(ModuleName, []byte("FarmingFeeCollectorAcc")))
DefaultDelayedStakingGasFee = sdk.Gas(60000) // See https://github.com/tendermint/farming/issues/102 for details.
// ReserveAddressType is an address type of reserve accounts for staking or rewards.
// The module uses the address type of 32 bytes length, but it can be changed depending on Cosmos SDK's direction.
// The discussion around this issue can be found in this link.
// https://github.com/tendermint/farming/issues/200
ReserveAddressType = AddressType32Bytes
RewardsReserveAcc = DeriveAddress(ReserveAddressType, ModuleName, RewardReserveAccPrefix)
)
var _ paramstypes.ParamSet = (*Params)(nil)
// ParamKeyTable returns the parameter key table.
func ParamKeyTable() paramstypes.KeyTable {
return paramstypes.NewKeyTable().RegisterParamSet(&Params{})
}
// DefaultParams returns the default farming module parameters.
func DefaultParams() Params {
return Params{
PrivatePlanCreationFee: DefaultPrivatePlanCreationFee,
NextEpochDays: DefaultNextEpochDays,
FarmingFeeCollector: DefaultFarmingFeeCollector.String(),
DelayedStakingGasFee: DefaultDelayedStakingGasFee,
}
}
// ParamSetPairs implements paramstypes.ParamSet.
func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {
return paramstypes.ParamSetPairs{
paramstypes.NewParamSetPair(KeyPrivatePlanCreationFee, &p.PrivatePlanCreationFee, validatePrivatePlanCreationFee),
paramstypes.NewParamSetPair(KeyNextEpochDays, &p.NextEpochDays, validateNextEpochDays),
paramstypes.NewParamSetPair(KeyFarmingFeeCollector, &p.FarmingFeeCollector, validateFarmingFeeCollector),
paramstypes.NewParamSetPair(KeyDelayedStakingGasFee, &p.DelayedStakingGasFee, validateDelayedStakingGas),
}
}
// String returns a human readable string representation of the parameters.
func (p Params) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
// Validate validates parameters.
func (p Params) Validate() error {
for _, v := range []struct {
value interface{}
validator func(interface{}) error
}{
{p.PrivatePlanCreationFee, validatePrivatePlanCreationFee},
{p.NextEpochDays, validateNextEpochDays},
{p.FarmingFeeCollector, validateFarmingFeeCollector},
{p.DelayedStakingGasFee, validateDelayedStakingGas},
} {
if err := v.validator(v.value); err != nil {
return err
}
}
return nil
}
func validatePrivatePlanCreationFee(i interface{}) error {
v, ok := i.(sdk.Coins)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if err := v.Validate(); err != nil {
return err
}
return nil
}
func validateNextEpochDays(i interface{}) error {
v, ok := i.(uint32)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v <= 0 {
return fmt.Errorf("next epoch days must be positive: %d", v)
}
return nil
}
func validateFarmingFeeCollector(i interface{}) error {
v, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v == "" {
return fmt.Errorf("farming fee collector address must not be empty")
}
_, err := sdk.AccAddressFromBech32(v)
if err != nil {
return fmt.Errorf("invalid account address: %v", v)
}
return nil
}
func validateDelayedStakingGas(i interface{}) error {
_, ok := i.(sdk.Gas)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}