aboutsummaryrefslogtreecommitdiffstats
path: root/eth/tracers
diff options
context:
space:
mode:
authorjm <jm.huang@cobinhood.com>2019-01-16 17:32:29 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:03 +0800
commitd3b485a5af768db59bd648175849f961e25bc630 (patch)
treeec43033c9aa438969cea45fb9de19e50a88a5cd8 /eth/tracers
parent266068a53cdf9e06acacf982d63653c03133a634 (diff)
downloaddexon-d3b485a5af768db59bd648175849f961e25bc630.tar
dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.gz
dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.bz2
dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.lz
dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.xz
dexon-d3b485a5af768db59bd648175849f961e25bc630.tar.zst
dexon-d3b485a5af768db59bd648175849f961e25bc630.zip
core: vm: extract stateDB and contract out
Extract stateDB and contract out from core/vm/evm to core/vm, such that other vm type can use the common modules.
Diffstat (limited to 'eth/tracers')
-rw-r--r--eth/tracers/tracer.go12
-rw-r--r--eth/tracers/tracer_test.go9
-rw-r--r--eth/tracers/tracers_test.go5
3 files changed, 14 insertions, 12 deletions
diff --git a/eth/tracers/tracer.go b/eth/tracers/tracer.go
index f232df49e..d26cc1fae 100644
--- a/eth/tracers/tracer.go
+++ b/eth/tracers/tracer.go
@@ -178,7 +178,7 @@ func (sw *stackWrapper) pushObject(vm *duktape.Context) {
// dbWrapper provides a JavaScript wrapper around evm.Database.
type dbWrapper struct {
- db evm.StateDB
+ db vm.StateDB
}
// pushObject assembles a JSVM object wrapping a swappable database and pushes it
@@ -233,7 +233,7 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) {
// contractWrapper provides a JavaScript wrapper around evm.Contract
type contractWrapper struct {
- contract *evm.Contract
+ contract *vm.Contract
}
// pushObject assembles a JSVM object wrapping a swappable contract and pushes it
@@ -259,7 +259,7 @@ func (cw *contractWrapper) pushObject(vm *duktape.Context) {
// Push the wrapper for contract.Value
vm.PushGoFunction(func(ctx *duktape.Context) int {
- pushBigInt(cw.contract.Value(), ctx)
+ pushBigInt(cw.contract.Value, ctx)
return 1
})
vm.PutPropString(obj, "getValue")
@@ -391,7 +391,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
})
@@ -533,7 +533,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 *evm.EVM, pc uint64, op evm.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 {
@@ -572,7 +572,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 *evm.EVM, pc uint64, op evm.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..42343f91a 100644
--- a/eth/tracers/tracer_test.go
+++ b/eth/tracers/tracer_test.go
@@ -26,7 +26,8 @@ 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/core/vm/evm"
"github.com/dexon-foundation/dexon/params"
)
@@ -51,10 +52,10 @@ type dummyStatedb struct {
func (*dummyStatedb) GetRefund() uint64 { return 1337 }
func runTrace(tracer *Tracer) (json.RawMessage, error) {
- env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
+ env := evm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, evm.Config{Debug: true, Tracer: tracer})
contract := vm.NewContract(account{}, account{}, big.NewInt(0), 10000)
- contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x1, 0x0}
+ contract.Code = []byte{byte(evm.PUSH1), 0x1, byte(evm.PUSH1), 0x1, 0x0}
_, err := env.Interpreter().Run(contract, []byte{}, false)
if err != nil {
@@ -133,7 +134,7 @@ func TestHaltBetweenSteps(t *testing.T) {
t.Fatal(err)
}
- env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
+ env := evm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, evm.Config{Debug: true, Tracer: tracer})
contract := vm.NewContract(&account{}, &account{}, big.NewInt(0), 0)
tracer.CaptureState(env, 0, 0, 0, 0, nil, nil, contract, 0, nil)
diff --git a/eth/tracers/tracers_test.go b/eth/tracers/tracers_test.go
index 0b8f75ab3..783c41b7a 100644
--- a/eth/tracers/tracers_test.go
+++ b/eth/tracers/tracers_test.go
@@ -32,7 +32,8 @@ 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/core/vm/evm"
"github.com/dexon-foundation/dexon/crypto"
"github.com/dexon-foundation/dexon/ethdb"
"github.com/dexon-foundation/dexon/params"
@@ -248,7 +249,7 @@ func TestCallTracer(t *testing.T) {
if err != nil {
t.Fatalf("failed to create call tracer: %v", err)
}
- evm := vm.NewEVM(context, statedb, test.Genesis.Config, vm.Config{Debug: true, Tracer: tracer})
+ evm := evm.NewEVM(context, statedb, test.Genesis.Config, evm.Config{Debug: true, Tracer: tracer})
msg, err := tx.AsMessage(signer)
if err != nil {