-
Notifications
You must be signed in to change notification settings - Fork 51
/
params.go
120 lines (110 loc) · 2.63 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
package types
import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"gopkg.in/yaml.v2"
)
// NewParams creates a new Params instance
func NewParams(
minCommissionRate sdk.Dec,
maxVotingPower sdk.Dec,
minSelfDelegation math.Int,
brokerAddress string,
totalBlocksPerYear int64,
rewardsDataLifeTime int64,
wasmMaxLabelSize math.Int,
wasmMaxSize math.Int,
wasmMaxProposalWasmSize math.Int,
) Params {
return Params{
MinCommissionRate: minCommissionRate,
MaxVotingPower: maxVotingPower,
MinSelfDelegation: minSelfDelegation,
BrokerAddress: brokerAddress,
TotalBlocksPerYear: totalBlocksPerYear,
RewardsDataLifetime: rewardsDataLifeTime,
WasmMaxLabelSize: wasmMaxLabelSize,
WasmMaxSize: wasmMaxSize,
WasmMaxProposalWasmSize: wasmMaxProposalWasmSize,
}
}
// DefaultParams returns a default set of parameters
func DefaultParams() Params {
return NewParams(
sdk.NewDecWithPrec(5, 2),
sdk.NewDec(100),
sdk.OneInt(),
"elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l",
6307200,
86400, // 1 day
sdk.NewInt(256), //128*2
sdk.NewInt(1638400), //819200 * 2
sdk.NewInt(6291456), //3145728 * 2
)
}
// Validate validates the set of params
func (p Params) Validate() error {
if err := validateMinCommissionRate(p.MinCommissionRate); err != nil {
return err
}
if err := validateMaxVotingPower(p.MaxVotingPower); err != nil {
return err
}
if err := validateMinSelfDelegation(p.MinSelfDelegation); err != nil {
return err
}
if err := validateBrokerAddress(p.BrokerAddress); err != nil {
return err
}
return nil
}
// String implements the Stringer interface.
func (p Params) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}
func validateMinCommissionRate(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return ErrInvalidMinCommissionRate
}
if v.IsNegative() {
return ErrInvalidMinCommissionRate
}
return nil
}
func validateMaxVotingPower(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return ErrInvalidMaxVotingPower
}
if v.IsNegative() {
return ErrInvalidMaxVotingPower
}
return nil
}
func validateMinSelfDelegation(i interface{}) error {
v, ok := i.(math.Int)
if !ok {
return ErrInvalidMinSelfDelegation
}
if v.IsNegative() {
return ErrInvalidMinSelfDelegation
}
return nil
}
func validateBrokerAddress(i interface{}) error {
v, ok := i.(string)
if !ok {
return ErrInvalidBrokerAddress
}
if v == "" {
return ErrInvalidBrokerAddress
}
return nil
}
// String implements the Stringer interface.
func (p LegacyParams) String() string {
out, _ := yaml.Marshal(p)
return string(out)
}