Skip to content

Commit

Permalink
adjust debug_traceCall client method and params
Browse files Browse the repository at this point in the history
  • Loading branch information
canercidam committed Jun 17, 2024
1 parent 559ceda commit 7ee1a3d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
17 changes: 14 additions & 3 deletions domain/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ type TransactionReceipt struct {
TransactionIndex *string `json:"transactionIndex"`
}

// DebugTraceCallTransaction The transaction call object which contains the following fields
type DebugTraceCallTransaction struct {
// TraceCallTransaction contains the fields of the to-be-simulated transaction.
type TraceCallTransaction struct {
From string `json:"from"`
To string `json:"to"`
Gas *int64 `json:"gas,omitempty"`
Expand All @@ -299,7 +299,18 @@ type DebugTraceCallTransaction struct {
Data string `json:"data"`
}

type CustomDebugTraceCallResult struct{}
// TraceCallConfig contains the tracer configuration to be used while simulating the transaction.
type TraceCallConfig struct {
Tracer string `json:"tracer,omitempty"`
TracerConfig *TracerConfig `json:"tracerConfig,omitempty"`
StateOverrides map[string]interface{} `json:"stateOverrides,omitempty"`
}

// TracerConfig contains some extra tracer parameters.
type TracerConfig struct {
WithLog bool `json:"withLog,omitempty"`
OnlyTopCall bool `json:"onlyTopCall,omitempty"`
}

// TraceAction is an element of a trace_block Trace response
type TraceAction struct {
Expand Down
25 changes: 13 additions & 12 deletions ethereum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ type Client interface {
TransactionReceipt(ctx context.Context, txHash string) (*domain.TransactionReceipt, error)
ChainID(ctx context.Context) (*big.Int, error)
TraceBlock(ctx context.Context, number *big.Int) ([]domain.Trace, error)
CustomDebugTraceCall(ctx context.Context, req domain.DebugTraceCallTransaction, stateOverrides map[string]interface{}) (*domain.CustomDebugTraceCallResult, error)
DebugTraceCall(
ctx context.Context, req *domain.TraceCallTransaction,
block *rpc.BlockNumberOrHash, traceCallConfig domain.TraceCallConfig,
result interface{},
) error
GetLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
SubscribeToHead(ctx context.Context) (domain.HeaderCh, error)

Expand Down Expand Up @@ -246,17 +250,15 @@ func (e *streamEthClient) TraceBlock(ctx context.Context, number *big.Int) ([]do
return result, err
}

// CustomDebugTraceCall returns traced call with custom js tracer
func (e *streamEthClient) CustomDebugTraceCall(
ctx context.Context, req domain.DebugTraceCallTransaction, stateOverrides map[string]interface{},
) (*domain.CustomDebugTraceCallResult, error) {
// DebugTraceCall returns the traces of a call.
func (e *streamEthClient) DebugTraceCall(
ctx context.Context, req *domain.TraceCallTransaction,
block *rpc.BlockNumberOrHash, traceCallConfig domain.TraceCallConfig,
result interface{},
) error {
name := fmt.Sprintf("%s(%v)", debugTraceCall, req)
log.Debugf(name)
var result domain.CustomDebugTraceCallResult
args := []interface{}{req, []string{"trace"}, "latest"}
if stateOverrides != nil {
args = append(args, map[string]interface{}{"stateOverrides": stateOverrides})
}
args := []interface{}{req, block, traceCallConfig}

err := withBackoff(ctx, name, func(ctx context.Context) error {
err := e.rpcClient.CallContext(ctx, &result, debugTraceCall, args...)
Expand All @@ -270,8 +272,7 @@ func (e *streamEthClient) CustomDebugTraceCall(
MaxElapsedTime: pointDur(1 * time.Minute),
MaxBackoff: pointDur(e.retryInterval),
}, nil, nil)

return &result, err
return err
}

// GetLogs returns the set of logs for a block
Expand Down
18 changes: 9 additions & 9 deletions ethereum/mocks/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7ee1a3d

Please sign in to comment.