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