Skip to content

Commit

Permalink
update ssz.go with latest changes (ledgerwatch#991)
Browse files Browse the repository at this point in the history
cl/cltypes/ssz.go in the erigon client repo changed before I had the
chance to remove it
  • Loading branch information
roberto-bayardo authored and calmbeing committed Jul 12, 2023
1 parent 2f796fd commit d1c8a9b
Showing 1 changed file with 5 additions and 7 deletions.
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

0 comments on commit d1c8a9b

Please sign in to comment.