Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add trace_get #987

Merged
merged 5 commits into from
Jun 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/provider/src/ext/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ where
hash: TxHash,
) -> TransportResult<Vec<LocalizedTransactionTrace>>;

/// Traces of the transaction on the given positions
async fn trace_get(
&self,
hash: TxHash,
index: u64,
) -> TransportResult<LocalizedTransactionTrace>;

/// Trace the given raw transaction.
async fn trace_raw_transaction(
&self,
Expand Down Expand Up @@ -119,6 +126,15 @@ where
self.client().request("trace_transaction", (hash,)).await
}

async fn trace_get(
&self,
hash: TxHash,
index: u64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is an index, I wonder if we should use usize here because I assume most of the time this value is derived from doing some vec.len() +- ops

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, put usize in there.
I think it would be less convenient to put Index as type because then all calls to trace_get would require a .into() call from the user. It probably would be less convenient.

) -> TransportResult<LocalizedTransactionTrace> {
// We are using vec![indices] because API accepts a list, but in fact works only if list.len == 1
SozinM marked this conversation as resolved.
Show resolved Hide resolved
self.client().request("trace_get", (hash, vec![index])).await
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use tuples for lists in JSON since they're equivalent to avoid allocating on the heap, see above in trace_transaction

Copy link
Member

@mattsse mattsse Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also use the Index type of rpc-types-eth, because this should ideally be formatted as hex

https://docs.alchemy.com/reference/trace-get

}

async fn trace_raw_transaction(
&self,
data: &[u8],
Expand Down