Skip to content

Commit

Permalink
rusk-wallet: Throw error if archival node is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksh14 committed Dec 30, 2024
1 parent 3f6349c commit 5426767
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
18 changes: 12 additions & 6 deletions rusk-wallet/src/bin/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions rusk-wallet/src/bin/command/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,6 @@ pub(crate) async fn moonlight_history(
Ok(collected_history)
}

pub async fn moonlight_and_phoenix_history(
settings: &Settings,
notes: Vec<DecodedNote>,
address: rusk_wallet::Address,
) -> anyhow::Result<Vec<TransactionHistory>> {
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,
Expand Down
4 changes: 2 additions & 2 deletions rusk-wallet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dusk_bytes::Error> for Error {
Expand Down
4 changes: 2 additions & 2 deletions rusk-wallet/src/gql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FullMoonlightHistory>(&response)
.map_err(|err| Error::ArchivalJsonError(err.to_string()))?;
.map_err(|err| Error::ArchiveJsonError(err.to_string()))?;

Ok(response)
}
Expand Down

0 comments on commit 5426767

Please sign in to comment.