openzeppelin_monitor/services/filter/filters/
mod.rs

1//! Block filtering implementations.
2//!
3//! Provides trait definition and implementations for filtering blocks
4//! across different blockchain types. Includes:
5//! - Generic BlockFilter trait
6//! - EVM-specific implementation
7//! - Stellar-specific implementation
8
9pub mod evm {
10	pub mod evaluator;
11	pub mod filter;
12	pub mod helpers;
13}
14pub mod stellar {
15	pub mod evaluator;
16	pub mod filter;
17	pub mod helpers;
18}
19
20use async_trait::async_trait;
21
22use crate::{
23	models::{BlockType, ContractSpec, Monitor, MonitorMatch, Network},
24	services::{blockchain::BlockFilterFactory, filter::error::FilterError},
25};
26pub use evm::evaluator::{EVMArgs, EVMConditionEvaluator};
27pub use evm::filter::EVMBlockFilter;
28pub use stellar::evaluator::{StellarArgs, StellarConditionEvaluator};
29pub use stellar::filter::{EventMap, StellarBlockFilter};
30
31/// Trait for filtering blockchain data
32///
33/// This trait must be implemented by all blockchain-specific clients to provide
34/// a way to filter blockchain data.
35#[async_trait]
36pub trait BlockFilter {
37	type Client;
38	async fn filter_block(
39		&self,
40		client: &Self::Client,
41		network: &Network,
42		block: &BlockType,
43		monitors: &[Monitor],
44		contract_specs: Option<&[(String, ContractSpec)]>,
45	) -> Result<Vec<MonitorMatch>, FilterError>;
46}
47
48/// Service for filtering blockchain data
49///
50/// This service provides a way to filter blockchain data based on a set of monitors.
51pub struct FilterService {}
52
53impl FilterService {
54	pub fn new() -> Self {
55		FilterService {}
56	}
57}
58
59impl Default for FilterService {
60	fn default() -> Self {
61		Self::new()
62	}
63}
64
65impl FilterService {
66	pub async fn filter_block<T: BlockFilterFactory<T>>(
67		&self,
68		client: &T,
69		network: &Network,
70		block: &BlockType,
71		monitors: &[Monitor],
72		contract_specs: Option<&[(String, ContractSpec)]>,
73	) -> Result<Vec<MonitorMatch>, FilterError> {
74		let filter = T::filter();
75		filter
76			.filter_block(client, network, block, monitors, contract_specs)
77			.await
78	}
79}