Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

update ssz.go with latest changes #991

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions types/ssz/ssz.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/length"

"github.com/ledgerwatch/erigon-lib/types/clonable"
)

Expand All @@ -45,8 +44,7 @@ type Marshaler interface {
}

type Unmarshaler interface {
DecodeSSZ(buf []byte) error
DecodeSSZWithVersion(buf []byte, version int) error
DecodeSSZ(buf []byte, version int) error
clonable.Clonable
}

Expand Down Expand Up @@ -87,7 +85,7 @@ func UnmarshalUint64SSZ(x []byte) uint64 {
return binary.LittleEndian.Uint64(x)
}

func DecodeDynamicList[T Unmarshaler](bytes []byte, start, end uint32, max uint64) ([]T, error) {
func DecodeDynamicList[T Unmarshaler](bytes []byte, start, end uint32, max uint64, version int) ([]T, error) {
if start > end || len(bytes) < int(end) {
return nil, ErrBadOffset
}
Expand Down Expand Up @@ -115,15 +113,15 @@ func DecodeDynamicList[T Unmarshaler](bytes []byte, start, end uint32, max uint6
return nil, ErrBadOffset
}
objs[i] = objs[i].Clone().(T)
if err := objs[i].DecodeSSZ(buf[currentOffset:endOffset]); err != nil {
if err := objs[i].DecodeSSZ(buf[currentOffset:endOffset], version); err != nil {
return nil, err
}
currentOffset = endOffset
}
return objs, nil
}

func DecodeStaticList[T Unmarshaler](bytes []byte, start, end, bytesPerElement uint32, max uint64) ([]T, error) {
func DecodeStaticList[T Unmarshaler](bytes []byte, start, end, bytesPerElement uint32, max uint64, version int) ([]T, error) {
if start > end || len(bytes) < int(end) {
return nil, ErrBadOffset
}
Expand All @@ -139,7 +137,7 @@ func DecodeStaticList[T Unmarshaler](bytes []byte, start, end, bytesPerElement u
objs := make([]T, elementsNum)
for i := range objs {
objs[i] = objs[i].Clone().(T)
if err := objs[i].DecodeSSZ(buf[i*int(bytesPerElement):]); err != nil {
if err := objs[i].DecodeSSZ(buf[i*int(bytesPerElement):], version); err != nil {
return nil, err
}
}
Expand Down
Loading