Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
add subscribe_full_pending_txs() (#2424)
Browse files Browse the repository at this point in the history
* add subscribe_full_pending_txs()

* Update middleware.rs
  • Loading branch information
0xlosh authored May 23, 2023
1 parent 00d10f4 commit 573847c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ethers-middleware/src/timelag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ where
Err(TimeLagError::Unsupported)
}

async fn subscribe_full_pending_txs(
&self,
) -> Result<ethers_providers::SubscriptionStream<'_, Self::Provider, Transaction>, Self::Error>
where
Self::Provider: ethers_providers::PubsubClient,
{
Err(TimeLagError::Unsupported)
}

async fn subscribe_logs<'a>(
&'a self,
_filter: &ethers_core::types::Filter,
Expand Down
19 changes: 18 additions & 1 deletion ethers-providers/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ pub trait Middleware: Sync + Send + Debug {
self.inner().subscribe_blocks().await.map_err(MiddlewareError::from_err)
}

/// Subscribe to a stream of pending transactions.
/// Subscribe to a stream of pending transaction hashes.
///
/// This function is only available on pubsub clients, such as Websockets
/// or IPC. For a polling alternative available over HTTP, use
Expand All @@ -920,6 +920,23 @@ pub trait Middleware: Sync + Send + Debug {
self.inner().subscribe_pending_txs().await.map_err(MiddlewareError::from_err)
}

/// Subscribe to a stream of pending transaction bodies.
///
/// This function is only available on pubsub clients, such as Websockets
/// or IPC. For a polling alternative available over HTTP, use
/// [`Middleware::watch_pending_transactions`]. However, be aware that
/// polling increases RPC usage drastically.
///
/// Note: This endpoint is compatible only with Geth client version 1.11.0 or later.
async fn subscribe_full_pending_txs(
&self,
) -> Result<SubscriptionStream<'_, Self::Provider, Transaction>, Self::Error>
where
<Self as Middleware>::Provider: PubsubClient,
{
self.inner().subscribe_full_pending_txs().await.map_err(MiddlewareError::from_err)
}

/// Subscribe to a stream of event logs matchin the provided [`Filter`].
///
/// This function is only available on pubsub clients, such as Websockets
Expand Down
9 changes: 9 additions & 0 deletions ethers-providers/src/rpc/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,15 @@ impl<P: JsonRpcClient> Middleware for Provider<P> {
self.subscribe(["newPendingTransactions"]).await
}

async fn subscribe_full_pending_txs(
&self,
) -> Result<SubscriptionStream<'_, P, Transaction>, ProviderError>
where
P: PubsubClient,
{
self.subscribe([utils::serialize(&"newPendingTransactions"), utils::serialize(&true)]).await
}

async fn subscribe_logs<'a>(
&'a self,
filter: &Filter,
Expand Down

0 comments on commit 573847c

Please sign in to comment.