mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 06:11:20 +00:00
types: move MakeVote / MakeBlock functions (#3819)
to the types package Paritally Fixes #3584
This commit is contained in:
@ -5,8 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func MakeCommit(blockID BlockID, height int64, round int,
|
||||
voteSet *VoteSet,
|
||||
validators []PrivValidator) (*Commit, error) {
|
||||
voteSet *VoteSet, validators []PrivValidator) (*Commit, error) {
|
||||
|
||||
// all sign
|
||||
for i := 0; i < len(validators); i++ {
|
||||
@ -37,3 +36,40 @@ func signAddVote(privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bo
|
||||
}
|
||||
return voteSet.AddVote(vote)
|
||||
}
|
||||
|
||||
func MakeVote(height int64, blockID BlockID, valSet *ValidatorSet, privVal PrivValidator, chainID string) (*Vote, error) {
|
||||
addr := privVal.GetPubKey().Address()
|
||||
idx, _ := valSet.GetByAddress(addr)
|
||||
vote := &Vote{
|
||||
ValidatorAddress: addr,
|
||||
ValidatorIndex: idx,
|
||||
Height: height,
|
||||
Round: 0,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: PrecommitType,
|
||||
BlockID: blockID,
|
||||
}
|
||||
if err := privVal.SignVote(chainID, vote); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return vote, nil
|
||||
}
|
||||
|
||||
// MakeBlock returns a new block with an empty header, except what can be
|
||||
// computed from itself.
|
||||
// It populates the same set of fields validated by ValidateBasic.
|
||||
func MakeBlock(height int64, txs []Tx, lastCommit *Commit, evidence []Evidence) *Block {
|
||||
block := &Block{
|
||||
Header: Header{
|
||||
Height: height,
|
||||
NumTxs: int64(len(txs)),
|
||||
},
|
||||
Data: Data{
|
||||
Txs: txs,
|
||||
},
|
||||
Evidence: EvidenceData{Evidence: evidence},
|
||||
LastCommit: lastCommit,
|
||||
}
|
||||
block.fillHeader()
|
||||
return block
|
||||
}
|
||||
|
Reference in New Issue
Block a user