-
Notifications
You must be signed in to change notification settings - Fork 57
/
blindedbeaconblock_ssz.go
139 lines (108 loc) · 3.03 KB
/
blindedbeaconblock_ssz.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Code generated by fastssz. DO NOT EDIT.
// Hash: cf64e9fea43a736bb29db8f20e642d7bb66ea251b3db8108b7b21826fb9a0a9d
// Version: 0.1.3
package bellatrix
import (
"github.com/attestantio/go-eth2-client/spec/phase0"
ssz "github.com/ferranbt/fastssz"
)
// MarshalSSZ ssz marshals the BlindedBeaconBlock object
func (b *BlindedBeaconBlock) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(b)
}
// MarshalSSZTo ssz marshals the BlindedBeaconBlock object to a target array
func (b *BlindedBeaconBlock) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
offset := int(84)
// Field (0) 'Slot'
dst = ssz.MarshalUint64(dst, uint64(b.Slot))
// Field (1) 'ProposerIndex'
dst = ssz.MarshalUint64(dst, uint64(b.ProposerIndex))
// Field (2) 'ParentRoot'
dst = append(dst, b.ParentRoot[:]...)
// Field (3) 'StateRoot'
dst = append(dst, b.StateRoot[:]...)
// Offset (4) 'Body'
dst = ssz.WriteOffset(dst, offset)
if b.Body == nil {
b.Body = new(BlindedBeaconBlockBody)
}
offset += b.Body.SizeSSZ()
// Field (4) 'Body'
if dst, err = b.Body.MarshalSSZTo(dst); err != nil {
return
}
return
}
// UnmarshalSSZ ssz unmarshals the BlindedBeaconBlock object
func (b *BlindedBeaconBlock) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size < 84 {
return ssz.ErrSize
}
tail := buf
var o4 uint64
// Field (0) 'Slot'
b.Slot = phase0.Slot(ssz.UnmarshallUint64(buf[0:8]))
// Field (1) 'ProposerIndex'
b.ProposerIndex = phase0.ValidatorIndex(ssz.UnmarshallUint64(buf[8:16]))
// Field (2) 'ParentRoot'
copy(b.ParentRoot[:], buf[16:48])
// Field (3) 'StateRoot'
copy(b.StateRoot[:], buf[48:80])
// Offset (4) 'Body'
if o4 = ssz.ReadOffset(buf[80:84]); o4 > size {
return ssz.ErrOffset
}
if o4 < 84 {
return ssz.ErrInvalidVariableOffset
}
// Field (4) 'Body'
{
buf = tail[o4:]
if b.Body == nil {
b.Body = new(BlindedBeaconBlockBody)
}
if err = b.Body.UnmarshalSSZ(buf); err != nil {
return err
}
}
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the BlindedBeaconBlock object
func (b *BlindedBeaconBlock) SizeSSZ() (size int) {
size = 84
// Field (4) 'Body'
if b.Body == nil {
b.Body = new(BlindedBeaconBlockBody)
}
size += b.Body.SizeSSZ()
return
}
// HashTreeRoot ssz hashes the BlindedBeaconBlock object
func (b *BlindedBeaconBlock) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(b)
}
// HashTreeRootWith ssz hashes the BlindedBeaconBlock object with a hasher
func (b *BlindedBeaconBlock) HashTreeRootWith(hh ssz.HashWalker) (err error) {
indx := hh.Index()
// Field (0) 'Slot'
hh.PutUint64(uint64(b.Slot))
// Field (1) 'ProposerIndex'
hh.PutUint64(uint64(b.ProposerIndex))
// Field (2) 'ParentRoot'
hh.PutBytes(b.ParentRoot[:])
// Field (3) 'StateRoot'
hh.PutBytes(b.StateRoot[:])
// Field (4) 'Body'
if err = b.Body.HashTreeRootWith(hh); err != nil {
return
}
hh.Merkleize(indx)
return
}
// GetTree ssz hashes the BlindedBeaconBlock object
func (b *BlindedBeaconBlock) GetTree() (*ssz.Node, error) {
return ssz.ProofTree(b)
}