cosmos-sdk/x/distribution/types/genesis.go

70 lines
2.6 KiB
Go
Raw Normal View History

2018-09-17 20:02:15 -07:00
package types
2018-10-04 15:29:03 -07:00
import 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"`
}
2018-09-17 20:02:15 -07:00
// GenesisState - all distribution state that must be provided at genesis
type GenesisState struct {
2018-09-19 16:00:21 -07:00
FeePool FeePool `json:"fee_pool"`
2018-10-04 17:20:43 -07:00
CommunityTax sdk.Dec `json:"community_tax"`
2018-10-15 13:12:42 -07:00
BaseProposerReward sdk.Dec `json:"base_proposer_reward"`
BonusProposerReward sdk.Dec `json:"bonus_proposer_reward"`
2018-09-19 16:00:21 -07:00
ValidatorDistInfos []ValidatorDistInfo `json:"validator_dist_infos"`
2018-10-05 17:32:06 -07:00
DelegationDistInfos []DelegationDistInfo `json:"delegator_dist_infos"`
2018-09-19 16:00:21 -07:00
DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos"`
PreviousProposer sdk.ConsAddress `json:"previous_proposer"`
2018-09-17 20:02:15 -07:00
}
2018-10-15 13:12:42 -07:00
func NewGenesisState(feePool FeePool, communityTax, baseProposerReward, bonusProposerReward sdk.Dec,
vdis []ValidatorDistInfo, ddis []DelegationDistInfo, dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress) GenesisState {
2018-10-04 17:20:43 -07:00
2018-09-17 20:02:15 -07:00
return GenesisState{
2018-10-04 17:20:43 -07:00
FeePool: feePool,
CommunityTax: communityTax,
2018-10-15 13:12:42 -07:00
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
2018-10-04 17:20:43 -07:00
ValidatorDistInfos: vdis,
2018-10-05 17:32:06 -07:00
DelegationDistInfos: ddis,
2018-10-04 17:20:43 -07:00
DelegatorWithdrawInfos: dwis,
PreviousProposer: pp,
2018-09-17 20:02:15 -07:00
}
}
// get raw genesis raw message for testing
func DefaultGenesisState() GenesisState {
return GenesisState{
2018-10-15 13:12:42 -07:00
FeePool: InitialFeePool(),
CommunityTax: sdk.NewDecWithPrec(2, 2), // 2%
BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1%
BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4%
2018-09-17 20:02:15 -07:00
}
}
2018-10-05 17:32:06 -07:00
// 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%
2018-10-15 13:12:42 -07:00
BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1%
BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4%
2018-10-05 17:32:06 -07:00
ValidatorDistInfos: vdis,
DelegationDistInfos: ddis,
}
}