github.com/MetalBlockchain/subnet-evm@v0.4.9/sync/syncutils/iterators.go (about) 1 // (c) 2021-2022, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package syncutils 5 6 import ( 7 "github.com/MetalBlockchain/subnet-evm/core/state/snapshot" 8 "github.com/MetalBlockchain/subnet-evm/ethdb" 9 ) 10 11 var ( 12 _ ethdb.Iterator = &AccountIterator{} 13 _ ethdb.Iterator = &StorageIterator{} 14 ) 15 16 // AccountIterator wraps a [snapshot.AccountIterator] to conform to [ethdb.Iterator] 17 // accounts will be returned in consensus (FullRLP) format for compatibility with trie data. 18 type AccountIterator struct { 19 snapshot.AccountIterator 20 err error 21 val []byte 22 } 23 24 func (it *AccountIterator) Next() bool { 25 if it.err != nil { 26 return false 27 } 28 for it.AccountIterator.Next() { 29 it.val, it.err = snapshot.FullAccountRLP(it.Account()) 30 return it.err == nil 31 } 32 it.val = nil 33 return false 34 } 35 36 func (it *AccountIterator) Key() []byte { 37 if it.err != nil { 38 return nil 39 } 40 return it.Hash().Bytes() 41 } 42 43 func (it *AccountIterator) Value() []byte { 44 if it.err != nil { 45 return nil 46 } 47 return it.val 48 } 49 50 func (it *AccountIterator) Error() error { 51 if it.err != nil { 52 return it.err 53 } 54 return it.AccountIterator.Error() 55 } 56 57 // StorageIterator wraps a [snapshot.StorageIterator] to conform to [ethdb.Iterator] 58 type StorageIterator struct { 59 snapshot.StorageIterator 60 } 61 62 func (it *StorageIterator) Key() []byte { 63 return it.Hash().Bytes() 64 } 65 66 func (it *StorageIterator) Value() []byte { 67 return it.Slot() 68 }