Skip to content

Commit 389ccac

Browse files
committed
feat: implement retrieval of transactions by block range in aggregator
1 parent 7094e3a commit 389ccac

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

mithril-aggregator/src/database/provider/cardano_transaction/get_cardano_transaction.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ops::Range;
22

33
use sqlite::Value;
44

5-
use mithril_common::entities::{BlockNumber, TransactionHash};
5+
use mithril_common::entities::{BlockNumber, BlockRange, TransactionHash};
66
use mithril_persistence::sqlite::{
77
Provider, SourceAlias, SqLiteEntity, SqliteConnection, WhereCondition,
88
};
@@ -43,6 +43,24 @@ impl<'client> GetCardanoTransactionProvider<'client> {
4343
WhereCondition::where_in("transaction_hash", hashes_values)
4444
}
4545

46+
pub fn get_transaction_block_ranges_condition(
47+
&self,
48+
block_ranges: Vec<BlockRange>,
49+
) -> WhereCondition {
50+
let mut where_condition = WhereCondition::default();
51+
for block_range in block_ranges {
52+
where_condition = where_condition.or_where(WhereCondition::new(
53+
"(block_number >= ?* and block_number < ?*)",
54+
vec![
55+
Value::Integer(block_range.start as i64),
56+
Value::Integer(block_range.end as i64),
57+
],
58+
))
59+
}
60+
61+
where_condition
62+
}
63+
4664
pub fn get_transaction_between_blocks_condition(
4765
&self,
4866
range: Range<BlockNumber>,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,20 @@ impl TransactionsRetriever for CardanoTransactionRepository {
313313
.map(|record| record.into())
314314
.collect())
315315
}
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+
}
316330
}
317331

318332
#[async_trait]

0 commit comments

Comments
 (0)