1use arch_sdk::AccountInfo;
2
3use crate::{
4 account::AccountMetadata,
5 datasource::{
6 AccountDeletion, BitcoinBlock, BlockDetails, DatasourceId, ReappliedTransactionsEvent,
7 RolledbackTransactionsEvent,
8 },
9 instruction::{NestedInstruction, NestedInstructions},
10 transaction::TransactionMetadata,
11};
12
13pub trait Filter {
14 fn filter_account(
15 &self,
16 _datasource_id: &DatasourceId,
17 _account_metadata: &AccountMetadata,
18 _account: &AccountInfo,
19 ) -> bool {
20 true
21 }
22
23 fn filter_instruction(
24 &self,
25 _datasource_id: &DatasourceId,
26 _nested_instruction: &NestedInstruction,
27 ) -> bool {
28 true
29 }
30
31 fn filter_transaction(
32 &self,
33 _datasource_id: &DatasourceId,
34 _transaction_metadata: &TransactionMetadata,
35 _nested_instructions: &NestedInstructions,
36 ) -> bool {
37 true
38 }
39
40 fn filter_account_deletion(
41 &self,
42 _datasource_id: &DatasourceId,
43 _account_deletion: &AccountDeletion,
44 ) -> bool {
45 true
46 }
47
48 fn filter_block_details(
49 &self,
50 _datasource_id: &DatasourceId,
51 _block_details: &BlockDetails,
52 ) -> bool {
53 true
54 }
55
56 fn filter_bitcoin_block(&self, _datasource_id: &DatasourceId, _block: &BitcoinBlock) -> bool {
57 true
58 }
59
60 fn filter_rolledback_transactions(
61 &self,
62 _datasource_id: &DatasourceId,
63 _event: &RolledbackTransactionsEvent,
64 ) -> bool {
65 true
66 }
67
68 fn filter_reapplied_transactions(
69 &self,
70 _datasource_id: &DatasourceId,
71 _event: &ReappliedTransactionsEvent,
72 ) -> bool {
73 true
74 }
75}
76
77pub struct DatasourceFilter {
78 pub allowed_datasources: Vec<DatasourceId>,
79}
80
81impl DatasourceFilter {
82 pub fn new(datasource_id: DatasourceId) -> Self {
83 Self {
84 allowed_datasources: vec![datasource_id],
85 }
86 }
87
88 pub fn new_many(datasource_ids: Vec<DatasourceId>) -> Self {
89 Self {
90 allowed_datasources: datasource_ids,
91 }
92 }
93}
94
95impl Filter for DatasourceFilter {
96 fn filter_account(
97 &self,
98 datasource_id: &DatasourceId,
99 _account_metadata: &AccountMetadata,
100 _account: &AccountInfo,
101 ) -> bool {
102 self.allowed_datasources.contains(datasource_id)
103 }
104
105 fn filter_instruction(
106 &self,
107 datasource_id: &DatasourceId,
108 _nested_instruction: &NestedInstruction,
109 ) -> bool {
110 self.allowed_datasources.contains(datasource_id)
111 }
112
113 fn filter_transaction(
114 &self,
115 datasource_id: &DatasourceId,
116 _transaction_metadata: &TransactionMetadata,
117 _nested_instructions: &NestedInstructions,
118 ) -> bool {
119 self.allowed_datasources.contains(datasource_id)
120 }
121
122 fn filter_account_deletion(
123 &self,
124 datasource_id: &DatasourceId,
125 _account_deletion: &AccountDeletion,
126 ) -> bool {
127 self.allowed_datasources.contains(datasource_id)
128 }
129
130 fn filter_block_details(
131 &self,
132 datasource_id: &DatasourceId,
133 _block_details: &BlockDetails,
134 ) -> bool {
135 self.allowed_datasources.contains(datasource_id)
136 }
137
138 fn filter_bitcoin_block(&self, datasource_id: &DatasourceId, _block: &BitcoinBlock) -> bool {
139 self.allowed_datasources.contains(datasource_id)
140 }
141
142 fn filter_rolledback_transactions(
143 &self,
144 datasource_id: &DatasourceId,
145 _event: &RolledbackTransactionsEvent,
146 ) -> bool {
147 self.allowed_datasources.contains(datasource_id)
148 }
149
150 fn filter_reapplied_transactions(
151 &self,
152 datasource_id: &DatasourceId,
153 _event: &ReappliedTransactionsEvent,
154 ) -> bool {
155 self.allowed_datasources.contains(datasource_id)
156 }
157}