mithril_common/
lib.rs

1#![warn(missing_docs)]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4//! Shared datatypes and traits used by Mithril rust projects
5//!
6//! Provide:
7//! - [Digester][digesters] to compute mithril digest from a Cardano database
8//! - Helpers for the [Mithril STM](https://mithril.network/rust-doc/mithril_stm/index.html)
9//!   lib with the [crypto_helper].
10//! - [certificate chain][certificate_chain] used to validate the Certificate Chain created by an aggregator
11//! - The [entities] used by, and exchanged between, the aggregator, signers and client.
12
13macro_rules! cfg_fs {
14    ($($item:item)*) => {
15        $(
16            #[cfg(feature = "fs")]
17            #[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
18            $item
19        )*
20    }
21}
22
23macro_rules! cfg_test_tools {
24    ($($item:item)*) => {
25        $(
26            #[cfg(any(test, feature = "test_tools"))]
27            #[cfg_attr(docsrs, doc(cfg(feature = "test_tools")))]
28            $item
29        )*
30    }
31}
32
33pub mod api_version;
34pub mod certificate_chain;
35pub mod chain_observer;
36pub mod crypto_helper;
37pub mod entities;
38#[macro_use]
39pub mod era;
40pub mod logging;
41pub mod messages;
42pub mod protocol;
43pub mod signable_builder;
44
45cfg_test_tools! {
46    pub mod test_utils;
47}
48
49cfg_fs! {
50    mod ticker_service;
51    pub mod digesters;
52    pub mod cardano_block_scanner;
53    pub mod chain_reader;
54
55    pub use ticker_service::{TickerService, MithrilTickerService};
56}
57
58pub use entities::{CardanoNetwork, MagicId};
59
60/// Generic error type
61pub type StdError = anyhow::Error;
62
63/// Generic result type
64pub type StdResult<T> = anyhow::Result<T, StdError>;
65
66/// Mithril API protocol version header name
67pub const MITHRIL_API_VERSION_HEADER: &str = "mithril-api-version";
68
69/// Mithril signer node version header name
70pub const MITHRIL_SIGNER_VERSION_HEADER: &str = "signer-node-version";
71
72/// Mithril aggregator node version header name
73pub const MITHRIL_AGGREGATOR_VERSION_HEADER: &str = "aggregator-node-version";
74
75/// Mithril origin of the request
76pub const MITHRIL_ORIGIN_TAG_HEADER: &str = "mithril-origin-tag";
77
78#[cfg(test)]
79mod tests {
80    #[cfg(feature = "apispec")]
81    #[test]
82    fn test_openapi_examples_conformity() {
83        use crate::test_utils::apispec::APISpec;
84        let api_spec = APISpec::from_file(&APISpec::get_default_spec_file());
85
86        let errors: Vec<String> = api_spec.verify_examples();
87
88        assert!(
89            errors.is_empty(),
90            "Errors in examples\n{}",
91            errors.join("\n")
92        );
93    }
94}