2018-09-17 20:02:15 -07:00
|
|
|
package types
|
|
|
|
|
2018-12-06 16:22:24 -08:00
|
|
|
import (
|
|
|
|
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 {
|
2019-07-05 16:25:56 -07:00
|
|
|
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
|
|
|
WithdrawAddress sdk.AccAddress `json:"withdraw_address" yaml:"withdraw_address"`
|
2018-10-04 15:29:03 -07:00
|
|
|
}
|
|
|
|
|
2019-03-06 10:54:12 -08:00
|
|
|
// used for import/export via genesis json
|
|
|
|
type ValidatorOutstandingRewardsRecord struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
|
|
OutstandingRewards sdk.DecCoins `json:"outstanding_rewards" yaml:"outstanding_rewards"`
|
2019-03-06 10:54:12 -08:00
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// used for import / export via genesis json
|
|
|
|
type ValidatorAccumulatedCommissionRecord struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
|
|
Accumulated ValidatorAccumulatedCommission `json:"accumulated" yaml:"accumulated"`
|
2019-01-16 13:38:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// used for import / export via genesis json
|
|
|
|
type ValidatorHistoricalRewardsRecord struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
|
|
Period uint64 `json:"period" yaml:"period"`
|
|
|
|
Rewards ValidatorHistoricalRewards `json:"rewards" yaml:"rewards"`
|
2019-01-16 13:38:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// used for import / export via genesis json
|
|
|
|
type ValidatorCurrentRewardsRecord struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
|
|
Rewards ValidatorCurrentRewards `json:"rewards" yaml:"rewards"`
|
2019-01-16 13:38:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// used for import / export via genesis json
|
|
|
|
type DelegatorStartingInfoRecord struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
|
|
StartingInfo DelegatorStartingInfo `json:"starting_info" yaml:"starting_info"`
|
2019-01-16 13:38:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// used for import / export via genesis json
|
|
|
|
type ValidatorSlashEventRecord struct {
|
2019-07-05 16:25:56 -07:00
|
|
|
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
|
|
Height uint64 `json:"height" yaml:"height"`
|
|
|
|
Period uint64 `json:"period" yaml:"period"`
|
|
|
|
Event ValidatorSlashEvent `json:"validator_slash_event" yaml:"validator_slash_event"`
|
2019-01-16 13:38:05 -08:00
|
|
|
}
|
|
|
|
|
2018-09-17 20:02:15 -07:00
|
|
|
// GenesisState - all distribution state that must be provided at genesis
|
|
|
|
type GenesisState struct {
|
2020-01-10 12:08:14 -08:00
|
|
|
Params Params `json:"params" yaml:"params"`
|
2019-07-05 16:25:56 -07:00
|
|
|
FeePool FeePool `json:"fee_pool" yaml:"fee_pool"`
|
|
|
|
DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos" yaml:"delegator_withdraw_infos"`
|
|
|
|
PreviousProposer sdk.ConsAddress `json:"previous_proposer" yaml:"previous_proposer"`
|
|
|
|
OutstandingRewards []ValidatorOutstandingRewardsRecord `json:"outstanding_rewards" yaml:"outstanding_rewards"`
|
|
|
|
ValidatorAccumulatedCommissions []ValidatorAccumulatedCommissionRecord `json:"validator_accumulated_commissions" yaml:"validator_accumulated_commissions"`
|
|
|
|
ValidatorHistoricalRewards []ValidatorHistoricalRewardsRecord `json:"validator_historical_rewards" yaml:"validator_historical_rewards"`
|
|
|
|
ValidatorCurrentRewards []ValidatorCurrentRewardsRecord `json:"validator_current_rewards" yaml:"validator_current_rewards"`
|
|
|
|
DelegatorStartingInfos []DelegatorStartingInfoRecord `json:"delegator_starting_infos" yaml:"delegator_starting_infos"`
|
|
|
|
ValidatorSlashEvents []ValidatorSlashEventRecord `json:"validator_slash_events" yaml:"validator_slash_events"`
|
2018-09-17 20:02:15 -07:00
|
|
|
}
|
|
|
|
|
2020-01-10 12:08:14 -08:00
|
|
|
func NewGenesisState(
|
|
|
|
params Params, fp FeePool, dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, r []ValidatorOutstandingRewardsRecord,
|
2019-01-16 13:38:05 -08:00
|
|
|
acc []ValidatorAccumulatedCommissionRecord, historical []ValidatorHistoricalRewardsRecord,
|
2020-01-10 12:08:14 -08:00
|
|
|
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{
|
2020-01-10 12:08:14 -08:00
|
|
|
Params: params,
|
|
|
|
FeePool: fp,
|
2019-01-16 13:38:05 -08:00
|
|
|
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(),
|
2020-01-10 12:08:14 -08:00
|
|
|
Params: DefaultParams(),
|
2019-01-16 13:38:05 -08:00
|
|
|
DelegatorWithdrawInfos: []DelegatorWithdrawInfo{},
|
|
|
|
PreviousProposer: nil,
|
2019-03-06 10:54:12 -08:00
|
|
|
OutstandingRewards: []ValidatorOutstandingRewardsRecord{},
|
2019-01-16 13:38:05 -08:00
|
|
|
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
|
2020-01-10 12:08:14 -08:00
|
|
|
func ValidateGenesis(gs GenesisState) error {
|
|
|
|
if err := gs.Params.ValidateBasic(); err != nil {
|
|
|
|
return err
|
2018-12-06 16:22:24 -08:00
|
|
|
}
|
2020-01-10 12:08:14 -08:00
|
|
|
return gs.FeePool.ValidateGenesis()
|
2018-12-06 16:22:24 -08:00
|
|
|
}
|