@@ -18,6 +18,7 @@ import (
1818type StateDB struct {
1919 db common.Database
2020 trie * trie.SecureTrie
21+ root common.Hash
2122
2223 stateObjects map [string ]* StateObject
2324
@@ -31,7 +32,7 @@ type StateDB struct {
3132// Create a new state from a given trie
3233func New (root common.Hash , db common.Database ) * StateDB {
3334 trie := trie .NewSecure (root [:], db )
34- return & StateDB {db : db , trie : trie , stateObjects : make (map [string ]* StateObject ), refund : new (big.Int ), logs : make (map [common.Hash ]Logs )}
35+ return & StateDB {root : root , db : db , trie : trie , stateObjects : make (map [string ]* StateObject ), refund : new (big.Int ), logs : make (map [common.Hash ]Logs )}
3536}
3637
3738func (self * StateDB ) PrintRoot () {
@@ -185,7 +186,7 @@ func (self *StateDB) DeleteStateObject(stateObject *StateObject) {
185186 addr := stateObject .Address ()
186187 self .trie .Delete (addr [:])
187188
188- delete (self .stateObjects , addr .Str ())
189+ // delete(self.stateObjects, addr.Str())
189190}
190191
191192// Retrieve a state object given my the address. Nil if not found
@@ -323,7 +324,8 @@ func (self *StateDB) Refunds() *big.Int {
323324 return self .refund
324325}
325326
326- func (self * StateDB ) Update () {
327+ // SyncIntermediate updates the intermediate state and all mid steps
328+ func (self * StateDB ) SyncIntermediate () {
327329 self .refund = new (big.Int )
328330
329331 for _ , stateObject := range self .stateObjects {
@@ -340,6 +342,24 @@ func (self *StateDB) Update() {
340342 }
341343}
342344
345+ // SyncObjects syncs the changed objects to the trie
346+ func (self * StateDB ) SyncObjects () {
347+ self .trie = trie .NewSecure (self .root [:], self .db )
348+
349+ self .refund = new (big.Int )
350+
351+ for _ , stateObject := range self .stateObjects {
352+ if stateObject .remove {
353+ self .DeleteStateObject (stateObject )
354+ } else {
355+ stateObject .Update ()
356+
357+ self .UpdateStateObject (stateObject )
358+ }
359+ stateObject .dirty = false
360+ }
361+ }
362+
343363// Debug stuff
344364func (self * StateDB ) CreateOutputForDiff () {
345365 for _ , stateObject := range self .stateObjects {
0 commit comments