aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-18 03:40:33 +0800
committerobscuren <geffobscura@gmail.com>2014-02-18 03:40:33 +0800
commit7413552a28c538ca4f33d0dafe28907b7b761863 (patch)
tree9cfe8d50d712f50f7bc180ec34fdc29f6ec92b69 /ethutil
parentb7a636b8949a2270ae030f56791c88060fa5483a (diff)
downloadgo-tangerine-7413552a28c538ca4f33d0dafe28907b7b761863.tar
go-tangerine-7413552a28c538ca4f33d0dafe28907b7b761863.tar.gz
go-tangerine-7413552a28c538ca4f33d0dafe28907b7b761863.tar.bz2
go-tangerine-7413552a28c538ca4f33d0dafe28907b7b761863.tar.lz
go-tangerine-7413552a28c538ca4f33d0dafe28907b7b761863.tar.xz
go-tangerine-7413552a28c538ca4f33d0dafe28907b7b761863.tar.zst
go-tangerine-7413552a28c538ca4f33d0dafe28907b7b761863.zip
Root should reset on undo
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/trie.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/ethutil/trie.go b/ethutil/trie.go
index 7140a1b36..95abca602 100644
--- a/ethutil/trie.go
+++ b/ethutil/trie.go
@@ -98,22 +98,25 @@ func (cache *Cache) Undo() {
// Please note that the data isn't persisted unless `Sync` is
// explicitly called.
type Trie struct {
- Root interface{}
+ prevRoot interface{}
+ Root interface{}
//db Database
cache *Cache
}
func NewTrie(db Database, Root interface{}) *Trie {
- return &Trie{cache: NewCache(db), Root: Root}
+ return &Trie{cache: NewCache(db), Root: Root, prevRoot: Root}
}
// Save the cached value to the database.
func (t *Trie) Sync() {
t.cache.Commit()
+ t.prevRoot = t.Root
}
func (t *Trie) Undo() {
t.cache.Undo()
+ t.Root = t.prevRoot
}
/*
@@ -181,6 +184,7 @@ func (t *Trie) GetNode(node interface{}) *Value {
}
func (t *Trie) UpdateState(node interface{}, key []int, value string) interface{} {
+
if value != "" {
return t.InsertState(node, key, value)
} else {
@@ -241,6 +245,7 @@ func (t *Trie) InsertState(node interface{}, key []int, value interface{}) inter
// Check for "special" 2 slice type node
if currentNode.Len() == 2 {
// Decode the key
+
k := CompactDecode(currentNode.Get(0).Str())
v := currentNode.Get(1).Raw()