@@ -39,6 +39,18 @@ impl CardanoTransactionRepository {
39
39
Ok ( transactions. collect ( ) )
40
40
}
41
41
42
+ /// Return all the [CardanoTransactionRecord]s in the database using chronological order.
43
+ pub async fn get_transactions_between_blocks (
44
+ & self ,
45
+ range : RangeInclusive < BlockNumber > ,
46
+ ) -> StdResult < Vec < CardanoTransactionRecord > > {
47
+ let provider = GetCardanoTransactionProvider :: new ( & self . connection ) ;
48
+ let filters = provider. get_transaction_between_blocks_condition ( range) ;
49
+ let transactions = provider. find ( filters) ?;
50
+
51
+ Ok ( transactions. collect ( ) )
52
+ }
53
+
42
54
/// Return all the [CardanoTransactionRecord]s in the database up to the given beacon using
43
55
/// chronological order.
44
56
pub async fn get_transactions_up_to (
@@ -141,7 +153,11 @@ impl TransactionStore for CardanoTransactionRepository {
141
153
& self ,
142
154
range : RangeInclusive < BlockNumber > ,
143
155
) -> StdResult < Vec < CardanoTransaction > > {
144
- todo ! ( )
156
+ self . get_transactions_between_blocks ( range) . await . map ( |v| {
157
+ v. into_iter ( )
158
+ . map ( |record| record. into ( ) )
159
+ . collect :: < Vec < CardanoTransaction > > ( )
160
+ } )
145
161
}
146
162
147
163
async fn get_up_to ( & self , beacon : ImmutableFileNumber ) -> StdResult < Vec < CardanoTransaction > > {
@@ -383,4 +399,41 @@ mod tests {
383
399
let highest_beacon = repository. get_highest_beacon ( ) . await . unwrap ( ) ;
384
400
assert_eq ! ( Some ( 100 ) , highest_beacon) ;
385
401
}
402
+
403
+ #[ tokio:: test]
404
+ async fn repository_get_transactions_between_blocks ( ) {
405
+ let connection = Arc :: new ( cardano_tx_db_connection ( ) . unwrap ( ) ) ;
406
+ let repository = CardanoTransactionRepository :: new ( connection) ;
407
+
408
+ let transactions = vec ! [
409
+ CardanoTransaction :: new( "tx-hash-1" , 10 , 50 , "block-hash-1" , 99 ) ,
410
+ CardanoTransaction :: new( "tx-hash-2" , 11 , 51 , "block-hash-2" , 100 ) ,
411
+ CardanoTransaction :: new( "tx-hash-3" , 12 , 52 , "block-hash-3" , 101 ) ,
412
+ ] ;
413
+ repository
414
+ . create_transactions ( transactions. clone ( ) )
415
+ . await
416
+ . unwrap ( ) ;
417
+
418
+ {
419
+ let transaction_result = repository. get_transactions_between ( 0 ..=9 ) . await . unwrap ( ) ;
420
+ assert_eq ! ( Vec :: <CardanoTransaction >:: new( ) , transaction_result) ;
421
+ }
422
+ {
423
+ let transaction_result = repository. get_transactions_between ( 13 ..=20 ) . await . unwrap ( ) ;
424
+ assert_eq ! ( Vec :: <CardanoTransaction >:: new( ) , transaction_result) ;
425
+ }
426
+ {
427
+ let transaction_result = repository. get_transactions_between ( 9 ..=11 ) . await . unwrap ( ) ;
428
+ assert_eq ! ( transactions[ 0 ..=1 ] . to_vec( ) , transaction_result) ;
429
+ }
430
+ {
431
+ let transaction_result = repository. get_transactions_between ( 10 ..=12 ) . await . unwrap ( ) ;
432
+ assert_eq ! ( transactions. clone( ) , transaction_result) ;
433
+ }
434
+ {
435
+ let transaction_result = repository. get_transactions_between ( 11 ..=13 ) . await . unwrap ( ) ;
436
+ assert_eq ! ( transactions[ 1 ..=2 ] . to_vec( ) , transaction_result) ;
437
+ }
438
+ }
386
439
}
0 commit comments