You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1005 B

  1. package factory
  2. import (
  3. "context"
  4. "time"
  5. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. func MakeCommit(ctx context.Context, blockID types.BlockID, height int64, round int32, voteSet *types.VoteSet, validators []types.PrivValidator, now time.Time) (*types.Commit, error) {
  9. // all sign
  10. for i := 0; i < len(validators); i++ {
  11. pubKey, err := validators[i].GetPubKey(ctx)
  12. if err != nil {
  13. return nil, err
  14. }
  15. vote := &types.Vote{
  16. ValidatorAddress: pubKey.Address(),
  17. ValidatorIndex: int32(i),
  18. Height: height,
  19. Round: round,
  20. Type: tmproto.PrecommitType,
  21. BlockID: blockID,
  22. Timestamp: now,
  23. }
  24. v := vote.ToProto()
  25. if err := validators[i].SignVote(ctx, voteSet.ChainID(), v); err != nil {
  26. return nil, err
  27. }
  28. vote.Signature = v.Signature
  29. if _, err := voteSet.AddVote(vote); err != nil {
  30. return nil, err
  31. }
  32. }
  33. return voteSet.MakeCommit(), nil
  34. }