Skip to content

Commit

Permalink
ethrpc: small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 committed Oct 23, 2024
1 parent 2ae9595 commit 9a0b412
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
13 changes: 7 additions & 6 deletions ethrpc/ethrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion ethrpc/ethrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions ethrpc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
50 changes: 25 additions & 25 deletions ethrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}},
}
}

0 comments on commit 9a0b412

Please sign in to comment.