-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterators.go
68 lines (57 loc) · 1.36 KB
/
iterators.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
// (c) 2021-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package syncutils
import (
"github.com/coinflect/coreth/core/state/snapshot"
"github.com/coinflect/coreth/ethdb"
)
var (
_ ethdb.Iterator = &AccountIterator{}
_ ethdb.Iterator = &StorageIterator{}
)
// AccountIterator wraps a [snapshot.AccountIterator] to conform to [ethdb.Iterator]
// accounts will be returned in consensus (FullRLP) format for compatibility with trie data.
type AccountIterator struct {
snapshot.AccountIterator
err error
val []byte
}
func (it *AccountIterator) Next() bool {
if it.err != nil {
return false
}
for it.AccountIterator.Next() {
it.val, it.err = snapshot.FullAccountRLP(it.Account())
return it.err == nil
}
it.val = nil
return false
}
func (it *AccountIterator) Key() []byte {
if it.err != nil {
return nil
}
return it.Hash().Bytes()
}
func (it *AccountIterator) Value() []byte {
if it.err != nil {
return nil
}
return it.val
}
func (it *AccountIterator) Error() error {
if it.err != nil {
return it.err
}
return it.AccountIterator.Error()
}
// StorageIterator wraps a [snapshot.StorageIterator] to conform to [ethdb.Iterator]
type StorageIterator struct {
snapshot.StorageIterator
}
func (it *StorageIterator) Key() []byte {
return it.Hash().Bytes()
}
func (it *StorageIterator) Value() []byte {
return it.Slot()
}