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.

67 lines
1.7 KiB

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, blockPartsTotal uint16, blockPartsHash []byte,
  22. polPartsTotal uint16, polPartsHash []byte) *Proposal {
  23. return &Proposal{
  24. Height: height,
  25. Round: round,
  26. BlockPartsTotal: blockPartsTotal,
  27. BlockPartsHash: blockPartsHash,
  28. POLPartsTotal: polPartsTotal,
  29. POLPartsHash: polPartsHash,
  30. }
  31. }
  32. func ReadProposal(r io.Reader, n *int64, err *error) *Proposal {
  33. return &Proposal{
  34. Height: ReadUInt32(r, n, err),
  35. Round: ReadUInt16(r, n, err),
  36. BlockPartsTotal: ReadUInt16(r, n, err),
  37. BlockPartsHash: ReadByteSlice(r, n, err),
  38. POLPartsTotal: ReadUInt16(r, n, err),
  39. POLPartsHash: ReadByteSlice(r, n, err),
  40. Signature: ReadSignature(r, n, err),
  41. }
  42. }
  43. func (p *Proposal) WriteTo(w io.Writer) (n int64, err error) {
  44. WriteUInt32(w, p.Height, &n, &err)
  45. WriteUInt16(w, p.Round, &n, &err)
  46. WriteUInt16(w, p.BlockPartsTotal, &n, &err)
  47. WriteByteSlice(w, p.BlockPartsHash, &n, &err)
  48. WriteUInt16(w, p.POLPartsTotal, &n, &err)
  49. WriteByteSlice(w, p.POLPartsHash, &n, &err)
  50. WriteBinary(w, p.Signature, &n, &err)
  51. return
  52. }
  53. func (p *Proposal) GetSignature() Signature {
  54. return p.Signature
  55. }
  56. func (p *Proposal) SetSignature(sig Signature) {
  57. p.Signature = sig
  58. }