Skip to content

Commit

Permalink
Make *_ignore_errors infallible
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 19, 2023
1 parent e2703a1 commit bba983f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 36 deletions.
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 @@ -260,7 +260,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)
.await?
.await
.iter()
.map(OutputWithMetadataResponse::from)
.collect();
Expand Down
45 changes: 18 additions & 27 deletions sdk/src/client/node_api/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ impl Client {

/// Requests outputs by their output ID in parallel, ignoring failed requests.
/// 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)
.collect(),
)
pub async fn get_outputs_ignore_errors(&self, output_ids: &[OutputId]) -> Vec<Output> {
futures::future::join_all(output_ids.iter().map(|id| self.get_output(id)))
.await
.into_iter()
.filter_map(Result::ok)
.collect()
}

/// Requests metadata for outputs by their output ID in parallel.
Expand All @@ -49,14 +47,12 @@ impl Client {
}

/// 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(),
)
pub async fn get_outputs_metadata_ignore_errors(&self, output_ids: &[OutputId]) -> Vec<OutputMetadata> {
futures::future::join_all(output_ids.iter().map(|id| self.get_output_metadata(id)))
.await
.into_iter()
.filter_map(Result::ok)
.collect()
}

/// Requests outputs and their metadata by their output ID in parallel.
Expand All @@ -66,16 +62,11 @@ impl Client {

/// Requests outputs and their metadata by their output ID in parallel, ignoring failed requests.
/// Useful to get data about spent outputs, that might not be pruned yet.
pub async fn get_outputs_with_metadata_ignore_errors(
&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(),
)
pub async fn get_outputs_with_metadata_ignore_errors(&self, output_ids: &[OutputId]) -> Vec<OutputWithMetadata> {
futures::future::join_all(output_ids.iter().map(|id| self.get_output_with_metadata(id)))
.await
.into_iter()
.filter_map(Result::ok)
.collect()
}
}
5 changes: 4 additions & 1 deletion sdk/src/wallet/operations/syncing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ where
let time_now = crate::client::unix_timestamp_now().as_millis();
let mut last_synced = self.last_synced.lock().await;
log::debug!("[SYNC] last time synced before {}ms", time_now - *last_synced);

if !options.force_syncing && time_now - *last_synced < MIN_SYNC_INTERVAL {
log::debug!(
"[SYNC] synced within the latest {} ms, only calculating balance",
Expand Down Expand Up @@ -88,7 +89,9 @@ where
// Update last_synced mutex
let time_now = crate::client::unix_timestamp_now().as_millis();
*last_synced = time_now;

log::debug!("[SYNC] finished syncing in {:.2?}", syc_start_time.elapsed());

Ok(balance)
}

Expand Down Expand Up @@ -120,7 +123,7 @@ where
let spent_or_unsynced_output_metadata_responses = self
.client()
.get_outputs_metadata_ignore_errors(&spent_or_not_synced_output_ids)
.await?;
.await;

// Add the output response to the output ids, the output response is optional, because an output could be
// pruned and then we can't get the metadata
Expand Down
10 changes: 3 additions & 7 deletions sdk/src/wallet/operations/syncing/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ where
basic_block_body.payload()
{
let inputs_with_meta =
get_inputs_for_transaction_payload(&client, transaction_payload)
.await?;
get_inputs_for_transaction_payload(&client, transaction_payload).await;
let inputs_response: Vec<OutputWithMetadataResponse> = inputs_with_meta
.into_iter()
.map(OutputWithMetadataResponse::from)
Expand Down Expand Up @@ -210,7 +209,7 @@ where
pub(crate) async fn get_inputs_for_transaction_payload(
client: &Client,
transaction_payload: &SignedTransactionPayload,
) -> crate::wallet::Result<Vec<OutputWithMetadata>> {
) -> Vec<OutputWithMetadata> {
let output_ids = transaction_payload
.transaction()
.inputs()
Expand All @@ -221,8 +220,5 @@ pub(crate) async fn get_inputs_for_transaction_payload(
})
.collect::<Vec<_>>();

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

0 comments on commit bba983f

Please sign in to comment.