-
Notifications
You must be signed in to change notification settings - Fork 59
/
deposit_encoding.go
108 lines (92 loc) · 2.12 KB
/
deposit_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
// Code generated by fastssz. DO NOT EDIT.
package phase0
import (
ssz "github.com/ferranbt/fastssz"
)
// MarshalSSZ ssz marshals the Deposit object
func (d *Deposit) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(d)
}
// MarshalSSZTo ssz marshals the Deposit object to a target array
func (d *Deposit) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
// Field (0) 'Proof'
if len(d.Proof) != 33 {
err = ssz.ErrVectorLength
return
}
for ii := 0; ii < 33; ii++ {
if len(d.Proof[ii]) != 32 {
err = ssz.ErrBytesLength
return
}
dst = append(dst, d.Proof[ii]...)
}
// Field (1) 'Data'
if d.Data == nil {
d.Data = new(DepositData)
}
if dst, err = d.Data.MarshalSSZTo(dst); err != nil {
return
}
return
}
// UnmarshalSSZ ssz unmarshals the Deposit object
func (d *Deposit) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size != 1240 {
return ssz.ErrSize
}
// Field (0) 'Proof'
d.Proof = make([][]byte, 33)
for ii := 0; ii < 33; ii++ {
if cap(d.Proof[ii]) == 0 {
d.Proof[ii] = make([]byte, 0, len(buf[0:1056][ii*32:(ii+1)*32]))
}
d.Proof[ii] = append(d.Proof[ii], buf[0:1056][ii*32:(ii+1)*32]...)
}
// Field (1) 'Data'
if d.Data == nil {
d.Data = new(DepositData)
}
if err = d.Data.UnmarshalSSZ(buf[1056:1240]); err != nil {
return err
}
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the Deposit object
func (d *Deposit) SizeSSZ() (size int) {
size = 1240
return
}
// HashTreeRoot ssz hashes the Deposit object
func (d *Deposit) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(d)
}
// HashTreeRootWith ssz hashes the Deposit object with a hasher
func (d *Deposit) HashTreeRootWith(hh *ssz.Hasher) (err error) {
indx := hh.Index()
// Field (0) 'Proof'
{
if len(d.Proof) != 33 {
err = ssz.ErrVectorLength
return
}
subIndx := hh.Index()
for _, i := range d.Proof {
if len(i) != 32 {
err = ssz.ErrBytesLength
return
}
hh.Append(i)
}
hh.Merkleize(subIndx)
}
// Field (1) 'Data'
if err = d.Data.HashTreeRootWith(hh); err != nil {
return
}
hh.Merkleize(indx)
return
}