partner_chains_dolos_data_sources/
lib.rs1#[cfg(feature = "candidate-source")]
2mod candidate;
3#[cfg(feature = "candidate-source")]
4pub use candidate::AuthoritySelectionDataSourceImpl;
5
6#[cfg(feature = "governed-map")]
7mod governed_map;
8#[cfg(feature = "governed-map")]
9pub use governed_map::GovernedMapDataSourceImpl;
10
11#[cfg(feature = "mc-hash")]
12mod mc_hash;
13#[cfg(feature = "mc-hash")]
14pub use mc_hash::McHashDataSourceImpl;
15
16#[cfg(feature = "sidechain-rpc")]
17mod sidechain_rpc;
18#[cfg(feature = "sidechain-rpc")]
19pub use sidechain_rpc::SidechainRpcDataSourceImpl;
20
21#[cfg(feature = "block-participation")]
22mod stake_distribution;
23#[cfg(feature = "block-participation")]
24pub use stake_distribution::StakeDistributionDataSourceImpl;
25
26#[cfg(feature = "bridge")]
27mod bridge;
28#[cfg(feature = "bridge")]
29pub use bridge::TokenBridgeDataSourceImpl;
30
31mod block;
32pub use block::BlockDataSourceImpl;
33use sidechain_domain::mainchain_epoch::MainchainEpochConfig;
34
35use crate::client::MiniBFClient;
36
37pub mod client;
38
39type ResultErr = Box<dyn std::error::Error + Send + Sync>;
40type Result<T> = std::result::Result<T, ResultErr>;
41
42#[derive(Debug, PartialEq, thiserror::Error)]
44pub enum DataSourceError {
45 #[error("Bad request: `{0}`.")]
47 BadRequest(String),
48 #[error("Dolos client call error: `{0}`.")]
50 DolosCallError(String),
51 #[error("Dolos client response parse error: `{0}`.")]
53 DolosResponseParseError(String),
54 #[error(
56 "'{0}' not found. Possible causes: data source configuration error, Dolos not synced fully, or data not set on the main chain."
57 )]
58 ExpectedDataNotFound(String),
59 #[error(
61 "Invalid data. {0} Possible cause is an error in Plutus scripts or data source is outdated."
62 )]
63 InvalidData(String),
64}
65
66pub fn get_connection_from_env() -> Result<MiniBFClient> {
71 log::warn!("Dolos data sources are still WIP and should not be used in production");
72 let config = ConnectionConfig::from_env()?;
73 Ok(MiniBFClient::new(config.dolos_minibf_url.as_str(), std::time::Duration::from_secs(30)))
74}
75
76#[derive(Debug, Clone, serde::Deserialize)]
78pub struct ConnectionConfig {
79 pub(crate) dolos_minibf_url: String,
81}
82
83impl ConnectionConfig {
84 pub fn from_env() -> Result<Self> {
86 let config: Self = figment::Figment::new()
87 .merge(figment::providers::Env::raw())
88 .extract()
89 .map_err(|e| format!("Failed to read Dolos data source connection: {e}"))?;
90 Ok(config)
91 }
92}
93
94#[cfg(feature = "block-source")]
98pub fn read_mc_epoch_config() -> Result<MainchainEpochConfig> {
99 Ok(MainchainEpochConfig::read_from_env()
100 .map_err(|e| format!("Failed to read main chain config: {}", e))?)
101}