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