/
genesis.go
69 lines (58 loc) · 1.92 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
package types
import (
"encoding/json"
"errors"
"github.com/maticnetwork/heimdall/bor/types"
hmTypes "github.com/maticnetwork/heimdall/types"
)
// GenesisState is the checkpoint state that must be provided at genesis.
type GenesisState struct {
Params Params `json:"params" yaml:"params"`
BufferedCheckpoint *hmTypes.Checkpoint `json:"buffered_checkpoint" yaml:"buffered_checkpoint"`
LastNoACK uint64 `json:"last_no_ack" yaml:"last_no_ack"`
AckCount uint64 `json:"ack_count" yaml:"ack_count"`
Checkpoints []hmTypes.Checkpoint `json:"checkpoints" yaml:"checkpoints"`
}
// NewGenesisState creates a new genesis state.
func NewGenesisState(
params Params,
bufferedCheckpoint *hmTypes.Checkpoint,
lastNoACK uint64,
ackCount uint64,
checkpoints []hmTypes.Checkpoint,
) GenesisState {
return GenesisState{
Params: params,
BufferedCheckpoint: bufferedCheckpoint,
LastNoACK: lastNoACK,
AckCount: ackCount,
Checkpoints: checkpoints,
}
}
// DefaultGenesisState returns a default genesis state
func DefaultGenesisState() GenesisState {
return GenesisState{
Params: DefaultParams(),
}
}
// ValidateGenesis performs basic validation of bor genesis data returning an
// error for any failed validation criteria.
func ValidateGenesis(data GenesisState) error {
if err := data.Params.Validate(); err != nil {
return err
}
if len(data.Checkpoints) != 0 {
if int(data.AckCount) != len(data.Checkpoints) {
return errors.New("Incorrect state in state-dump , Please Check")
}
}
return nil
}
// GetGenesisStateFromAppState returns staking GenesisState given raw application genesis state
func GetGenesisStateFromAppState(appState map[string]json.RawMessage) GenesisState {
var genesisState GenesisState
if appState[ModuleName] != nil {
types.ModuleCdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
}
return genesisState
}