forked from attestantio/go-builder-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builderbid_ssz.go
136 lines (111 loc) · 2.8 KB
/
builderbid_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
// Code generated by fastssz. DO NOT EDIT.
// Hash: 9eb249d7f5f08129f3d3a9bd85af740731ca3ae3150677f16209e6b728acd4f5
// Version: 0.1.3
package capella
import (
"github.com/MEV-HEPU/go-eth2-client/spec/capella"
ssz "github.com/MEV-HEPU/fastssz"
"github.com/holiman/uint256"
)
// MarshalSSZ ssz marshals the BuilderBid object
func (b *BuilderBid) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(b)
}
// MarshalSSZTo ssz marshals the BuilderBid object to a target array
func (b *BuilderBid) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
offset := int(84)
// Offset (0) 'Header'
dst = ssz.WriteOffset(dst, offset)
if b.Header == nil {
b.Header = new(capella.ExecutionPayloadHeader)
}
offset += b.Header.SizeSSZ()
// Field (1) 'Value'
value := b.Value.Bytes32()
for i := 0; i < 32; i++ {
dst = append(dst, value[31-i])
}
// Field (2) 'Pubkey'
dst = append(dst, b.Pubkey[:]...)
// Field (0) 'Header'
if dst, err = b.Header.MarshalSSZTo(dst); err != nil {
return
}
return
}
// UnmarshalSSZ ssz unmarshals the BuilderBid object
func (b *BuilderBid) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size < 84 {
return ssz.ErrSize
}
tail := buf
var o0 uint64
// Offset (0) 'Header'
if o0 = ssz.ReadOffset(buf[0:4]); o0 > size {
return ssz.ErrOffset
}
if o0 < 84 {
return ssz.ErrInvalidVariableOffset
}
// Field (1) 'Value'
value := make([]byte, 32)
for i := 0; i < 32; i++ {
value[i] = buf[35-i]
}
if b.Value == nil {
b.Value = new(uint256.Int)
}
b.Value.SetBytes32(value)
// Field (2) 'Pubkey'
copy(b.Pubkey[:], buf[36:84])
// Field (0) 'Header'
{
buf = tail[o0:]
if b.Header == nil {
b.Header = new(capella.ExecutionPayloadHeader)
}
if err = b.Header.UnmarshalSSZ(buf); err != nil {
return err
}
}
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the BuilderBid object
func (b *BuilderBid) SizeSSZ() (size int) {
size = 84
// Field (0) 'Header'
if b.Header == nil {
b.Header = new(capella.ExecutionPayloadHeader)
}
size += b.Header.SizeSSZ()
return
}
// HashTreeRoot ssz hashes the BuilderBid object
func (b *BuilderBid) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(b)
}
// HashTreeRootWith ssz hashes the BuilderBid object with a hasher
func (b *BuilderBid) HashTreeRootWith(hh ssz.HashWalker) (err error) {
indx := hh.Index()
// Field (0) 'Header'
if err = b.Header.HashTreeRootWith(hh); err != nil {
return
}
// Field (1) 'Value'
value := b.Value.Bytes32()
for i, j := 0, 31; i < j; i, j = i+1, j-1 {
value[i], value[j] = value[j], value[i]
}
hh.PutBytes(value[:])
// Field (2) 'Pubkey'
hh.PutBytes(b.Pubkey[:])
hh.Merkleize(indx)
return
}
// GetTree ssz hashes the BuilderBid object
func (b *BuilderBid) GetTree() (*ssz.Node, error) {
return ssz.ProofTree(b)
}