Skip to content

Commit 150f5eb

Browse files
committed
Simplify get_transactions_between signature by using a range
1 parent b6a6939 commit 150f5eb

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

mithril-signer/src/cardano_transactions_importer.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ops::RangeInclusive;
12
use std::path::{Path, PathBuf};
23
use std::sync::Arc;
34

@@ -25,8 +26,7 @@ pub trait TransactionStore: Send + Sync {
2526
/// Get transactions between two block numbers
2627
async fn get_transactions_between(
2728
&self,
28-
start: BlockNumber,
29-
end: BlockNumber,
29+
range: RangeInclusive<BlockNumber>,
3030
) -> StdResult<Vec<CardanoTransaction>>;
3131

3232
/// Get stored transactions up to the given beacon
@@ -144,7 +144,7 @@ impl CardanoTransactionsImporter {
144144

145145
let transactions: Vec<CardanoTransaction> = self
146146
.transaction_store
147-
.get_transactions_between(start, end)
147+
.get_transactions_between(start..=end)
148148
.await?;
149149

150150
let block_ranges_with_merkle_root: Vec<(BlockRange, MKTreeNode)> = block_ranges
@@ -315,8 +315,8 @@ mod tests {
315315
.returning(|| Ok(Some((0, BlockRange::LENGTH * 5 + 1))));
316316
store_mock
317317
.expect_get_transactions_between()
318-
.withf(|start, end| start == &0 && end == &(BlockRange::LENGTH * 5))
319-
.return_once(move |_, _| Ok(expected_stored_transactions))
318+
.withf(|range| range == &(0..=(BlockRange::LENGTH * 5)))
319+
.return_once(move |_| Ok(expected_stored_transactions))
320320
.once();
321321
store_mock
322322
.expect_store_block_ranges()
@@ -441,10 +441,8 @@ mod tests {
441441
.returning(|| Ok(Some((BlockRange::LENGTH + 2, BlockRange::LENGTH * 5 + 1))));
442442
store_mock
443443
.expect_get_transactions_between()
444-
.withf(|start, end| {
445-
start == &BlockRange::LENGTH && end == &(BlockRange::LENGTH * 5)
446-
})
447-
.return_once(move |_, _| Ok(expected_stored_transactions))
444+
.withf(|range| range == &(BlockRange::LENGTH..=(BlockRange::LENGTH * 5)))
445+
.return_once(move |_| Ok(expected_stored_transactions))
448446
.once();
449447
store_mock
450448
.expect_store_block_ranges()
@@ -502,7 +500,7 @@ mod tests {
502500
.returning(|| Ok(Some((0, BlockRange::LENGTH * 2))));
503501
store_mock
504502
.expect_get_transactions_between()
505-
.return_once(move |_, _| Ok(expected_stored_transactions))
503+
.return_once(move |_| Ok(expected_stored_transactions))
506504
.once();
507505
store_mock
508506
.expect_store_block_ranges()

mithril-signer/src/database/repository/cardano_transaction_repository.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ops::RangeInclusive;
12
use std::sync::Arc;
23

34
use anyhow::Context;
@@ -138,8 +139,7 @@ impl TransactionStore for CardanoTransactionRepository {
138139

139140
async fn get_transactions_between(
140141
&self,
141-
_start: BlockNumber,
142-
_end: BlockNumber,
142+
range: RangeInclusive<BlockNumber>,
143143
) -> StdResult<Vec<CardanoTransaction>> {
144144
todo!()
145145
}

0 commit comments

Comments
 (0)