alloy_provider/ext/
reth.rs1#[cfg(feature = "pubsub")]
3use crate::GetSubscription;
4use crate::Provider;
5use alloy_network::Network;
6use alloy_primitives::{map::HashMap, Address, U256};
7use alloy_rpc_types_eth::BlockId;
8use alloy_transport::TransportResult;
9
10#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
12#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
13pub trait RethProviderExt<N: Network>: Send + Sync {
14 async fn reth_get_balance_changes_in_block(
16 &self,
17 block_id: BlockId,
18 ) -> TransportResult<HashMap<Address, U256>>;
19
20 #[cfg(feature = "pubsub")]
22 async fn reth_subscribe_chain_notifications(
23 &self,
24 ) -> GetSubscription<alloy_rpc_client::NoParams, serde_json::Value>;
25
26 #[cfg(feature = "pubsub")]
30 async fn reth_subscribe_persisted_block(
31 &self,
32 ) -> GetSubscription<alloy_rpc_client::NoParams, serde_json::Value>;
33}
34
35#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
36#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
37impl<N, P> RethProviderExt<N> for P
38where
39 N: Network,
40 P: Provider<N>,
41{
42 async fn reth_get_balance_changes_in_block(
43 &self,
44 block_id: BlockId,
45 ) -> TransportResult<HashMap<Address, U256>> {
46 self.client().request("reth_getBalanceChangesInBlock", (block_id,)).await
47 }
48
49 #[cfg(feature = "pubsub")]
50 async fn reth_subscribe_chain_notifications(
51 &self,
52 ) -> GetSubscription<alloy_rpc_client::NoParams, serde_json::Value> {
53 self.subscribe_to("reth_subscribeChainNotifications")
54 }
55
56 #[cfg(feature = "pubsub")]
57 async fn reth_subscribe_persisted_block(
58 &self,
59 ) -> GetSubscription<alloy_rpc_client::NoParams, serde_json::Value> {
60 self.subscribe_to("reth_subscribePersistedBlock")
61 }
62}