@@ -241,3 +241,145 @@ impl Filter for DatasourceFilter {
241241 }
242242 }
243243}
244+
245+ #[ derive( Debug , Clone ) ]
246+ pub struct SlotRangeFilter {
247+ from_slot : Option < u64 > ,
248+ from_transaction_index : Option < u64 > ,
249+ to_slot : Option < u64 > ,
250+ to_transaction_index : Option < u64 > ,
251+ }
252+
253+ impl SlotRangeFilter {
254+ pub fn from ( slot : u64 , transaction_index : Option < u64 > ) -> Self {
255+ Self {
256+ from_slot : Some ( slot) ,
257+ from_transaction_index : transaction_index,
258+ to_slot : None ,
259+ to_transaction_index : None ,
260+ }
261+ }
262+
263+ pub fn to ( slot : u64 , transaction_index : Option < u64 > ) -> Self {
264+ Self {
265+ from_slot : None ,
266+ from_transaction_index : None ,
267+ to_slot : Some ( slot) ,
268+ to_transaction_index : transaction_index,
269+ }
270+ }
271+
272+ pub fn between (
273+ from_slot : u64 ,
274+ from_transaction_index : Option < u64 > ,
275+ to_slot : u64 ,
276+ to_transaction_index : Option < u64 > ,
277+ ) -> Self {
278+ Self {
279+ from_slot : Some ( from_slot) ,
280+ from_transaction_index,
281+ to_slot : Some ( to_slot) ,
282+ to_transaction_index,
283+ }
284+ }
285+
286+ #[ inline( always) ]
287+ pub fn contains ( & self , slot : u64 , index : Option < u64 > ) -> bool {
288+ if let Some ( from) = self . from_slot {
289+ if slot < from {
290+ return false ;
291+ }
292+
293+ if slot == from {
294+ if let ( Some ( from_idx) , Some ( tx_idx) ) = ( self . from_transaction_index , index) {
295+ if tx_idx < from_idx {
296+ return false ;
297+ }
298+ }
299+ }
300+ }
301+
302+ if let Some ( to) = self . to_slot {
303+ if slot > to {
304+ return false ;
305+ }
306+
307+ if slot == to {
308+ if let ( Some ( to_idx) , Some ( tx_idx) ) = ( self . to_transaction_index , index) {
309+ if tx_idx >= to_idx {
310+ return false ;
311+ }
312+ }
313+ }
314+ }
315+
316+ true
317+ }
318+ }
319+
320+ impl Filter for SlotRangeFilter {
321+ fn filter_instruction (
322+ & self ,
323+ _context : & FilterContext ,
324+ instruction : & NestedInstruction ,
325+ ) -> FilterResult {
326+ let slot = instruction. metadata . transaction_metadata . slot ;
327+ let index = instruction. metadata . transaction_metadata . index ;
328+
329+ if self . contains ( slot, index) {
330+ FilterResult :: Accept
331+ } else {
332+ FilterResult :: Reject
333+ }
334+ }
335+
336+ fn filter_account (
337+ & self ,
338+ _context : & FilterContext ,
339+ metadata : & AccountMetadata ,
340+ _account : & solana_account:: Account ,
341+ ) -> FilterResult {
342+ if self . contains ( metadata. slot , None ) {
343+ FilterResult :: Accept
344+ } else {
345+ FilterResult :: Reject
346+ }
347+ }
348+
349+ fn filter_transaction (
350+ & self ,
351+ _context : & FilterContext ,
352+ metadata : & TransactionMetadata ,
353+ _instructions : & NestedInstructions ,
354+ ) -> FilterResult {
355+ if self . contains ( metadata. slot , metadata. index ) {
356+ FilterResult :: Accept
357+ } else {
358+ FilterResult :: Reject
359+ }
360+ }
361+
362+ fn filter_account_deletion (
363+ & self ,
364+ _context : & FilterContext ,
365+ deletion : & crate :: datasource:: AccountDeletion ,
366+ ) -> FilterResult {
367+ if self . contains ( deletion. slot , None ) {
368+ FilterResult :: Accept
369+ } else {
370+ FilterResult :: Reject
371+ }
372+ }
373+
374+ fn filter_block_details (
375+ & self ,
376+ _context : & FilterContext ,
377+ details : & crate :: datasource:: BlockDetails ,
378+ ) -> FilterResult {
379+ if self . contains ( details. slot , None ) {
380+ FilterResult :: Accept
381+ } else {
382+ FilterResult :: Reject
383+ }
384+ }
385+ }
0 commit comments