Skip to content

Commit

Permalink
Ignore not found
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 20, 2023
1 parent 6a189d9 commit aad65c8
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 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 @@ -34,13 +34,11 @@ impl Client {
/// 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_not_found(&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)
.collect(),
)
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.
Expand All @@ -50,13 +48,11 @@ impl Client {

/// 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>> {
Ok(
futures::future::join_all(output_ids.iter().map(|id| self.get_output_metadata(id)))
.await
.into_iter()
.filter_map(Result::ok)
.collect(),
)
futures::future::join_all(output_ids.iter().map(|id| self.get_output_metadata(id)))
.await
.into_iter()
.filter(|res| !matches!(res, Err(Error::Node(NodeApiError::NotFound(_)))))
.collect()
}

/// Requests outputs and their metadata by their output ID in parallel.
Expand All @@ -70,12 +66,10 @@ impl Client {
&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)))
.await
.into_iter()
.filter(|res| !matches!(res, Err(Error::Node(NodeApiError::NotFound(_)))))
.collect()
}
}

0 comments on commit aad65c8

Please sign in to comment.