aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/trie.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-06-30 19:08:00 +0800
committerobscuren <geffobscura@gmail.com>2014-06-30 19:08:00 +0800
commit5a86892ecbd68c3d466cb1ef282c4cb81300abce (patch)
treede51bb2eeda7ae39de026491ff200173ebd454d0 /ethutil/trie.go
parent8151858e70e19996d05928e4c63d36cd4847daa8 (diff)
downloaddexon-5a86892ecbd68c3d466cb1ef282c4cb81300abce.tar
dexon-5a86892ecbd68c3d466cb1ef282c4cb81300abce.tar.gz
dexon-5a86892ecbd68c3d466cb1ef282c4cb81300abce.tar.bz2
dexon-5a86892ecbd68c3d466cb1ef282c4cb81300abce.tar.lz
dexon-5a86892ecbd68c3d466cb1ef282c4cb81300abce.tar.xz
dexon-5a86892ecbd68c3d466cb1ef282c4cb81300abce.tar.zst
dexon-5a86892ecbd68c3d466cb1ef282c4cb81300abce.zip
Using remote for test cases
Diffstat (limited to 'ethutil/trie.go')
-rw-r--r--ethutil/trie.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/ethutil/trie.go b/ethutil/trie.go
index 18d0a5f0a..ce9c2da27 100644
--- a/ethutil/trie.go
+++ b/ethutil/trie.go
@@ -43,11 +43,11 @@ func NewCache(db Database) *Cache {
return &Cache{db: db, nodes: make(map[string]*Node)}
}
-func (cache *Cache) Put(v interface{}) interface{} {
+func (cache *Cache) PutValue(v interface{}, force bool) interface{} {
value := NewValue(v)
enc := value.Encode()
- if len(enc) >= 32 {
+ if len(enc) >= 32 || force {
sha := Sha3Bin(enc)
cache.nodes[string(sha)] = NewNode(sha, value, true)
@@ -59,6 +59,10 @@ func (cache *Cache) Put(v interface{}) interface{} {
return v
}
+func (cache *Cache) Put(v interface{}) interface{} {
+ return cache.PutValue(v, false)
+}
+
func (cache *Cache) Get(key []byte) *Value {
// First check if the key is the cache
if cache.nodes[string(key)] != nil {
@@ -168,7 +172,12 @@ func (t *Trie) Update(key string, value string) {
k := CompactHexDecode(key)
- t.Root = t.UpdateState(t.Root, k, value)
+ root := t.UpdateState(t.Root, k, value)
+ if _, ok := root.([]byte); !ok {
+ t.Root = t.cache.PutValue(root, true)
+ } else {
+ t.Root = root
+ }
}
func (t *Trie) Get(key string) string {
@@ -527,6 +536,8 @@ func (it *TrieIterator) fetchNode(key []int, node []byte, cb EachCallback) {
}
func (it *TrieIterator) iterateNode(key []int, currentNode *Value, cb EachCallback) {
+ //fmt.Println("node", currentNode)
+
if currentNode.Len() == 2 {
k := CompactDecode(currentNode.Get(0).Str())