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.

50 lines
1.6 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/config"
  10. "github.com/tendermint/tendermint/types"
  11. )
  12. var (
  13. ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature")
  14. ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
  15. )
  16. type Proposal struct {
  17. Height uint `json:"height"`
  18. Round uint `json:"round"`
  19. BlockParts types.PartSetHeader `json:"block_parts"`
  20. POLParts types.PartSetHeader `json:"pol_parts"`
  21. Signature account.SignatureEd25519 `json:"signature"`
  22. }
  23. func NewProposal(height uint, round uint, blockParts, polParts types.PartSetHeader) *Proposal {
  24. return &Proposal{
  25. Height: height,
  26. Round: round,
  27. BlockParts: blockParts,
  28. POLParts: polParts,
  29. }
  30. }
  31. func (p *Proposal) String() string {
  32. return fmt.Sprintf("Proposal{%v/%v %v %v %v}", p.Height, p.Round,
  33. p.BlockParts, p.POLParts, p.Signature)
  34. }
  35. func (p *Proposal) WriteSignBytes(w io.Writer, n *int64, err *error) {
  36. // We hex encode the network name so we don't deal with escaping issues.
  37. binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.App().GetString("Network"))), w, n, err)
  38. binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err)
  39. p.BlockParts.WriteSignBytes(w, n, err)
  40. binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err)
  41. p.POLParts.WriteSignBytes(w, n, err)
  42. binary.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
  43. }