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

     1  package types
     2  
     3  import "fmt"
     4  
     5  // GenesisState defines the module's genesis state.
     6  type GenesisState struct {
     7  	// module parameters
     8  	Params Params `json:"params"`
     9  	// active registered contracts for fee distribution
    10  	FeeSplits []FeeSplit `json:"fee_splits"`
    11  }
    12  
    13  // NewGenesisState creates a new genesis state.
    14  func NewGenesisState(params Params, feeSplits []FeeSplit) GenesisState {
    15  	return GenesisState{
    16  		Params:    params,
    17  		FeeSplits: feeSplits,
    18  	}
    19  }
    20  
    21  // DefaultGenesisState sets default evm genesis state with empty accounts and
    22  // default params and chain config values.
    23  func DefaultGenesisState() GenesisState {
    24  	return GenesisState{
    25  		Params: DefaultParams(),
    26  	}
    27  }
    28  
    29  // Validate performs basic genesis state validation returning an error upon any
    30  // failure.
    31  func (gs GenesisState) Validate() error {
    32  	seenContract := make(map[string]bool)
    33  	for _, fs := range gs.FeeSplits {
    34  		// only one fee per contract
    35  		if seenContract[fs.ContractAddress.String()] {
    36  			return fmt.Errorf("contract duplicated on genesis '%s'", fs.ContractAddress)
    37  		}
    38  
    39  		if err := fs.Validate(); err != nil {
    40  			return err
    41  		}
    42  
    43  		seenContract[fs.ContractAddress.String()] = true
    44  	}
    45  
    46  	return gs.Params.Validate()
    47  }