/
genesis.go
38 lines (31 loc) · 1.08 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
package types
import (
"fmt"
"github.com/spf13/cast"
)
// DefaultIndex is the default global index
const DefaultIndex uint64 = 1
// DefaultGenesis returns the default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
pubkeyChangeProposalCount := len(gs.ActivePubkeysChangeProposals) +
len(gs.FinishedPubkeysChangeProposals)
if cast.ToUint64(pubkeyChangeProposalCount) != gs.ProposalStats.PubkeysChangeCount {
return fmt.Errorf("sum of active and settled public keys change proposal must be equal to statistics %d <> %d",
pubkeyChangeProposalCount, gs.ProposalStats.PubkeysChangeCount)
}
for _, active := range gs.ActivePubkeysChangeProposals {
for _, finished := range gs.FinishedPubkeysChangeProposals {
if active.Id == finished.Proposal.Id {
return fmt.Errorf("proposal with id is present in both active and finished list %d", &active.Id)
}
}
}
return gs.Params.Validate()
}