-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
genesis.go
78 lines (66 loc) · 2.25 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
package types
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// NewGenesisState creates a new genesis state for the governance module
func NewGenesisState(startingProposalID uint64, dp DepositParams, vp VotingParams, tp TallyParams) *GenesisState {
return &GenesisState{
StartingProposalId: startingProposalID,
DepositParams: dp,
VotingParams: vp,
TallyParams: tp,
}
}
// DefaultGenesisState defines the default governance genesis state
func DefaultGenesisState() *GenesisState {
return NewGenesisState(
DefaultStartingProposalID,
DefaultDepositParams(),
DefaultVotingParams(),
DefaultTallyParams(),
)
}
func (data GenesisState) Equal(other GenesisState) bool {
return data.StartingProposalId == other.StartingProposalId &&
data.Deposits.Equal(other.Deposits) &&
data.Votes.Equal(other.Votes) &&
data.Proposals.Equal(other.Proposals) &&
data.DepositParams.Equal(other.DepositParams) &&
data.TallyParams.Equal(other.TallyParams) &&
data.VotingParams.Equal(other.VotingParams)
}
// Empty returns true if a GenesisState is empty
func (data GenesisState) Empty() bool {
return data.Equal(GenesisState{})
}
// ValidateGenesis checks if parameters are within valid ranges
func ValidateGenesis(data *GenesisState) error {
threshold := data.TallyParams.Threshold
if threshold.IsNegative() || threshold.GT(sdk.OneDec()) {
return fmt.Errorf("governance vote threshold should be positive and less or equal to one, is %s",
threshold.String())
}
veto := data.TallyParams.VetoThreshold
if veto.IsNegative() || veto.GT(sdk.OneDec()) {
return fmt.Errorf("governance vote veto threshold should be positive and less or equal to one, is %s",
veto.String())
}
if !data.DepositParams.MinDeposit.IsValid() {
return fmt.Errorf("governance deposit amount must be a valid sdk.Coins amount, is %s",
data.DepositParams.MinDeposit.String())
}
return nil
}
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
}