From 90118f945c9cefa8b2cbcc4c9cf7f7321c5aa000 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Tue, 3 Mar 2026 14:21:26 -0600 Subject: [PATCH] Initate spark payments from background Previously payments could block and we would end up waiting for the payment to complete before ever returning. This could cause our payment metadata to get screwed up as we weren't able to mark it as a trusted/rebalance payment immedaitely. Now we generate the id ourselves and init the payment in the background so we do not block on this and an safely set our payment metadata. --- orange-sdk/src/trusted_wallet/spark/mod.rs | 34 +++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/orange-sdk/src/trusted_wallet/spark/mod.rs b/orange-sdk/src/trusted_wallet/spark/mod.rs index f7629b7..5010599 100644 --- a/orange-sdk/src/trusted_wallet/spark/mod.rs +++ b/orange-sdk/src/trusted_wallet/spark/mod.rs @@ -218,17 +218,29 @@ impl TrustedWalletInterface for Spark { }; let prepare = self.spark_wallet.prepare_send_payment(params).await?; - let res = self - .spark_wallet - .send_payment(SendPaymentRequest { - prepare_response: prepare, - options: None, - idempotency_key: None, - }) - .await?; - - let id = parse_payment_id(&res.payment.id)?; - Ok(id) + let uuid = Uuid::now_v7(); + // spawn payment send in background since it can take a while and we don't want to block the caller + let w = Arc::clone(&self.spark_wallet); + let logger = Arc::clone(&self.logger); + tokio::spawn(async move { + match w + .send_payment(SendPaymentRequest { + prepare_response: prepare, + options: None, + idempotency_key: Some(uuid.to_string()), + }) + .await + { + Ok(res) => { + log_info!(logger, "Payment sent successfully: {res:?}"); + }, + Err(e) => { + log_error!(logger, "Failed to send payment: {e:?}"); + }, + } + }); + + Ok(parse_payment_id(&uuid.to_string())?) } else { Err(TrustedError::UnsupportedOperation( "Only BOLT 11 is currently supported".to_owned(),