github.com/Finschia/finschia-sdk@v0.48.1/x/staking/types/genesis.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/Finschia/finschia-sdk/codec"
     7  	codectypes "github.com/Finschia/finschia-sdk/codec/types"
     8  )
     9  
    10  // NewGenesisState creates a new GenesisState instanc e
    11  func NewGenesisState(params Params, validators []Validator, delegations []Delegation) *GenesisState {
    12  	return &GenesisState{
    13  		Params:      params,
    14  		Validators:  validators,
    15  		Delegations: delegations,
    16  	}
    17  }
    18  
    19  // DefaultGenesisState gets the raw genesis raw message for testing
    20  func DefaultGenesisState() *GenesisState {
    21  	return &GenesisState{
    22  		Params: DefaultParams(),
    23  	}
    24  }
    25  
    26  // GetGenesisStateFromAppState returns x/staking GenesisState given raw application
    27  // genesis state.
    28  func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.RawMessage) *GenesisState {
    29  	var genesisState GenesisState
    30  
    31  	if appState[ModuleName] != nil {
    32  		cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
    33  	}
    34  
    35  	return &genesisState
    36  }
    37  
    38  // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
    39  func (g GenesisState) UnpackInterfaces(c codectypes.AnyUnpacker) error {
    40  	for i := range g.Validators {
    41  		if err := g.Validators[i].UnpackInterfaces(c); err != nil {
    42  			return err
    43  		}
    44  	}
    45  	return nil
    46  }