mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
feat: add TraceCallWithCallTracer and TraceTransactionWithCallTracer
This commit is contained in:
parent
eb879a76cf
commit
3962af30e1
2 changed files with 45 additions and 0 deletions
|
|
@ -38,6 +38,10 @@ func init() {
|
||||||
tracers.DefaultDirectory.Register("callTracer", newCallTracer, false)
|
tracers.DefaultDirectory.Register("callTracer", newCallTracer, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CallFrame struct {
|
||||||
|
callFrame
|
||||||
|
}
|
||||||
|
|
||||||
type callLog struct {
|
type callLog struct {
|
||||||
Address common.Address `json:"address"`
|
Address common.Address `json:"address"`
|
||||||
Topics []common.Hash `json:"topics"`
|
Topics []common.Hash `json:"topics"`
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"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/native"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
@ -348,3 +350,42 @@ func (o BlockOverrides) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
return json.Marshal(output)
|
return json.Marshal(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// geth debug module
|
||||||
|
|
||||||
|
// TraceTransactionWithCallTracer trace a transaction with call tracer
|
||||||
|
func (c *Client) TraceTransactionWithCallTracer(ctx context.Context, txHash common.Hash, config *tracers.TraceCallConfig) (*native.CallFrame, error) {
|
||||||
|
// var result interface{}
|
||||||
|
var result native.CallFrame
|
||||||
|
tracer := "callTracer"
|
||||||
|
if config == nil {
|
||||||
|
config = &tracers.TraceCallConfig{
|
||||||
|
TraceConfig: tracers.TraceConfig{
|
||||||
|
Tracer: &tracer,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := c.c.CallContext(ctx, &result, "debug_traceTransaction", txHash, config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TraceCallWithCallTracer trace a call with call tracer
|
||||||
|
func (c *Client) TraceCallWithCallTracer(ctx context.Context, args ethereum.CallMsg, config *tracers.TraceCallConfig, blockNumber *big.Int) (*native.CallFrame, error) {
|
||||||
|
var result native.CallFrame
|
||||||
|
if config == nil {
|
||||||
|
tracer := "callTracer"
|
||||||
|
config = &tracers.TraceCallConfig{
|
||||||
|
TraceConfig: tracers.TraceConfig{
|
||||||
|
Tracer: &tracer,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := c.c.CallContext(ctx, &result, "debug_traceCall", toCallArg(args), toBlockNumArg(blockNumber), config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue