From 542676788e322eda8ceb50525cb0b052eeb1a4f0 Mon Sep 17 00:00:00 2001 From: Daksh <41485688+Daksh14@users.noreply.github.com> Date: Sat, 28 Dec 2024 17:04:22 -0500 Subject: [PATCH] rusk-wallet: Throw error if archival node is not available --- rusk-wallet/src/bin/command.rs | 18 ++++++++++++------ rusk-wallet/src/bin/command/history.rs | 13 ------------- rusk-wallet/src/error.rs | 4 ++-- rusk-wallet/src/gql.rs | 4 ++-- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/rusk-wallet/src/bin/command.rs b/rusk-wallet/src/bin/command.rs index 5ad979113..750665c10 100644 --- a/rusk-wallet/src/bin/command.rs +++ b/rusk-wallet/src/bin/command.rs @@ -515,14 +515,20 @@ impl Command { wallet.sync().await?; let notes = wallet.get_all_notes(profile_idx).await?; - let public_key = wallet.public_address(profile_idx)?; + let address = wallet.public_address(profile_idx)?; - let history = history::moonlight_and_phoenix_history( - settings, notes, public_key, - ) - .await?; + let mut phoenix_history = + history::transaction_from_notes(settings, notes).await?; + + if let Ok(mut moonlight_history) = + history::moonlight_history(settings, address).await + { + phoenix_history.append(&mut moonlight_history); + } else { + tracing::error!("Cannot fetch archive history"); + } - Ok(RunResult::History(history)) + Ok(RunResult::History(phoenix_history)) } Command::Unshield { profile_idx, diff --git a/rusk-wallet/src/bin/command/history.rs b/rusk-wallet/src/bin/command/history.rs index de181bc72..950ff88b6 100644 --- a/rusk-wallet/src/bin/command/history.rs +++ b/rusk-wallet/src/bin/command/history.rs @@ -207,19 +207,6 @@ pub(crate) async fn moonlight_history( Ok(collected_history) } -pub async fn moonlight_and_phoenix_history( - settings: &Settings, - notes: Vec, - address: rusk_wallet::Address, -) -> anyhow::Result> { - let mut phoenix = transaction_from_notes(settings, notes).await?; - let mut moonlight = moonlight_history(settings, address).await?; - - phoenix.append(&mut moonlight); - - Ok(phoenix) -} - #[derive(PartialEq, Debug)] enum TransactionDirection { In, diff --git a/rusk-wallet/src/error.rs b/rusk-wallet/src/error.rs index 39dda28a0..807421fef 100644 --- a/rusk-wallet/src/error.rs +++ b/rusk-wallet/src/error.rs @@ -163,8 +163,8 @@ pub enum Error { #[error("Inquire error: {0}")] InquireError(String), /// Error while querying archival node - #[error("Archival node query error: {0}")] - ArchivalJsonError(String), + #[error("Archive node query error: {0}")] + ArchiveJsonError(String), } impl From for Error { diff --git a/rusk-wallet/src/gql.rs b/rusk-wallet/src/gql.rs index d942a17e8..731198b1f 100644 --- a/rusk-wallet/src/gql.rs +++ b/rusk-wallet/src/gql.rs @@ -191,11 +191,11 @@ impl GraphQL { let response = self .query(&query) .await - .map_err(|err| Error::ArchivalJsonError(err.to_string()))?; + .map_err(|err| Error::ArchiveJsonError(err.to_string()))?; let response = serde_json::from_slice::(&response) - .map_err(|err| Error::ArchivalJsonError(err.to_string()))?; + .map_err(|err| Error::ArchiveJsonError(err.to_string()))?; Ok(response) }