-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
59 lines (51 loc) · 2.54 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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// DelegatorWithdrawInfo is 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 {
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
WithdrawAddress sdk.AccAddress `json:"withdraw_address" yaml:"withdraw_address"`
}
// ValidatorAccumulatedCommissionRecord is used for import / export via genesis json
type ValidatorAccumulatedCommissionRecord struct {
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
Accumulated ValidatorAccumulatedCommission `json:"accumulated" yaml:"accumulated"`
}
// GenesisState - all distribution state that must be provided at genesis
type GenesisState struct {
Params Params `json:"params" yaml:"params"`
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"`
ValidatorAccumulatedCommissions []ValidatorAccumulatedCommissionRecord `json:"validator_accumulated_commissions" yaml:"validator_accumulated_commissions"`
}
// NewGenesisState creates a new object of GenesisState
func NewGenesisState( params Params, feePool FeePool,
dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, acc []ValidatorAccumulatedCommissionRecord) GenesisState {
return GenesisState{
Params: params,
FeePool: feePool,
DelegatorWithdrawInfos: dwis,
PreviousProposer: pp,
ValidatorAccumulatedCommissions: acc,
}
}
// DefaultGenesisState returns default genesis
func DefaultGenesisState() GenesisState {
return GenesisState{
FeePool: InitialFeePool(),
Params: DefaultParams(),
DelegatorWithdrawInfos: []DelegatorWithdrawInfo{},
PreviousProposer: nil,
ValidatorAccumulatedCommissions: []ValidatorAccumulatedCommissionRecord{},
}
}
// ValidateGenesis validates the genesis state of distribution genesis input
func ValidateGenesis(gs GenesisState) error {
if err := gs.Params.ValidateBasic(); err != nil {
return err
}
return gs.FeePool.ValidateGenesis()
}