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.

51 lines
1.7 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 types
  2. import (
  3. "errors"
  4. "fmt"
  5. "io"
  6. . "github.com/tendermint/go-common"
  7. "github.com/tendermint/go-crypto"
  8. "github.com/tendermint/go-wire"
  9. )
  10. var (
  11. ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
  12. ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
  13. )
  14. type Proposal struct {
  15. Height int `json:"height"`
  16. Round int `json:"round"`
  17. BlockPartsHeader PartSetHeader `json:"block_parts_header"`
  18. POLRound int `json:"pol_round"` // -1 if null.
  19. POLBlockID BlockID `json:"pol_block_id"` // zero if null.
  20. Signature crypto.SignatureEd25519 `json:"signature"`
  21. }
  22. // polRound: -1 if no polRound.
  23. func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
  24. return &Proposal{
  25. Height: height,
  26. Round: round,
  27. BlockPartsHeader: blockPartsHeader,
  28. POLRound: polRound,
  29. POLBlockID: polBlockID,
  30. }
  31. }
  32. func (p *Proposal) String() string {
  33. return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v}", p.Height, p.Round,
  34. p.BlockPartsHeader, p.POLRound, p.POLBlockID, p.Signature)
  35. }
  36. func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
  37. wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
  38. wire.WriteTo([]byte(`,"proposal":{"block_parts_header":`), w, n, err)
  39. p.BlockPartsHeader.WriteSignBytes(w, n, err)
  40. wire.WriteTo([]byte(Fmt(`,"height":%v,"pol_block_id":`, p.Height)), w, n, err)
  41. p.POLBlockID.WriteSignBytes(w, n, err)
  42. wire.WriteTo([]byte(Fmt(`,"pol_round":%v`, p.POLRound)), w, n, err)
  43. wire.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
  44. }