diff --git a/ethrpc/ethrpc.go b/ethrpc/ethrpc.go index 9fb58ed..f2e3bbb 100644 --- a/ethrpc/ethrpc.go +++ b/ethrpc/ethrpc.go @@ -67,6 +67,7 @@ var ( var _ Interface = &Provider{} var _ RawInterface = &Provider{} var _ StrictnessLevelGetter = &Provider{} +var _ DebugInterface = &Provider{} // Provider adheres to the go-ethereum bind.ContractBackend interface. In case we ever // want to break this interface, we could also write an adapter type to keep them compat. @@ -463,20 +464,20 @@ func (p *Provider) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint6 return result, err } -func (p *Provider) DebugTraceBlockByNumber(ctx context.Context, blockNum *big.Int) ([]*DebugTraceTransactionResult, error) { - var result []*DebugTraceTransactionResult +func (p *Provider) DebugTraceBlockByNumber(ctx context.Context, blockNum *big.Int) ([]*TransactionDebugTrace, error) { + var result []*TransactionDebugTrace _, err := p.Do(ctx, DebugTraceBlockByNumber(blockNum).Into(&result)) return result, err } -func (p *Provider) DebugTraceBlockByHash(ctx context.Context, blockHash common.Hash) ([]*DebugTraceTransactionResult, error) { - var result []*DebugTraceTransactionResult +func (p *Provider) DebugTraceBlockByHash(ctx context.Context, blockHash common.Hash) ([]*TransactionDebugTrace, error) { + var result []*TransactionDebugTrace _, err := p.Do(ctx, DebugTraceBlockByHash(blockHash).Into(&result)) return result, err } -func (p *Provider) DebugTraceTransaction(ctx context.Context, txHash common.Hash) (*DebugTraceCallResult, error) { - var result *DebugTraceCallResult +func (p *Provider) DebugTraceTransaction(ctx context.Context, txHash common.Hash) (*CallDebugTrace, error) { + var result *CallDebugTrace _, err := p.Do(ctx, DebugTraceTransaction(txHash).Into(&result)) return result, err } diff --git a/ethrpc/ethrpc_test.go b/ethrpc/ethrpc_test.go index e90af17..8730c3a 100644 --- a/ethrpc/ethrpc_test.go +++ b/ethrpc/ethrpc_test.go @@ -225,7 +225,7 @@ func TestRaw(t *testing.T) { } } -// Commented out because of missing test credentials +// todo: uncommented when those call are available on node-gateway /*func TestDebugTraceBlockByNumber(t *testing.T) { p, err := ethrpc.NewProvider("...") require.NoError(t, err) diff --git a/ethrpc/interface.go b/ethrpc/interface.go index 5f1fa80..10395a6 100644 --- a/ethrpc/interface.go +++ b/ethrpc/interface.go @@ -197,3 +197,10 @@ type RawInterface interface { type StrictnessLevelGetter interface { StrictnessLevel() StrictnessLevel } + +// DebugInterface provides additional debugging methods +type DebugInterface interface { + DebugTraceBlockByNumber(ctx context.Context, blockNum *big.Int) ([]*TransactionDebugTrace, error) + DebugTraceBlockByHash(ctx context.Context, blockHash common.Hash) ([]*TransactionDebugTrace, error) + DebugTraceTransaction(ctx context.Context, txHash common.Hash) (*CallDebugTrace, error) +} diff --git a/ethrpc/methods.go b/ethrpc/methods.go index 23f6e36..ac28d50 100644 --- a/ethrpc/methods.go +++ b/ethrpc/methods.go @@ -426,46 +426,46 @@ const ( DebugTracerPreStateTracer DebugTracer = "prestateTracer" ) -type debugTracerParam struct { +type debugTracerOptions struct { Name string `json:"tracer"` } -type DebugTraceCallResult struct { - Type string `json:"type"` - From common.Address `json:"from"` - To common.Address `json:"to"` - Value *hexutil.Big `json:"value"` - Gas *hexutil.Big `json:"gas"` - GasUsed *hexutil.Big `json:"gasUsed"` - Input hexutil.Bytes `json:"input"` - Output hexutil.Bytes `json:"output"` - Error string `json:"error"` - RevertReason string `json:"revertReason"` - Calls []*DebugTraceCallResult `json:"calls"` +type CallDebugTrace struct { + Type string `json:"type"` + From common.Address `json:"from"` + To common.Address `json:"to"` + Value *hexutil.Big `json:"value"` + Gas *hexutil.Big `json:"gas"` + GasUsed *hexutil.Big `json:"gasUsed"` + Input hexutil.Bytes `json:"input"` + Output hexutil.Bytes `json:"output"` + Error string `json:"error"` + RevertReason string `json:"revertReason"` + Calls []*CallDebugTrace `json:"calls"` } -type DebugTraceTransactionResult struct { - TxHash common.Hash `json:"txHash"` - Result DebugTraceCallResult `json:"result"` +type TransactionDebugTrace struct { + TxHash common.Hash `json:"txHash"` + Result CallDebugTrace `json:"result"` } -func DebugTraceBlockByNumber(blockNum *big.Int) CallBuilder[[]*DebugTraceTransactionResult] { - return CallBuilder[[]*DebugTraceTransactionResult]{ +func DebugTraceBlockByNumber(blockNum *big.Int) CallBuilder[[]*TransactionDebugTrace] { + return CallBuilder[[]*TransactionDebugTrace]{ method: "debug_traceBlockByNumber", - params: []any{toBlockNumArg(blockNum), debugTracerParam{Name: string(DebugTracerCallTracer)}}, + params: []any{toBlockNumArg(blockNum), debugTracerOptions{Name: string(DebugTracerCallTracer)}}, } } -func DebugTraceBlockByHash(hash common.Hash) CallBuilder[[]*DebugTraceTransactionResult] { - return CallBuilder[[]*DebugTraceTransactionResult]{ +func DebugTraceBlockByHash(hash common.Hash) CallBuilder[[]*TransactionDebugTrace] { + return CallBuilder[[]*TransactionDebugTrace]{ method: "debug_traceBlockByHash", - params: []any{hash, debugTracerParam{Name: string(DebugTracerCallTracer)}}, + params: []any{hash, debugTracerOptions{Name: string(DebugTracerCallTracer)}}, } } -func DebugTraceTransaction(txHash common.Hash) CallBuilder[*DebugTraceCallResult] { - return CallBuilder[*DebugTraceCallResult]{ +func DebugTraceTransaction(txHash common.Hash) CallBuilder[*CallDebugTrace] { + return CallBuilder[*CallDebugTrace]{ method: "debug_traceTransaction", - params: []any{txHash, debugTracerParam{Name: string(DebugTracerCallTracer)}}, + params: []any{txHash, debugTracerOptions{Name: string(DebugTracerCallTracer)}}, } }