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.

45 lines
1.1 KiB

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