Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change *_ignore_errors to *_ignore_not_found #1642

2 changes: 1 addition & 1 deletion bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
}
ClientMethod::GetOutputsIgnoreErrors { output_ids } => {
let outputs_response = client
.get_outputs_with_metadata_ignore_errors(&output_ids)
.get_outputs_with_metadata_ignore_not_found(&output_ids)
.await?
.iter()
.map(OutputWithMetadataResponse::from)
Expand Down
2 changes: 1 addition & 1 deletion cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ async fn print_outputs(mut outputs: Vec<OutputData>, title: &str) -> Result<(),
};

println_log_info!(
"{:<5}{}\t{}\t{}",
"{:<5}{} {:<16}{}",
i,
&output_data.output_id,
kind_str,
Expand Down
50 changes: 22 additions & 28 deletions sdk/src/client/node_api/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod routes;
use packable::PackableExt;

use crate::{
client::{Client, Result},
client::{node_api::error::Error as NodeApiError, Client, Error, Result},
types::block::output::{Output, OutputId, OutputMetadata, OutputWithMetadata},
};

Expand All @@ -31,51 +31,45 @@ impl Client {
futures::future::try_join_all(output_ids.iter().map(|id| self.get_output(id))).await
}

/// Requests outputs by their output ID in parallel, ignoring failed requests.
/// Requests outputs by their output ID in parallel, ignoring outputs not found.
/// Useful to get data about spent outputs, that might not be pruned yet.
pub async fn get_outputs_ignore_errors(&self, output_ids: &[OutputId]) -> Result<Vec<Output>> {
Ok(
futures::future::join_all(output_ids.iter().map(|id| self.get_output(id)))
.await
.into_iter()
.filter_map(Result::ok)
Thoralf-M marked this conversation as resolved.
Show resolved Hide resolved
.collect(),
)
pub async fn get_outputs_ignore_not_found(&self, output_ids: &[OutputId]) -> Result<Vec<Output>> {
futures::future::join_all(output_ids.iter().map(|id| self.get_output(id)))
.await
.into_iter()
.filter(|res| !matches!(res, Err(Error::Node(NodeApiError::NotFound(_)))))
.collect()
}

/// Requests metadata for outputs by their output ID in parallel.
pub async fn get_outputs_metadata(&self, output_ids: &[OutputId]) -> Result<Vec<OutputMetadata>> {
futures::future::try_join_all(output_ids.iter().map(|id| self.get_output_metadata(id))).await
}

/// Requests metadata for outputs by their output ID in parallel, ignoring failed requests.
pub async fn get_outputs_metadata_ignore_errors(&self, output_ids: &[OutputId]) -> Result<Vec<OutputMetadata>> {
Ok(
futures::future::join_all(output_ids.iter().map(|id| self.get_output_metadata(id)))
.await
.into_iter()
.filter_map(Result::ok)
.collect(),
)
/// Requests metadata for outputs by their output ID in parallel, ignoring outputs not found.
pub async fn get_outputs_metadata_ignore_not_found(&self, output_ids: &[OutputId]) -> Result<Vec<OutputMetadata>> {
futures::future::join_all(output_ids.iter().map(|id| self.get_output_metadata(id)))
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
.await
.into_iter()
.filter(|res| !matches!(res, Err(Error::Node(NodeApiError::NotFound(_)))))
.collect()
}

/// Requests outputs and their metadata by their output ID in parallel.
pub async fn get_outputs_with_metadata(&self, output_ids: &[OutputId]) -> Result<Vec<OutputWithMetadata>> {
futures::future::try_join_all(output_ids.iter().map(|id| self.get_output_with_metadata(id))).await
}

/// Requests outputs and their metadata by their output ID in parallel, ignoring failed requests.
/// Requests outputs and their metadata by their output ID in parallel, ignoring outputs not found.
/// Useful to get data about spent outputs, that might not be pruned yet.
pub async fn get_outputs_with_metadata_ignore_errors(
pub async fn get_outputs_with_metadata_ignore_not_found(
&self,
output_ids: &[OutputId],
) -> Result<Vec<OutputWithMetadata>> {
Ok(
futures::future::join_all(output_ids.iter().map(|id| self.get_output_with_metadata(id)))
.await
.into_iter()
.filter_map(Result::ok)
.collect(),
)
futures::future::join_all(output_ids.iter().map(|id| self.get_output_with_metadata(id)))
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
.await
.into_iter()
.filter(|res| !matches!(res, Err(Error::Node(NodeApiError::NotFound(_)))))
.collect()
}
}
12 changes: 6 additions & 6 deletions sdk/src/wallet/operations/syncing/addresses/output_ids/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ where
tasks.push(
async {
let bech32_address = address.clone();
let account = self.clone();
let wallet = self.clone();
tokio::spawn(async move {
account
wallet
.get_basic_output_ids_with_any_unlock_condition(bech32_address)
.await
})
Expand All @@ -108,9 +108,9 @@ where
tasks.push(
async {
let bech32_address = address.clone();
let account = self.clone();
let wallet = self.clone();
tokio::spawn(async move {
account
wallet
.get_nft_output_ids_with_any_unlock_condition(bech32_address)
.await
})
Expand Down Expand Up @@ -140,9 +140,9 @@ where
async {
let bech32_address = address.clone();
let sync_options = sync_options.clone();
let account = self.clone();
let wallet = self.clone();
tokio::spawn(async move {
account
wallet
.get_account_and_foundry_output_ids(bech32_address, &sync_options)
.await
})
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/operations/syncing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ where
log::debug!("[SYNC] spent_or_not_synced_outputs: {spent_or_not_synced_output_ids:?}");
let spent_or_unsynced_output_metadata_responses = self
.client()
.get_outputs_metadata_ignore_errors(&spent_or_not_synced_output_ids)
.get_outputs_metadata_ignore_not_found(&spent_or_not_synced_output_ids)
.await?;

// Add the output response to the output ids, the output response is optional, because an output could be
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/operations/syncing/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub(crate) async fn get_inputs_for_transaction_payload(
.collect::<Vec<_>>();

client
.get_outputs_with_metadata_ignore_errors(&output_ids)
.get_outputs_with_metadata_ignore_not_found(&output_ids)
.await
.map_err(|e| e.into())
}
Loading