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.

81 lines
2.2 KiB

  1. package types
  2. import (
  3. "github.com/tendermint/go-wire/data"
  4. )
  5. // canonical json is go-wire's json for structs with fields in alphabetical order
  6. type CanonicalJSONBlockID struct {
  7. Hash data.Bytes `json:"hash,omitempty"`
  8. PartsHeader CanonicalJSONPartSetHeader `json:"parts,omitempty"`
  9. }
  10. type CanonicalJSONPartSetHeader struct {
  11. Hash data.Bytes `json:"hash"`
  12. Total int `json:"total"`
  13. }
  14. type CanonicalJSONProposal struct {
  15. BlockPartsHeader CanonicalJSONPartSetHeader `json:"block_parts_header"`
  16. Height int `json:"height"`
  17. POLBlockID CanonicalJSONBlockID `json:"pol_block_id"`
  18. POLRound int `json:"pol_round"`
  19. Round int `json:"round"`
  20. }
  21. type CanonicalJSONVote struct {
  22. BlockID CanonicalJSONBlockID `json:"block_id"`
  23. Height int `json:"height"`
  24. Round int `json:"round"`
  25. Type byte `json:"type"`
  26. }
  27. //------------------------------------
  28. // Messages including a "chain id" can only be applied to one chain, hence "Once"
  29. type CanonicalJSONOnceProposal struct {
  30. ChainID string `json:"chain_id"`
  31. Proposal CanonicalJSONProposal `json:"proposal"`
  32. }
  33. type CanonicalJSONOnceVote struct {
  34. ChainID string `json:"chain_id"`
  35. Vote CanonicalJSONVote `json:"vote"`
  36. }
  37. //-----------------------------------
  38. // Canonicalize the structs
  39. func CanonicalBlockID(blockID BlockID) CanonicalJSONBlockID {
  40. return CanonicalJSONBlockID{
  41. Hash: blockID.Hash,
  42. PartsHeader: CanonicalPartSetHeader(blockID.PartsHeader),
  43. }
  44. }
  45. func CanonicalPartSetHeader(psh PartSetHeader) CanonicalJSONPartSetHeader {
  46. return CanonicalJSONPartSetHeader{
  47. psh.Hash,
  48. psh.Total,
  49. }
  50. }
  51. func CanonicalProposal(proposal *Proposal) CanonicalJSONProposal {
  52. return CanonicalJSONProposal{
  53. BlockPartsHeader: CanonicalPartSetHeader(proposal.BlockPartsHeader),
  54. Height: proposal.Height,
  55. POLBlockID: CanonicalBlockID(proposal.POLBlockID),
  56. POLRound: proposal.POLRound,
  57. Round: proposal.Round,
  58. }
  59. }
  60. func CanonicalVote(vote *Vote) CanonicalJSONVote {
  61. return CanonicalJSONVote{
  62. CanonicalBlockID(vote.BlockID),
  63. vote.Height,
  64. vote.Round,
  65. vote.Type,
  66. }
  67. }