diff options
author | JM <jm@dexon.org> | 2019-01-15 23:33:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-15 23:33:28 +0800 |
commit | 020c8a477578cef3764b54f33d9ca0cf6caf7631 (patch) | |
tree | 08a669a19cc428b8c48dad180f1f32096885826b /eth | |
parent | bdde6109ffa6fa4d295708a2a75271186a12c761 (diff) | |
download | dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.tar.gz dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.tar.zst dexon-020c8a477578cef3764b54f33d9ca0cf6caf7631.zip |
core: vm: refactor file structure (#151)
For support other vm types, this pr modified the core/vm file
structures.
Diffstat (limited to 'eth')
-rw-r--r-- | eth/api_backend.go | 2 | ||||
-rw-r--r-- | eth/api_tracer.go | 2 | ||||
-rw-r--r-- | eth/backend.go | 2 | ||||
-rw-r--r-- | eth/handler_test.go | 2 | ||||
-rw-r--r-- | eth/helper_test.go | 2 | ||||
-rw-r--r-- | eth/tracers/tracer.go | 27 | ||||
-rw-r--r-- | eth/tracers/tracer_test.go | 2 | ||||
-rw-r--r-- | eth/tracers/tracers_test.go | 2 |
8 files changed, 21 insertions, 20 deletions
diff --git a/eth/api_backend.go b/eth/api_backend.go index 32faea206..9c8fe2684 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" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "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 974917f60..ed446d878 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" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "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 50d7779a3..28265d5ae 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" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "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 a9fdaa87f..4041fbe59 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" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "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 e4d7a28fb..a6e90e7c1 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" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "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 082bb8912..89b2c3585 100644 --- a/eth/tracers/tracer.go +++ b/eth/tracers/tracer.go @@ -28,6 +28,7 @@ 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" @@ -68,7 +69,7 @@ func pushBigInt(n *big.Int, ctx *duktape.Context) { // opWrapper provides a JavaScript wrapper around OpCode. type opWrapper struct { - op vm.OpCode + op evm.OpCode } // pushObject assembles a JSVM object wrapping a swappable opcode and pushes it @@ -140,20 +141,20 @@ func (mw *memoryWrapper) pushObject(vm *duktape.Context) { vm.PutPropString(obj, "getUint") } -// stackWrapper provides a JavaScript wrapper around vm.Stack. +// stackWrapper provides a JavaScript wrapper around evm.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 @@ -161,7 +162,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 @@ -175,9 +176,9 @@ func (sw *stackWrapper) pushObject(vm *duktape.Context) { vm.PutPropString(obj, "peek") } -// dbWrapper provides a JavaScript wrapper around vm.Database. +// dbWrapper provides a JavaScript wrapper around evm.Database. type dbWrapper struct { - db vm.StateDB + db evm.StateDB } // pushObject assembles a JSVM object wrapping a swappable database and pushes it @@ -230,9 +231,9 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) { vm.PutPropString(obj, "exists") } -// contractWrapper provides a JavaScript wrapper around vm.Contract +// contractWrapper provides a JavaScript wrapper around evm.Contract type contractWrapper struct { - contract *vm.Contract + contract *evm.Contract } // pushObject assembles a JSVM object wrapping a swappable contract and pushes it @@ -368,7 +369,7 @@ func New(code string) (*Tracer, error) { return 1 }) tracer.vm.PushGlobalGoFunction("isPrecompiled", func(ctx *duktape.Context) int { - _, ok := vm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))] + _, ok := evm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))] ctx.PushBoolean(ok) return 1 }) @@ -510,7 +511,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 *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { +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 { if jst.err == nil { // Initialize the context if it wasn't done yet if !jst.inited { @@ -549,7 +550,7 @@ func (jst *Tracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost // CaptureFault implements the Tracer interface to trace an execution fault // while running an opcode. -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 { +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 { 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 75140a5db..eacc9a591 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" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/params" ) diff --git a/eth/tracers/tracers_test.go b/eth/tracers/tracers_test.go index 116402400..f6eb519ed 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" - "github.com/dexon-foundation/dexon/core/vm" + vm "github.com/dexon-foundation/dexon/core/vm/evm" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/rlp" "github.com/dexon-foundation/dexon/tests" |