@@ -278,12 +278,15 @@ impl CardanoTransactionRepository {
278
278
}
279
279
280
280
/// Create new [CardanoTransactionRecord]s in the database.
281
- pub async fn create_transactions (
281
+ pub async fn create_transactions < T : Into < CardanoTransactionRecord > > (
282
282
& self ,
283
- transactions : Vec < CardanoTransactionRecord > ,
283
+ transactions : Vec < T > ,
284
284
) -> StdResult < Vec < CardanoTransactionRecord > > {
285
+ let records: Vec < CardanoTransactionRecord > =
286
+ transactions. into_iter ( ) . map ( |tx| tx. into ( ) ) . collect ( ) ;
287
+
285
288
let provider = InsertCardanoTransactionProvider :: new ( & self . connection ) ;
286
- let filters = provider. get_insert_many_condition ( transactions ) ?;
289
+ let filters = provider. get_insert_many_condition ( records ) ?;
287
290
let cursor = provider. find ( filters) ?;
288
291
289
292
Ok ( cursor. collect ( ) )
@@ -328,9 +331,7 @@ impl TransactionStore for CardanoTransactionRepository {
328
331
}
329
332
330
333
async fn store_transactions ( & self , transactions : & [ CardanoTransaction ] ) -> StdResult < ( ) > {
331
- let records: Vec < CardanoTransactionRecord > =
332
- transactions. iter ( ) . map ( |tx| tx. to_owned ( ) . into ( ) ) . collect ( ) ;
333
- self . create_transactions ( records)
334
+ self . create_transactions ( transactions. to_vec ( ) )
334
335
. await
335
336
. with_context ( || "CardanoTransactionRepository can not store transactions" ) ?;
336
337
@@ -574,8 +575,8 @@ mod tests {
574
575
let connection = get_connection ( ) . await ;
575
576
let repository = CardanoTransactionRepository :: new ( connection. clone ( ) ) ;
576
577
577
- let cardano_transactions: Vec < CardanoTransaction > = ( 20 ..=40 )
578
- . map ( |i| CardanoTransaction {
578
+ let cardano_transactions: Vec < CardanoTransactionRecord > = ( 20 ..=40 )
579
+ . map ( |i| CardanoTransactionRecord {
579
580
transaction_hash : format ! ( "tx-hash-{i}" ) ,
580
581
block_number : i % 10 ,
581
582
slot_number : i * 100 ,
@@ -584,24 +585,18 @@ mod tests {
584
585
} )
585
586
. collect ( ) ;
586
587
repository
587
- . store_transactions ( & cardano_transactions)
588
+ . create_transactions ( cardano_transactions. clone ( ) )
588
589
. await
589
590
. unwrap ( ) ;
590
591
591
- let transaction_result = repository. get_up_to ( 34 ) . await . unwrap ( ) ;
592
-
592
+ let transaction_result = repository. get_transactions_up_to ( 34 ) . await . unwrap ( ) ;
593
593
assert_eq ! ( cardano_transactions[ 0 ..=14 ] . to_vec( ) , transaction_result) ;
594
594
595
- let transaction_result = repository. get_up_to ( 300 ) . await . unwrap ( ) ;
596
-
597
- assert_eq ! (
598
- cardano_transactions. into_iter( ) . collect:: <Vec <_>>( ) ,
599
- transaction_result
600
- ) ;
601
-
602
- let transaction_result = repository. get_up_to ( 19 ) . await . unwrap ( ) ;
595
+ let transaction_result = repository. get_transactions_up_to ( 300 ) . await . unwrap ( ) ;
596
+ assert_eq ! ( cardano_transactions. clone( ) , transaction_result) ;
603
597
604
- assert_eq ! ( Vec :: <CardanoTransaction >:: new( ) , transaction_result) ;
598
+ let transaction_result = repository. get_transactions_up_to ( 19 ) . await . unwrap ( ) ;
599
+ assert_eq ! ( Vec :: <CardanoTransactionRecord >:: new( ) , transaction_result) ;
605
600
}
606
601
607
602
#[ tokio:: test]
0 commit comments