This commit is contained in:
obscuren
2015-03-16 16:36:58 +01:00
parent d338650089
commit 0dd9ac375b
5 changed files with 68 additions and 90 deletions

View File

@@ -2,19 +2,17 @@ package trie
import (
"bytes"
"github.com/ethereum/go-ethereum/common"
)
type Iterator struct {
trie *Trie
Key common.Hash
Key []byte
Value []byte
}
func NewIterator(trie *Trie) *Iterator {
return &Iterator{trie: trie}
return &Iterator{trie: trie, Key: nil}
}
func (self *Iterator) Next() bool {
@@ -22,15 +20,15 @@ func (self *Iterator) Next() bool {
defer self.trie.mu.Unlock()
isIterStart := false
if (self.Key == common.Hash{}) {
if self.Key == nil {
isIterStart = true
//self.Key = make([]byte, 32)
self.Key = make([]byte, 32)
}
key := RemTerm(CompactHexDecode(self.Key.Str()))
key := RemTerm(CompactHexDecode(string(self.Key)))
k := self.next(self.trie.root, key, isIterStart)
self.Key = common.StringToHash(DecodeCompact(k))
self.Key = []byte(DecodeCompact(k))
return len(k) > 0
}