2021-06-26 03:38:04 +00:00
|
|
|
package tracers
|
|
|
|
|
|
|
|
import (
|
2021-09-08 21:38:17 +00:00
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/plugins"
|
|
|
|
"github.com/ethereum/go-ethereum/plugins/interfaces"
|
|
|
|
"github.com/ethereum/go-ethereum/plugins/wrappers"
|
|
|
|
"github.com/openrelayxyz/plugeth-utils/core"
|
2021-06-26 03:38:04 +00:00
|
|
|
)
|
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func GetPluginTracer(pl *plugins.PluginLoader, name string) (func(*state.StateDB) interfaces.TracerResult, bool) {
|
|
|
|
tracers := pl.Lookup("Tracers", func(item interface{}) bool {
|
|
|
|
_, ok := item.(*map[string]func(*state.StateDB) interfaces.TracerResult)
|
|
|
|
if !ok {
|
|
|
|
log.Warn("Found tracer that did not match type", "tracer", reflect.TypeOf(item))
|
|
|
|
}
|
|
|
|
return ok
|
|
|
|
})
|
|
|
|
|
|
|
|
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 wrappers.NewWrappedTracer(tracer(wrappers.NewWrappedStateDB(sdb)))
|
|
|
|
}, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Info("Tracer not found", "name", name, "tracers", len(tracers))
|
|
|
|
return nil, false
|
2021-06-26 03:38:04 +00:00
|
|
|
}
|
2021-06-26 04:02:25 +00:00
|
|
|
|
2021-09-08 21:38:17 +00:00
|
|
|
func getPluginTracer(name string) (func(*state.StateDB) interfaces.TracerResult, bool) {
|
|
|
|
if plugins.DefaultPluginLoader == nil {
|
2021-06-26 04:02:25 +00:00
|
|
|
log.Warn("Attempting GetPluginTracer, but default PluginLoader has not been initialized")
|
2021-09-08 21:38:17 +00:00
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
return GetPluginTracer(plugins.DefaultPluginLoader, name)
|
2021-06-26 04:02:25 +00:00
|
|
|
}
|