Skip to content

Commit 65218e9

Browse files
committed
feature(client-lib, examples): adapt examples with the new compute_cardano_database_message function
1 parent b1c65bf commit 65218e9

File tree

2 files changed

+27
-27
lines changed
  • examples/client-cardano-database-v2/src
  • mithril-client/src/cardano_database_client

2 files changed

+27
-27
lines changed

examples/client-cardano-database-v2/src/main.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::time::Duration;
1717
use tokio::sync::RwLock;
1818

1919
use mithril_client::feedback::{FeedbackReceiver, MithrilEvent, MithrilEventCardanoDatabase};
20-
use mithril_client::{ClientBuilder, MessageBuilder, MithrilResult};
20+
use mithril_client::{ClientBuilder, MessageBuilder, MithrilError, MithrilResult};
2121

2222
#[derive(Parser, Debug)]
2323
#[command(version)]
@@ -104,21 +104,6 @@ async fn main() -> MithrilResult<()> {
104104
.download_and_verify_digests(&certificate, &cardano_database_snapshot)
105105
.await?;
106106

107-
println!("Computing Cardano database Merkle proof...",);
108-
let merkle_proof = client
109-
.cardano_database_v2()
110-
.compute_merkle_proof(
111-
&certificate,
112-
cardano_database_snapshot.beacon.immutable_file_number,
113-
&immutable_file_range,
114-
&unpacked_dir,
115-
&verified_digest,
116-
)
117-
.await?;
118-
merkle_proof
119-
.verify()
120-
.with_context(|| "Merkle proof verification failed")?;
121-
122107
println!("Sending usage statistics to the aggregator...");
123108
let full_restoration = immutable_file_range == ImmutableFileRange::Full;
124109
let include_ancillary = download_unpack_options.include_ancillary;
@@ -140,9 +125,17 @@ async fn main() -> MithrilResult<()> {
140125
"Computing Cardano database snapshot '{}' message...",
141126
cardano_database_snapshot.hash
142127
);
128+
let allow_missing_immutables_files = false;
143129
let message = wait_spinner(
144130
&progress_bar,
145-
MessageBuilder::new().compute_cardano_database_message(&certificate, merkle_proof.root()),
131+
MessageBuilder::new().compute_cardano_database_message(
132+
&certificate,
133+
&cardano_database_snapshot,
134+
&immutable_file_range,
135+
allow_missing_immutables_files,
136+
&unpacked_dir,
137+
&verified_digest,
138+
),
146139
)
147140
.await?;
148141

@@ -268,10 +261,13 @@ fn get_temp_dir() -> MithrilResult<PathBuf> {
268261
Ok(dir)
269262
}
270263

271-
async fn wait_spinner<T>(
264+
pub async fn wait_spinner<T, E>(
272265
progress_bar: &MultiProgress,
273-
future: impl Future<Output = MithrilResult<T>>,
274-
) -> MithrilResult<T> {
266+
future: impl Future<Output = Result<T, E>>,
267+
) -> MithrilResult<T>
268+
where
269+
MithrilError: From<E>,
270+
{
275271
let pb = progress_bar.add(ProgressBar::new_spinner());
276272
let spinner = async move {
277273
loop {
@@ -282,6 +278,6 @@ async fn wait_spinner<T>(
282278

283279
tokio::select! {
284280
_ = spinner => Err(anyhow!("timeout")),
285-
res = future => res,
281+
res = future => res.map_err(Into::into),
286282
}
287283
}

mithril-client/src/cardano_database_client/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//! - [get][CardanoDatabaseClient::get]: get a Cardano database data from its hash
55
//! - [list][CardanoDatabaseClient::list]: get the list of available Cardano database
66
//! - [download_unpack][CardanoDatabaseClient::download_unpack]: download and unpack a Cardano database snapshot for a given immutable files range
7-
//! - [compute_merkle_proof][CardanoDatabaseClient::compute_merkle_proof]: compute a Merkle proof for a given Cardano database snapshot and a given immutable files range
87
//!
98
//! # Get a Cardano database
109
//!
@@ -88,7 +87,7 @@
8887
//! ```no_run
8988
//! # #[cfg(feature = "fs")]
9089
//! # async fn run() -> mithril_client::MithrilResult<()> {
91-
//! use mithril_client::{ClientBuilder, cardano_database_client::{ImmutableFileRange, DownloadUnpackOptions}};
90+
//! use mithril_client::{ClientBuilder, MessageBuilder, cardano_database_client::{ImmutableFileRange, DownloadUnpackOptions}};
9291
//! use std::path::Path;
9392
//!
9493
//! let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;
@@ -120,10 +119,15 @@
120119
//! &cardano_database_snapshot)
121120
//! .await?;
122121
//!
123-
//! let merkle_proof = client
124-
//! .cardano_database_v2()
125-
//! .compute_merkle_proof(&certificate, cardano_database_snapshot.beacon.immutable_file_number, &immutable_file_range, &target_directory, &verified_digests)
126-
//! .await?;
122+
//! let allow_missing_immutables_files = false;
123+
//! let message = MessageBuilder::new().compute_cardano_database_message(
124+
//! &certificate,
125+
//! &cardano_database_snapshot,
126+
//! &immutable_file_range,
127+
//! allow_missing_immutables_files,
128+
//! &target_directory,
129+
//! &verified_digests,
130+
//! ).await?;
127131
//! #
128132
//! # Ok(())
129133
//! # }

0 commit comments

Comments
 (0)