Get tracers working, returning results

This commit is contained in:
Austin Roberts 2021-06-25 14:57:24 -05:00
parent 97cf240fe0
commit ad8719a64a
2 changed files with 17 additions and 8 deletions

View File

@ -851,6 +851,9 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *txTrac
StructLogs: ethapi.FormatLogs(tracer.StructLogs()), StructLogs: ethapi.FormatLogs(tracer.StructLogs()),
}, nil }, nil
case plugins.TracerResult:
return tracer.GetResult()
case *Tracer: case *Tracer:
return tracer.GetResult() return tracer.GetResult()

View File

@ -13,15 +13,20 @@ import (
"strings" "strings"
"path" "path"
"fmt" "fmt"
"reflect"
) )
type APILoader func(*node.Node, Backend) []rpc.API type APILoader func(*node.Node, Backend) []rpc.API
type Subcommand func(*cli.Context, []string) error type Subcommand func(*cli.Context, []string) error
type TracerResult interface {
vm.Tracer
GetResult() (interface{}, error)
}
type PluginLoader struct{ type PluginLoader struct{
Tracers map[string]func(*state.StateDB)vm.Tracer Tracers map[string]func(*state.StateDB)TracerResult
StateHooks []interface{} // TODO: Set interface StateHooks []interface{} // TODO: Set interface
ChainEventHooks []interface{} // TODO: Set interface ChainEventHooks []interface{} // TODO: Set interface
RPCPlugins []APILoader RPCPlugins []APILoader
@ -36,6 +41,7 @@ func NewPluginLoader(target string) (*PluginLoader, error) {
pl := &PluginLoader{ pl := &PluginLoader{
RPCPlugins: []APILoader{}, RPCPlugins: []APILoader{},
Subcommands: make(map[string]Subcommand), Subcommands: make(map[string]Subcommand),
Tracers: make(map[string]func(*state.StateDB)TracerResult),
Flags: []*flag.FlagSet{}, Flags: []*flag.FlagSet{},
} }
files, err := ioutil.ReadDir(target) files, err := ioutil.ReadDir(target)
@ -76,11 +82,11 @@ func NewPluginLoader(target string) (*PluginLoader, error) {
sb, err := plug.Lookup("Subcommands") sb, err := plug.Lookup("Subcommands")
if err == nil { if err == nil {
subcommands, ok := sb.(map[string]func(*cli.Context, []string) error) subcommands, ok := sb.(*map[string]func(*cli.Context, []string) error)
if !ok { if !ok {
log.Warn("Could not cast plugin.Subcommands to `map[string]func(*cli.Context, []string) error`", "file", fpath) log.Warn("Could not cast plugin.Subcommands to `map[string]func(*cli.Context, []string) error`", "file", fpath, "type", reflect.TypeOf(sb))
} else { } else {
for k, v := range subcommands { for k, v := range *subcommands {
if _, ok := pl.Subcommands[k]; ok { if _, ok := pl.Subcommands[k]; ok {
log.Warn("Subcommand redeclared", "file", fpath, "subcommand", k) log.Warn("Subcommand redeclared", "file", fpath, "subcommand", k)
} }
@ -90,11 +96,11 @@ func NewPluginLoader(target string) (*PluginLoader, error) {
} }
tr, err := plug.Lookup("Tracers") tr, err := plug.Lookup("Tracers")
if err == nil { if err == nil {
tracers, ok := tr.(map[string]func(*state.StateDB)vm.Tracer) tracers, ok := tr.(*map[string]func(*state.StateDB)TracerResult)
if !ok { if !ok {
log.Warn("Could not cast plugin.Tracers to `map[string]vm.Tracer`", "file", fpath) log.Warn("Could not cast plugin.Tracers to `map[string]vm.Tracer`", "file", fpath)
} else { } else {
for k, v := range tracers { for k, v := range *tracers {
if _, ok := pl.Tracers[k]; ok { if _, ok := pl.Tracers[k]; ok {
log.Warn("Tracer redeclared", "file", fpath, "tracer", k) log.Warn("Tracer redeclared", "file", fpath, "tracer", k)
} }
@ -155,12 +161,12 @@ func GetAPIs(stack *node.Node, backend Backend) []rpc.API {
return defaultPluginLoader.GetAPIs(stack, backend) return defaultPluginLoader.GetAPIs(stack, backend)
} }
func (pl *PluginLoader) GetTracer(s string) (func(*state.StateDB)vm.Tracer, bool) { func (pl *PluginLoader) GetTracer(s string) (func(*state.StateDB)TracerResult, bool) {
tr, ok := pl.Tracers[s] tr, ok := pl.Tracers[s]
return tr, ok return tr, ok
} }
func GetTracer(s string) (func(*state.StateDB)vm.Tracer, bool) { func GetTracer(s string) (func(*state.StateDB)TracerResult, bool) {
if defaultPluginLoader == nil { if defaultPluginLoader == nil {
log.Warn("Attempting GetTracer, but default PluginLoader has not been initialized") log.Warn("Attempting GetTracer, but default PluginLoader has not been initialized")
return nil, false return nil, false