core/state/snapshot: full featured account iteration
This commit is contained in:
@ -40,10 +40,10 @@ func (dl *diffLayer) newBinaryAccountIterator() AccountIterator {
|
||||
parent, ok := dl.parent.(*diffLayer)
|
||||
if !ok {
|
||||
// parent is the disk layer
|
||||
return dl.newAccountIterator()
|
||||
return dl.AccountIterator(common.Hash{})
|
||||
}
|
||||
l := &binaryAccountIterator{
|
||||
a: dl.newAccountIterator(),
|
||||
a: dl.AccountIterator(common.Hash{}).(*diffAccountIterator),
|
||||
b: parent.newBinaryAccountIterator(),
|
||||
}
|
||||
l.aDone = !l.a.Next()
|
||||
@ -51,12 +51,6 @@ func (dl *diffLayer) newBinaryAccountIterator() AccountIterator {
|
||||
return l
|
||||
}
|
||||
|
||||
// Seek steps the iterator forward as many elements as needed, so that after
|
||||
// calling Next(), the iterator will be at a key higher than the given hash.
|
||||
func (it *binaryAccountIterator) Seek(key common.Hash) {
|
||||
panic("todo: implement")
|
||||
}
|
||||
|
||||
// Next steps the iterator forward one element, returning false if exhausted,
|
||||
// or an error if iteration failed for some reason (e.g. root being iterated
|
||||
// becomes stale and garbage collected).
|
||||
@ -64,9 +58,9 @@ func (it *binaryAccountIterator) Next() bool {
|
||||
if it.aDone && it.bDone {
|
||||
return false
|
||||
}
|
||||
nextB := it.b.Key()
|
||||
nextB := it.b.Hash()
|
||||
first:
|
||||
nextA := it.a.Key()
|
||||
nextA := it.a.Hash()
|
||||
if it.aDone {
|
||||
it.bDone = !it.b.Next()
|
||||
it.k = nextB
|
||||
@ -97,15 +91,15 @@ func (it *binaryAccountIterator) Error() error {
|
||||
return it.fail
|
||||
}
|
||||
|
||||
// Key returns the hash of the account the iterator is currently at.
|
||||
func (it *binaryAccountIterator) Key() common.Hash {
|
||||
// Hash returns the hash of the account the iterator is currently at.
|
||||
func (it *binaryAccountIterator) Hash() common.Hash {
|
||||
return it.k
|
||||
}
|
||||
|
||||
// Value returns the RLP encoded slim account the iterator is currently at, or
|
||||
// Account returns the RLP encoded slim account the iterator is currently at, or
|
||||
// nil if the iterated snapshot stack became stale (you can check Error after
|
||||
// to see if it failed or not).
|
||||
func (it *binaryAccountIterator) Value() []byte {
|
||||
func (it *binaryAccountIterator) Account() []byte {
|
||||
blob, err := it.a.layer.AccountRLP(it.k)
|
||||
if err != nil {
|
||||
it.fail = err
|
||||
@ -113,3 +107,9 @@ func (it *binaryAccountIterator) Value() []byte {
|
||||
}
|
||||
return blob
|
||||
}
|
||||
|
||||
// Release recursively releases all the iterators in the stack.
|
||||
func (it *binaryAccountIterator) Release() {
|
||||
it.a.Release()
|
||||
it.b.Release()
|
||||
}
|
||||
|
Reference in New Issue
Block a user