Skip to main content

alloy_provider/ext/
reth.rs

1//! Reth-specific provider extensions.
2#[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/// Reth API namespace for reth-specific methods
11#[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    /// Returns all ETH balance changes in a block
15    async fn reth_get_balance_changes_in_block(
16        &self,
17        block_id: BlockId,
18    ) -> TransportResult<HashMap<Address, U256>>;
19
20    /// Re-executes a block (or a range of blocks) and returns the execution outcome including
21    /// receipts, state changes, and EIP-7685 requests.
22    ///
23    /// If `count` is provided, re-executes `count` consecutive blocks starting from `block_id`
24    /// and returns the merged execution outcome.
25    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    /// Subscribe to json `ChainNotifications`
32    #[cfg(feature = "pubsub")]
33    async fn reth_subscribe_chain_notifications(
34        &self,
35    ) -> GetSubscription<alloy_rpc_client::NoParams, serde_json::Value>;
36
37    /// Subscribe to persisted block notifications.
38    ///
39    /// Emits a notification with the block number and hash when a new block is persisted to disk.
40    #[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}