mithril_aggregator/database/repository/
cardano_transaction_repository.rs1use std::ops::Range;
2
3use async_trait::async_trait;
4
5use mithril_common::crypto_helper::MKTreeNode;
6use mithril_common::entities::{
7 BlockNumber, BlockRange, CardanoTransaction, ChainPoint, SlotNumber, TransactionHash,
8};
9use mithril_common::StdResult;
10use mithril_persistence::database::repository::CardanoTransactionRepository;
11
12use crate::services::{TransactionStore, TransactionsRetriever};
13
14#[async_trait]
15impl TransactionStore for CardanoTransactionRepository {
16 async fn get_highest_beacon(&self) -> StdResult<Option<ChainPoint>> {
17 self.get_transaction_highest_chain_point().await
18 }
19
20 async fn get_highest_block_range(&self) -> StdResult<Option<BlockRange>> {
21 let record = self.retrieve_highest_block_range_root().await?;
22 Ok(record.map(|record| record.range))
23 }
24
25 async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()> {
26 self.store_transactions(transactions).await
27 }
28
29 async fn get_transactions_in_range(
30 &self,
31 range: Range<BlockNumber>,
32 ) -> StdResult<Vec<CardanoTransaction>> {
33 self.get_transactions_in_range_blocks(range).await.map(|v| {
34 v.into_iter()
35 .map(|record| record.into())
36 .collect::<Vec<CardanoTransaction>>()
37 })
38 }
39
40 async fn store_block_range_roots(
41 &self,
42 block_ranges: Vec<(BlockRange, MKTreeNode)>,
43 ) -> StdResult<()> {
44 if !block_ranges.is_empty() {
45 self.create_block_range_roots(block_ranges).await?;
46 }
47 Ok(())
48 }
49
50 async fn remove_rolled_back_transactions_and_block_range(
51 &self,
52 slot_number: SlotNumber,
53 ) -> StdResult<()> {
54 self.remove_rolled_back_transactions_and_block_range_by_slot_number(slot_number)
55 .await
56 }
57}
58
59#[async_trait]
60impl TransactionsRetriever for CardanoTransactionRepository {
61 async fn get_by_hashes(
62 &self,
63 hashes: Vec<TransactionHash>,
64 up_to: BlockNumber,
65 ) -> StdResult<Vec<CardanoTransaction>> {
66 self.get_transaction_by_hashes(hashes, up_to)
67 .await
68 .map(|v| {
69 v.into_iter()
70 .map(|record| record.into())
71 .collect::<Vec<CardanoTransaction>>()
72 })
73 }
74
75 async fn get_by_block_ranges(
76 &self,
77 block_ranges: Vec<BlockRange>,
78 ) -> StdResult<Vec<CardanoTransaction>> {
79 self.get_transaction_by_block_ranges(block_ranges)
80 .await
81 .map(|v| {
82 v.into_iter()
83 .map(|record| record.into())
84 .collect::<Vec<CardanoTransaction>>()
85 })
86 }
87}