mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
eth/tracers: live tracer return apis
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
f76f25fe8c
commit
4881b880a1
4 changed files with 13 additions and 10 deletions
|
|
@ -552,7 +552,7 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG
|
||||||
traceOutputFilename := path.Join(traceOutputPath, "supply.jsonl")
|
traceOutputFilename := path.Join(traceOutputPath, "supply.jsonl")
|
||||||
|
|
||||||
// Load supply tracer
|
// Load supply tracer
|
||||||
tracer, err := tracers.LiveDirectory.New("supply", json.RawMessage(fmt.Sprintf(`{"path":"%s"}`, traceOutputPath)), nil)
|
tracer, _, err := tracers.LiveDirectory.New("supply", json.RawMessage(fmt.Sprintf(`{"path":"%s"}`, traceOutputPath)), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to create call tracer: %v", err)
|
return nil, nil, fmt.Errorf("failed to create call tracer: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/tracing"
|
"github.com/ethereum/go-ethereum/core/tracing"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ctorFunc func(config json.RawMessage, backend Backend) (*tracing.Hooks, error)
|
type ctorFunc func(config json.RawMessage, backend Backend) (*tracing.Hooks, []rpc.API, error)
|
||||||
|
|
||||||
// LiveDirectory is the collection of tracers which can be used
|
// LiveDirectory is the collection of tracers which can be used
|
||||||
// during normal block import operations.
|
// during normal block import operations.
|
||||||
|
|
@ -23,9 +24,9 @@ func (d *liveDirectory) Register(name string, f ctorFunc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New instantiates a tracer by name.
|
// New instantiates a tracer by name.
|
||||||
func (d *liveDirectory) New(name string, config json.RawMessage, backend Backend) (*tracing.Hooks, error) {
|
func (d *liveDirectory) New(name string, config json.RawMessage, backend Backend) (*tracing.Hooks, []rpc.API, error) {
|
||||||
if f, ok := d.elems[name]; ok {
|
if f, ok := d.elems[name]; ok {
|
||||||
return f(config, backend)
|
return f(config, backend)
|
||||||
}
|
}
|
||||||
return nil, errors.New("not found")
|
return nil, nil, errors.New("not found")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -21,7 +22,7 @@ func init() {
|
||||||
// as soon as we have a real live tracer.
|
// as soon as we have a real live tracer.
|
||||||
type noop struct{}
|
type noop struct{}
|
||||||
|
|
||||||
func newNoopTracer(_ json.RawMessage, _ tracers.Backend) (*tracing.Hooks, error) {
|
func newNoopTracer(_ json.RawMessage, _ tracers.Backend) (*tracing.Hooks, []rpc.API, error) {
|
||||||
t := &noop{}
|
t := &noop{}
|
||||||
return &tracing.Hooks{
|
return &tracing.Hooks{
|
||||||
OnTxStart: t.OnTxStart,
|
OnTxStart: t.OnTxStart,
|
||||||
|
|
@ -41,7 +42,7 @@ func newNoopTracer(_ json.RawMessage, _ tracers.Backend) (*tracing.Hooks, error)
|
||||||
OnCodeChange: t.OnCodeChange,
|
OnCodeChange: t.OnCodeChange,
|
||||||
OnStorageChange: t.OnStorageChange,
|
OnStorageChange: t.OnStorageChange,
|
||||||
OnLog: t.OnLog,
|
OnLog: t.OnLog,
|
||||||
}, nil
|
}, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *noop) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
func (t *noop) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"gopkg.in/natefinch/lumberjack.v2"
|
"gopkg.in/natefinch/lumberjack.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -74,15 +75,15 @@ 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.
|
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.Backend) (*tracing.Hooks, error) {
|
func newSupply(cfg json.RawMessage, _ tracers.Backend) (*tracing.Hooks, []rpc.API, error) {
|
||||||
var config supplyTracerConfig
|
var config supplyTracerConfig
|
||||||
if cfg != nil {
|
if cfg != nil {
|
||||||
if err := json.Unmarshal(cfg, &config); err != nil {
|
if err := json.Unmarshal(cfg, &config); err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse config: %v", err)
|
return nil, nil, fmt.Errorf("failed to parse config: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.Path == "" {
|
if config.Path == "" {
|
||||||
return nil, errors.New("supply tracer output path is required")
|
return nil, nil, errors.New("supply tracer output path is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store traces in a rotating file
|
// Store traces in a rotating file
|
||||||
|
|
@ -106,7 +107,7 @@ func newSupply(cfg json.RawMessage, _ tracers.Backend) (*tracing.Hooks, error) {
|
||||||
OnEnter: t.OnEnter,
|
OnEnter: t.OnEnter,
|
||||||
OnExit: t.OnExit,
|
OnExit: t.OnExit,
|
||||||
OnClose: t.OnClose,
|
OnClose: t.OnClose,
|
||||||
}, nil
|
}, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSupplyInfo() supplyInfo {
|
func newSupplyInfo() supplyInfo {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue