mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 20:43:57 -05:00
* Move ssz_query objects into testing folder (ensuring test objects only used in test environment) * Add containers for response * Export sszInfo * Add QueryBeaconState/Block * Add comments and few refactor * Fix merge conflict issues * Return 500 when calculate offset fails * Add test for QueryBeaconState * Add test for QueryBeaconBlock * Changelog :) * Rename `QuerySSZRequest` to `SSZQueryRequest` * Fix middleware hooks for RPC to accept JSON from client and return SSZ * Convert to `SSZObject` directly from proto * Move marshalling/calculating hash tree root part after `CalculateOffsetAndLength` * Make nogo happy * Add informing comment for using proto unsafe conversion --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
411 lines
8.6 KiB
Go
411 lines
8.6 KiB
Go
// Code generated by fastssz. DO NOT EDIT.
|
|
package ssz_query
|
|
|
|
import (
|
|
ssz "github.com/prysmaticlabs/fastssz"
|
|
)
|
|
|
|
// MarshalSSZ ssz marshals the SSZQueryProof object
|
|
func (s *SSZQueryProof) MarshalSSZ() ([]byte, error) {
|
|
return ssz.MarshalSSZ(s)
|
|
}
|
|
|
|
// MarshalSSZTo ssz marshals the SSZQueryProof object to a target array
|
|
func (s *SSZQueryProof) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
|
dst = buf
|
|
offset := int(44)
|
|
|
|
// Field (0) 'Leaf'
|
|
if size := len(s.Leaf); size != 32 {
|
|
err = ssz.ErrBytesLengthFn("--.Leaf", size, 32)
|
|
return
|
|
}
|
|
dst = append(dst, s.Leaf...)
|
|
|
|
// Field (1) 'Gindex'
|
|
dst = ssz.MarshalUint64(dst, s.Gindex)
|
|
|
|
// Offset (2) 'Proofs'
|
|
dst = ssz.WriteOffset(dst, offset)
|
|
offset += len(s.Proofs) * 32
|
|
|
|
// Field (2) 'Proofs'
|
|
if size := len(s.Proofs); size > 64 {
|
|
err = ssz.ErrListTooBigFn("--.Proofs", size, 64)
|
|
return
|
|
}
|
|
for ii := 0; ii < len(s.Proofs); ii++ {
|
|
if size := len(s.Proofs[ii]); size != 32 {
|
|
err = ssz.ErrBytesLengthFn("--.Proofs[ii]", size, 32)
|
|
return
|
|
}
|
|
dst = append(dst, s.Proofs[ii]...)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// UnmarshalSSZ ssz unmarshals the SSZQueryProof object
|
|
func (s *SSZQueryProof) UnmarshalSSZ(buf []byte) error {
|
|
var err error
|
|
size := uint64(len(buf))
|
|
if size < 44 {
|
|
return ssz.ErrSize
|
|
}
|
|
|
|
tail := buf
|
|
var o2 uint64
|
|
|
|
// Field (0) 'Leaf'
|
|
if cap(s.Leaf) == 0 {
|
|
s.Leaf = make([]byte, 0, len(buf[0:32]))
|
|
}
|
|
s.Leaf = append(s.Leaf, buf[0:32]...)
|
|
|
|
// Field (1) 'Gindex'
|
|
s.Gindex = ssz.UnmarshallUint64(buf[32:40])
|
|
|
|
// Offset (2) 'Proofs'
|
|
if o2 = ssz.ReadOffset(buf[40:44]); o2 > size {
|
|
return ssz.ErrOffset
|
|
}
|
|
|
|
if o2 != 44 {
|
|
return ssz.ErrInvalidVariableOffset
|
|
}
|
|
|
|
// Field (2) 'Proofs'
|
|
{
|
|
buf = tail[o2:]
|
|
num, err := ssz.DivideInt2(len(buf), 32, 64)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
s.Proofs = make([][]byte, num)
|
|
for ii := 0; ii < num; ii++ {
|
|
if cap(s.Proofs[ii]) == 0 {
|
|
s.Proofs[ii] = make([]byte, 0, len(buf[ii*32:(ii+1)*32]))
|
|
}
|
|
s.Proofs[ii] = append(s.Proofs[ii], buf[ii*32:(ii+1)*32]...)
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
// SizeSSZ returns the ssz encoded size in bytes for the SSZQueryProof object
|
|
func (s *SSZQueryProof) SizeSSZ() (size int) {
|
|
size = 44
|
|
|
|
// Field (2) 'Proofs'
|
|
size += len(s.Proofs) * 32
|
|
|
|
return
|
|
}
|
|
|
|
// HashTreeRoot ssz hashes the SSZQueryProof object
|
|
func (s *SSZQueryProof) HashTreeRoot() ([32]byte, error) {
|
|
return ssz.HashWithDefaultHasher(s)
|
|
}
|
|
|
|
// HashTreeRootWith ssz hashes the SSZQueryProof object with a hasher
|
|
func (s *SSZQueryProof) HashTreeRootWith(hh *ssz.Hasher) (err error) {
|
|
indx := hh.Index()
|
|
|
|
// Field (0) 'Leaf'
|
|
if size := len(s.Leaf); size != 32 {
|
|
err = ssz.ErrBytesLengthFn("--.Leaf", size, 32)
|
|
return
|
|
}
|
|
hh.PutBytes(s.Leaf)
|
|
|
|
// Field (1) 'Gindex'
|
|
hh.PutUint64(s.Gindex)
|
|
|
|
// Field (2) 'Proofs'
|
|
{
|
|
if size := len(s.Proofs); size > 64 {
|
|
err = ssz.ErrListTooBigFn("--.Proofs", size, 64)
|
|
return
|
|
}
|
|
subIndx := hh.Index()
|
|
for _, i := range s.Proofs {
|
|
if len(i) != 32 {
|
|
err = ssz.ErrBytesLength
|
|
return
|
|
}
|
|
hh.Append(i)
|
|
}
|
|
|
|
numItems := uint64(len(s.Proofs))
|
|
hh.MerkleizeWithMixin(subIndx, numItems, 64)
|
|
}
|
|
|
|
hh.Merkleize(indx)
|
|
return
|
|
}
|
|
|
|
// MarshalSSZ ssz marshals the SSZQueryResponse object
|
|
func (s *SSZQueryResponse) MarshalSSZ() ([]byte, error) {
|
|
return ssz.MarshalSSZ(s)
|
|
}
|
|
|
|
// MarshalSSZTo ssz marshals the SSZQueryResponse object to a target array
|
|
func (s *SSZQueryResponse) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
|
dst = buf
|
|
offset := int(36)
|
|
|
|
// Field (0) 'Root'
|
|
if size := len(s.Root); size != 32 {
|
|
err = ssz.ErrBytesLengthFn("--.Root", size, 32)
|
|
return
|
|
}
|
|
dst = append(dst, s.Root...)
|
|
|
|
// Offset (1) 'Result'
|
|
dst = ssz.WriteOffset(dst, offset)
|
|
offset += len(s.Result)
|
|
|
|
// Field (1) 'Result'
|
|
if size := len(s.Result); size > 1073741824 {
|
|
err = ssz.ErrBytesLengthFn("--.Result", size, 1073741824)
|
|
return
|
|
}
|
|
dst = append(dst, s.Result...)
|
|
|
|
return
|
|
}
|
|
|
|
// UnmarshalSSZ ssz unmarshals the SSZQueryResponse object
|
|
func (s *SSZQueryResponse) UnmarshalSSZ(buf []byte) error {
|
|
var err error
|
|
size := uint64(len(buf))
|
|
if size < 36 {
|
|
return ssz.ErrSize
|
|
}
|
|
|
|
tail := buf
|
|
var o1 uint64
|
|
|
|
// Field (0) 'Root'
|
|
if cap(s.Root) == 0 {
|
|
s.Root = make([]byte, 0, len(buf[0:32]))
|
|
}
|
|
s.Root = append(s.Root, buf[0:32]...)
|
|
|
|
// Offset (1) 'Result'
|
|
if o1 = ssz.ReadOffset(buf[32:36]); o1 > size {
|
|
return ssz.ErrOffset
|
|
}
|
|
|
|
if o1 != 36 {
|
|
return ssz.ErrInvalidVariableOffset
|
|
}
|
|
|
|
// Field (1) 'Result'
|
|
{
|
|
buf = tail[o1:]
|
|
if len(buf) > 1073741824 {
|
|
return ssz.ErrBytesLength
|
|
}
|
|
if cap(s.Result) == 0 {
|
|
s.Result = make([]byte, 0, len(buf))
|
|
}
|
|
s.Result = append(s.Result, buf...)
|
|
}
|
|
return err
|
|
}
|
|
|
|
// SizeSSZ returns the ssz encoded size in bytes for the SSZQueryResponse object
|
|
func (s *SSZQueryResponse) SizeSSZ() (size int) {
|
|
size = 36
|
|
|
|
// Field (1) 'Result'
|
|
size += len(s.Result)
|
|
|
|
return
|
|
}
|
|
|
|
// HashTreeRoot ssz hashes the SSZQueryResponse object
|
|
func (s *SSZQueryResponse) HashTreeRoot() ([32]byte, error) {
|
|
return ssz.HashWithDefaultHasher(s)
|
|
}
|
|
|
|
// HashTreeRootWith ssz hashes the SSZQueryResponse object with a hasher
|
|
func (s *SSZQueryResponse) HashTreeRootWith(hh *ssz.Hasher) (err error) {
|
|
indx := hh.Index()
|
|
|
|
// Field (0) 'Root'
|
|
if size := len(s.Root); size != 32 {
|
|
err = ssz.ErrBytesLengthFn("--.Root", size, 32)
|
|
return
|
|
}
|
|
hh.PutBytes(s.Root)
|
|
|
|
// Field (1) 'Result'
|
|
{
|
|
elemIndx := hh.Index()
|
|
byteLen := uint64(len(s.Result))
|
|
if byteLen > 1073741824 {
|
|
err = ssz.ErrIncorrectListSize
|
|
return
|
|
}
|
|
hh.PutBytes(s.Result)
|
|
hh.MerkleizeWithMixin(elemIndx, byteLen, (1073741824+31)/32)
|
|
}
|
|
|
|
hh.Merkleize(indx)
|
|
return
|
|
}
|
|
|
|
// MarshalSSZ ssz marshals the SSZQueryResponseWithProof object
|
|
func (s *SSZQueryResponseWithProof) MarshalSSZ() ([]byte, error) {
|
|
return ssz.MarshalSSZ(s)
|
|
}
|
|
|
|
// MarshalSSZTo ssz marshals the SSZQueryResponseWithProof object to a target array
|
|
func (s *SSZQueryResponseWithProof) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
|
dst = buf
|
|
offset := int(40)
|
|
|
|
// Field (0) 'Root'
|
|
if size := len(s.Root); size != 32 {
|
|
err = ssz.ErrBytesLengthFn("--.Root", size, 32)
|
|
return
|
|
}
|
|
dst = append(dst, s.Root...)
|
|
|
|
// Offset (1) 'Result'
|
|
dst = ssz.WriteOffset(dst, offset)
|
|
offset += len(s.Result)
|
|
|
|
// Offset (2) 'Proof'
|
|
dst = ssz.WriteOffset(dst, offset)
|
|
if s.Proof == nil {
|
|
s.Proof = new(SSZQueryProof)
|
|
}
|
|
offset += s.Proof.SizeSSZ()
|
|
|
|
// Field (1) 'Result'
|
|
if size := len(s.Result); size > 1073741824 {
|
|
err = ssz.ErrBytesLengthFn("--.Result", size, 1073741824)
|
|
return
|
|
}
|
|
dst = append(dst, s.Result...)
|
|
|
|
// Field (2) 'Proof'
|
|
if dst, err = s.Proof.MarshalSSZTo(dst); err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// UnmarshalSSZ ssz unmarshals the SSZQueryResponseWithProof object
|
|
func (s *SSZQueryResponseWithProof) UnmarshalSSZ(buf []byte) error {
|
|
var err error
|
|
size := uint64(len(buf))
|
|
if size < 40 {
|
|
return ssz.ErrSize
|
|
}
|
|
|
|
tail := buf
|
|
var o1, o2 uint64
|
|
|
|
// Field (0) 'Root'
|
|
if cap(s.Root) == 0 {
|
|
s.Root = make([]byte, 0, len(buf[0:32]))
|
|
}
|
|
s.Root = append(s.Root, buf[0:32]...)
|
|
|
|
// Offset (1) 'Result'
|
|
if o1 = ssz.ReadOffset(buf[32:36]); o1 > size {
|
|
return ssz.ErrOffset
|
|
}
|
|
|
|
if o1 != 40 {
|
|
return ssz.ErrInvalidVariableOffset
|
|
}
|
|
|
|
// Offset (2) 'Proof'
|
|
if o2 = ssz.ReadOffset(buf[36:40]); o2 > size || o1 > o2 {
|
|
return ssz.ErrOffset
|
|
}
|
|
|
|
// Field (1) 'Result'
|
|
{
|
|
buf = tail[o1:o2]
|
|
if len(buf) > 1073741824 {
|
|
return ssz.ErrBytesLength
|
|
}
|
|
if cap(s.Result) == 0 {
|
|
s.Result = make([]byte, 0, len(buf))
|
|
}
|
|
s.Result = append(s.Result, buf...)
|
|
}
|
|
|
|
// Field (2) 'Proof'
|
|
{
|
|
buf = tail[o2:]
|
|
if s.Proof == nil {
|
|
s.Proof = new(SSZQueryProof)
|
|
}
|
|
if err = s.Proof.UnmarshalSSZ(buf); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
// SizeSSZ returns the ssz encoded size in bytes for the SSZQueryResponseWithProof object
|
|
func (s *SSZQueryResponseWithProof) SizeSSZ() (size int) {
|
|
size = 40
|
|
|
|
// Field (1) 'Result'
|
|
size += len(s.Result)
|
|
|
|
// Field (2) 'Proof'
|
|
if s.Proof == nil {
|
|
s.Proof = new(SSZQueryProof)
|
|
}
|
|
size += s.Proof.SizeSSZ()
|
|
|
|
return
|
|
}
|
|
|
|
// HashTreeRoot ssz hashes the SSZQueryResponseWithProof object
|
|
func (s *SSZQueryResponseWithProof) HashTreeRoot() ([32]byte, error) {
|
|
return ssz.HashWithDefaultHasher(s)
|
|
}
|
|
|
|
// HashTreeRootWith ssz hashes the SSZQueryResponseWithProof object with a hasher
|
|
func (s *SSZQueryResponseWithProof) HashTreeRootWith(hh *ssz.Hasher) (err error) {
|
|
indx := hh.Index()
|
|
|
|
// Field (0) 'Root'
|
|
if size := len(s.Root); size != 32 {
|
|
err = ssz.ErrBytesLengthFn("--.Root", size, 32)
|
|
return
|
|
}
|
|
hh.PutBytes(s.Root)
|
|
|
|
// Field (1) 'Result'
|
|
{
|
|
elemIndx := hh.Index()
|
|
byteLen := uint64(len(s.Result))
|
|
if byteLen > 1073741824 {
|
|
err = ssz.ErrIncorrectListSize
|
|
return
|
|
}
|
|
hh.PutBytes(s.Result)
|
|
hh.MerkleizeWithMixin(elemIndx, byteLen, (1073741824+31)/32)
|
|
}
|
|
|
|
// Field (2) 'Proof'
|
|
if err = s.Proof.HashTreeRootWith(hh); err != nil {
|
|
return
|
|
}
|
|
|
|
hh.Merkleize(indx)
|
|
return
|
|
}
|