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.

48 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
  1. package consensus
  2. import (
  3. "errors"
  4. "fmt"
  5. "io"
  6. "github.com/tendermint/tendermint/account"
  7. "github.com/tendermint/tendermint/binary"
  8. . "github.com/tendermint/tendermint/common"
  9. "github.com/tendermint/tendermint/types"
  10. )
  11. var (
  12. ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
  13. ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
  14. )
  15. type Proposal struct {
  16. Height uint `json:"height"`
  17. Round uint `json:"round"`
  18. BlockParts types.PartSetHeader `json:"block_parts"`
  19. POLParts types.PartSetHeader `json:"pol_parts"`
  20. Signature account.SignatureEd25519 `json:"signature"`
  21. }
  22. func NewProposal(height uint, round uint, blockParts, polParts types.PartSetHeader) *Proposal {
  23. return &Proposal{
  24. Height: height,
  25. Round: round,
  26. BlockParts: blockParts,
  27. POLParts: polParts,
  28. }
  29. }
  30. func (p *Proposal) String() string {
  31. return fmt.Sprintf("Proposal{%v/%v %v %v %v}", p.Height, p.Round,
  32. p.BlockParts, p.POLParts, p.Signature)
  33. }
  34. func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
  35. binary.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
  36. binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err)
  37. p.BlockParts.WriteSignBytes(w, n, err)
  38. binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err)
  39. p.POLParts.WriteSignBytes(w, n, err)
  40. binary.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
  41. }