github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/distribution/types/genesis.go (about)

     1  package types
     2  
     3  import (
     4  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     5  )
     6  
     7  // DelegatorWithdrawInfo is the address for where distributions rewards are withdrawn to by default
     8  // this struct is only used at genesis to feed in default withdraw addresses
     9  type DelegatorWithdrawInfo struct {
    10  	DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
    11  	WithdrawAddress  sdk.AccAddress `json:"withdraw_address" yaml:"withdraw_address"`
    12  }
    13  
    14  // ValidatorAccumulatedCommissionRecord is used for import / export via genesis json
    15  type ValidatorAccumulatedCommissionRecord struct {
    16  	ValidatorAddress sdk.ValAddress                 `json:"validator_address" yaml:"validator_address"`
    17  	Accumulated      ValidatorAccumulatedCommission `json:"accumulated" yaml:"accumulated"`
    18  }
    19  
    20  // GenesisState - all distribution state that must be provided at genesis
    21  type GenesisState struct {
    22  	Params                          Params                                 `json:"params" yaml:"params"`
    23  	FeePool                         FeePool                                `json:"fee_pool" yaml:"fee_pool"`
    24  	DelegatorWithdrawInfos          []DelegatorWithdrawInfo                `json:"delegator_withdraw_infos" yaml:"delegator_withdraw_infos"`
    25  	PreviousProposer                sdk.ConsAddress                        `json:"previous_proposer" yaml:"previous_proposer"`
    26  	ValidatorAccumulatedCommissions []ValidatorAccumulatedCommissionRecord `json:"validator_accumulated_commissions" yaml:"validator_accumulated_commissions"`
    27  }
    28  
    29  // NewGenesisState creates a new object of GenesisState
    30  func NewGenesisState(params Params, feePool FeePool,
    31  	dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, acc []ValidatorAccumulatedCommissionRecord) GenesisState {
    32  
    33  	return GenesisState{
    34  		Params:                          params,
    35  		FeePool:                         feePool,
    36  		DelegatorWithdrawInfos:          dwis,
    37  		PreviousProposer:                pp,
    38  		ValidatorAccumulatedCommissions: acc,
    39  	}
    40  }
    41  
    42  // DefaultGenesisState returns default genesis
    43  func DefaultGenesisState() GenesisState {
    44  	return GenesisState{
    45  		FeePool:                         InitialFeePool(),
    46  		Params:                          DefaultParams(),
    47  		DelegatorWithdrawInfos:          []DelegatorWithdrawInfo{},
    48  		PreviousProposer:                nil,
    49  		ValidatorAccumulatedCommissions: []ValidatorAccumulatedCommissionRecord{},
    50  	}
    51  }
    52  
    53  // ValidateGenesis validates the genesis state of distribution genesis input
    54  func ValidateGenesis(gs GenesisState) error {
    55  	if err := gs.Params.ValidateBasic(); err != nil {
    56  		return err
    57  	}
    58  	return gs.FeePool.ValidateGenesis()
    59  }