This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
genesis.go
96 lines (84 loc) · 3.59 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
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// the address for where distributions rewards are withdrawn to by default
// this struct is only used at genesis to feed in default withdraw addresses
type DelegatorWithdrawInfo struct {
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
WithdrawAddr sdk.AccAddress `json:"withdraw_addr"`
}
// GenesisState - all distribution state that must be provided at genesis
type GenesisState struct {
FeePool FeePool `json:"fee_pool"`
CommunityTax sdk.Dec `json:"community_tax"`
BaseProposerReward sdk.Dec `json:"base_proposer_reward"`
BonusProposerReward sdk.Dec `json:"bonus_proposer_reward"`
ValidatorDistInfos []ValidatorDistInfo `json:"validator_dist_infos"`
DelegationDistInfos []DelegationDistInfo `json:"delegator_dist_infos"`
DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos"`
PreviousProposer sdk.ConsAddress `json:"previous_proposer"`
}
func NewGenesisState(feePool FeePool, communityTax, baseProposerReward, bonusProposerReward sdk.Dec,
vdis []ValidatorDistInfo, ddis []DelegationDistInfo, dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress) GenesisState {
return GenesisState{
FeePool: feePool,
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
ValidatorDistInfos: vdis,
DelegationDistInfos: ddis,
DelegatorWithdrawInfos: dwis,
PreviousProposer: pp,
}
}
// get raw genesis raw message for testing
func DefaultGenesisState() GenesisState {
return GenesisState{
FeePool: InitialFeePool(),
CommunityTax: sdk.NewDecWithPrec(2, 2), // 2%
BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1%
BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4%
}
}
// default genesis utility function, initialize for starting validator set
func DefaultGenesisWithValidators(valAddrs []sdk.ValAddress) GenesisState {
vdis := make([]ValidatorDistInfo, len(valAddrs))
ddis := make([]DelegationDistInfo, len(valAddrs))
for i, valAddr := range valAddrs {
vdis[i] = NewValidatorDistInfo(valAddr, 0)
accAddr := sdk.AccAddress(valAddr)
ddis[i] = NewDelegationDistInfo(accAddr, valAddr, 0)
}
return GenesisState{
FeePool: InitialFeePool(),
CommunityTax: sdk.NewDecWithPrec(2, 2), // 2%
BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1%
BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4%
ValidatorDistInfos: vdis,
DelegationDistInfos: ddis,
}
}
// ValidateGenesis validates the genesis state of distribution genesis input
func ValidateGenesis(data GenesisState) error {
if data.CommunityTax.IsNegative() || data.CommunityTax.GT(sdk.OneDec()) {
return fmt.Errorf("mint parameter CommunityTax should non-negative and "+
"less than one, is %s", data.CommunityTax.String())
}
if data.BaseProposerReward.IsNegative() {
return fmt.Errorf("mint parameter BaseProposerReward should be positive, is %s",
data.BaseProposerReward.String())
}
if data.BonusProposerReward.IsNegative() {
return fmt.Errorf("mint parameter BonusProposerReward should be positive, is %s",
data.BonusProposerReward.String())
}
if (data.BaseProposerReward.Add(data.BonusProposerReward)).
GT(sdk.OneDec()) {
return fmt.Errorf("mint parameters BaseProposerReward and "+
"BonusProposerReward cannot add to be greater than one, "+
"adds to %s", data.BaseProposerReward.Add(data.BonusProposerReward).String())
}
return data.FeePool.ValidateGenesis()
}