mithril_client/lib.rs
1#![warn(missing_docs)]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4//! Define all the tooling necessary to manipulate Mithril certified types from a
5//! [Mithril Aggregator](https://mithril.network/rust-doc/mithril_aggregator/index.html).
6//!
7//! It handles the different types that can be queried to a Mithril aggregator:
8//!
9//! - [Cardano Database v1 (aka Snapshot)][snapshot_client]: list, get, download archive and record statistics.
10//! - [Cardano Database v2][cardano_database_client] list, get, download archive and record statistics.
11//! - [Cardano transactions][cardano_transaction_client] list & get snapshot, get proofs.
12//! - [Cardano stake distribution][cardano_stake_distribution_client] list, get and get by epoch.
13//! - [Mithril stake distribution][mithril_stake_distribution_client] list and get.
14//! - [Certificates][certificate_client] list, get, and chain validation.
15//! - [MithrilEraClient][era]: retrieve the current Mithril era.
16//!
17//! The [Client] aggregates the queries of all of those types.
18//!
19//! **NOTE:** Snapshot download and Certificate chain validation can take quite some time even with a fast
20//! computer and network.
21//! For those a feedback mechanism is available, more details on it in the [feedback] submodule.
22//!
23//! # Example
24//!
25//! Below is an example describing the usage of most of the library's functions together:
26//!
27//! **Note:** _Snapshot download and the compute snapshot message functions are available using crate feature_ **fs**.
28//!
29//! ```no_run
30//! # #[cfg(feature = "fs")]
31//! # async fn run() -> mithril_client::MithrilResult<()> {
32//! use mithril_client::{ClientBuilder, MessageBuilder};
33//! use std::path::Path;
34//!
35//! let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;
36//!
37//! let snapshots = client.snapshot().list().await?;
38//!
39//! let last_digest = snapshots.first().unwrap().digest.as_ref();
40//! let snapshot = client.snapshot().get(last_digest).await?.unwrap();
41//!
42//! let certificate = client
43//! .certificate()
44//! .verify_chain(&snapshot.certificate_hash)
45//! .await?;
46//!
47//! // Note: the directory must already exist, and the user running the binary must have read/write access to it.
48//! let target_directory = Path::new("/home/user/download/");
49//! client
50//! .snapshot()
51//! .download_unpack(&snapshot, &target_directory)
52//! .await?;
53//!
54//! if let Err(e) = client.snapshot().add_statistics(&snapshot).await {
55//! println!("Could not increment snapshot download statistics: {:?}", e);
56//! }
57//!
58//! let message = MessageBuilder::new()
59//! .compute_snapshot_message(&certificate, &target_directory)
60//! .await?;
61//!
62//! assert!(certificate.match_message(&message));
63//! # Ok(())
64//! # }
65//! ```
66//!
67//! ## Optional Features
68//!
69//! The following are a list of [Cargo features](https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-features-section) that can be
70//! enabled or disabled:
71//!
72//! - **fs**: Enables file system related functionalities.
73//! - **unstable**: Enables experimental or in-development `mithril-client` features that may change.
74//! - **rug-backend** *(enabled by default)*: Enables usage of `rug` numerical backend in `mithril-stm` (dependency of `mithril-common`).
75//! - **num-integer-backend**: Enables usage of `num-integer` numerical backend in `mithril-stm` (dependency of `mithril-common`).
76//!
77//! To allow fine tuning of the http queries, the following [Reqwest](https://docs.rs/reqwest/latest/reqwest/#optional-features) features are re-exported:
78//! - **native-tls** *(enabled by default)*: Enables TLS functionality provided by `native-tls`.
79//! - **native-tls-vendored**: Enables the `vendored` feature of `native-tls`.
80//! - **native-tls-alpn**: Enables the `alpn` feature of `native-tls`.
81//! - **rustls-tls**: Enables TLS functionality provided by `rustls`.
82//! Equivalent to `rustls-tls-webpki-roots`.
83//! - **rustls-tls-manual-roots**: Enables TLS functionality provided by `rustls`,
84//! without setting any root certificates. Roots have to be specified manually.
85//! - **rustls-tls-webpki-roots**: Enables TLS functionality provided by `rustls`,
86//! while using root certificates from the `webpki-roots` crate.
87//! - **rustls-tls-native-roots**: Enables TLS functionality provided by `rustls`,
88//! while using root certificates from the `rustls-native-certs` crate.
89//! - **enable-http-compression** *(enabled by default)*: Enables compressed traffic with `reqwest`.
90
91macro_rules! cfg_fs {
92 ($($item:item)*) => {
93 $(
94 #[cfg(feature = "fs")]
95 #[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
96 $item
97 )*
98 }
99}
100
101#[allow(unused_macros)]
102macro_rules! cfg_unstable {
103 ($($item:item)*) => {
104 $(
105 #[cfg(feature = "unstable")]
106 #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
107 $item
108 )*
109 }
110}
111
112#[allow(unused_macros)]
113macro_rules! cfg_fs_unstable {
114 ($($item:item)*) => {
115 $(
116 #[cfg(all(feature = "unstable", feature = "fs"))]
117 #[cfg_attr(docsrs, doc(cfg(all(feature = "unstable", feature = "fs"))))]
118 $item
119 )*
120 }
121}
122
123pub mod aggregator_client;
124pub mod cardano_database_client;
125pub mod cardano_stake_distribution_client;
126pub mod cardano_transaction_client;
127pub mod certificate_client;
128mod client;
129pub mod era;
130pub mod feedback;
131mod message;
132pub mod mithril_stake_distribution_client;
133pub mod snapshot_client;
134cfg_fs! {
135 pub mod file_downloader;
136}
137
138mod type_alias;
139mod utils;
140
141pub use client::*;
142pub use message::*;
143pub use type_alias::*;
144
145#[cfg(test)]
146pub(crate) mod test_utils {
147 mithril_common::define_test_logger!();
148}