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.

37 lines
825 B

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