/
block_data.go
58 lines (45 loc) · 1.2 KB
/
block_data.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only
package types
import (
"fmt"
"github.com/ChainSafe/gossamer/lib/common"
)
// BlockData is stored within the BlockDB
// The BlockData fields are optionals and thus are represented as pointers to ensure
// correct encoding
type BlockData struct {
Hash common.Hash
Header *Header
Body *Body
Receipt *[]byte
MessageQueue *[]byte
Justification *[]byte
}
// NewEmptyBlockData Creates an empty blockData struct
func NewEmptyBlockData() *BlockData {
return &BlockData{}
}
// Number returns the block header number.
func (bd *BlockData) Number() uint {
return bd.Header.Number
}
func (bd *BlockData) String() string {
str := fmt.Sprintf("Hash=%s ", bd.Hash)
if bd.Header != nil {
str = str + fmt.Sprintf("Header=%s ", bd.Header)
}
if bd.Body != nil {
str = str + fmt.Sprintf("Body=%s ", *bd.Body)
}
if bd.Receipt != nil {
str = str + fmt.Sprintf("Receipt=0x%x ", bd.Receipt)
}
if bd.MessageQueue != nil {
str = str + fmt.Sprintf("MessageQueue=0x%x ", bd.MessageQueue)
}
if bd.Justification != nil {
str = str + fmt.Sprintf("Justification=0x%x ", bd.Justification)
}
return str
}