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
2.2 KiB

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