Moved state reset to defered function

This commit is contained in:
obscuren 2014-10-16 13:39:30 +02:00
parent febec5ca4a
commit 86f789333a
1 changed files with 6 additions and 5 deletions

View File

@ -28,6 +28,11 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) (ret []byte, err
env := self.vm.Env()
snapshot := env.State().Copy()
defer func() {
if err != nil {
env.State().Set(snapshot)
}
}()
msg := env.State().Manifest().AddMessage(&ethstate.Message{
To: self.address, From: caller.Address(),
@ -49,7 +54,7 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) (ret []byte, err
caller.Object().SubAmount(self.value)
stateObject.AddAmount(self.value)
// Precompiled contracts (address.go) 1, 2 & 3.
// Pre-compiled contracts (address.go) 1, 2 & 3.
naddr := ethutil.BigD(codeAddr).Uint64()
if p := Precompiled[naddr]; p != nil {
if self.gas.Cmp(p.Gas) >= 0 {
@ -74,9 +79,5 @@ func (self *Execution) Exec(codeAddr []byte, caller ClosureRef) (ret []byte, err
}
}
if err != nil {
env.State().Set(snapshot)
}
return
}