mithril_signer/database/repository/
cardano_transaction_repository.rs

1use 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,
8};
9use mithril_common::StdResult;
10use mithril_persistence::database::repository::CardanoTransactionRepository;
11
12use crate::services::{HighestTransactionBlockNumberGetter, TransactionPruner, TransactionStore};
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 TransactionPruner for CardanoTransactionRepository {
61    async fn prune(&self, number_of_blocks_to_keep: BlockNumber) -> StdResult<()> {
62        self.prune_transaction(number_of_blocks_to_keep).await
63    }
64}
65
66#[async_trait]
67impl HighestTransactionBlockNumberGetter for CardanoTransactionRepository {
68    async fn get(&self) -> StdResult<Option<BlockNumber>> {
69        let highest_chain_point = self.get_transaction_highest_chain_point().await?;
70        Ok(highest_chain_point.map(|c| c.block_number))
71    }
72}