mithril_client/cardano_database_client/mod.rs
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
//! A client to retrieve Cardano databases data from an Aggregator.
//!
//! In order to do so it defines a [CardanoDatabaseClient] which exposes the following features:
//! - [get][CardanoDatabaseClient::get]: get a Cardano database data from its hash
//! - [list][CardanoDatabaseClient::list]: get the list of available Cardano database
//! - [download_unpack][CardanoDatabaseClient::download_unpack]: download and unpack a Cardano database snapshot for a given immutable files range
//! - [compute_merkle_proof][CardanoDatabaseClient::compute_merkle_proof]: compute a Merkle proof for a given Cardano database snapshot and a given immutable files range
//!
//! # Get a Cardano database
//!
//! To get a Cardano database using the [ClientBuilder][crate::client::ClientBuilder].
//!
//! ```no_run
//! # async fn run() -> mithril_client::MithrilResult<()> {
//! use mithril_client::ClientBuilder;
//!
//! let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;
//! let cardano_database = client.cardano_database().get("CARDANO_DATABASE_HASH").await?.unwrap();
//!
//! println!(
//! "Cardano database hash={}, merkle_root={}, immutable_file_number={:?}",
//! cardano_database.hash,
//! cardano_database.merkle_root,
//! cardano_database.beacon.immutable_file_number
//! );
//! # Ok(())
//! # }
//! ```
//!
//! # List available Cardano databases
//!
//! To list available Cardano databases using the [ClientBuilder][crate::client::ClientBuilder].
//!
//! ```no_run
//! # async fn run() -> mithril_client::MithrilResult<()> {
//! use mithril_client::ClientBuilder;
//!
//! let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;
//! let cardano_databases = client.cardano_database().list().await?;
//!
//! for cardano_database in cardano_databases {
//! println!("Cardano database hash={}, immutable_file_number={}", cardano_database.hash, cardano_database.beacon.immutable_file_number);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! # Download a Cardano database snapshot
//! **Note:** _Available on crate feature_ **fs** _only._
//!
//! To download a partial or a full Cardano database folder the [ClientBuilder][crate::client::ClientBuilder].
//!
//! ```no_run
//! # #[cfg(feature = "fs")]
//! # async fn run() -> mithril_client::MithrilResult<()> {
//! use mithril_client::{ClientBuilder, cardano_database_client::{ImmutableFileRange, DownloadUnpackOptions}};
//! use std::path::Path;
//!
//! let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;
//! let cardano_database_snapshot = client.cardano_database().get("CARDANO_DATABASE_HASH").await?.unwrap();
//!
//! // 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()
//! .download_unpack(
//! &cardano_database_snapshot,
//! &immutable_file_range,
//! &target_directory,
//! download_unpack_options,
//! )
//! .await?;
//! #
//! # Ok(())
//! # }
//! ```
//! # Compute a Merkle proof for a Cardano database snapshot
//! **Note:** _Available on crate feature_ **fs** _only._
//!
//! To compute proof of membership of downloaded immutable files in a Cardano database folder the [ClientBuilder][crate::client::ClientBuilder].
//!
//! ```no_run
//! # #[cfg(feature = "fs")]
//! # async fn run() -> mithril_client::MithrilResult<()> {
//! use mithril_client::{ClientBuilder, cardano_database_client::{ImmutableFileRange, DownloadUnpackOptions}};
//! use std::path::Path;
//!
//! let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;
//! let cardano_database_snapshot = client.cardano_database().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::Full;
//! let download_unpack_options = DownloadUnpackOptions {
//! allow_override: true,
//! include_ancillary: true,
//! ..DownloadUnpackOptions::default()
//! };
//! client
//! .cardano_database()
//! .download_unpack(
//! &cardano_database_snapshot,
//! &immutable_file_range,
//! &target_directory,
//! download_unpack_options,
//! )
//! .await?;
//!
//! let merkle_proof = client
//! .cardano_database()
//! .compute_merkle_proof(&certificate, &cardano_database_snapshot, &immutable_file_range, &target_directory)
//! .await?;
//! #
//! # Ok(())
//! # }
//! ```
mod api;
mod fetch;
#[cfg(test)]
pub(crate) use api::test_dependency_injector::CardanoDatabaseClientDependencyInjector;
pub use api::CardanoDatabaseClient;
cfg_fs! {
mod immutable_file_range;
mod download_unpack;
mod proving;
pub use download_unpack::DownloadUnpackOptions;
pub use immutable_file_range::ImmutableFileRange;
}