1
- use std:: ops:: RangeInclusive ;
1
+ use std:: ops:: Range ;
2
2
use std:: sync:: Arc ;
3
3
4
4
use anyhow:: Context ;
@@ -46,7 +46,7 @@ impl CardanoTransactionRepository {
46
46
/// Return all the [CardanoTransactionRecord]s in the database using chronological order.
47
47
pub async fn get_transactions_between_blocks (
48
48
& self ,
49
- range : RangeInclusive < BlockNumber > ,
49
+ range : Range < BlockNumber > ,
50
50
) -> StdResult < Vec < CardanoTransactionRecord > > {
51
51
let provider = GetCardanoTransactionProvider :: new ( & self . connection ) ;
52
52
let filters = provider. get_transaction_between_blocks_condition ( range) ;
@@ -180,9 +180,27 @@ impl TransactionStore for CardanoTransactionRepository {
180
180
}
181
181
}
182
182
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
+
183
201
async fn get_block_interval_without_block_range_root (
184
202
& self ,
185
- ) -> StdResult < Option < RangeInclusive < BlockNumber > > > {
203
+ ) -> StdResult < Option < Range < BlockNumber > > > {
186
204
let provider = GetIntervalWithoutBlockRangeRootProvider :: new ( & self . connection ) ;
187
205
let row = provider
188
206
. find ( provider. get_interval_without_block_range_condition ( ) ) ?
@@ -193,7 +211,7 @@ impl TransactionStore for CardanoTransactionRepository {
193
211
None => panic ! ( "IntervalWithoutBlockRangeProvider should always return a single row" ) ,
194
212
Some ( interval) => match ( interval. start , interval. end ) {
195
213
( _, None ) => Ok ( None ) ,
196
- ( None , Some ( end) ) => Ok ( Some ( 0 ..= end) ) ,
214
+ ( None , Some ( end) ) => Ok ( Some ( 0 ..( end + 1 ) ) ) ,
197
215
( Some ( start) , Some ( end) ) if end < start => {
198
216
// To discuss : should we prune all block ranges from the DB to force recompute ?
199
217
warn ! (
@@ -204,14 +222,14 @@ impl TransactionStore for CardanoTransactionRepository {
204
222
) ;
205
223
Ok ( None )
206
224
}
207
- ( Some ( start) , Some ( end) ) => Ok ( Some ( start..= end) ) ,
225
+ ( Some ( start) , Some ( end) ) => Ok ( Some ( start..( end + 1 ) ) ) ,
208
226
} ,
209
227
}
210
228
}
211
229
212
230
async fn get_transactions_between (
213
231
& self ,
214
- range : RangeInclusive < BlockNumber > ,
232
+ range : Range < BlockNumber > ,
215
233
) -> StdResult < Vec < CardanoTransaction > > {
216
234
self . get_transactions_between_blocks ( range) . await . map ( |v| {
217
235
v. into_iter ( )
@@ -220,24 +238,6 @@ impl TransactionStore for CardanoTransactionRepository {
220
238
} )
221
239
}
222
240
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
-
241
241
async fn store_block_ranges (
242
242
& self ,
243
243
block_ranges : Vec < ( BlockRange , MKTreeNode ) > ,
@@ -481,23 +481,23 @@ mod tests {
481
481
. unwrap ( ) ;
482
482
483
483
{
484
- let transaction_result = repository. get_transactions_between ( 0 ..= 9 ) . await . unwrap ( ) ;
484
+ let transaction_result = repository. get_transactions_between ( 0 ..10 ) . await . unwrap ( ) ;
485
485
assert_eq ! ( Vec :: <CardanoTransaction >:: new( ) , transaction_result) ;
486
486
}
487
487
{
488
- let transaction_result = repository. get_transactions_between ( 13 ..= 20 ) . await . unwrap ( ) ;
488
+ let transaction_result = repository. get_transactions_between ( 13 ..21 ) . await . unwrap ( ) ;
489
489
assert_eq ! ( Vec :: <CardanoTransaction >:: new( ) , transaction_result) ;
490
490
}
491
491
{
492
- let transaction_result = repository. get_transactions_between ( 9 ..= 11 ) . await . unwrap ( ) ;
492
+ let transaction_result = repository. get_transactions_between ( 9 ..12 ) . await . unwrap ( ) ;
493
493
assert_eq ! ( transactions[ 0 ..=1 ] . to_vec( ) , transaction_result) ;
494
494
}
495
495
{
496
- let transaction_result = repository. get_transactions_between ( 10 ..= 12 ) . await . unwrap ( ) ;
496
+ let transaction_result = repository. get_transactions_between ( 10 ..13 ) . await . unwrap ( ) ;
497
497
assert_eq ! ( transactions. clone( ) , transaction_result) ;
498
498
}
499
499
{
500
- let transaction_result = repository. get_transactions_between ( 11 ..= 13 ) . await . unwrap ( ) ;
500
+ let transaction_result = repository. get_transactions_between ( 11 ..14 ) . await . unwrap ( ) ;
501
501
assert_eq ! ( transactions[ 1 ..=2 ] . to_vec( ) , transaction_result) ;
502
502
}
503
503
}
@@ -529,7 +529,7 @@ mod tests {
529
529
. await
530
530
. unwrap ( ) ;
531
531
532
- assert_eq ! ( Some ( 0 ..= last_transaction_block_number) , interval) ;
532
+ assert_eq ! ( Some ( 0 ..( last_transaction_block_number + 1 ) ) , interval) ;
533
533
}
534
534
{
535
535
// The last block range give the lower bound
@@ -548,7 +548,7 @@ mod tests {
548
548
. unwrap ( ) ;
549
549
550
550
assert_eq ! (
551
- Some ( last_block_range. end..= last_transaction_block_number) ,
551
+ Some ( last_block_range. end..( last_transaction_block_number + 1 ) ) ,
552
552
interval
553
553
) ;
554
554
}
0 commit comments