-
Notifications
You must be signed in to change notification settings - Fork 31
/
genesis.go
104 lines (84 loc) · 2.56 KB
/
genesis.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
package types
import (
"fmt"
)
var (
defaultGenesisState = GenesisState{
Params: Params{
PoolCreationFee: DefaultPoolCreationFee,
TaxRate: DefaulttTaxRate,
MaxRewardCategories: DefaultMaxRewardCategories,
},
}
)
// NewGenesisState constructs a new GenesisState instance
func NewGenesisState(params Params, pools []FarmPool, farmInfos []FarmInfo, sequence uint64, escrow []EscrowInfo) *GenesisState {
return &GenesisState{
params, pools, farmInfos, sequence, escrow,
}
}
// DefaultGenesisState gets the default genesis state for testing
func DefaultGenesisState() *GenesisState {
return &defaultGenesisState
}
func SetDefaultGenesisState(state GenesisState) {
defaultGenesisState = state
}
// ValidateGenesis validates the provided farm genesis state to ensure the
// expected invariants holds.
func ValidateGenesis(data GenesisState) error {
var maxSeq uint64
for _, pool := range data.Pools {
seq, err := ValidatepPoolId(pool.Id)
if err != nil {
return err
}
if seq > maxSeq {
maxSeq = seq
}
if err := ValidateDescription(pool.Description); err != nil {
return err
}
if err := ValidateAddress(pool.Creator); err != nil {
return err
}
if err := ValidateCoins("TotalLptLocked", pool.TotalLptLocked); err != nil {
return err
}
for _, r := range pool.Rules {
if err := ValidateLpTokenDenom(r.Reward); err != nil {
return err
}
if !r.TotalReward.IsPositive() {
return fmt.Errorf("totalReward must be positive, but got %s", r.TotalReward.String())
}
if r.RemainingReward.IsNegative() {
return fmt.Errorf("temainingReward must be greater than zero, but got %s", r.RemainingReward.String())
}
if !r.RewardPerBlock.IsPositive() {
return fmt.Errorf("rewardPerBlock must be positive, but got %s", r.RewardPerBlock.String())
}
if !r.RewardPerShare.IsPositive() {
return fmt.Errorf("rewardPerShare must be positive, but got %s", r.RewardPerShare.String())
}
}
}
if data.Sequence < maxSeq {
return fmt.Errorf("sequence must be equeal or greater than maxSeq, but got %d, %d", data.Sequence, maxSeq)
}
for _, info := range data.FarmInfos {
if _, err := ValidatepPoolId(info.PoolId); err != nil {
return err
}
if err := ValidateAddress(info.Address); err != nil {
return err
}
if !info.Locked.IsPositive() {
return fmt.Errorf("locked must be positive, but got %s", info.Locked.String())
}
if err := ValidateCoins("RewardDebt", info.RewardDebt...); err != nil {
return err
}
}
return ValidateCoins("PoolCreationFee", data.Params.PoolCreationFee)
}