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.

65 lines
1.5 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package consensus
  2. import (
  3. "errors"
  4. "fmt"
  5. "io"
  6. . "github.com/tendermint/tendermint/binary"
  7. . "github.com/tendermint/tendermint/blocks"
  8. )
  9. var (
  10. ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
  11. ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
  12. )
  13. type Proposal struct {
  14. Height uint32
  15. Round uint16
  16. BlockParts PartSetHeader
  17. POLParts PartSetHeader
  18. Signature Signature
  19. }
  20. func NewProposal(height uint32, round uint16, blockParts, polParts PartSetHeader) *Proposal {
  21. return &Proposal{
  22. Height: height,
  23. Round: round,
  24. BlockParts: blockParts,
  25. POLParts: polParts,
  26. }
  27. }
  28. func ReadProposal(r io.Reader, n *int64, err *error) *Proposal {
  29. return &Proposal{
  30. Height: ReadUInt32(r, n, err),
  31. Round: ReadUInt16(r, n, err),
  32. BlockParts: ReadPartSetHeader(r, n, err),
  33. POLParts: ReadPartSetHeader(r, n, err),
  34. Signature: ReadSignature(r, n, err),
  35. }
  36. }
  37. func (p *Proposal) WriteTo(w io.Writer) (n int64, err error) {
  38. WriteUInt32(w, p.Height, &n, &err)
  39. WriteUInt16(w, p.Round, &n, &err)
  40. WriteBinary(w, p.BlockParts, &n, &err)
  41. WriteBinary(w, p.POLParts, &n, &err)
  42. WriteBinary(w, p.Signature, &n, &err)
  43. return
  44. }
  45. func (p *Proposal) GetSignature() Signature {
  46. return p.Signature
  47. }
  48. func (p *Proposal) SetSignature(sig Signature) {
  49. p.Signature = sig
  50. }
  51. func (p *Proposal) String() string {
  52. return fmt.Sprintf("Proposal{%v/%v %v %v %v}", p.Height, p.Round,
  53. p.BlockParts, p.POLParts, p.Signature)
  54. }