-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
genesis.go
50 lines (41 loc) · 1.23 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
package v1
import (
"errors"
"github.com/cosmos/cosmos-sdk/codec/types"
)
// NewGenesisState creates a new genesis state for the governance module
func NewGenesisState(startingProposalID uint64, params Params) *GenesisState {
return &GenesisState{
StartingProposalId: startingProposalID,
Params: ¶ms,
}
}
// DefaultGenesisState defines the default governance genesis state
func DefaultGenesisState() *GenesisState {
return NewGenesisState(
DefaultStartingProposalID,
DefaultParams(),
)
}
// Empty returns true if a GenesisState is empty
func (data GenesisState) Empty() bool {
return data.StartingProposalId == 0 || data.Params == nil
}
// ValidateGenesis checks if parameters are within valid ranges
func ValidateGenesis(data *GenesisState) error {
if data.StartingProposalId == 0 {
return errors.New("starting proposal id must be greater than 0")
}
return data.Params.ValidateBasic()
}
var _ types.UnpackInterfacesMessage = GenesisState{}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (data GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error {
for _, p := range data.Proposals {
err := p.UnpackInterfaces(unpacker)
if err != nil {
return err
}
}
return nil
}