-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis_state.go
46 lines (38 loc) · 1.08 KB
/
genesis_state.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
package types
import (
"encoding/json"
"errors"
"fmt"
stakingtypes "github.com/fastock/fastock-chain/x/staking/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
// GenesisState defines the raw genesis transaction in JSON
type GenesisState struct {
GenTxs []json.RawMessage `json:"gentxs" yaml:"gentxs"`
}
// NewGenesisState creates a new GenesisState object
func NewGenesisState(genTxs []json.RawMessage) GenesisState {
return GenesisState{
GenTxs: genTxs,
}
}
// ValidateGenesis validates GenTx transactions
func ValidateGenesis(genesisState GenesisState) error {
for i, genTx := range genesisState.GenTxs {
var tx authtypes.StdTx
if err := ModuleCdc.UnmarshalJSON(genTx, &tx); err != nil {
return err
}
msgs := tx.GetMsgs()
if len(msgs) != 1 {
return errors.New(
"must provide genesis StdTx with exactly 1 CreateValidator message")
}
// TODO: abstract back to staking
if _, ok := msgs[0].(stakingtypes.MsgCreateValidator); !ok {
return fmt.Errorf(
"genesis transaction %v does not contain a MsgCreateValidator", i)
}
}
return nil
}