Skip to content

Commit

Permalink
feat: Add trace_get (#987)
Browse files Browse the repository at this point in the history
* trace_get implementation

* Review

* Update crates/provider/src/ext/trace.rs

docs

Co-authored-by: Matthias Seitz <[email protected]>

* Cargo fmt

---------

Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
SozinM and mattsse authored Jun 29, 2024
1 parent b15bb6a commit 7b47529
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions crates/provider/src/ext/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{Provider, RpcWithBlock};
use alloy_eips::BlockNumberOrTag;
use alloy_network::Network;
use alloy_primitives::TxHash;
use alloy_rpc_types_eth::Index;
use alloy_rpc_types_trace::{
filter::TraceFilter,
parity::{LocalizedTransactionTrace, TraceResults, TraceResultsWithTransactionHash, TraceType},
Expand Down Expand Up @@ -50,6 +51,18 @@ where
hash: TxHash,
) -> TransportResult<Vec<LocalizedTransactionTrace>>;

/// Traces of the transaction on the given positions
///
/// # Note
///
/// This function accepts single index and build list with it under the hood because
/// trace_get method accepts list of indices but limits this list to len == 1.
async fn trace_get(
&self,
hash: TxHash,
index: usize,
) -> TransportResult<LocalizedTransactionTrace>;

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

async fn trace_get(
&self,
hash: TxHash,
index: usize,
) -> TransportResult<LocalizedTransactionTrace> {
// We are using `[index]` because API accepts a list, but only supports a single index
self.client().request("trace_get", (hash, (Index::from(index),))).await
}

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

0 comments on commit 7b47529

Please sign in to comment.