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, U64};
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 async fn reth_get_block_execution_outcome(
26 &self,
27 block_id: BlockId,
28 count: Option<U64>,
29 ) -> TransportResult<Option<serde_json::Value>>;
30
31 #[cfg(feature = "pubsub")]
33 async fn reth_subscribe_chain_notifications(
34 &self,
35 ) -> GetSubscription<alloy_rpc_client::NoParams, serde_json::Value>;
36
37 #[cfg(feature = "pubsub")]
41 async fn reth_subscribe_persisted_block(
42 &self,
43 ) -> GetSubscription<alloy_rpc_client::NoParams, serde_json::Value>;
44}
45
46#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
47#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
48impl<N, P> RethProviderExt<N> for P
49where
50 N: Network,
51 P: Provider<N>,
52{
53 async fn reth_get_balance_changes_in_block(
54 &self,
55 block_id: BlockId,
56 ) -> TransportResult<HashMap<Address, U256>> {
57 self.client().request("reth_getBalanceChangesInBlock", (block_id,)).await
58 }
59
60 async fn reth_get_block_execution_outcome(
61 &self,
62 block_id: BlockId,
63 count: Option<U64>,
64 ) -> TransportResult<Option<serde_json::Value>> {
65 self.client().request("reth_getBlockExecutionOutcome", (block_id, count)).await
66 }
67
68 #[cfg(feature = "pubsub")]
69 async fn reth_subscribe_chain_notifications(
70 &self,
71 ) -> GetSubscription<alloy_rpc_client::NoParams, serde_json::Value> {
72 self.subscribe_to("reth_subscribeChainNotifications")
73 }
74
75 #[cfg(feature = "pubsub")]
76 async fn reth_subscribe_persisted_block(
77 &self,
78 ) -> GetSubscription<alloy_rpc_client::NoParams, serde_json::Value> {
79 self.subscribe_to("reth_subscribePersistedBlock")
80 }
81}