-
Notifications
You must be signed in to change notification settings - Fork 99
/
genesis.go
45 lines (39 loc) · 1006 Bytes
/
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
package types
import (
errorsmod "cosmossdk.io/errors"
"fmt"
)
// DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
NumMessages: 0,
DelayedMessages: []*DelayedMessage{},
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
ids := make(map[uint32]struct{}, len(gs.DelayedMessages))
for i, msg := range gs.DelayedMessages {
if err := msg.Validate(); err != nil {
return errorsmod.Wrap(
ErrInvalidGenesisState,
fmt.Sprintf("invalid delayed message at index %v with id %v: %v", i, msg.Id, err),
)
}
if msg.Id >= gs.NumMessages {
return errorsmod.Wrap(
ErrInvalidGenesisState,
"delayed message id exceeds total number of messages",
)
}
if _, ok := ids[msg.Id]; ok {
return errorsmod.Wrap(
ErrInvalidGenesisState,
"duplicate delayed message id",
)
}
ids[msg.Id] = struct{}{}
}
return nil
}