Moved debug hook to Vm directly

pull/150/head
obscuren 11 years ago
parent 1954ef47e6
commit d15952c867
  1. 6
      ethchain/closure.go
  2. 2
      ethchain/state_transition.go
  3. 12
      ethchain/vm.go

@ -74,12 +74,10 @@ func (c *Closure) Address() []byte {
return c.object.Address() return c.object.Address()
} }
type DebugHook func(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool func (c *Closure) Call(vm *Vm, args []byte) ([]byte, *big.Int, error) {
func (c *Closure) Call(vm *Vm, args []byte, hook DebugHook) ([]byte, *big.Int, error) {
c.Args = args c.Args = args
ret, err := vm.RunClosure(c, hook) ret, err := vm.RunClosure(c)
return ret, c.UsedGas, err return ret, c.UsedGas, err
} }

@ -261,7 +261,7 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
} }
func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr bool) { func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr bool) {
ret, _, err = closure.Call(vm, data, nil) ret, _, err = closure.Call(vm, data)
deepErr = vm.err != nil deepErr = vm.err != nil
Paranoia := ethutil.Config.Paranoia Paranoia := ethutil.Config.Paranoia

@ -52,8 +52,12 @@ type Vm struct {
logStr string logStr string
err error err error
Hook DebugHook
} }
type DebugHook func(step int, op OpCode, mem *Memory, stack *Stack, stateObject *StateObject) bool
type RuntimeVars struct { type RuntimeVars struct {
Origin []byte Origin []byte
Block *Block Block *Block
@ -91,7 +95,7 @@ var Pow256 = ethutil.BigPow(2, 256)
var isRequireError = false var isRequireError = false
func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err error) { func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
// Recover from any require exception // Recover from any require exception
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
@ -642,7 +646,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
// Call the closure and set the return value as // Call the closure and set the return value as
// main script. // main script.
var err error var err error
c.Script, gas, err = c.Call(vm, nil, hook) c.Script, gas, err = c.Call(vm, nil)
if err != nil { if err != nil {
stack.Push(ethutil.BigFalse) stack.Push(ethutil.BigFalse)
@ -738,8 +742,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
vm.Endl() vm.Endl()
if hook != nil { if vm.Hook != nil {
if !hook(prevStep, op, mem, stack, closure.Object()) { if !vm.Hook(prevStep, op, mem, stack, closure.Object()) {
return nil, nil return nil, nil
} }
} }

Loading…
Cancel
Save