Cleaned up objects
This commit is contained in:
parent
a7f4ade711
commit
59ef6e3693
|
@ -49,9 +49,7 @@ func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
|
func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
|
||||||
evm := vm.New(self, vm.DebugVmTy)
|
return core.NewExecution(self, addr, data, gas, price, value)
|
||||||
|
|
||||||
return core.NewExecution(evm, addr, data, gas, price, value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VMEnv) Call(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
|
func (self *VMEnv) Call(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
|
||||||
|
|
|
@ -16,8 +16,10 @@ type Execution struct {
|
||||||
SkipTransfer bool
|
SkipTransfer bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExecution(vm vm.VirtualMachine, address, input []byte, gas, gasPrice, value *big.Int) *Execution {
|
func NewExecution(env vm.Environment, address, input []byte, gas, gasPrice, value *big.Int) *Execution {
|
||||||
return &Execution{vm: vm, address: address, input: input, Gas: gas, price: gasPrice, value: value}
|
evm := vm.New(env, vm.DebugVmTy)
|
||||||
|
|
||||||
|
return &Execution{vm: evm, address: address, input: input, Gas: gas, price: gasPrice, value: value}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Execution) Addr() []byte {
|
func (self *Execution) Addr() []byte {
|
||||||
|
|
|
@ -43,9 +43,7 @@ func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *Execution {
|
func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *Execution {
|
||||||
evm := vm.New(self, vm.DebugVmTy)
|
return NewExecution(self, addr, data, gas, price, value)
|
||||||
|
|
||||||
return NewExecution(evm, addr, data, gas, price, value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
|
func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
|
||||||
|
|
|
@ -68,8 +68,7 @@ func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Env) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
|
func (self *Env) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
|
||||||
evm := vm.New(self, vm.DebugVmTy)
|
exec := core.NewExecution(self, addr, data, gas, price, value)
|
||||||
exec := core.NewExecution(evm, addr, data, gas, price, value)
|
|
||||||
exec.SkipTransfer = self.skipTransfer
|
exec.SkipTransfer = self.skipTransfer
|
||||||
|
|
||||||
return exec
|
return exec
|
||||||
|
|
|
@ -3,7 +3,6 @@ package vm
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,8 +10,6 @@ type ClosureRef interface {
|
||||||
ReturnGas(*big.Int, *big.Int)
|
ReturnGas(*big.Int, *big.Int)
|
||||||
Address() []byte
|
Address() []byte
|
||||||
SetCode([]byte)
|
SetCode([]byte)
|
||||||
GetStorage(*big.Int) *ethutil.Value
|
|
||||||
SetStorage(*big.Int, *ethutil.Value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Closure struct {
|
type Closure struct {
|
||||||
|
@ -41,10 +38,6 @@ func NewClosure(msg *state.Message, caller ClosureRef, object ClosureRef, code [
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Closure) GetValue(x uint64) *ethutil.Value {
|
|
||||||
return c.GetRangeValue(x, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Closure) GetOp(x uint64) OpCode {
|
func (c *Closure) GetOp(x uint64) OpCode {
|
||||||
return OpCode(c.GetByte(x))
|
return OpCode(c.GetByte(x))
|
||||||
}
|
}
|
||||||
|
@ -65,30 +58,12 @@ func (c *Closure) GetBytes(x, y int) []byte {
|
||||||
return c.Code[x : x+y]
|
return c.Code[x : x+y]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Closure) GetRangeValue(x, y uint64) *ethutil.Value {
|
func (c *Closure) GetRangeValue(x, y uint64) []byte {
|
||||||
if x >= uint64(len(c.Code)) || y >= uint64(len(c.Code)) {
|
if x >= uint64(len(c.Code)) || y >= uint64(len(c.Code)) {
|
||||||
return ethutil.NewValue(0)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
partial := c.Code[x : x+y]
|
return c.Code[x : x+y]
|
||||||
|
|
||||||
return ethutil.NewValue(partial)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* State storage functions
|
|
||||||
*/
|
|
||||||
func (c *Closure) SetStorage(x *big.Int, val *ethutil.Value) {
|
|
||||||
c.object.SetStorage(x, val)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Closure) GetStorage(x *big.Int) *ethutil.Value {
|
|
||||||
m := c.object.GetStorage(x)
|
|
||||||
if m == nil {
|
|
||||||
return ethutil.EmptyValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
return m
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Closure) Return(ret []byte) []byte {
|
func (c *Closure) Return(ret []byte) []byte {
|
||||||
|
@ -123,10 +98,6 @@ func (c *Closure) ReturnGas(gas, price *big.Int) {
|
||||||
/*
|
/*
|
||||||
* Set / Get
|
* Set / Get
|
||||||
*/
|
*/
|
||||||
func (c *Closure) Caller() ClosureRef {
|
|
||||||
return c.caller
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Closure) Address() []byte {
|
func (c *Closure) Address() []byte {
|
||||||
return c.object.Address()
|
return c.object.Address()
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,6 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
||||||
|
|
||||||
var mult *big.Int
|
var mult *big.Int
|
||||||
y, x := stack.Peekn()
|
y, x := stack.Peekn()
|
||||||
//val := closure.GetStorage(x)
|
|
||||||
val := statedb.GetState(closure.Address(), x.Bytes())
|
val := statedb.GetState(closure.Address(), x.Bytes())
|
||||||
if len(val) == 0 && len(y.Bytes()) > 0 {
|
if len(val) == 0 && len(y.Bytes()) > 0 {
|
||||||
// 0 => non 0
|
// 0 => non 0
|
||||||
|
@ -714,8 +713,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
||||||
//a := big.NewInt(int64(op) - int64(PUSH1) + 1)
|
//a := big.NewInt(int64(op) - int64(PUSH1) + 1)
|
||||||
a := uint64(op - PUSH1 + 1)
|
a := uint64(op - PUSH1 + 1)
|
||||||
//pc.Add(pc, ethutil.Big1)
|
//pc.Add(pc, ethutil.Big1)
|
||||||
data := closure.GetRangeValue(pc+1, a)
|
val := ethutil.BigD(closure.GetRangeValue(pc+1, a))
|
||||||
val := ethutil.BigD(data.Bytes())
|
|
||||||
// Push value to stack
|
// Push value to stack
|
||||||
stack.Push(val)
|
stack.Push(val)
|
||||||
pc += a
|
pc += a
|
||||||
|
@ -723,7 +721,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
||||||
|
|
||||||
step += int(op) - int(PUSH1) + 1
|
step += int(op) - int(PUSH1) + 1
|
||||||
|
|
||||||
self.Printf(" => 0x%x", data.Bytes())
|
self.Printf(" => 0x%x", val.Bytes())
|
||||||
case POP:
|
case POP:
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16:
|
case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16:
|
||||||
|
|
|
@ -47,9 +47,7 @@ func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
|
func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution {
|
||||||
evm := vm.New(self, vm.DebugVmTy)
|
return core.NewExecution(self, addr, data, gas, price, value)
|
||||||
|
|
||||||
return core.NewExecution(evm, addr, data, gas, price, value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
|
func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
|
||||||
|
|
Loading…
Reference in New Issue