-
Notifications
You must be signed in to change notification settings - Fork 113
/
genesis.go
104 lines (88 loc) · 2.46 KB
/
genesis.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package types
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/axelarnetwork/axelar-core/x/tss/exported"
)
// NewGenesisState is the constructor for GenesisState
func NewGenesisState(
params Params,
keyRecoveryInfos []KeyRecoveryInfo,
keys []exported.Key,
multisigInfos []MultisigInfo,
externalKeys []ExternalKeys,
signatures []exported.Signature,
validatorStatuses []ValidatorStatus,
) *GenesisState {
return &GenesisState{
Params: params,
KeyRecoveryInfos: keyRecoveryInfos,
Keys: keys,
MultisigInfos: multisigInfos,
ExternalKeys: externalKeys,
Signatures: signatures,
ValidatorStatuses: validatorStatuses,
}
}
// DefaultGenesisState represents the default genesis state
func DefaultGenesisState() *GenesisState {
return NewGenesisState(
DefaultParams(),
[]KeyRecoveryInfo{},
[]exported.Key{},
[]MultisigInfo{},
[]ExternalKeys{},
[]exported.Signature{},
[]ValidatorStatus{},
)
}
// Validate validates the genesis state
func (m GenesisState) Validate() error {
if err := m.Params.Validate(); err != nil {
return getValidateError(err)
}
for _, keyRecoveryInfo := range m.KeyRecoveryInfos {
if err := keyRecoveryInfo.Validate(); err != nil {
return getValidateError(err)
}
}
for _, key := range m.Keys {
if err := key.Validate(); err != nil {
return getValidateError(err)
}
}
for _, multisigInfo := range m.MultisigInfos {
if err := multisigInfo.Validate(); err != nil {
return getValidateError(err)
}
}
for _, externalKeys := range m.ExternalKeys {
if err := externalKeys.Validate(); err != nil {
return getValidateError(err)
}
}
for _, signature := range m.Signatures {
if err := signature.Validate(); err != nil {
return getValidateError(err)
}
}
for _, validatorStatus := range m.ValidatorStatuses {
if err := validatorStatus.Validate(); err != nil {
return getValidateError(err)
}
}
return nil
}
func getValidateError(err error) error {
return sdkerrors.Wrapf(err, "genesis state for module %s is invalid", ModuleName)
}
// GetGenesisStateFromAppState returns x/tss GenesisState given raw application
// genesis state.
func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.RawMessage) GenesisState {
var genesisState GenesisState
if appState[ModuleName] != nil {
cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
}
return genesisState
}