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 crypto_helper;
36pub mod entities;
37pub mod logging;
38pub mod messages;
39pub mod protocol;
40pub mod signable_builder;
41
42cfg_test_tools! {
43    pub mod test_utils;
44}
45
46cfg_fs! {
47    pub mod digesters;
48}
49
50pub use entities::{CardanoNetwork, MagicId};
51
52/// Generic error type
53pub type StdError = anyhow::Error;
54
55/// Generic result type
56pub type StdResult<T> = anyhow::Result<T, StdError>;
57
58/// Mithril API protocol version header name
59pub const MITHRIL_API_VERSION_HEADER: &str = "mithril-api-version";
60
61/// Mithril signer node version header name
62pub const MITHRIL_SIGNER_VERSION_HEADER: &str = "signer-node-version";
63
64/// Mithril aggregator node version header name
65pub const MITHRIL_AGGREGATOR_VERSION_HEADER: &str = "aggregator-node-version";
66
67/// Mithril origin of the request
68pub const MITHRIL_ORIGIN_TAG_HEADER: &str = "mithril-origin-tag";
69
70/// Mithril client type of the request
71pub const MITHRIL_CLIENT_TYPE_HEADER: &str = "mithril-client-type";
72
73/// Macro used to mark the code that should be cleaned up when the new era is activated
74#[macro_export]
75macro_rules! era_deprecate {
76    ( $comment:literal ) => {};
77}
78
79#[cfg(test)]
80mod tests {
81    #[cfg(feature = "apispec")]
82    #[test]
83    fn test_openapi_examples_conformity() {
84        use crate::test_utils::apispec::APISpec;
85        let api_spec = APISpec::from_file(&APISpec::get_default_spec_file());
86
87        let errors: Vec<String> = api_spec.verify_examples();
88
89        assert!(
90            errors.is_empty(),
91            "Errors in examples\n{}",
92            errors.join("\n")
93        );
94    }
95}