From a186031eefb6a9c3d3aba6c30dd8f40c832f4a7c Mon Sep 17 00:00:00 2001 From: Mikhail Sozin Date: Fri, 28 Jun 2024 21:04:01 +0200 Subject: [PATCH 1/4] trace_get implementation --- crates/provider/src/ext/trace.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 90b7598457a..4984d2038bd 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -50,6 +50,13 @@ where hash: TxHash, ) -> TransportResult>; + /// Traces of the transaction on the given positions + async fn trace_get( + &self, + hash: TxHash, + index: u64, + ) -> TransportResult; + /// Trace the given raw transaction. async fn trace_raw_transaction( &self, @@ -119,6 +126,15 @@ where self.client().request("trace_transaction", (hash,)).await } + async fn trace_get( + &self, + hash: TxHash, + index: u64, + ) -> TransportResult { + // We are using vec![indices] because API accepts a list, but in fact works only if list.len == 1 + self.client().request("trace_get", (hash, vec![index])).await + } + async fn trace_raw_transaction( &self, data: &[u8], From 04597eba30615ae029f9d864a9c81c7a661d3307 Mon Sep 17 00:00:00 2001 From: Mikhail Sozin Date: Sat, 29 Jun 2024 09:06:35 +0200 Subject: [PATCH 2/4] Review --- crates/provider/src/ext/trace.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 4984d2038bd..785c110a1c7 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -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}, @@ -51,10 +52,15 @@ where ) -> TransportResult>; /// 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: u64, + index: usize, ) -> TransportResult; /// Trace the given raw transaction. @@ -129,10 +135,10 @@ where async fn trace_get( &self, hash: TxHash, - index: u64, + index: usize, ) -> TransportResult { // We are using vec![indices] because API accepts a list, but in fact works only if list.len == 1 - self.client().request("trace_get", (hash, vec![index])).await + self.client().request("trace_get", (hash, (Index::from(index),))).await } async fn trace_raw_transaction( From 56b739bc4c88bf9ace42ac1cb244d39cc4a458c3 Mon Sep 17 00:00:00 2001 From: Misha Date: Sat, 29 Jun 2024 14:20:54 +0700 Subject: [PATCH 3/4] Update crates/provider/src/ext/trace.rs docs Co-authored-by: Matthias Seitz --- crates/provider/src/ext/trace.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 785c110a1c7..3eed9f7ec9c 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -137,7 +137,7 @@ where hash: TxHash, index: usize, ) -> TransportResult { - // We are using vec![indices] because API accepts a list, but in fact works only if list.len == 1 + // 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 } From 0cb986cc3a4f66fdc48bc0bb4b23409a88a66889 Mon Sep 17 00:00:00 2001 From: Mikhail Sozin Date: Sat, 29 Jun 2024 09:33:01 +0200 Subject: [PATCH 4/4] Cargo fmt --- crates/provider/src/ext/trace.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/provider/src/ext/trace.rs b/crates/provider/src/ext/trace.rs index 3eed9f7ec9c..334ef2a883a 100644 --- a/crates/provider/src/ext/trace.rs +++ b/crates/provider/src/ext/trace.rs @@ -52,10 +52,10 @@ where ) -> TransportResult>; /// Traces of the transaction on the given positions - /// + /// /// # Note - /// - /// This function accepts single index and build list with it under the hood because + /// + /// 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,