github.com/evdatsion/aphelion-dpos-bft@v0.32.1/types/block_meta.go (about) 1 package types 2 3 // BlockMeta contains meta information about a block - namely, it's ID and Header. 4 type BlockMeta struct { 5 BlockID BlockID `json:"block_id"` // the block hash and partsethash 6 Header Header `json:"header"` // The block's Header 7 } 8 9 // NewBlockMeta returns a new BlockMeta from the block and its blockParts. 10 func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta { 11 return &BlockMeta{ 12 BlockID: BlockID{block.Hash(), blockParts.Header()}, 13 Header: block.Header, 14 } 15 } 16 17 //----------------------------------------------------------- 18 // These methods are for Protobuf Compatibility 19 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 26 // Marshal returns the amino encoding. 27 func (bm *BlockMeta) Marshal() ([]byte, error) { 28 return cdc.MarshalBinaryBare(bm) 29 } 30 31 // MarshalTo calls Marshal and copies to the given buffer. 32 func (bm *BlockMeta) MarshalTo(data []byte) (int, error) { 33 bs, err := bm.Marshal() 34 if err != nil { 35 return -1, err 36 } 37 return copy(data, bs), nil 38 } 39 40 // Unmarshal deserializes from amino encoded form. 41 func (bm *BlockMeta) Unmarshal(bs []byte) error { 42 return cdc.UnmarshalBinaryBare(bs, bm) 43 }