Skip to main content

reth_rpc_eth_api/
filter.rs

1//! `eth_` RPC API for filtering.
2
3use alloy_json_rpc::RpcObject;
4use alloy_rpc_types_eth::{Filter, FilterChanges, FilterId, PendingTransactionFilterKind};
5use jsonrpsee::{core::RpcResult, proc_macros::rpc};
6use std::future::Future;
7
8/// Rpc Interface for poll-based ethereum filter API.
9#[rpc(server, namespace = "eth")]
10pub trait EthFilterApi<T: RpcObject, L: RpcObject> {
11    /// Creates a new filter and returns its id.
12    #[method(name = "newFilter")]
13    async fn new_filter(&self, filter: Filter) -> RpcResult<FilterId>;
14
15    /// Creates a new block filter and returns its id.
16    #[method(name = "newBlockFilter")]
17    async fn new_block_filter(&self) -> RpcResult<FilterId>;
18
19    /// Creates a pending transaction filter and returns its id.
20    #[method(name = "newPendingTransactionFilter")]
21    async fn new_pending_transaction_filter(
22        &self,
23        kind: Option<PendingTransactionFilterKind>,
24    ) -> RpcResult<FilterId>;
25
26    /// Returns all filter changes since last poll.
27    #[method(name = "getFilterChanges")]
28    async fn filter_changes(&self, id: FilterId) -> RpcResult<FilterChanges<T, L>>;
29
30    /// Returns all logs matching given filter (in a range 'from' - 'to').
31    #[method(name = "getFilterLogs")]
32    async fn filter_logs(&self, id: FilterId) -> RpcResult<Vec<L>>;
33
34    /// Uninstalls filter.
35    #[method(name = "uninstallFilter")]
36    async fn uninstall_filter(&self, id: FilterId) -> RpcResult<bool>;
37
38    /// Returns logs matching given filter object.
39    #[method(name = "getLogs")]
40    async fn logs(&self, filter: Filter) -> RpcResult<Vec<L>>;
41}
42
43/// Limits for logs queries
44#[derive(Default, Debug, Clone, Copy)]
45pub struct QueryLimits {
46    /// Maximum number of blocks that could be scanned per filter
47    pub max_blocks_per_filter: Option<u64>,
48    /// Maximum number of logs that can be returned in a response
49    pub max_logs_per_response: Option<usize>,
50}
51
52impl QueryLimits {
53    /// Construct an object with no limits (more explicit than using default constructor)
54    pub fn no_limits() -> Self {
55        Default::default()
56    }
57}
58
59/// Rpc Interface for poll-based ethereum filter API, implementing only the `eth_getLogs` method.
60/// Used for the engine API, with possibility to specify [`QueryLimits`].
61pub trait EngineEthFilter<L: RpcObject>: Send + Sync + 'static {
62    /// Returns logs matching given filter object.
63    fn logs(
64        &self,
65        filter: Filter,
66        limits: QueryLimits,
67    ) -> impl Future<Output = RpcResult<Vec<L>>> + Send;
68}