Skip to content

Commit 59ef6e3

Browse files
committed
Cleaned up objects
1 parent a7f4ade commit 59ef6e3

File tree

7 files changed

+13
-49
lines changed

7 files changed

+13
-49
lines changed

cmd/utils/vm_env.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
4949
}
5050

5151
func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
52-
evm := vm.New(self, vm.DebugVmTy)
53-
54-
return core.NewExecution(evm, addr, data, gas, price, value)
52+
return core.NewExecution(self, addr, data, gas, price, value)
5553
}
5654

5755
func (self *VMEnv) Call(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {

core/execution.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ type Execution struct {
1616
SkipTransfer bool
1717
}
1818

19-
func NewExecution(vm vm.VirtualMachine, address, input []byte, gas, gasPrice, value *big.Int) *Execution {
20-
return &Execution{vm: vm, address: address, input: input, Gas: gas, price: gasPrice, value: value}
19+
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}
2123
}
2224

2325
func (self *Execution) Addr() []byte {

core/vm_env.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
4343
}
4444

4545
func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *Execution {
46-
evm := vm.New(self, vm.DebugVmTy)
47-
48-
return NewExecution(evm, addr, data, gas, price, value)
46+
return NewExecution(self, addr, data, gas, price, value)
4947
}
5048

5149
func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {

tests/helper/vm.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error {
6868
}
6969

7070
func (self *Env) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
71-
evm := vm.New(self, vm.DebugVmTy)
72-
exec := core.NewExecution(evm, addr, data, gas, price, value)
71+
exec := core.NewExecution(self, addr, data, gas, price, value)
7372
exec.SkipTransfer = self.skipTransfer
7473

7574
return exec

vm/closure.go

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ package vm
33
import (
44
"math/big"
55

6-
"github.com/ethereum/go-ethereum/ethutil"
76
"github.com/ethereum/go-ethereum/state"
87
)
98

109
type ClosureRef interface {
1110
ReturnGas(*big.Int, *big.Int)
1211
Address() []byte
1312
SetCode([]byte)
14-
GetStorage(*big.Int) *ethutil.Value
15-
SetStorage(*big.Int, *ethutil.Value)
1613
}
1714

1815
type Closure struct {
@@ -41,10 +38,6 @@ func NewClosure(msg *state.Message, caller ClosureRef, object ClosureRef, code [
4138
return c
4239
}
4340

44-
func (c *Closure) GetValue(x uint64) *ethutil.Value {
45-
return c.GetRangeValue(x, 1)
46-
}
47-
4841
func (c *Closure) GetOp(x uint64) OpCode {
4942
return OpCode(c.GetByte(x))
5043
}
@@ -65,30 +58,12 @@ func (c *Closure) GetBytes(x, y int) []byte {
6558
return c.Code[x : x+y]
6659
}
6760

68-
func (c *Closure) GetRangeValue(x, y uint64) *ethutil.Value {
61+
func (c *Closure) GetRangeValue(x, y uint64) []byte {
6962
if x >= uint64(len(c.Code)) || y >= uint64(len(c.Code)) {
70-
return ethutil.NewValue(0)
71-
}
72-
73-
partial := c.Code[x : x+y]
74-
75-
return ethutil.NewValue(partial)
76-
}
77-
78-
/*
79-
* State storage functions
80-
*/
81-
func (c *Closure) SetStorage(x *big.Int, val *ethutil.Value) {
82-
c.object.SetStorage(x, val)
83-
}
84-
85-
func (c *Closure) GetStorage(x *big.Int) *ethutil.Value {
86-
m := c.object.GetStorage(x)
87-
if m == nil {
88-
return ethutil.EmptyValue()
63+
return nil
8964
}
9065

91-
return m
66+
return c.Code[x : x+y]
9267
}
9368

9469
func (c *Closure) Return(ret []byte) []byte {
@@ -123,10 +98,6 @@ func (c *Closure) ReturnGas(gas, price *big.Int) {
12398
/*
12499
* Set / Get
125100
*/
126-
func (c *Closure) Caller() ClosureRef {
127-
return c.caller
128-
}
129-
130101
func (c *Closure) Address() []byte {
131102
return c.object.Address()
132103
}

vm/vm_debug.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
181181

182182
var mult *big.Int
183183
y, x := stack.Peekn()
184-
//val := closure.GetStorage(x)
185184
val := statedb.GetState(closure.Address(), x.Bytes())
186185
if len(val) == 0 && len(y.Bytes()) > 0 {
187186
// 0 => non 0
@@ -714,16 +713,15 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
714713
//a := big.NewInt(int64(op) - int64(PUSH1) + 1)
715714
a := uint64(op - PUSH1 + 1)
716715
//pc.Add(pc, ethutil.Big1)
717-
data := closure.GetRangeValue(pc+1, a)
718-
val := ethutil.BigD(data.Bytes())
716+
val := ethutil.BigD(closure.GetRangeValue(pc+1, a))
719717
// Push value to stack
720718
stack.Push(val)
721719
pc += a
722720
//pc.Add(pc, a.Sub(a, big.NewInt(1)))
723721

724722
step += int(op) - int(PUSH1) + 1
725723

726-
self.Printf(" => 0x%x", data.Bytes())
724+
self.Printf(" => 0x%x", val.Bytes())
727725
case POP:
728726
stack.Pop()
729727
case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16:

xeth/vm_env.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
4747
}
4848

4949
func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
50-
evm := vm.New(self, vm.DebugVmTy)
51-
52-
return core.NewExecution(evm, addr, data, gas, price, value)
50+
return core.NewExecution(self, addr, data, gas, price, value)
5351
}
5452

5553
func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {

0 commit comments

Comments
 (0)