types: move MakeVote / MakeBlock functions (#3819)

to the types package

Paritally Fixes #3584
This commit is contained in:
Marko
2019-07-25 10:13:19 +02:00
committed by Anton Kaliaev
parent 98cb8c9783
commit 4b9e8505cb
6 changed files with 50 additions and 83 deletions

View File

@ -69,29 +69,11 @@ func makeAndApplyGoodBlock(state sm.State, height int64, lastCommit *types.Commi
return state, blockID, nil
}
func makeVote(height int64, blockID types.BlockID, valSet *types.ValidatorSet, privVal types.PrivValidator) (*types.Vote, error) {
addr := privVal.GetPubKey().Address()
idx, _ := valSet.GetByAddress(addr)
vote := &types.Vote{
ValidatorAddress: addr,
ValidatorIndex: idx,
Height: height,
Round: 0,
Timestamp: tmtime.Now(),
Type: types.PrecommitType,
BlockID: blockID,
}
if err := privVal.SignVote(chainID, vote); err != nil {
return nil, err
}
return vote, nil
}
func makeValidCommit(height int64, blockID types.BlockID, vals *types.ValidatorSet, privVals map[string]types.PrivValidator) (*types.Commit, error) {
sigs := make([]*types.CommitSig, 0)
for i := 0; i < vals.Size(); i++ {
_, val := vals.GetByIndex(i)
vote, err := makeVote(height, blockID, vals, privVals[val.Address.String()])
vote, err := types.MakeVote(height, blockID, vals, privVals[val.Address.String()], chainID)
if err != nil {
return nil, err
}