Skip to content

Commit 7191912

Browse files
committed
feature(client-cli): adapt call of compute_cardano_database_message to handle the new typed error
1 parent 862bc82 commit 7191912

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

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

Lines changed: 33 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,37 @@ 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+
match message {
128+
Err(e) => match e.downcast_ref::<ComputeCardanoDatabaseMessageError>() {
129+
Some(ComputeCardanoDatabaseMessageError::ImmutableFilesVerification(lists)) => {
130+
// let missing_files = lists.missing;
131+
Ok(())
132+
}
133+
_ => Err(e),
134+
},
135+
Ok(message) => {
136+
shared_steps::verify_message_matches_certificate(
137+
&context.logger().clone(),
138+
4,
139+
&progress_printer,
140+
&certificate,
141+
&message,
142+
&cardano_db_message,
143+
db_dir,
144+
)
145+
.await?;
146+
147+
Self::log_verified_information(
148+
db_dir,
149+
&cardano_db_message.hash,
150+
context.is_json_output_enabled(),
151+
)?;
152+
153+
Ok(())
154+
}
155+
}
145156
}
146157

147158
fn log_verified_information(

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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)