github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/genutil/types/genesis_state.go (about) 1 package types 2 3 import ( 4 "encoding/json" 5 "errors" 6 "fmt" 7 8 stakingtypes "github.com/fibonacci-chain/fbc/x/staking/types" 9 10 authtypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/types" 11 ) 12 13 // GenesisState defines the raw genesis transaction in JSON 14 type GenesisState struct { 15 GenTxs []json.RawMessage `json:"gentxs" yaml:"gentxs"` 16 } 17 18 // NewGenesisState creates a new GenesisState object 19 func NewGenesisState(genTxs []json.RawMessage) GenesisState { 20 return GenesisState{ 21 GenTxs: genTxs, 22 } 23 } 24 25 // ValidateGenesis validates GenTx transactions 26 func ValidateGenesis(genesisState GenesisState) error { 27 for i, genTx := range genesisState.GenTxs { 28 var tx authtypes.StdTx 29 if err := ModuleCdc.UnmarshalJSON(genTx, &tx); err != nil { 30 return err 31 } 32 33 msgs := tx.GetMsgs() 34 if len(msgs) != 1 { 35 return errors.New( 36 "must provide genesis StdTx with exactly 1 CreateValidator message") 37 } 38 39 // TODO: abstract back to staking 40 if _, ok := msgs[0].(stakingtypes.MsgCreateValidator); !ok { 41 return fmt.Errorf( 42 "genesis transaction %v does not contain a MsgCreateValidator", i) 43 } 44 } 45 return nil 46 }