Fixed state overwriting issue

This commit is contained in:
obscuren
2014-05-21 01:12:28 +02:00
parent 6ef2832083
commit 3c35ba7c31
5 changed files with 20 additions and 11 deletions

View File

@ -3,8 +3,13 @@ package ethutil
import (
"fmt"
"reflect"
"sync"
)
func (s *Cache) Len() int {
return len(s.nodes)
}
// TODO
// A StateObject is an object that has a state root
// This is goig to be the object for the second level caching (the caching of object which have a state such as contracts)
@ -113,6 +118,7 @@ func (cache *Cache) Undo() {
// Please note that the data isn't persisted unless `Sync` is
// explicitly called.
type Trie struct {
mut sync.RWMutex
prevRoot interface{}
Root interface{}
//db Database
@ -157,12 +163,18 @@ func (t *Trie) Cache() *Cache {
* Public (query) interface functions
*/
func (t *Trie) Update(key string, value string) {
t.mut.Lock()
defer t.mut.Unlock()
k := CompactHexDecode(key)
t.Root = t.UpdateState(t.Root, k, value)
}
func (t *Trie) Get(key string) string {
t.mut.RLock()
defer t.mut.RUnlock()
k := CompactHexDecode(key)
c := NewValue(t.GetState(t.Root, k))