aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state.go
diff options
context:
space:
mode:
Diffstat (limited to 'ethchain/state.go')
-rw-r--r--ethchain/state.go33
1 files changed, 27 insertions, 6 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index 9a9d0a278..993f1fb08 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -13,8 +13,6 @@ import (
type State struct {
// The trie for this structure
trie *ethutil.Trie
- // Nested states
- states map[string]*State
stateObjects map[string]*StateObject
@@ -23,7 +21,7 @@ type State struct {
// Create a new state from a given trie
func NewState(trie *ethutil.Trie) *State {
- return &State{trie: trie, states: make(map[string]*State), stateObjects: make(map[string]*StateObject), manifest: NewManifest()}
+ return &State{trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest()}
}
// Resets the trie and all siblings
@@ -38,12 +36,16 @@ func (s *State) Reset() {
stateObject.state.Reset()
}
+
+ s.Empty()
}
// Syncs the trie and all siblings
func (s *State) Sync() {
// Sync all nested states
for _, stateObject := range s.stateObjects {
+ s.UpdateStateObject(stateObject)
+
if stateObject.state == nil {
continue
}
@@ -52,6 +54,18 @@ func (s *State) Sync() {
}
s.trie.Sync()
+
+ s.Empty()
+}
+
+func (self *State) Empty() {
+ self.stateObjects = make(map[string]*StateObject)
+}
+
+func (self *State) Update() {
+ for _, stateObject := range self.stateObjects {
+ self.UpdateStateObject(stateObject)
+ }
}
// Purges the current trie.
@@ -68,6 +82,7 @@ func (self *State) UpdateStateObject(stateObject *StateObject) {
addr := stateObject.Address()
if self.stateObjects[string(addr)] == nil {
+ panic("?")
self.stateObjects[string(addr)] = stateObject
}
@@ -98,13 +113,19 @@ func (self *State) GetStateObject(addr []byte) *StateObject {
func (self *State) GetOrNewStateObject(addr []byte) *StateObject {
stateObject := self.GetStateObject(addr)
if stateObject == nil {
- stateObject = NewStateObject(addr)
- self.stateObjects[string(addr)] = stateObject
+ stateObject = self.NewStateObject(addr)
}
return stateObject
}
+func (self *State) NewStateObject(addr []byte) *StateObject {
+ stateObject := NewStateObject(addr)
+ self.stateObjects[string(addr)] = stateObject
+
+ return stateObject
+}
+
func (self *State) GetAccount(addr []byte) *StateObject {
return self.GetOrNewStateObject(addr)
}
@@ -132,7 +153,7 @@ func (s *State) Snapshot() *State {
func (s *State) Revert(snapshot *State) {
s.trie = snapshot.trie
- s.states = snapshot.states
+ s.stateObjects = snapshot.stateObjects
}
func (s *State) Put(key, object []byte) {