1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// TODO: Remove this allow once migration from deprecated AggregatorClient types is complete
//! Define all the tooling necessary to manipulate Mithril certified types from a
//! [Mithril Aggregator](https://mithril.network/rust-doc/mithril_aggregator/index.html).
//!
//! It handles the different types that can be queried to a Mithril aggregator:
//!
//! - [Cardano Database v2][cardano_database_client] list, get, download archive and record statistics.
//! - [Cardano transactions][cardano_transaction_client] list & get snapshot, get proofs.
//! - [Cardano stake distribution][cardano_stake_distribution_client] list, get and get by epoch.
//! - [Mithril stake distribution][mithril_stake_distribution_client] list and get.
//! - [Certificates][certificate_client] list, get, and chain validation.
//! - [MithrilEraClient][era]: retrieve the current Mithril era.
//!
//! The [Client] aggregates the queries of all of those types.
//!
//! **NOTE:** Snapshot download and Certificate chain validation can take quite some time even with a fast
//! computer and network.
//! For those a feedback mechanism is available, more details on it in the [feedback] submodule.
//!
//! # Example
//!
//! Below is an example describing the usage of most of the library's functions together:
//!
//! **Note:** _Snapshot download and the compute snapshot message functions are available using crate feature_ **fs**.
//!
//! ```no_run
//! # #[cfg(feature = "fs")]
//! # async fn run() -> mithril_client::MithrilResult<()> {
//! use mithril_client::{ClientBuilder, MessageBuilder};
//! use mithril_client::cardano_database_client::{DownloadUnpackOptions, ImmutableFileRange};
//! use std::path::Path;
//!
//! let client =
//! ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY")
//! .build()?;
//! let cardano_database_snapshot = client
//! .cardano_database_v2()
//! .get("CARDANO_DATABASE_HASH")
//! .await?
//! .unwrap();
//!
//! let certificate = client
//! .certificate()
//! .verify_chain(&cardano_database_snapshot.certificate_hash)
//! .await?;
//!
//! // Note: the directory must already exist, and the user running the binary must have read/write access to it.
//! let target_directory = Path::new("/home/user/download/");
//! let immutable_file_range = ImmutableFileRange::Range(3, 6);
//! let download_unpack_options = DownloadUnpackOptions {
//! allow_override: true,
//! include_ancillary: true,
//! ..DownloadUnpackOptions::default()
//! };
//! client
//! .cardano_database_v2()
//! .download_unpack(
//! &cardano_database_snapshot,
//! &immutable_file_range,
//! &target_directory,
//! download_unpack_options,
//! )
//! .await?;
//!
//! let verified_digests = client
//! .cardano_database_v2()
//! .download_and_verify_digests(&certificate, &cardano_database_snapshot)
//! .await?;
//!
//! let full_restoration = immutable_file_range == ImmutableFileRange::Full;
//! let include_ancillary = download_unpack_options.include_ancillary;
//! let number_of_immutable_files_restored =
//! immutable_file_range.length(cardano_database_snapshot.beacon.immutable_file_number);
//! if let Err(error) = client
//! .cardano_database_v2()
//! .add_statistics(
//! full_restoration,
//! include_ancillary,
//! number_of_immutable_files_restored,
//! )
//! .await
//! {
//! println!("Could not increment snapshot download statistics: {error:?}");
//! }
//!
//! let allow_missing_immutables_files = false;
//! let merkle_proof = client
//! .cardano_database_v2()
//! .verify_cardano_database(
//! &certificate,
//! &cardano_database_snapshot,
//! &immutable_file_range,
//! allow_missing_immutables_files,
//! &target_directory,
//! &verified_digests,
//! )
//! .await?;
//!
//! let message = MessageBuilder::new()
//! .compute_cardano_database_message(&certificate, &merkle_proof)
//! .await?;
//!
//! assert!(certificate.match_message(&message));
//! # Ok(())
//! # }
//! ```
//!
//! ## Optional Features
//!
//! The following is a list of [Cargo features](https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-features-section) that can be
//! enabled or disabled:
//!
//! - **fs**: Enables file system-related functionalities.
//! - **unstable**: Enables experimental or in-development `mithril-client` features that may change.
//! - **rug-backend**: Enables usage of `rug` numerical backend in `mithril-stm` (dependency of `mithril-common`).
//! - **num-integer-backend**: Enables usage of `num-integer` numerical backend in `mithril-stm` (dependency of `mithril-common`).
//!
//! To allow fine-tuning of the http queries, the following [Reqwest](https://docs.rs/reqwest/latest/reqwest/#optional-features) features are re-exported.
//! No TLS backend is enabled by default: you must enable at least one of the TLS-related
//! features below, otherwise the crate will fail to compile.
//! - **native-tls**: Enables TLS functionality provided by `native-tls`.
//! - **native-tls-vendored**: Enables the `vendored` feature of `native-tls`.
//! - **native-tls-no-alpn**: Enables `native-tls` without its `alpn` feature.
//! - **native-tls-vendored-no-alpn**: Enables the `vendored` feature of `native-tls` without its `alpn` feature.
//! - **rustls**: Enables TLS functionality provided by `rustls`.
//! - **rustls-no-provider**: Enables TLS functionality provided by `rustls` without setting `aws-lc-rs` as its TLS provider.
// Ensure at least one TLS backend is enabled
compile_error!;
cfg_unstable!
cfg_fs!
pub use *;
pub use *;
pub use *;
pub