forked from cerc-io/plugeth
Changes in service of extending block context object into the tracer plugins
This commit is contained in:
+1
-1
@@ -882,7 +882,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex
|
||||
}
|
||||
// Get the tracer from the plugin loader
|
||||
if tr, ok := getPluginTracer(*config.Tracer); ok {
|
||||
tracer = tr(statedb)
|
||||
tracer = tr(statedb, vmctx)
|
||||
} else {
|
||||
// Constuct the JavaScript tracer to execute with
|
||||
if t, err := New(*config.Tracer, txctx); err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/plugins"
|
||||
"github.com/ethereum/go-ethereum/plugins/interfaces"
|
||||
@@ -11,29 +12,44 @@ import (
|
||||
"github.com/openrelayxyz/plugeth-utils/core"
|
||||
)
|
||||
|
||||
func GetPluginTracer(pl *plugins.PluginLoader, name string) (func(*state.StateDB) interfaces.TracerResult, bool) {
|
||||
func GetPluginTracer(pl *plugins.PluginLoader, name string) (func(*state.StateDB, vm.BlockContext) interfaces.TracerResult, bool) {
|
||||
tracers := pl.Lookup("Tracers", func(item interface{}) bool {
|
||||
_, ok := item.(*map[string]func(core.StateDB) core.TracerResult)
|
||||
if !ok {
|
||||
_, ok2 := item.(*map[string]func(core.StateDB, core.BlockContext) core.TracerResult)
|
||||
if !(ok || ok2) {
|
||||
log.Warn("Found tracer that did not match type", "tracer", reflect.TypeOf(item))
|
||||
}
|
||||
return ok
|
||||
return ok || ok2
|
||||
})
|
||||
|
||||
for _, tmap := range tracers {
|
||||
if tracerMap, ok := tmap.(*map[string]func(core.StateDB) core.TracerResult); ok {
|
||||
if tracer, ok := (*tracerMap)[name]; ok {
|
||||
return func(sdb *state.StateDB) interfaces.TracerResult {
|
||||
return func(sdb *state.StateDB, vmctx vm.BlockContext) interfaces.TracerResult {
|
||||
return wrappers.NewWrappedTracer(tracer(wrappers.NewWrappedStateDB(sdb)))
|
||||
}, true
|
||||
}
|
||||
}
|
||||
if tracerMap, ok := tmap.(*map[string]func(core.StateDB, core.BlockContext) core.TracerResult); ok {
|
||||
if tracer, ok := (*tracerMap)[name]; ok {
|
||||
return func(sdb *state.StateDB, vmctx vm.BlockContext) interfaces.TracerResult {
|
||||
return wrappers.NewWrappedTracer(tracer(wrappers.NewWrappedStateDB(sdb), core.BlockContext{
|
||||
Coinbase: core.Address(vmctx.Coinbase),
|
||||
GasLimit: vmctx.GasLimit,
|
||||
BlockNumber: vmctx.BlockNumber,
|
||||
Time: vmctx.Time,
|
||||
Difficulty: vmctx.Difficulty,
|
||||
BaseFee: vmctx.BaseFee,
|
||||
}))
|
||||
}, true
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Info("Tracer not found", "name", name, "tracers", len(tracers))
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func getPluginTracer(name string) (func(*state.StateDB) interfaces.TracerResult, bool) {
|
||||
func getPluginTracer(name string) (func(*state.StateDB, vm.BlockContext) interfaces.TracerResult, bool) {
|
||||
if plugins.DefaultPluginLoader == nil {
|
||||
log.Warn("Attempting GetPluginTracer, but default PluginLoader has not been initialized")
|
||||
return nil, false
|
||||
|
||||
Reference in New Issue
Block a user