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.

43 lines
1.2 KiB

7 years ago
7 years ago
  1. package types
  2. // BlockMeta contains meta information about a block - namely, it's ID and Header.
  3. type BlockMeta struct {
  4. BlockID BlockID `json:"block_id"` // the block hash and partsethash
  5. Header Header `json:"header"` // The block's Header
  6. }
  7. // NewBlockMeta returns a new BlockMeta from the block and its blockParts.
  8. func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta {
  9. return &BlockMeta{
  10. BlockID: BlockID{block.Hash(), blockParts.Header()},
  11. Header: block.Header,
  12. }
  13. }
  14. //-----------------------------------------------------------
  15. // These methods are for Protobuf Compatibility
  16. // Size returns the size of the amino encoding, in bytes.
  17. func (bm *BlockMeta) Size() int {
  18. bs, _ := bm.Marshal()
  19. return len(bs)
  20. }
  21. // Marshal returns the amino encoding.
  22. func (bm *BlockMeta) Marshal() ([]byte, error) {
  23. return cdc.MarshalBinaryBare(bm)
  24. }
  25. // MarshalTo calls Marshal and copies to the given buffer.
  26. func (bm *BlockMeta) MarshalTo(data []byte) (int, error) {
  27. bs, err := bm.Marshal()
  28. if err != nil {
  29. return -1, err
  30. }
  31. return copy(data, bs), nil
  32. }
  33. // Unmarshal deserializes from amino encoded form.
  34. func (bm *BlockMeta) Unmarshal(bs []byte) error {
  35. return cdc.UnmarshalBinaryBare(bs, bm)
  36. }