aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-06-17 17:06:06 +0800
committerobscuren <geffobscura@gmail.com>2014-06-17 17:06:06 +0800
commit53e30f750dd0c91279bfebe01bb12fd170cb74ff (patch)
treeb14fcd5845ce21c774ae7730bdd1d42f8836e5a2 /ethchain/state.go
parent6656f99c54aef4aaf03ba76dcab3df1cc363ab9a (diff)
downloadgo-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.tar
go-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.tar.gz
go-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.tar.bz2
go-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.tar.lz
go-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.tar.xz
go-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.tar.zst
go-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.zip
Removal of manual updating of state objects
* You'll only ever need to update the state by calling Update. Update will take care of the updating of it's child state objects.
Diffstat (limited to 'ethchain/state.go')
-rw-r--r--ethchain/state.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index 9a9d0a278..f5a3d3071 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -38,12 +38,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 +56,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 +84,7 @@ func (self *State) UpdateStateObject(stateObject *StateObject) {
addr := stateObject.Address()
if self.stateObjects[string(addr)] == nil {
+ panic("?")
self.stateObjects[string(addr)] = stateObject
}
@@ -98,13 +115,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)
}