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.

47 lines
1.2 KiB

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