github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/eth/tracers/live.go (about)

     1  package tracers
     2  
     3  import (
     4  	"encoding/json"
     5  	"errors"
     6  
     7  	"github.com/ethereum/go-ethereum/core/tracing"
     8  )
     9  
    10  type ctorFunc func(config json.RawMessage) (*tracing.Hooks, error)
    11  
    12  // LiveDirectory is the collection of tracers which can be used
    13  // during normal block import operations.
    14  var LiveDirectory = liveDirectory{elems: make(map[string]ctorFunc)}
    15  
    16  type liveDirectory struct {
    17  	elems map[string]ctorFunc
    18  }
    19  
    20  // Register registers a tracer constructor by name.
    21  func (d *liveDirectory) Register(name string, f ctorFunc) {
    22  	d.elems[name] = f
    23  }
    24  
    25  // New instantiates a tracer by name.
    26  func (d *liveDirectory) New(name string, config json.RawMessage) (*tracing.Hooks, error) {
    27  	if f, ok := d.elems[name]; ok {
    28  		return f(config)
    29  	}
    30  	return nil, errors.New("not found")
    31  }