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.

77 lines
1.9 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
  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. BlockPartsTotal uint16
  17. BlockPartsHash []byte
  18. POLPartsTotal uint16
  19. POLPartsHash []byte
  20. Signature Signature
  21. }
  22. func NewProposal(height uint32, round uint16,
  23. blockPartsTotal uint16, blockPartsHash []byte,
  24. polPartsTotal uint16, polPartsHash []byte) *Proposal {
  25. return &Proposal{
  26. Height: height,
  27. Round: round,
  28. BlockPartsTotal: blockPartsTotal,
  29. BlockPartsHash: blockPartsHash,
  30. POLPartsTotal: polPartsTotal,
  31. POLPartsHash: polPartsHash,
  32. }
  33. }
  34. func ReadProposal(r io.Reader, n *int64, err *error) *Proposal {
  35. return &Proposal{
  36. Height: ReadUInt32(r, n, err),
  37. Round: ReadUInt16(r, n, err),
  38. BlockPartsTotal: ReadUInt16(r, n, err),
  39. BlockPartsHash: ReadByteSlice(r, n, err),
  40. POLPartsTotal: ReadUInt16(r, n, err),
  41. POLPartsHash: ReadByteSlice(r, n, err),
  42. Signature: ReadSignature(r, n, err),
  43. }
  44. }
  45. func (p *Proposal) WriteTo(w io.Writer) (n int64, err error) {
  46. WriteUInt32(w, p.Height, &n, &err)
  47. WriteUInt16(w, p.Round, &n, &err)
  48. WriteUInt16(w, p.BlockPartsTotal, &n, &err)
  49. WriteByteSlice(w, p.BlockPartsHash, &n, &err)
  50. WriteUInt16(w, p.POLPartsTotal, &n, &err)
  51. WriteByteSlice(w, p.POLPartsHash, &n, &err)
  52. WriteBinary(w, p.Signature, &n, &err)
  53. return
  54. }
  55. func (p *Proposal) GetSignature() Signature {
  56. return p.Signature
  57. }
  58. func (p *Proposal) SetSignature(sig Signature) {
  59. p.Signature = sig
  60. }
  61. func (p *Proposal) String() string {
  62. return fmt.Sprintf("Proposal{%v/%v %X/%v %X/%v %v}", p.Height, p.Round,
  63. p.BlockPartsHash, p.BlockPartsTotal,
  64. p.POLPartsHash, p.POLPartsTotal,
  65. p.Signature)
  66. }