File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 11// Copyright 2023-, Semiotic AI, Inc.
22// SPDX-License-Identifier: Apache-2.0
33
4+ use std:: ops:: Range ;
5+
46use crate :: tap_receipt:: ReceivedReceipt ;
57
68pub trait ReceiptStorageAdapter {
@@ -20,11 +22,19 @@ pub trait ReceiptStorageAdapter {
2022 & self ,
2123 timestamp_ns : u64 ,
2224 ) -> Result < Vec < ( u64 , ReceivedReceipt ) > , Self :: AdapterError > ;
25+ fn retrieve_receipts_in_timestamp_range (
26+ & self ,
27+ timestamp_range_ns : Range < u64 > ,
28+ ) -> Result < Vec < ( u64 , ReceivedReceipt ) > , Self :: AdapterError > ;
2329 fn update_receipt_by_id (
2430 & mut self ,
2531 receipt_id : u64 ,
2632 receipt : ReceivedReceipt ,
2733 ) -> Result < ( ) , Self :: AdapterError > ;
2834 fn remove_receipt_by_id ( & mut self , receipt_id : u64 ) -> Result < ( ) , Self :: AdapterError > ;
2935 fn remove_receipts_by_ids ( & mut self , receipt_ids : & [ u64 ] ) -> Result < ( ) , Self :: AdapterError > ;
36+ fn remove_receipts_in_timestamp_range (
37+ & mut self ,
38+ timestamp_ns : Range < u64 > ,
39+ ) -> Result < ( ) , Self :: AdapterError > ;
3040}
Original file line number Diff line number Diff line change 33
44use std:: {
55 collections:: HashMap ,
6+ ops:: Range ,
67 sync:: { Arc , RwLock } ,
78} ;
89
@@ -79,6 +80,19 @@ impl ReceiptStorageAdapter for ReceiptStorageAdapterMock {
7980 . map ( |( & id, rx_receipt) | ( id, rx_receipt. clone ( ) ) )
8081 . collect ( ) )
8182 }
83+ fn retrieve_receipts_in_timestamp_range (
84+ & self ,
85+ timestamp_range_ns : Range < u64 > ,
86+ ) -> Result < Vec < ( u64 , ReceivedReceipt ) > , Self :: AdapterError > {
87+ let receipt_storage = self . receipt_storage . read ( ) . unwrap ( ) ;
88+ Ok ( receipt_storage
89+ . iter ( )
90+ . filter ( |( _, rx_receipt) | {
91+ timestamp_range_ns. contains ( & rx_receipt. signed_receipt . message . timestamp_ns )
92+ } )
93+ . map ( |( & id, rx_receipt) | ( id, rx_receipt. clone ( ) ) )
94+ . collect ( ) )
95+ }
8296 fn update_receipt_by_id (
8397 & mut self ,
8498 receipt_id : u64 ,
@@ -111,4 +125,14 @@ impl ReceiptStorageAdapter for ReceiptStorageAdapterMock {
111125 }
112126 Ok ( ( ) )
113127 }
128+ fn remove_receipts_in_timestamp_range (
129+ & mut self ,
130+ timestamp_ns : Range < u64 > ,
131+ ) -> Result < ( ) , Self :: AdapterError > {
132+ let mut receipt_storage = self . receipt_storage . write ( ) . unwrap ( ) ;
133+ receipt_storage. retain ( |_, rx_receipt| {
134+ !timestamp_ns. contains ( & rx_receipt. signed_receipt . message . timestamp_ns )
135+ } ) ;
136+ Ok ( ( ) )
137+ }
114138}
You can’t perform that action at this time.
0 commit comments