Skip to content

Commit 0a860b6

Browse files
committed
WIP: adapt call of compute_cardano_database_message to handle the new error
1 parent fda10d2 commit 0a860b6

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

mithril-client-cli/src/commands/cardano_db/verify.rs

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use std::{
44
sync::Arc,
55
};
66

7-
use anyhow::Context;
7+
use anyhow::{Context, anyhow};
88
use chrono::Utc;
99
use clap::Parser;
10-
use mithril_client::MithrilResult;
10+
use mithril_client::{ComputeCardanoDatabaseMessageError, MithrilResult};
1111

1212
use crate::{
1313
CommandContext,
@@ -122,26 +122,38 @@ impl CardanoDbVerifyCommand {
122122
db_dir,
123123
&verified_digests,
124124
)
125-
.await?;
126-
127-
shared_steps::verify_message_matches_certificate(
128-
&context.logger().clone(),
129-
4,
130-
&progress_printer,
131-
&certificate,
132-
&message,
133-
&cardano_db_message,
134-
db_dir,
135-
)
136-
.await?;
137-
138-
Self::log_verified_information(
139-
db_dir,
140-
&cardano_db_message.hash,
141-
context.is_json_output_enabled(),
142-
)?;
143-
144-
Ok(())
125+
.await;
126+
127+
//TODO due to wait spinner, we need to cast error to access the inner error's lists, could it be improved to avoid downcasting?
128+
match message {
129+
Err(e) => match e.downcast_ref::<ComputeCardanoDatabaseMessageError>() {
130+
Some(ComputeCardanoDatabaseMessageError::ImmutableFilesVerification(lists)) => {
131+
// let missing_files = lists.missing;
132+
Ok(())
133+
}
134+
_ => Err(anyhow!(e)),
135+
},
136+
Ok(message) => {
137+
shared_steps::verify_message_matches_certificate(
138+
&context.logger().clone(),
139+
4,
140+
&progress_printer,
141+
&certificate,
142+
&message,
143+
&cardano_db_message,
144+
db_dir,
145+
)
146+
.await?;
147+
148+
Self::log_verified_information(
149+
db_dir,
150+
&cardano_db_message.hash,
151+
context.is_json_output_enabled(),
152+
)?;
153+
154+
Ok(())
155+
}
156+
}
145157
}
146158

147159
fn log_verified_information(

mithril-client-cli/src/utils/cardano_db.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use indicatif::{MultiProgress, ProgressBar};
44
use std::time::Duration;
55

66
use super::CardanoDbDownloadCheckerError;
7-
use mithril_client::{MithrilError, MithrilResult};
7+
use mithril_client::{ComputeCardanoDatabaseMessageError, MithrilError, MithrilResult};
88

99
/// Utility functions for to the CardanoDb commands
1010
pub struct CardanoDbUtils;
@@ -22,10 +22,13 @@ impl CardanoDbUtils {
2222
}
2323

2424
/// Display a spinner while waiting for the result of a future
25-
pub async fn wait_spinner<T>(
25+
pub async fn wait_spinner<T, E>(
2626
progress_bar: &MultiProgress,
27-
future: impl Future<Output = MithrilResult<T>>,
28-
) -> MithrilResult<T> {
27+
future: impl Future<Output = Result<T, E>>,
28+
) -> MithrilResult<T>
29+
where
30+
MithrilError: From<E>,
31+
{
2932
let pb = progress_bar.add(ProgressBar::new_spinner());
3033
let spinner = async move {
3134
loop {
@@ -36,7 +39,7 @@ impl CardanoDbUtils {
3639

3740
tokio::select! {
3841
_ = spinner => Err(anyhow!("timeout")),
39-
res = future => res,
42+
res = future => res.map_err(Into::into),
4043
}
4144
}
4245

0 commit comments

Comments
 (0)