eth/tracers: clean-up and comments
This commit is contained in:
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Register("callTracerNative", NewCallTracer)
|
register("callTracerNative", NewCallTracer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type callFrame struct {
|
type callFrame struct {
|
||||||
@ -33,7 +33,11 @@ type CallTracer struct {
|
|||||||
callstack []callFrame
|
callstack []callFrame
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCallTracer returns a native go tracer which tracks
|
||||||
|
// call frames of a tx, and implements vm.Tracer.
|
||||||
func NewCallTracer() Tracer {
|
func NewCallTracer() Tracer {
|
||||||
|
// First callframe contains tx context info
|
||||||
|
// and is populated on start and end.
|
||||||
t := &CallTracer{callstack: make([]callFrame, 1)}
|
t := &CallTracer{callstack: make([]callFrame, 1)}
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
@ -6,19 +6,27 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Tracer interface extends vm.Tracer and additionally
|
||||||
|
// allows collecting the tracing result.
|
||||||
type Tracer interface {
|
type Tracer interface {
|
||||||
vm.Tracer
|
vm.Tracer
|
||||||
GetResult() (json.RawMessage, error)
|
GetResult() (json.RawMessage, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Constructor func() Tracer
|
// constructor creates a new instance of a Tracer.
|
||||||
|
type constructor func() Tracer
|
||||||
|
|
||||||
var tracers map[string]Constructor = make(map[string]Constructor)
|
var tracers map[string]constructor = make(map[string]constructor)
|
||||||
|
|
||||||
func Register(name string, fn Constructor) {
|
// register makes native tracers in this directory which adhere
|
||||||
|
// to the `Tracer` interface available to the rest of the codebase.
|
||||||
|
// It is typically invoked in the `init()` function.
|
||||||
|
func register(name string, fn constructor) {
|
||||||
tracers[name] = fn
|
tracers[name] = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New returns a new instance of a tracer, if one was
|
||||||
|
// registered under the given name.
|
||||||
func New(name string) (Tracer, bool) {
|
func New(name string) (Tracer, bool) {
|
||||||
if fn, ok := tracers[name]; ok {
|
if fn, ok := tracers[name]; ok {
|
||||||
return fn(), true
|
return fn(), true
|
||||||
|
Reference in New Issue
Block a user