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