eth/tracers: clean-up and comments

This commit is contained in:
Sina Mahmoodi
2021-10-13 17:14:06 +02:00
parent a2b0d3d48e
commit 18c4c17ba5
2 changed files with 16 additions and 4 deletions

View File

@ -13,7 +13,7 @@ import (
)
func init() {
Register("callTracerNative", NewCallTracer)
register("callTracerNative", NewCallTracer)
}
type callFrame struct {
@ -33,7 +33,11 @@ type CallTracer struct {
callstack []callFrame
}
// NewCallTracer returns a native go tracer which tracks
// call frames of a tx, and implements vm.Tracer.
func NewCallTracer() Tracer {
// First callframe contains tx context info
// and is populated on start and end.
t := &CallTracer{callstack: make([]callFrame, 1)}
return t
}

View File

@ -6,19 +6,27 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
)
// Tracer interface extends vm.Tracer and additionally
// allows collecting the tracing result.
type Tracer interface {
vm.Tracer
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
}
// New returns a new instance of a tracer, if one was
// registered under the given name.
func New(name string) (Tracer, bool) {
if fn, ok := tracers[name]; ok {
return fn(), true