mithril_cardano_node_chain/chain_scanner/
interface.rs

1use async_trait::async_trait;
2
3use mithril_common::StdResult;
4use mithril_common::entities::{BlockNumber, SlotNumber};
5
6use crate::entities::{RawCardanoPoint, ScannedBlock};
7
8/// A scanner that can read cardano transactions in a cardano database
9#[cfg_attr(test, mockall::automock)]
10#[async_trait]
11pub trait BlockScanner: Sync + Send {
12    /// Scan the transactions
13    async fn scan(
14        &self,
15        from: Option<RawCardanoPoint>,
16        until: BlockNumber,
17    ) -> StdResult<Box<dyn BlockStreamer>>;
18}
19
20/// [ChainScannedBlocks] allows to scan new blocks and handle rollbacks
21#[derive(Debug, Clone, PartialEq)]
22pub enum ChainScannedBlocks {
23    /// Roll forward on the chain to the next list of [ScannedBlock]
24    RollForwards(Vec<ScannedBlock>),
25    /// Roll backward on the chain to the previous [SlotNumber]
26    RollBackward(SlotNumber),
27}
28
29/// Trait that define how blocks are streamed from a Cardano database
30#[async_trait]
31pub trait BlockStreamer: Sync + Send {
32    /// Stream the next available blocks
33    async fn poll_next(&mut self) -> StdResult<Option<ChainScannedBlocks>>;
34
35    /// Get the last polled point of the chain
36    fn last_polled_point(&self) -> Option<RawCardanoPoint>;
37}