mithril_cardano_node_chain/chain_observer/
interface.rs

1use async_trait::async_trait;
2use thiserror::Error;
3
4use mithril_common::StdError;
5use mithril_common::crypto_helper::KesPeriod;
6use mithril_common::entities::{ChainPoint, Epoch, StakeDistribution};
7
8use crate::entities::{ChainAddress, TxDatum};
9
10/// [ChainObserver] related errors.
11#[derive(Debug, Error)]
12pub enum ChainObserverError {
13    /// Generic [ChainObserver] error.
14    #[error("general error")]
15    General(#[source] StdError),
16
17    /// Error raised when the content could not be parsed.
18    #[error("could not parse content")]
19    InvalidContent(#[source] StdError),
20}
21
22/// Retrieve data from the cardano network
23#[cfg_attr(test, mockall::automock)]
24#[async_trait]
25pub trait ChainObserver: Sync + Send {
26    /// Retrieve the datums associated to an address
27    async fn get_current_datums(
28        &self,
29        address: &ChainAddress,
30    ) -> Result<Vec<TxDatum>, ChainObserverError>;
31
32    /// Retrieve the current era of the Cardano network
33    async fn get_current_era(&self) -> Result<Option<String>, ChainObserverError>;
34
35    /// Retrieve the current epoch of the Cardano network
36    async fn get_current_epoch(&self) -> Result<Option<Epoch>, ChainObserverError>;
37
38    /// Retrieve the current chain point of the Cardano network
39    async fn get_current_chain_point(&self) -> Result<Option<ChainPoint>, ChainObserverError>;
40
41    /// Retrieve the current stake distribution of the Cardano network
42    async fn get_current_stake_distribution(
43        &self,
44    ) -> Result<Option<StakeDistribution>, ChainObserverError>;
45
46    /// Retrieve the current KES period
47    async fn get_current_kes_period(&self) -> Result<Option<KesPeriod>, ChainObserverError> {
48        Ok(None)
49    }
50}