-
Notifications
You must be signed in to change notification settings - Fork 339
/
genesis.go
46 lines (38 loc) · 1.2 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
package types
import (
"bytes"
"errors"
"time"
tmtime "github.com/tendermint/tendermint/types/time"
)
// GenesisState - all auth state that must be provided at genesis
type GenesisState struct {
PreviousBlockTime time.Time `json:"previous_block_time" yaml:"previous_block_time"`
}
// NewGenesisState - Create a new genesis state
func NewGenesisState(prevBlockTime time.Time) GenesisState {
return GenesisState{
PreviousBlockTime: prevBlockTime,
}
}
// DefaultGenesisState - Return a default genesis state
func DefaultGenesisState() GenesisState {
return NewGenesisState(tmtime.Canonical(time.Unix(0, 0)))
}
// Equal checks whether two gov GenesisState structs are equivalent
func (data GenesisState) Equal(data2 GenesisState) bool {
b1 := ModuleCdc.MustMarshalBinaryBare(data)
b2 := ModuleCdc.MustMarshalBinaryBare(data2)
return bytes.Equal(b1, b2)
}
// IsEmpty returns true if a GenesisState is empty
func (data GenesisState) IsEmpty() bool {
return data.Equal(GenesisState{})
}
// ValidateGenesis returns nil because accounts are validated by auth
func ValidateGenesis(data GenesisState) error {
if data.PreviousBlockTime.IsZero() {
return errors.New("previous block time cannot be zero")
}
return nil
}