Skip to main content

reth_rpc_api/
reth.rs

1use alloy_eips::BlockId;
2use alloy_primitives::{map::AddressMap, U256};
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    /// Subscribe to json `ChainNotifications`
20    #[subscription(
21        name = "subscribeChainNotifications",
22        unsubscribe = "unsubscribeChainNotifications",
23        item = reth_chain_state::CanonStateNotification
24    )]
25    async fn reth_subscribe_chain_notifications(&self) -> jsonrpsee::core::SubscriptionResult;
26
27    /// Subscribe to persisted block notifications.
28    ///
29    /// Emits a notification with the block number and hash when a new block is persisted to disk.
30    #[subscription(
31        name = "subscribePersistedBlock",
32        unsubscribe = "unsubscribePersistedBlock",
33        item = alloy_eips::BlockNumHash
34    )]
35    async fn reth_subscribe_persisted_block(&self) -> jsonrpsee::core::SubscriptionResult;
36
37    /// Subscribe to finalized chain notifications.
38    ///
39    /// Buffers committed chain notifications and emits them once a new finalized block is received.
40    /// Each notification contains all committed chain segments up to the finalized block.
41    #[subscription(
42        name = "subscribeFinalizedChainNotifications",
43        unsubscribe = "unsubscribeFinalizedChainNotifications",
44        item = Vec<reth_chain_state::CanonStateNotification>
45    )]
46    async fn reth_subscribe_finalized_chain_notifications(
47        &self,
48    ) -> jsonrpsee::core::SubscriptionResult;
49}