github.com/number571/tendermint@v0.34.11-gost/internal/test/factory/commit.go (about)

     1  package factory
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"time"
     7  
     8  	tmproto "github.com/number571/tendermint/proto/tendermint/types"
     9  	"github.com/number571/tendermint/types"
    10  )
    11  
    12  func MakeCommit(blockID types.BlockID, height int64, round int32,
    13  	voteSet *types.VoteSet, validators []types.PrivValidator, now time.Time) (*types.Commit, error) {
    14  
    15  	// all sign
    16  	for i := 0; i < len(validators); i++ {
    17  		pubKey, err := validators[i].GetPubKey(context.Background())
    18  		if err != nil {
    19  			return nil, fmt.Errorf("can't get pubkey: %w", err)
    20  		}
    21  		vote := &types.Vote{
    22  			ValidatorAddress: pubKey.Address(),
    23  			ValidatorIndex:   int32(i),
    24  			Height:           height,
    25  			Round:            round,
    26  			Type:             tmproto.PrecommitType,
    27  			BlockID:          blockID,
    28  			Timestamp:        now,
    29  		}
    30  
    31  		_, err = signAddVote(validators[i], vote, voteSet)
    32  		if err != nil {
    33  			return nil, err
    34  		}
    35  	}
    36  
    37  	return voteSet.MakeCommit(), nil
    38  }
    39  
    40  func signAddVote(privVal types.PrivValidator, vote *types.Vote, voteSet *types.VoteSet) (signed bool, err error) {
    41  	v := vote.ToProto()
    42  	err = privVal.SignVote(context.Background(), voteSet.ChainID(), v)
    43  	if err != nil {
    44  		return false, err
    45  	}
    46  	vote.Signature = v.Signature
    47  	return voteSet.AddVote(vote)
    48  }