forked from cerc-io/plugeth
Root should reset on undo
This commit is contained in:
parent
b7a636b894
commit
7413552a28
@ -98,22 +98,25 @@ func (cache *Cache) Undo() {
|
|||||||
// Please note that the data isn't persisted unless `Sync` is
|
// Please note that the data isn't persisted unless `Sync` is
|
||||||
// explicitly called.
|
// explicitly called.
|
||||||
type Trie struct {
|
type Trie struct {
|
||||||
|
prevRoot interface{}
|
||||||
Root interface{}
|
Root interface{}
|
||||||
//db Database
|
//db Database
|
||||||
cache *Cache
|
cache *Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTrie(db Database, Root interface{}) *Trie {
|
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.
|
// Save the cached value to the database.
|
||||||
func (t *Trie) Sync() {
|
func (t *Trie) Sync() {
|
||||||
t.cache.Commit()
|
t.cache.Commit()
|
||||||
|
t.prevRoot = t.Root
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Trie) Undo() {
|
func (t *Trie) Undo() {
|
||||||
t.cache.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{} {
|
func (t *Trie) UpdateState(node interface{}, key []int, value string) interface{} {
|
||||||
|
|
||||||
if value != "" {
|
if value != "" {
|
||||||
return t.InsertState(node, key, value)
|
return t.InsertState(node, key, value)
|
||||||
} else {
|
} else {
|
||||||
@ -241,6 +245,7 @@ func (t *Trie) InsertState(node interface{}, key []int, value interface{}) inter
|
|||||||
// Check for "special" 2 slice type node
|
// Check for "special" 2 slice type node
|
||||||
if currentNode.Len() == 2 {
|
if currentNode.Len() == 2 {
|
||||||
// Decode the key
|
// Decode the key
|
||||||
|
|
||||||
k := CompactDecode(currentNode.Get(0).Str())
|
k := CompactDecode(currentNode.Get(0).Str())
|
||||||
v := currentNode.Get(1).Raw()
|
v := currentNode.Get(1).Raw()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user