2018-09-17 20:02:15 -07:00
|
|
|
package types
|
|
|
|
|
2018-12-06 16:22:24 -08:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
2018-10-04 15:29:03 -07:00
|
|
|
|
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// used for import / export via genesis json
|
|
|
|
type ValidatorAccumulatedCommissionRecord struct {
|
|
|
|
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
|
|
|
|
Accumulated ValidatorAccumulatedCommission `json:"accumulated"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// used for import / export via genesis json
|
|
|
|
type ValidatorHistoricalRewardsRecord struct {
|
|
|
|
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
|
|
|
|
Period uint64 `json:"period"`
|
|
|
|
Rewards ValidatorHistoricalRewards `json:"rewards"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// used for import / export via genesis json
|
|
|
|
type ValidatorCurrentRewardsRecord struct {
|
|
|
|
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
|
|
|
|
Rewards ValidatorCurrentRewards `json:"rewards"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// used for import / export via genesis json
|
|
|
|
type DelegatorStartingInfoRecord struct {
|
|
|
|
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
|
|
|
|
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
|
|
|
|
StartingInfo DelegatorStartingInfo `json:"starting_info"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// used for import / export via genesis json
|
|
|
|
type ValidatorSlashEventRecord struct {
|
|
|
|
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
|
|
|
|
Height uint64 `json:"height"`
|
|
|
|
Event ValidatorSlashEvent `json:"validator_slash_event"`
|
|
|
|
}
|
|
|
|
|
2018-09-17 20:02:15 -07:00
|
|
|
// GenesisState - all distribution state that must be provided at genesis
|
|
|
|
type GenesisState struct {
|
2019-01-16 13:38:05 -08:00
|
|
|
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"`
|
|
|
|
DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos"`
|
|
|
|
PreviousProposer sdk.ConsAddress `json:"previous_proposer"`
|
|
|
|
OutstandingRewards sdk.DecCoins `json:"outstanding_rewards"`
|
|
|
|
ValidatorAccumulatedCommissions []ValidatorAccumulatedCommissionRecord `json:"validator_accumulated_commissions"`
|
|
|
|
ValidatorHistoricalRewards []ValidatorHistoricalRewardsRecord `json:"validator_historical_rewards"`
|
|
|
|
ValidatorCurrentRewards []ValidatorCurrentRewardsRecord `json:"validator_current_rewards"`
|
|
|
|
DelegatorStartingInfos []DelegatorStartingInfoRecord `json:"delegator_starting_infos"`
|
|
|
|
ValidatorSlashEvents []ValidatorSlashEventRecord `json:"validator_slash_events"`
|
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,
|
2019-01-16 13:38:05 -08:00
|
|
|
dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, r OutstandingRewards,
|
|
|
|
acc []ValidatorAccumulatedCommissionRecord, historical []ValidatorHistoricalRewardsRecord,
|
|
|
|
cur []ValidatorCurrentRewardsRecord, dels []DelegatorStartingInfoRecord,
|
|
|
|
slashes []ValidatorSlashEventRecord) GenesisState {
|
2018-10-04 17:20:43 -07:00
|
|
|
|
2018-09-17 20:02:15 -07:00
|
|
|
return GenesisState{
|
2019-01-16 13:38:05 -08:00
|
|
|
FeePool: feePool,
|
|
|
|
CommunityTax: communityTax,
|
|
|
|
BaseProposerReward: baseProposerReward,
|
|
|
|
BonusProposerReward: bonusProposerReward,
|
|
|
|
DelegatorWithdrawInfos: dwis,
|
|
|
|
PreviousProposer: pp,
|
|
|
|
OutstandingRewards: r,
|
|
|
|
ValidatorAccumulatedCommissions: acc,
|
|
|
|
ValidatorHistoricalRewards: historical,
|
|
|
|
ValidatorCurrentRewards: cur,
|
|
|
|
DelegatorStartingInfos: dels,
|
|
|
|
ValidatorSlashEvents: slashes,
|
2018-09-17 20:02:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get raw genesis raw message for testing
|
|
|
|
func DefaultGenesisState() GenesisState {
|
|
|
|
return GenesisState{
|
2019-01-16 13:38:05 -08:00
|
|
|
FeePool: InitialFeePool(),
|
|
|
|
CommunityTax: sdk.NewDecWithPrec(2, 2), // 2%
|
|
|
|
BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1%
|
|
|
|
BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4%
|
|
|
|
DelegatorWithdrawInfos: []DelegatorWithdrawInfo{},
|
|
|
|
PreviousProposer: nil,
|
|
|
|
OutstandingRewards: sdk.DecCoins{},
|
|
|
|
ValidatorAccumulatedCommissions: []ValidatorAccumulatedCommissionRecord{},
|
|
|
|
ValidatorHistoricalRewards: []ValidatorHistoricalRewardsRecord{},
|
|
|
|
ValidatorCurrentRewards: []ValidatorCurrentRewardsRecord{},
|
|
|
|
DelegatorStartingInfos: []DelegatorStartingInfoRecord{},
|
|
|
|
ValidatorSlashEvents: []ValidatorSlashEventRecord{},
|
2018-10-05 17:32:06 -07:00
|
|
|
}
|
|
|
|
}
|
2018-12-06 16:22:24 -08:00
|
|
|
|
|
|
|
// 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()
|
|
|
|
}
|