diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-16 19:38:21 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-16 19:38:21 +0800 |
commit | 70f7a0be1187cc0e487e7b95cad238c6530d29ae (patch) | |
tree | f7b2787bf598db75ae6750e0d7c3fbf1fdfb4ede /ethstate/state.go | |
parent | 311c6f8a3fed5ac03ee4b442fd0f420072bc41b4 (diff) | |
download | dexon-70f7a0be1187cc0e487e7b95cad238c6530d29ae.tar dexon-70f7a0be1187cc0e487e7b95cad238c6530d29ae.tar.gz dexon-70f7a0be1187cc0e487e7b95cad238c6530d29ae.tar.bz2 dexon-70f7a0be1187cc0e487e7b95cad238c6530d29ae.tar.lz dexon-70f7a0be1187cc0e487e7b95cad238c6530d29ae.tar.xz dexon-70f7a0be1187cc0e487e7b95cad238c6530d29ae.tar.zst dexon-70f7a0be1187cc0e487e7b95cad238c6530d29ae.zip |
Use the state instead of the state object directly.
If a state gets reset and you still hold a pointer to the previous,
incorrect, state object you'll operate on the wrong object. Using the
state to set/get objects and attributes you won't have this problem
since the state will always have the correct object.
Diffstat (limited to 'ethstate/state.go')
-rw-r--r-- | ethstate/state.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ethstate/state.go b/ethstate/state.go index b897b7ce3..2efe2a311 100644 --- a/ethstate/state.go +++ b/ethstate/state.go @@ -48,6 +48,13 @@ func (self *State) GetNonce(addr []byte) uint64 { return 0 } +func (self *State) SetNonce(addr []byte, nonce uint64) { + stateObject := self.GetStateObject(addr) + if stateObject != nil { + stateObject.Nonce = nonce + } +} + func (self *State) GetCode(addr []byte) []byte { stateObject := self.GetStateObject(addr) if stateObject != nil { @@ -66,6 +73,24 @@ func (self *State) GetState(a, b []byte) []byte { return nil } +func (self *State) SetState(addr, key []byte, value interface{}) { + stateObject := self.GetStateObject(addr) + if stateObject != nil { + stateObject.SetState(key, ethutil.NewValue(value)) + } +} + +func (self *State) Delete(addr []byte) bool { + stateObject := self.GetStateObject(addr) + if stateObject != nil { + stateObject.MarkForDeletion() + + return true + } + + return false +} + // // Setting, updating & deleting state object methods // |