consensus_state.gno
1.05 Kb · 51 lines
1package cometbls
2
3type ConsensusState struct {
4 Timestamp uint64
5 Root MerkleRoot
6 NextValidatorsHash []byte
7}
8
9func NewConsensusState(
10 timestamp uint64,
11 root MerkleRoot,
12 nextValidatorsHash []byte,
13) *ConsensusState {
14 return &ConsensusState{
15 Timestamp: timestamp,
16 Root: root,
17 NextValidatorsHash: nextValidatorsHash,
18 }
19}
20
21func (ConsensusState) ClientType() string {
22 return ClientType
23}
24
25func (cs *ConsensusState) GetRoot() MerkleRoot {
26 return cs.Root
27}
28
29func (cs *ConsensusState) GetRootHash() []byte {
30 return cs.Root.Hash
31}
32
33func (cs *ConsensusState) GetTimestamp() uint64 {
34 return cs.Timestamp
35}
36
37func (cs *ConsensusState) GetNextValidatorsHash() []byte {
38 return cs.NextValidatorsHash
39}
40
41func (cs *ConsensusState) ValidateBasic() error {
42 if cs.Root.Hash == nil || cs.Root.Empty() {
43 return errorWithDetails(ErrInvalidConsensus, "root hash cannot be nil")
44 }
45
46 if err := validateHash(cs.NextValidatorsHash); err != nil {
47 return errorWithDetails(ErrInvalidNextValidatorsHash, err.Error())
48 }
49
50 return nil
51}