mithril_common/chain_observer/
interface.rs1use 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#[derive(Debug, Error)]
16pub enum ChainObserverError {
17 #[error("general error")]
19 General(#[source] StdError),
20
21 #[error("could not parse content")]
23 InvalidContent(#[source] StdError),
24}
25
26#[cfg_attr(test, automock)]
28#[async_trait]
29pub trait ChainObserver: Sync + Send {
30 async fn get_current_datums(
32 &self,
33 address: &ChainAddress,
34 ) -> Result<Vec<TxDatum>, ChainObserverError>;
35
36 async fn get_current_era(&self) -> Result<Option<String>, ChainObserverError>;
38
39 async fn get_current_epoch(&self) -> Result<Option<Epoch>, ChainObserverError>;
41
42 async fn get_current_chain_point(&self) -> Result<Option<ChainPoint>, ChainObserverError>;
44
45 async fn get_current_stake_distribution(
47 &self,
48 ) -> Result<Option<StakeDistribution>, ChainObserverError>;
49
50 async fn get_current_kes_period(
52 &self,
53 _opcert: &OpCert,
54 ) -> Result<Option<KESPeriod>, ChainObserverError> {
55 Ok(None)
56 }
57}