Skip to main content

reth_rpc_api/
reth.rs

1use alloy_eips::BlockId;
2use alloy_primitives::{map::AddressMap, U256, U64};
3use jsonrpsee::{core::RpcResult, proc_macros::rpc};
4
5// Required for the subscription attributes below
6use reth_chain_state as _;
7
8/// Reth API namespace for reth-specific methods
9#[cfg_attr(not(feature = "client"), rpc(server, namespace = "reth"))]
10#[cfg_attr(feature = "client", rpc(server, client, namespace = "reth"))]
11pub trait RethApi {
12    /// Returns all ETH balance changes in a block
13    #[method(name = "getBalanceChangesInBlock")]
14    async fn reth_get_balance_changes_in_block(
15        &self,
16        block_id: BlockId,
17    ) -> RpcResult<AddressMap<U256>>;
18
19    /// Re-executes a block (or a range of blocks) and returns the execution outcome including
20    /// receipts, state changes, and EIP-7685 requests.
21    ///
22    /// If `count` is provided, re-executes `count` consecutive blocks starting from `block_id`
23    /// and returns the merged execution outcome.
24    #[method(name = "getBlockExecutionOutcome")]
25    async fn reth_get_block_execution_outcome(
26        &self,
27        block_id: BlockId,
28        count: Option<U64>,
29    ) -> RpcResult<Option<serde_json::Value>>;
30
31    /// Subscribe to json `ChainNotifications`
32    #[subscription(
33        name = "subscribeChainNotifications",
34        unsubscribe = "unsubscribeChainNotifications",
35        item = reth_chain_state::CanonStateNotification
36    )]
37    async fn reth_subscribe_chain_notifications(&self) -> jsonrpsee::core::SubscriptionResult;
38
39    /// Subscribe to persisted block notifications.
40    ///
41    /// Emits a notification with the block number and hash when a new block is persisted to disk.
42    #[subscription(
43        name = "subscribePersistedBlock",
44        unsubscribe = "unsubscribePersistedBlock",
45        item = alloy_eips::BlockNumHash
46    )]
47    async fn reth_subscribe_persisted_block(&self) -> jsonrpsee::core::SubscriptionResult;
48
49    /// Subscribe to finalized chain notifications.
50    ///
51    /// Buffers committed chain notifications and emits them once a new finalized block is received.
52    /// Each notification contains all committed chain segments up to the finalized block.
53    #[subscription(
54        name = "subscribeFinalizedChainNotifications",
55        unsubscribe = "unsubscribeFinalizedChainNotifications",
56        item = Vec<reth_chain_state::CanonStateNotification>
57    )]
58    async fn reth_subscribe_finalized_chain_notifications(
59        &self,
60    ) -> jsonrpsee::core::SubscriptionResult;
61}