-
Notifications
You must be signed in to change notification settings - Fork 59
/
aggregateandproof_encoding.go
109 lines (86 loc) · 2.39 KB
/
aggregateandproof_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
// Code generated by fastssz. DO NOT EDIT.
package phase0
import (
ssz "github.com/ferranbt/fastssz"
)
// MarshalSSZ ssz marshals the AggregateAndProof object
func (a *AggregateAndProof) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(a)
}
// MarshalSSZTo ssz marshals the AggregateAndProof object to a target array
func (a *AggregateAndProof) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
offset := int(108)
// Field (0) 'AggregatorIndex'
dst = ssz.MarshalUint64(dst, uint64(a.AggregatorIndex))
// Offset (1) 'Aggregate'
dst = ssz.WriteOffset(dst, offset)
if a.Aggregate == nil {
a.Aggregate = new(Attestation)
}
offset += a.Aggregate.SizeSSZ()
// Field (2) 'SelectionProof'
dst = append(dst, a.SelectionProof[:]...)
// Field (1) 'Aggregate'
if dst, err = a.Aggregate.MarshalSSZTo(dst); err != nil {
return
}
return
}
// UnmarshalSSZ ssz unmarshals the AggregateAndProof object
func (a *AggregateAndProof) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size < 108 {
return ssz.ErrSize
}
tail := buf
var o1 uint64
// Field (0) 'AggregatorIndex'
a.AggregatorIndex = ValidatorIndex(ssz.UnmarshallUint64(buf[0:8]))
// Offset (1) 'Aggregate'
if o1 = ssz.ReadOffset(buf[8:12]); o1 > size {
return ssz.ErrOffset
}
// Field (2) 'SelectionProof'
copy(a.SelectionProof[:], buf[12:108])
// Field (1) 'Aggregate'
{
buf = tail[o1:]
if a.Aggregate == nil {
a.Aggregate = new(Attestation)
}
if err = a.Aggregate.UnmarshalSSZ(buf); err != nil {
return err
}
}
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the AggregateAndProof object
func (a *AggregateAndProof) SizeSSZ() (size int) {
size = 108
// Field (1) 'Aggregate'
if a.Aggregate == nil {
a.Aggregate = new(Attestation)
}
size += a.Aggregate.SizeSSZ()
return
}
// HashTreeRoot ssz hashes the AggregateAndProof object
func (a *AggregateAndProof) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(a)
}
// HashTreeRootWith ssz hashes the AggregateAndProof object with a hasher
func (a *AggregateAndProof) HashTreeRootWith(hh *ssz.Hasher) (err error) {
indx := hh.Index()
// Field (0) 'AggregatorIndex'
hh.PutUint64(uint64(a.AggregatorIndex))
// Field (1) 'Aggregate'
if err = a.Aggregate.HashTreeRootWith(hh); err != nil {
return
}
// Field (2) 'SelectionProof'
hh.PutBytes(a.SelectionProof[:])
hh.Merkleize(indx)
return
}