Skip to content

Commit 12671c8

Browse files
committed
Moved VM to execution
1 parent 59ef6e3 commit 12671c8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

core/execution.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ import (
99
)
1010

1111
type Execution struct {
12-
vm vm.VirtualMachine
12+
env vm.Environment
1313
address, input []byte
1414
Gas, price, value *big.Int
1515
object *state.StateObject
1616
SkipTransfer bool
1717
}
1818

1919
func NewExecution(env vm.Environment, address, input []byte, gas, gasPrice, value *big.Int) *Execution {
20-
evm := vm.New(env, vm.DebugVmTy)
21-
22-
return &Execution{vm: evm, address: address, input: input, Gas: gas, price: gasPrice, value: value}
20+
return &Execution{env: env, address: address, input: input, Gas: gas, price: gasPrice, value: value}
2321
}
2422

2523
func (self *Execution) Addr() []byte {
@@ -28,16 +26,18 @@ func (self *Execution) Addr() []byte {
2826

2927
func (self *Execution) Call(codeAddr []byte, caller vm.ClosureRef) ([]byte, error) {
3028
// Retrieve the executing code
31-
code := self.vm.Env().State().GetCode(codeAddr)
29+
code := self.env.State().GetCode(codeAddr)
3230

3331
return self.exec(code, codeAddr, caller)
3432
}
3533

3634
func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret []byte, err error) {
37-
env := self.vm.Env()
35+
env := self.env
36+
evm := vm.New(env, vm.DebugVmTy)
37+
3838
chainlogger.Debugf("pre state %x\n", env.State().Root())
3939

40-
if self.vm.Env().Depth() == vm.MaxCallDepth {
40+
if env.Depth() == vm.MaxCallDepth {
4141
// Consume all gas (by not returning it) and return a depth error
4242
return nil, vm.DepthError{}
4343
}
@@ -56,21 +56,21 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret
5656

5757
snapshot := env.State().Copy()
5858
defer func() {
59-
if /*vm.IsDepthErr(err) ||*/ vm.IsOOGErr(err) {
59+
if vm.IsOOGErr(err) {
6060
env.State().Set(snapshot)
6161
}
6262
chainlogger.Debugf("post state %x\n", env.State().Root())
6363
}()
6464

6565
self.object = to
66-
ret, err = self.vm.Run(to, caller, code, self.value, self.Gas, self.price, self.input)
66+
ret, err = evm.Run(to, caller, code, self.value, self.Gas, self.price, self.input)
6767

6868
return
6969
}
7070

7171
func (self *Execution) Create(caller vm.ClosureRef) (ret []byte, err error, account *state.StateObject) {
7272
ret, err = self.exec(self.input, nil, caller)
73-
account = self.vm.Env().State().GetStateObject(self.address)
73+
account = self.env.State().GetStateObject(self.address)
7474

7575
return
7676
}

0 commit comments

Comments
 (0)