diff --git a/rlp/iterator.go b/rlp/iterator.go index a67e6651f5..f1f214c4bc 100644 --- a/rlp/iterator.go +++ b/rlp/iterator.go @@ -25,20 +25,20 @@ type Iterator struct { } // NewListIterator creates an iterator for the (list) represented by data. -func NewListIterator(data RawValue) (*Iterator, error) { +func NewListIterator(data RawValue) (Iterator, error) { k, t, c, err := readKind(data) if err != nil { - return nil, err + return Iterator{}, err } if k != List { - return nil, ErrExpectedList + return Iterator{}, ErrExpectedList } - it := &Iterator{data: data[t : t+c], offset: int(t)} + it := newIterator(data[t:t+c], int(t)) return it, nil } -func newIterator(data []byte) *Iterator { - return &Iterator{data: data} +func newIterator(data []byte, initialOffset int) Iterator { + return Iterator{data: data, offset: initialOffset} } // Next forwards the iterator one step. diff --git a/rlp/raw.go b/rlp/raw.go index 876a503d70..8d171ce0f6 100644 --- a/rlp/raw.go +++ b/rlp/raw.go @@ -122,8 +122,8 @@ func (r *RawList[T]) Empty() bool { // ContentIterator returns an iterator over the content of the list. // Note the offsets returned by iterator.Offset are relative to the // Content bytes of the list. -func (r *RawList[T]) ContentIterator() *Iterator { - return newIterator(r.Content()) +func (r *RawList[T]) ContentIterator() Iterator { + return newIterator(r.Content(), 0) } // Append adds an item to the end of the list.