Skip to content

Commit

Permalink
Added options to TraceTransaction function (#257)
Browse files Browse the repository at this point in the history
* Added options to TraceTransaction endpoint call wrapper function

* Added test case

* Removed struct field flag

* Minor updates
  • Loading branch information
begmaroman authored Oct 6, 2023
1 parent 1000cf3 commit 6b06836
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions jsonrpc/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ type Debug struct {
c *Client
}

// Eth returns the reference to the eth namespace
// Debug returns the reference to the debug namespace
func (c *Client) Debug() *Debug {
return c.endpoints.d
}

type TraceTransactionOptions struct {
EnableMemory bool `json:"enableMemory"`
DisableStack bool `json:"disableStack"`
DisableStorage bool `json:"disableStorage"`
EnableReturnData bool `json:"enableReturnData"`
Timeout string `json:"timeout,omitempty"`
Tracer string `json:"tracer,omitempty"`
TracerConfig map[string]interface{} `json:"tracerConfig,omitempty"`
}

type TransactionTrace struct {
Gas uint64
ReturnValue string
Expand All @@ -28,8 +38,8 @@ type StructLogs struct {
Storage map[string]string
}

func (d *Debug) TraceTransaction(hash ethgo.Hash) (*TransactionTrace, error) {
func (d *Debug) TraceTransaction(hash ethgo.Hash, opts TraceTransactionOptions) (*TransactionTrace, error) {
var res *TransactionTrace
err := d.c.Call("debug_traceTransaction", &res, hash)
err := d.c.Call("debug_traceTransaction", &res, hash, opts)
return res, err
}
2 changes: 1 addition & 1 deletion jsonrpc/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestDebug_TraceTransaction(t *testing.T) {
r, err := s.TxnTo(addr, "setA2")
require.NoError(t, err)

trace, err := c.Debug().TraceTransaction(r.TransactionHash)
trace, err := c.Debug().TraceTransaction(r.TransactionHash, TraceTransactionOptions{})
assert.NoError(t, err)
assert.Greater(t, trace.Gas, uint64(20000))
assert.NotEmpty(t, trace.StructLogs)
Expand Down

0 comments on commit 6b06836

Please sign in to comment.