diff --git a/crates/rpc/rpc-api/src/trace.rs b/crates/rpc/rpc-api/src/trace.rs index ab4f36758d..d38af056d7 100644 --- a/crates/rpc/rpc-api/src/trace.rs +++ b/crates/rpc/rpc-api/src/trace.rs @@ -71,6 +71,11 @@ pub trait TraceApi { async fn trace_filter(&self, filter: TraceFilter) -> RpcResult>; /// Returns transaction trace at given index. + /// + /// `indices` represent the index positions of the traces. + /// + /// Note: This expects a list of indices but only one is supported since this function returns a + /// single [LocalizedTransactionTrace]. #[method(name = "get")] async fn trace_get( &self, diff --git a/crates/rpc/rpc/src/trace.rs b/crates/rpc/rpc/src/trace.rs index 2fcf2d237b..ff2d09e50c 100644 --- a/crates/rpc/rpc/src/trace.rs +++ b/crates/rpc/rpc/src/trace.rs @@ -268,17 +268,36 @@ where .await } - /// Returns transaction trace with the given address. + /// Returns transaction trace objects at the given index + /// + /// Note: For compatibility reasons this only supports 1 single index, since this method is + /// supposed to return a single trace. See also: + /// + /// This returns `None` if `indices` is empty pub async fn trace_get( &self, hash: H256, - trace_address: Vec, + indices: Vec, + ) -> EthResult> { + if indices.len() != 1 { + // The OG impl failed if it gets more than a single index + return Ok(None) + } + self.trace_get_index(hash, indices[0]).await + } + + /// Returns transaction trace object at the given index. + /// + /// Returns `None` if the trace object at that index does not exist + pub async fn trace_get_index( + &self, + hash: H256, + index: usize, ) -> EthResult> { match self.trace_transaction(hash).await? { None => Ok(None), Some(traces) => { - let trace = - traces.into_iter().find(|trace| trace.trace.trace_address == trace_address); + let trace = traces.into_iter().nth(index); Ok(trace) } }