From e2cc14f78c43f251ba7008292076cc6948dcdea6 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 26 Aug 2024 17:32:15 +0800 Subject: [PATCH] feat: add block and transaction generics to otterscan and txpool types (#1183) * feat: add transaction generic to ots types * txpool generics --- crates/provider/src/ext/txpool.rs | 16 ++++++++----- crates/rpc-types-trace/src/otterscan.rs | 30 ++++++++++++++----------- crates/rpc-types-txpool/src/txpool.rs | 16 ++++++------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/crates/provider/src/ext/txpool.rs b/crates/provider/src/ext/txpool.rs index 9086926356c..83b1d64f73e 100644 --- a/crates/provider/src/ext/txpool.rs +++ b/crates/provider/src/ext/txpool.rs @@ -9,19 +9,22 @@ use alloy_transport::{Transport, TransportResult}; #[allow(unused, unreachable_pub)] #[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)] -pub trait TxPoolApi: Send + Sync { +pub trait TxPoolApi: Send + Sync { /// Returns the content of the transaction pool. /// /// Lists the exact details of all the transactions currently pending for inclusion in the next /// block(s), as well as the ones that are being scheduled for future execution only. /// /// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_content) for more details - async fn txpool_content(&self) -> TransportResult; + async fn txpool_content(&self) -> TransportResult>; /// Returns the content of the transaction pool filtered by a specific address. /// /// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_contentFrom) for more details - async fn txpool_content_from(&self, from: Address) -> TransportResult; + async fn txpool_content_from( + &self, + from: Address, + ) -> TransportResult>; /// Returns a textual summary of each transaction in the pool. /// @@ -50,11 +53,14 @@ where T: Transport + Clone, N: Network, { - async fn txpool_content(&self) -> TransportResult { + async fn txpool_content(&self) -> TransportResult> { self.client().request("txpool_content", ()).await } - async fn txpool_content_from(&self, from: Address) -> TransportResult { + async fn txpool_content_from( + &self, + from: Address, + ) -> TransportResult> { self.client().request("txpool_contentFrom", (from,)).await } diff --git a/crates/rpc-types-trace/src/otterscan.rs b/crates/rpc-types-trace/src/otterscan.rs index a56ed47366e..7d428a64913 100644 --- a/crates/rpc-types-trace/src/otterscan.rs +++ b/crates/rpc-types-trace/src/otterscan.rs @@ -102,17 +102,17 @@ pub struct InternalIssuance { /// Custom `Block` struct that includes transaction count for Otterscan responses #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct OtsBlock { +pub struct OtsBlock { /// The block information. #[serde(flatten)] - pub block: Block, + pub block: Block, /// The number of transactions in the block. #[doc(alias = "tx_count")] pub transaction_count: usize, } -impl From for OtsBlock { - fn from(block: Block) -> Self { +impl From> for OtsBlock { + fn from(block: Block) -> Self { Self { transaction_count: block.transactions.len(), block } } } @@ -138,8 +138,8 @@ pub struct OtsSlimBlock { pub transaction_count: usize, } -impl From for OtsSlimBlock { - fn from(block: Block) -> Self { +impl From> for OtsSlimBlock { + fn from(block: Block) -> Self { Self { header: block.header, uncles: block.uncles, @@ -162,8 +162,8 @@ pub struct BlockDetails { pub total_fees: U256, } -impl From> for BlockDetails { - fn from(rich_block: Rich) -> Self { +impl From>> for BlockDetails { + fn from(rich_block: Rich>) -> Self { Self { block: rich_block.inner.into(), issuance: Default::default(), @@ -174,7 +174,11 @@ impl From> for BlockDetails { impl BlockDetails { /// Create a new `BlockDetails` struct. - pub fn new(rich_block: Rich, issuance: InternalIssuance, total_fees: U256) -> Self { + pub fn new( + rich_block: Rich>, + issuance: InternalIssuance, + total_fees: U256, + ) -> Self { Self { block: rich_block.inner.into(), issuance, total_fees } } } @@ -220,9 +224,9 @@ pub struct OtsReceipt { /// Custom struct for otterscan `getBlockTransactions` RPC response #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct OtsBlockTransactions { +pub struct OtsBlockTransactions { /// The full block information with transaction count. - pub fullblock: OtsBlock, + pub fullblock: OtsBlock, /// The list of transaction receipts. pub receipts: Vec, } @@ -232,10 +236,10 @@ pub struct OtsBlockTransactions { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[doc(alias = "TxWithReceipts")] -pub struct TransactionsWithReceipts { +pub struct TransactionsWithReceipts { /// The list of transactions. #[doc(alias = "transactions")] - pub txs: Vec, + pub txs: Vec, /// The list of transaction receipts. pub receipts: Vec, /// Indicates if this is the first page of results. diff --git a/crates/rpc-types-txpool/src/txpool.rs b/crates/rpc-types-txpool/src/txpool.rs index ea244e455b3..f698708427e 100644 --- a/crates/rpc-types-txpool/src/txpool.rs +++ b/crates/rpc-types-txpool/src/txpool.rs @@ -111,16 +111,16 @@ impl Serialize for TxpoolInspectSummary { /// /// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_content) for more details #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] -pub struct TxpoolContent { +pub struct TxpoolContent { /// pending tx - pub pending: BTreeMap>, + pub pending: BTreeMap>, /// queued tx - pub queued: BTreeMap>, + pub queued: BTreeMap>, } -impl TxpoolContent { +impl TxpoolContent { /// Removes the transactions from the given sender - pub fn remove_from(&mut self, sender: &Address) -> TxpoolContentFrom { + pub fn remove_from(&mut self, sender: &Address) -> TxpoolContentFrom { TxpoolContentFrom { pending: self.pending.remove(sender).unwrap_or_default(), queued: self.queued.remove(sender).unwrap_or_default(), @@ -134,11 +134,11 @@ impl TxpoolContent { /// /// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_contentFrom) for more details #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] -pub struct TxpoolContentFrom { +pub struct TxpoolContentFrom { /// pending tx - pub pending: BTreeMap, + pub pending: BTreeMap, /// queued tx - pub queued: BTreeMap, + pub queued: BTreeMap, } /// Transaction Pool Inspect