-
Notifications
You must be signed in to change notification settings - Fork 59
/
beaconblock_encoding.go
138 lines (107 loc) · 2.89 KB
/
beaconblock_encoding.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
// Code generated by fastssz. DO NOT EDIT.
// Hash: 57040b46b62848e02069c034c214adc004278f76d6ba7c873cfb03861727c625
package altair
import (
"github.com/attestantio/go-eth2-client/spec/phase0"
ssz "github.com/ferranbt/fastssz"
)
// MarshalSSZ ssz marshals the BeaconBlock object
func (b *BeaconBlock) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(b)
}
// MarshalSSZTo ssz marshals the BeaconBlock object to a target array
func (b *BeaconBlock) 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(BeaconBlockBody)
}
offset += b.Body.SizeSSZ()
// Field (4) 'Body'
if dst, err = b.Body.MarshalSSZTo(dst); err != nil {
return
}
return
}
// UnmarshalSSZ ssz unmarshals the BeaconBlock object
func (b *BeaconBlock) 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(BeaconBlockBody)
}
if err = b.Body.UnmarshalSSZ(buf); err != nil {
return err
}
}
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the BeaconBlock object
func (b *BeaconBlock) SizeSSZ() (size int) {
size = 84
// Field (4) 'Body'
if b.Body == nil {
b.Body = new(BeaconBlockBody)
}
size += b.Body.SizeSSZ()
return
}
// HashTreeRoot ssz hashes the BeaconBlock object
func (b *BeaconBlock) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(b)
}
// HashTreeRootWith ssz hashes the BeaconBlock object with a hasher
func (b *BeaconBlock) 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 BeaconBlock object
func (b *BeaconBlock) GetTree() (*ssz.Node, error) {
return ssz.ProofTree(b)
}