go-ethereum/eth/tracers/live.go
jsvisa efbdfbbda3 eth,cmd: set tracer's backend after eth initalized
Signed-off-by: jsvisa <delweng@gmail.com>
2024-09-25 08:25:55 +08:00

32 lines
829 B
Go

package tracers
import (
"encoding/json"
"errors"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/rpc"
)
type ctorFunc func(config json.RawMessage) (*tracing.Hooks, []rpc.API, error)
// LiveDirectory is the collection of tracers which can be used
// during normal block import operations.
var LiveDirectory = liveDirectory{elems: make(map[string]ctorFunc)}
type liveDirectory struct {
elems map[string]ctorFunc
}
// Register registers a tracer constructor by name.
func (d *liveDirectory) Register(name string, f ctorFunc) {
d.elems[name] = f
}
// New instantiates a tracer by name.
func (d *liveDirectory) New(name string, config json.RawMessage) (*tracing.Hooks, []rpc.API, error) {
if f, ok := d.elems[name]; ok {
return f(config)
}
return nil, nil, errors.New("not found")
}