openzeppelin_monitor/services/filter/filters/
mod.rs1pub mod evm {
12 pub mod evaluator;
13 pub mod filter;
14 pub mod helpers;
15}
16pub mod stellar {
17 pub mod evaluator;
18 pub mod filter;
19 pub mod helpers;
20}
21
22pub mod midnight {
23 pub mod filter;
24 pub mod helpers;
25}
26
27pub mod solana {
28 pub mod evaluator;
29 pub mod filter;
30 pub mod helpers;
31}
32
33use async_trait::async_trait;
34
35use crate::{
36 models::{BlockType, ContractSpec, Monitor, MonitorMatch, Network},
37 services::{blockchain::BlockFilterFactory, filter::error::FilterError},
38};
39
40#[async_trait]
45pub trait BlockFilter {
46 type Client;
47 async fn filter_block(
48 &self,
49 client: &Self::Client,
50 network: &Network,
51 block: &BlockType,
52 monitors: &[Monitor],
53 contract_specs: Option<&[(String, ContractSpec)]>,
54 ) -> Result<Vec<MonitorMatch>, FilterError>;
55}
56
57#[async_trait]
58pub trait FilterServiceTrait: Send + Sync {
59 async fn filter_block<T: BlockFilterFactory<T> + Send + Sync + 'static>(
60 &self,
61 client: &T,
62 network: &Network,
63 block: &BlockType,
64 monitors: &[Monitor],
65 contract_specs: Option<&[(String, ContractSpec)]>,
66 ) -> Result<Vec<MonitorMatch>, FilterError>;
67}
68
69pub struct FilterService {}
73
74impl FilterService {
75 pub fn new() -> Self {
76 FilterService {}
77 }
78}
79
80impl Default for FilterService {
81 fn default() -> Self {
82 Self::new()
83 }
84}
85
86impl FilterService {
87 pub async fn filter_block<T: BlockFilterFactory<T>>(
88 &self,
89 client: &T,
90 network: &Network,
91 block: &BlockType,
92 monitors: &[Monitor],
93 contract_specs: Option<&[(String, ContractSpec)]>,
94 ) -> Result<Vec<MonitorMatch>, FilterError> {
95 let filter = T::filter();
96 filter
97 .filter_block(client, network, block, monitors, contract_specs)
98 .await
99 }
100}
101
102#[async_trait]
103impl FilterServiceTrait for FilterService {
104 async fn filter_block<T: BlockFilterFactory<T> + Send + Sync + 'static>(
105 &self,
106 client: &T,
107 network: &Network,
108 block: &BlockType,
109 monitors: &[Monitor],
110 contract_specs: Option<&[(String, ContractSpec)]>,
111 ) -> Result<Vec<MonitorMatch>, FilterError> {
112 let filter = T::filter();
113 filter
114 .filter_block(client, network, block, monitors, contract_specs)
115 .await
116 }
117}