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.

69 lines
1.7 KiB

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