mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
move live constructor to core/tracing
This commit is contained in:
parent
8a92d5aeac
commit
b54e788759
4 changed files with 16 additions and 14 deletions
|
|
@ -18,6 +18,7 @@ package tracing
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -80,7 +81,16 @@ type Backend interface {
|
|||
GetTransaction(ctx context.Context, txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64, error)
|
||||
}
|
||||
|
||||
// Node is the interface providing access to node-level
|
||||
// infra such as APIs and DBs.
|
||||
type Node interface {
|
||||
RegisterAPIs(apis []rpc.API)
|
||||
}
|
||||
|
||||
type (
|
||||
// LiveConstructor is the constructor for a live tracer.
|
||||
LiveConstructor = func(config json.RawMessage, stack Node, backend Backend) (*Hooks, error)
|
||||
|
||||
/*
|
||||
- VM events -
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,31 +5,23 @@ import (
|
|||
"errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/tracing"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
// LiveApiRegister is the interface that used to register JSON-RPC APIs
|
||||
type LiveApiRegister interface {
|
||||
RegisterAPIs(apis []rpc.API)
|
||||
}
|
||||
|
||||
type ctorFunc func(config json.RawMessage, stack LiveApiRegister, backend tracing.Backend) (*tracing.Hooks, error)
|
||||
|
||||
// LiveDirectory is the collection of tracers which can be used
|
||||
// during normal block import operations.
|
||||
var LiveDirectory = liveDirectory{elems: make(map[string]ctorFunc)}
|
||||
var LiveDirectory = liveDirectory{elems: make(map[string]tracing.LiveConstructor)}
|
||||
|
||||
type liveDirectory struct {
|
||||
elems map[string]ctorFunc
|
||||
elems map[string]tracing.LiveConstructor
|
||||
}
|
||||
|
||||
// Register registers a tracer constructor by name.
|
||||
func (d *liveDirectory) Register(name string, f ctorFunc) {
|
||||
func (d *liveDirectory) Register(name string, f tracing.LiveConstructor) {
|
||||
d.elems[name] = f
|
||||
}
|
||||
|
||||
// New instantiates a tracer by name.
|
||||
func (d *liveDirectory) New(name string, config json.RawMessage, stack LiveApiRegister, backend tracing.Backend) (*tracing.Hooks, error) {
|
||||
func (d *liveDirectory) New(name string, config json.RawMessage, stack tracing.Node, backend tracing.Backend) (*tracing.Hooks, error) {
|
||||
if f, ok := d.elems[name]; ok {
|
||||
return f(config, stack, backend)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func init() {
|
|||
// as soon as we have a real live tracer.
|
||||
type noop struct{}
|
||||
|
||||
func newNoopTracer(_ json.RawMessage, _ tracers.LiveApiRegister, _ tracing.Backend) (*tracing.Hooks, error) {
|
||||
func newNoopTracer(_ json.RawMessage, _ tracing.Node, _ tracing.Backend) (*tracing.Hooks, error) {
|
||||
t := &noop{}
|
||||
return &tracing.Hooks{
|
||||
OnTxStart: t.OnTxStart,
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ type supplyTracerConfig struct {
|
|||
MaxSize int `json:"maxSize"` // MaxSize is the maximum size in megabytes of the tracer log file before it gets rotated. It defaults to 100 megabytes.
|
||||
}
|
||||
|
||||
func newSupply(cfg json.RawMessage, _ tracers.LiveApiRegister, _ tracing.Backend) (*tracing.Hooks, error) {
|
||||
func newSupply(cfg json.RawMessage, _ tracing.Node, _ tracing.Backend) (*tracing.Hooks, error) {
|
||||
var config supplyTracerConfig
|
||||
if cfg != nil {
|
||||
if err := json.Unmarshal(cfg, &config); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue