/
consensus.go
83 lines (72 loc) · 2.2 KB
/
consensus.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
79
80
81
82
83
package types
import (
"time"
tmctypes "github.com/tendermint/tendermint/rpc/core/types"
)
// Block contains the data of a single chain block
type Block struct {
Height int64
Hash string
TxNum int
TotalGas uint64
ProposerAddress string
Timestamp time.Time
}
// NewBlock allows to build a new Block instance
func NewBlock(
height int64, hash string, txNum int, totalGas uint64, proposerAddress string, timestamp time.Time,
) *Block {
return &Block{
Height: height,
Hash: hash,
TxNum: txNum,
TotalGas: totalGas,
ProposerAddress: proposerAddress,
Timestamp: timestamp,
}
}
// NewBlockFromTmBlock builds a new Block instance from a given ResultBlock object
func NewBlockFromTmBlock(blk *tmctypes.ResultBlock, totalGas uint64) *Block {
return NewBlock(
blk.Block.Height,
blk.Block.Hash().String(),
len(blk.Block.Txs),
totalGas,
ConvertValidatorAddressToBech32String(blk.Block.ProposerAddress),
blk.Block.Time,
)
}
// ----------------------------------------------------------------------------------------------------------
// CommitSig contains the data of a single validator commit signature
type CommitSig struct {
Height int64
ValidatorAddress string
VotingPower int64
ProposerPriority int64
Timestamp time.Time
}
// NewCommitSig allows to build a new CommitSign object
func NewCommitSig(validatorAddress string, votingPower, proposerPriority, height int64, timestamp time.Time) *CommitSig {
return &CommitSig{
Height: height,
ValidatorAddress: validatorAddress,
VotingPower: votingPower,
ProposerPriority: proposerPriority,
Timestamp: timestamp,
}
}
// ----------------------------------------------------------------------------------------------------------
// Genesis contains the useful information about the genesis
type Genesis struct {
ChainID string
Time time.Time
InitialHeight int64
}
// NewGenesis allows to build a new Genesis instance
func NewGenesis(chainID string, startTime time.Time, initialHeight int64) *Genesis {
return &Genesis{
ChainID: chainID,
Time: startTime,
InitialHeight: initialHeight,
}
}