mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
trace_tx
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
0c6e9a2207
commit
b62bf22cb9
1 changed files with 44 additions and 7 deletions
|
|
@ -4,10 +4,14 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
var errTxNotFound = errors.New("transaction not found")
|
||||
|
||||
type filterAPI struct {
|
||||
backend tracers.Backend
|
||||
filter *filter
|
||||
|
|
@ -27,13 +31,9 @@ func (api *filterAPI) isSupportedTracer(tracer string) bool {
|
|||
}
|
||||
|
||||
func (api *filterAPI) Block(ctx context.Context, blockNr rpc.BlockNumber, cfg *traceConfig) ([]interface{}, error) {
|
||||
tracer := defaultTraceConfig.Tracer
|
||||
if cfg != nil {
|
||||
tracer = cfg.Tracer
|
||||
}
|
||||
|
||||
if !api.isSupportedTracer(tracer) {
|
||||
return nil, errors.New("tracer not found")
|
||||
tracer, err := api.getTracerOrDefault(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blknum := uint64(blockNr.Int64())
|
||||
|
|
@ -56,3 +56,40 @@ func (api *filterAPI) Block(ctx context.Context, blockNr rpc.BlockNumber, cfg *t
|
|||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (api *filterAPI) getTracerOrDefault(cfg *traceConfig) (string, error) {
|
||||
if cfg == nil {
|
||||
return defaultTraceConfig.Tracer, nil
|
||||
}
|
||||
tracer := cfg.Tracer
|
||||
|
||||
if !api.isSupportedTracer(tracer) {
|
||||
return "", errors.New("tracer not found")
|
||||
}
|
||||
return tracer, nil
|
||||
}
|
||||
|
||||
func (api *filterAPI) Transaction(ctx context.Context, hash common.Hash, cfg *traceConfig) (interface{}, error) {
|
||||
tracer, err := api.getTracerOrDefault(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
found, _, _, blknum, index, err := api.backend.GetTransaction(ctx, hash)
|
||||
if err != nil {
|
||||
return nil, ethapi.NewTxIndexingError()
|
||||
}
|
||||
if !found {
|
||||
return nil, errTxNotFound
|
||||
}
|
||||
traces, err := api.filter.readBlockTraces(ctx, tracer, blknum)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if index >= uint64(len(traces)) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return traces[index].Result, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue