Skip to content

Commit a538481

Browse files
committed
Use transfer id as id of outgoing lightning payments
1 parent 689a21b commit a538481

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

crates/breez-sdk/core/src/models/adaptors/spark_sdk.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ impl Payment {
154154
payment: LightningSendPayment,
155155
amount_sat: u64,
156156
) -> Result<Self, SdkError> {
157+
let id = payment
158+
.transfer_id
159+
.ok_or(SdkError::Generic(
160+
"Transfer id not found in LightningSendPayment".to_string(),
161+
))?
162+
.clone()
163+
.to_string();
164+
157165
let status = match payment.status {
158166
LightningSendStatus::LightningPaymentSucceeded => PaymentStatus::Completed,
159167
LightningSendStatus::LightningPaymentFailed => PaymentStatus::Failed,
@@ -173,7 +181,7 @@ impl Payment {
173181
};
174182

175183
Ok(Payment {
176-
id: payment.id,
184+
id,
177185
payment_type: PaymentType::Send,
178186
status,
179187
amount: amount_sat,

crates/breez-sdk/core/src/sdk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl BreezSdk {
429429
}
430430

431431
/// Syncs pending payments so that we have their latest status
432-
/// Uses the Spark SDK API (SparkWallet) to get the latest status of the payments
432+
/// Uses the Spark SDK API to get the latest status of the payments
433433
async fn sync_pending_payments(&self) -> Result<(), SdkError> {
434434
// TODO: implement pending payment syncing using sparkscan API (including live updates)
435435
// Advantages:
@@ -438,7 +438,7 @@ impl BreezSdk {
438438
// Why it can't be done now:
439439
// - Sparkscan needs one of the following:
440440
// - Batch transaction querying by id
441-
// - Sorting by updated_at timestamp in address transactions query (simpler)
441+
// - Sorting by updated_at timestamp in address transactions query (simpler)
442442

443443
let pending_payments = self
444444
.storage

crates/spark/src/services/lightning.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,16 @@ impl LightningService {
332332
let swap = self
333333
.start_lightning_swap(invoice, amount_to_send, leaves)
334334
.await?;
335-
let _ = self
335+
let transfer = self
336336
.transfer_service
337337
.deliver_transfer_package(&swap.transfer, &swap.leaves, Default::default())
338338
.await?;
339-
self.finalize_lightning_swap(&swap).await
339+
let mut lightning_payment = self.finalize_lightning_swap(&swap).await?;
340+
// If ssp doesn't return a transfer id, we use the transfer id from the transfer service
341+
if lightning_payment.transfer_id.is_none() {
342+
lightning_payment.transfer_id = Some(transfer.id);
343+
}
344+
Ok(lightning_payment)
340345
}
341346

342347
async fn start_lightning_swap(

0 commit comments

Comments
 (0)