1- use std:: ops:: RangeInclusive ;
1+ use std:: ops:: Range ;
22use std:: sync:: Arc ;
33
44use anyhow:: Context ;
@@ -46,7 +46,7 @@ impl CardanoTransactionRepository {
4646 /// Return all the [CardanoTransactionRecord]s in the database using chronological order.
4747 pub async fn get_transactions_between_blocks (
4848 & self ,
49- range : RangeInclusive < BlockNumber > ,
49+ range : Range < BlockNumber > ,
5050 ) -> StdResult < Vec < CardanoTransactionRecord > > {
5151 let provider = GetCardanoTransactionProvider :: new ( & self . connection ) ;
5252 let filters = provider. get_transaction_between_blocks_condition ( range) ;
@@ -180,9 +180,27 @@ impl TransactionStore for CardanoTransactionRepository {
180180 }
181181 }
182182
183+ async fn get_up_to ( & self , beacon : ImmutableFileNumber ) -> StdResult < Vec < CardanoTransaction > > {
184+ self . get_transactions_up_to ( beacon) . await . map ( |v| {
185+ v. into_iter ( )
186+ . map ( |record| record. into ( ) )
187+ . collect :: < Vec < CardanoTransaction > > ( )
188+ } )
189+ }
190+
191+ async fn store_transactions ( & self , transactions : Vec < CardanoTransaction > ) -> StdResult < ( ) > {
192+ // Chunk transactions to avoid an error when we exceed sqlite binding limitations
193+ for transactions_in_chunk in transactions. chunks ( 100 ) {
194+ self . create_transactions ( transactions_in_chunk. to_vec ( ) )
195+ . await
196+ . with_context ( || "CardanoTransactionRepository can not store transactions" ) ?;
197+ }
198+ Ok ( ( ) )
199+ }
200+
183201 async fn get_block_interval_without_block_range_root (
184202 & self ,
185- ) -> StdResult < Option < RangeInclusive < BlockNumber > > > {
203+ ) -> StdResult < Option < Range < BlockNumber > > > {
186204 let provider = GetIntervalWithoutBlockRangeRootProvider :: new ( & self . connection ) ;
187205 let row = provider
188206 . find ( provider. get_interval_without_block_range_condition ( ) ) ?
@@ -193,7 +211,7 @@ impl TransactionStore for CardanoTransactionRepository {
193211 None => panic ! ( "IntervalWithoutBlockRangeProvider should always return a single row" ) ,
194212 Some ( interval) => match ( interval. start , interval. end ) {
195213 ( _, None ) => Ok ( None ) ,
196- ( None , Some ( end) ) => Ok ( Some ( 0 ..= end) ) ,
214+ ( None , Some ( end) ) => Ok ( Some ( 0 ..( end + 1 ) ) ) ,
197215 ( Some ( start) , Some ( end) ) if end < start => {
198216 // To discuss : should we prune all block ranges from the DB to force recompute ?
199217 warn ! (
@@ -204,14 +222,14 @@ impl TransactionStore for CardanoTransactionRepository {
204222 ) ;
205223 Ok ( None )
206224 }
207- ( Some ( start) , Some ( end) ) => Ok ( Some ( start..= end) ) ,
225+ ( Some ( start) , Some ( end) ) => Ok ( Some ( start..( end + 1 ) ) ) ,
208226 } ,
209227 }
210228 }
211229
212230 async fn get_transactions_between (
213231 & self ,
214- range : RangeInclusive < BlockNumber > ,
232+ range : Range < BlockNumber > ,
215233 ) -> StdResult < Vec < CardanoTransaction > > {
216234 self . get_transactions_between_blocks ( range) . await . map ( |v| {
217235 v. into_iter ( )
@@ -220,24 +238,6 @@ impl TransactionStore for CardanoTransactionRepository {
220238 } )
221239 }
222240
223- async fn get_up_to ( & self , beacon : ImmutableFileNumber ) -> StdResult < Vec < CardanoTransaction > > {
224- self . get_transactions_up_to ( beacon) . await . map ( |v| {
225- v. into_iter ( )
226- . map ( |record| record. into ( ) )
227- . collect :: < Vec < CardanoTransaction > > ( )
228- } )
229- }
230-
231- async fn store_transactions ( & self , transactions : Vec < CardanoTransaction > ) -> StdResult < ( ) > {
232- // Chunk transactions to avoid an error when we exceed sqlite binding limitations
233- for transactions_in_chunk in transactions. chunks ( 100 ) {
234- self . create_transactions ( transactions_in_chunk. to_vec ( ) )
235- . await
236- . with_context ( || "CardanoTransactionRepository can not store transactions" ) ?;
237- }
238- Ok ( ( ) )
239- }
240-
241241 async fn store_block_ranges (
242242 & self ,
243243 block_ranges : Vec < ( BlockRange , MKTreeNode ) > ,
@@ -481,23 +481,23 @@ mod tests {
481481 . unwrap ( ) ;
482482
483483 {
484- let transaction_result = repository. get_transactions_between ( 0 ..= 9 ) . await . unwrap ( ) ;
484+ let transaction_result = repository. get_transactions_between ( 0 ..10 ) . await . unwrap ( ) ;
485485 assert_eq ! ( Vec :: <CardanoTransaction >:: new( ) , transaction_result) ;
486486 }
487487 {
488- let transaction_result = repository. get_transactions_between ( 13 ..= 20 ) . await . unwrap ( ) ;
488+ let transaction_result = repository. get_transactions_between ( 13 ..21 ) . await . unwrap ( ) ;
489489 assert_eq ! ( Vec :: <CardanoTransaction >:: new( ) , transaction_result) ;
490490 }
491491 {
492- let transaction_result = repository. get_transactions_between ( 9 ..= 11 ) . await . unwrap ( ) ;
492+ let transaction_result = repository. get_transactions_between ( 9 ..12 ) . await . unwrap ( ) ;
493493 assert_eq ! ( transactions[ 0 ..=1 ] . to_vec( ) , transaction_result) ;
494494 }
495495 {
496- let transaction_result = repository. get_transactions_between ( 10 ..= 12 ) . await . unwrap ( ) ;
496+ let transaction_result = repository. get_transactions_between ( 10 ..13 ) . await . unwrap ( ) ;
497497 assert_eq ! ( transactions. clone( ) , transaction_result) ;
498498 }
499499 {
500- let transaction_result = repository. get_transactions_between ( 11 ..= 13 ) . await . unwrap ( ) ;
500+ let transaction_result = repository. get_transactions_between ( 11 ..14 ) . await . unwrap ( ) ;
501501 assert_eq ! ( transactions[ 1 ..=2 ] . to_vec( ) , transaction_result) ;
502502 }
503503 }
@@ -529,7 +529,7 @@ mod tests {
529529 . await
530530 . unwrap ( ) ;
531531
532- assert_eq ! ( Some ( 0 ..= last_transaction_block_number) , interval) ;
532+ assert_eq ! ( Some ( 0 ..( last_transaction_block_number + 1 ) ) , interval) ;
533533 }
534534 {
535535 // The last block range give the lower bound
@@ -548,7 +548,7 @@ mod tests {
548548 . unwrap ( ) ;
549549
550550 assert_eq ! (
551- Some ( last_block_range. end..= last_transaction_block_number) ,
551+ Some ( last_block_range. end..( last_transaction_block_number + 1 ) ) ,
552552 interval
553553 ) ;
554554 }
0 commit comments