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.

39 lines
891 B

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package types
  2. import (
  3. tmtime "github.com/tendermint/tendermint/types/time"
  4. )
  5. func MakeCommit(blockID BlockID, height int64, round int,
  6. voteSet *VoteSet,
  7. validators []PrivValidator) (*Commit, error) {
  8. // all sign
  9. for i := 0; i < len(validators); i++ {
  10. addr := validators[i].GetPubKey().Address()
  11. vote := &Vote{
  12. ValidatorAddress: addr,
  13. ValidatorIndex: i,
  14. Height: height,
  15. Round: round,
  16. Type: PrecommitType,
  17. BlockID: blockID,
  18. Timestamp: tmtime.Now(),
  19. }
  20. _, err := signAddVote(validators[i], vote, voteSet)
  21. if err != nil {
  22. return nil, err
  23. }
  24. }
  25. return voteSet.MakeCommit(), nil
  26. }
  27. func signAddVote(privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bool, err error) {
  28. err = privVal.SignVote(voteSet.ChainID(), vote)
  29. if err != nil {
  30. return false, err
  31. }
  32. return voteSet.AddVote(vote)
  33. }