From 33f3f8254a83ccbaba1e61ca1c7b3b6390794cd9 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Thu, 17 Jan 2019 09:44:08 +0800 Subject: Revert "core: vm: refactor file structure (#151)" This reverts commit 020c8a477578cef3764b54f33d9ca0cf6caf7631. --- eth/api_backend.go | 2 +- eth/api_tracer.go | 2 +- eth/backend.go | 2 +- eth/handler_test.go | 2 +- eth/helper_test.go | 2 +- eth/tracers/tracer.go | 27 +++++++++++++-------------- eth/tracers/tracer_test.go | 2 +- eth/tracers/tracers_test.go | 2 +- 8 files changed, 20 insertions(+), 21 deletions(-) (limited to 'eth') diff --git a/eth/api_backend.go b/eth/api_backend.go index 9c8fe2684..32faea206 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -27,7 +27,7 @@ import ( "github.com/dexon-foundation/dexon/core/bloombits" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - vm "github.com/dexon-foundation/dexon/core/vm/evm" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/eth/gasprice" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" diff --git a/eth/api_tracer.go b/eth/api_tracer.go index ed446d878..974917f60 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -34,7 +34,7 @@ import ( "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - vm "github.com/dexon-foundation/dexon/core/vm/evm" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/eth/tracers" "github.com/dexon-foundation/dexon/internal/ethapi" "github.com/dexon-foundation/dexon/log" diff --git a/eth/backend.go b/eth/backend.go index 28265d5ae..50d7779a3 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -35,7 +35,7 @@ import ( "github.com/dexon-foundation/dexon/core/bloombits" "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/types" - vm "github.com/dexon-foundation/dexon/core/vm/evm" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/eth/downloader" "github.com/dexon-foundation/dexon/eth/filters" "github.com/dexon-foundation/dexon/eth/gasprice" diff --git a/eth/handler_test.go b/eth/handler_test.go index 4041fbe59..a9fdaa87f 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -29,7 +29,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" - vm "github.com/dexon-foundation/dexon/core/vm/evm" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/eth/downloader" "github.com/dexon-foundation/dexon/ethdb" diff --git a/eth/helper_test.go b/eth/helper_test.go index a6e90e7c1..e4d7a28fb 100644 --- a/eth/helper_test.go +++ b/eth/helper_test.go @@ -32,7 +32,7 @@ import ( "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/types" - vm "github.com/dexon-foundation/dexon/core/vm/evm" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/eth/downloader" "github.com/dexon-foundation/dexon/ethdb" diff --git a/eth/tracers/tracer.go b/eth/tracers/tracer.go index 89b2c3585..082bb8912 100644 --- a/eth/tracers/tracer.go +++ b/eth/tracers/tracer.go @@ -28,7 +28,6 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/common/hexutil" "github.com/dexon-foundation/dexon/core/vm" - "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/crypto" "github.com/dexon-foundation/dexon/log" duktape "gopkg.in/olebedev/go-duktape.v3" @@ -69,7 +68,7 @@ func pushBigInt(n *big.Int, ctx *duktape.Context) { // opWrapper provides a JavaScript wrapper around OpCode. type opWrapper struct { - op evm.OpCode + op vm.OpCode } // pushObject assembles a JSVM object wrapping a swappable opcode and pushes it @@ -141,20 +140,20 @@ func (mw *memoryWrapper) pushObject(vm *duktape.Context) { vm.PutPropString(obj, "getUint") } -// stackWrapper provides a JavaScript wrapper around evm.Stack. +// stackWrapper provides a JavaScript wrapper around vm.Stack. type stackWrapper struct { stack *vm.Stack } // peek returns the nth-from-the-top element of the stack. func (sw *stackWrapper) peek(idx int) *big.Int { - if len(sw.stack.Data) <= idx { + if len(sw.stack.Data()) <= idx { // TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go // runtime goes belly up https://github.com/golang/go/issues/15639. - log.Warn("Tracer accessed out of bound stack", "size", len(sw.stack.Data), "index", idx) + log.Warn("Tracer accessed out of bound stack", "size", len(sw.stack.Data()), "index", idx) return new(big.Int) } - return sw.stack.Data[len(sw.stack.Data)-idx-1] + return sw.stack.Data()[len(sw.stack.Data())-idx-1] } // pushObject assembles a JSVM object wrapping a swappable stack and pushes it @@ -162,7 +161,7 @@ func (sw *stackWrapper) peek(idx int) *big.Int { func (sw *stackWrapper) pushObject(vm *duktape.Context) { obj := vm.PushObject() - vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushInt(len(sw.stack.Data)); return 1 }) + vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushInt(len(sw.stack.Data())); return 1 }) vm.PutPropString(obj, "length") // Generate the `peek` method which takes an int and returns a bigint @@ -176,9 +175,9 @@ func (sw *stackWrapper) pushObject(vm *duktape.Context) { vm.PutPropString(obj, "peek") } -// dbWrapper provides a JavaScript wrapper around evm.Database. +// dbWrapper provides a JavaScript wrapper around vm.Database. type dbWrapper struct { - db evm.StateDB + db vm.StateDB } // pushObject assembles a JSVM object wrapping a swappable database and pushes it @@ -231,9 +230,9 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) { vm.PutPropString(obj, "exists") } -// contractWrapper provides a JavaScript wrapper around evm.Contract +// contractWrapper provides a JavaScript wrapper around vm.Contract type contractWrapper struct { - contract *evm.Contract + contract *vm.Contract } // pushObject assembles a JSVM object wrapping a swappable contract and pushes it @@ -369,7 +368,7 @@ func New(code string) (*Tracer, error) { return 1 }) tracer.vm.PushGlobalGoFunction("isPrecompiled", func(ctx *duktape.Context) int { - _, ok := evm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))] + _, ok := vm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))] ctx.PushBoolean(ok) return 1 }) @@ -511,7 +510,7 @@ func (jst *Tracer) CaptureStart(from common.Address, to common.Address, create b } // CaptureState implements the Tracer interface to trace a single step of VM execution. -func (jst *Tracer) CaptureState(env *evm.EVM, pc uint64, op evm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *evm.Contract, depth int, err error) error { +func (jst *Tracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { if jst.err == nil { // Initialize the context if it wasn't done yet if !jst.inited { @@ -550,7 +549,7 @@ func (jst *Tracer) CaptureState(env *evm.EVM, pc uint64, op evm.OpCode, gas, cos // CaptureFault implements the Tracer interface to trace an execution fault // while running an opcode. -func (jst *Tracer) CaptureFault(env *evm.EVM, pc uint64, op evm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *evm.Contract, depth int, err error) error { +func (jst *Tracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { if jst.err == nil { // Apart from the error, everything matches the previous invocation jst.errorValue = new(string) diff --git a/eth/tracers/tracer_test.go b/eth/tracers/tracer_test.go index eacc9a591..75140a5db 100644 --- a/eth/tracers/tracer_test.go +++ b/eth/tracers/tracer_test.go @@ -26,7 +26,7 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/state" - vm "github.com/dexon-foundation/dexon/core/vm/evm" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/params" ) diff --git a/eth/tracers/tracers_test.go b/eth/tracers/tracers_test.go index f6eb519ed..116402400 100644 --- a/eth/tracers/tracers_test.go +++ b/eth/tracers/tracers_test.go @@ -30,7 +30,7 @@ import ( "github.com/dexon-foundation/dexon/common/math" "github.com/dexon-foundation/dexon/core" "github.com/dexon-foundation/dexon/core/types" - vm "github.com/dexon-foundation/dexon/core/vm/evm" + "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/rlp" "github.com/dexon-foundation/dexon/tests" -- cgit v1.2.3