mithril_common/chain_observer/
interface.rs

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