@@ -313,6 +313,20 @@ impl TransactionsRetriever for CardanoTransactionRepository {
313
313
. map ( |record| record. into ( ) )
314
314
. collect ( ) )
315
315
}
316
+
317
+ async fn get_by_block_ranges (
318
+ & self ,
319
+ block_ranges : Vec < BlockRange > ,
320
+ ) -> StdResult < Vec < CardanoTransaction > > {
321
+ let provider = GetCardanoTransactionProvider :: new ( & self . connection ) ;
322
+ let filters = provider. get_transaction_block_ranges_condition ( block_ranges) ;
323
+ let transactions = provider. find ( filters) ?;
324
+
325
+ Ok ( transactions
326
+ . into_iter ( )
327
+ . map ( |record| record. into ( ) )
328
+ . collect ( ) )
329
+ }
316
330
}
317
331
318
332
#[ async_trait]
@@ -489,7 +503,7 @@ mod tests {
489
503
let connection = Arc :: new ( cardano_tx_db_connection ( ) . unwrap ( ) ) ;
490
504
let repository = CardanoTransactionRepository :: new ( connection) ;
491
505
492
- // Build transactions with block numbers from 10 to 40 and immutable file numbers from 12 to 14
506
+ // Build transactions with block numbers from 20 to 40 and immutable file numbers from 12 to 14
493
507
let cardano_transactions: Vec < CardanoTransactionRecord > = ( 20 ..=40 )
494
508
. map ( |i| CardanoTransactionRecord {
495
509
transaction_hash : format ! ( "tx-hash-{i}" ) ,
@@ -676,6 +690,63 @@ mod tests {
676
690
) ;
677
691
}
678
692
693
+ #[ tokio:: test]
694
+ async fn repository_get_transactions_by_block_ranges ( ) {
695
+ let connection = Arc :: new ( cardano_tx_db_connection ( ) . unwrap ( ) ) ;
696
+ let repository = CardanoTransactionRepository :: new ( connection) ;
697
+
698
+ let transactions = vec ! [
699
+ CardanoTransaction :: new( "tx-hash-1" , 10 , 50 , "block-hash-1" , 99 ) ,
700
+ CardanoTransaction :: new( "tx-hash-2" , 11 , 51 , "block-hash-2" , 100 ) ,
701
+ CardanoTransaction :: new( "tx-hash-3" , 20 , 52 , "block-hash-3" , 101 ) ,
702
+ CardanoTransaction :: new( "tx-hash-4" , 31 , 53 , "block-hash-4" , 102 ) ,
703
+ CardanoTransaction :: new( "tx-hash-5" , 35 , 54 , "block-hash-5" , 103 ) ,
704
+ CardanoTransaction :: new( "tx-hash-6" , 46 , 55 , "block-hash-6" , 104 ) ,
705
+ ] ;
706
+ repository
707
+ . create_transactions ( transactions. clone ( ) )
708
+ . await
709
+ . unwrap ( ) ;
710
+
711
+ {
712
+ let transaction_result = repository
713
+ . get_by_block_ranges ( vec ! [ BlockRange :: from_block_number( 100 ) ] )
714
+ . await
715
+ . unwrap ( ) ;
716
+ assert_eq ! ( Vec :: <CardanoTransaction >:: new( ) , transaction_result) ;
717
+ }
718
+ {
719
+ let transaction_result = repository
720
+ . get_by_block_ranges ( vec ! [ BlockRange :: from_block_number( 0 ) ] )
721
+ . await
722
+ . unwrap ( ) ;
723
+ assert_eq ! ( transactions[ 0 ..=1 ] . to_vec( ) , transaction_result) ;
724
+ }
725
+ {
726
+ let transaction_result = repository
727
+ . get_by_block_ranges ( vec ! [
728
+ BlockRange :: from_block_number( 0 ) ,
729
+ BlockRange :: from_block_number( 15 ) ,
730
+ ] )
731
+ . await
732
+ . unwrap ( ) ;
733
+ assert_eq ! ( transactions[ 0 ..=2 ] . to_vec( ) , transaction_result) ;
734
+ }
735
+ {
736
+ let transaction_result = repository
737
+ . get_by_block_ranges ( vec ! [
738
+ BlockRange :: from_block_number( 0 ) ,
739
+ BlockRange :: from_block_number( 30 ) ,
740
+ ] )
741
+ . await
742
+ . unwrap ( ) ;
743
+ assert_eq ! (
744
+ [ transactions[ 0 ..=1 ] . to_vec( ) , transactions[ 3 ..=4 ] . to_vec( ) ] . concat( ) ,
745
+ transaction_result
746
+ ) ;
747
+ }
748
+ }
749
+
679
750
#[ tokio:: test]
680
751
async fn repository_store_block_range ( ) {
681
752
let connection = Arc :: new ( cardano_tx_db_connection ( ) . unwrap ( ) ) ;
0 commit comments