Skip to content

Commit

Permalink
Merge pull request #593 from dleutenegger/include-payment-information…
Browse files Browse the repository at this point in the history
…-invoice-paid-event

Include payment information in `InvoicePaid`-event
  • Loading branch information
roeierez authored Nov 13, 2023
2 parents f5fac7e + 33a24e9 commit af67ee9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions libs/sdk-bindings/src/breez_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ dictionary LogEntry {
dictionary InvoicePaidDetails {
string payment_hash;
string bolt11;
Payment? payment;
};

dictionary PaymentFailedData {
Expand Down
4 changes: 3 additions & 1 deletion libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub struct PaymentFailedData {
pub struct InvoicePaidDetails {
pub payment_hash: String,
pub bolt11: String,
pub payment: Option<Payment>,
}

pub trait LogStream: Send + Sync {
Expand Down Expand Up @@ -1134,7 +1135,7 @@ impl BreezServices {
if payment.is_some() {
let res = cloned
.persister
.insert_or_update_payments(&vec![payment.unwrap()]);
.insert_or_update_payments(&vec![payment.clone().unwrap()]);
debug!("paid invoice was added to payments list {:?}", res);
}
if let Err(e) = cloned.do_sync(true).await {
Expand All @@ -1144,6 +1145,7 @@ impl BreezServices {
details: InvoicePaidDetails {
payment_hash: hex::encode(p.payment_hash),
bolt11: p.bolt11,
payment,
},
}).await;
}
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-core/src/bridge_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@ impl support::IntoDart for InvoicePaidDetails {
vec![
self.payment_hash.into_into_dart().into_dart(),
self.bolt11.into_into_dart().into_dart(),
self.payment.into_dart(),
]
.into_dart()
}
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-core/src/swap_in/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ mod tests {
details: crate::InvoicePaidDetails {
payment_hash: hex::encode(swap_info.payment_hash.clone()),
bolt11: "".to_string(),
payment: None,
},
})
.await?;
Expand Down
5 changes: 4 additions & 1 deletion libs/sdk-flutter/lib/bridge_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,12 @@ sealed class InputType with _$InputType {
class InvoicePaidDetails {
final String paymentHash;
final String bolt11;
final Payment? payment;

const InvoicePaidDetails({
required this.paymentHash,
required this.bolt11,
this.payment,
});
}

Expand Down Expand Up @@ -2802,10 +2804,11 @@ class BreezSdkCoreImpl implements BreezSdkCore {

InvoicePaidDetails _wire2api_invoice_paid_details(dynamic raw) {
final arr = raw as List<dynamic>;
if (arr.length != 2) throw Exception('unexpected arr length: expect 2 but see ${arr.length}');
if (arr.length != 3) throw Exception('unexpected arr length: expect 3 but see ${arr.length}');
return InvoicePaidDetails(
paymentHash: _wire2api_String(arr[0]),
bolt11: _wire2api_String(arr[1]),
payment: _wire2api_opt_box_autoadd_payment(arr[2]),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,16 +633,19 @@ fun asInvoicePaidDetails(invoicePaidDetails: ReadableMap): InvoicePaidDetails? {
}
val paymentHash = invoicePaidDetails.getString("paymentHash")!!
val bolt11 = invoicePaidDetails.getString("bolt11")!!
val payment = if (hasNonNullKey(invoicePaidDetails, "payment")) invoicePaidDetails.getMap("payment")?.let { asPayment(it) } else null
return InvoicePaidDetails(
paymentHash,
bolt11,
payment,
)
}

fun readableMapOf(invoicePaidDetails: InvoicePaidDetails): ReadableMap {
return readableMapOf(
"paymentHash" to invoicePaidDetails.paymentHash,
"bolt11" to invoicePaidDetails.bolt11,
"payment" to invoicePaidDetails.payment?.let { readableMapOf(it) },
)
}

Expand Down
8 changes: 7 additions & 1 deletion libs/sdk-react-native/ios/BreezSDKMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,23 @@ class BreezSDKMapper {
static func asInvoicePaidDetails(invoicePaidDetails: [String: Any?]) throws -> InvoicePaidDetails {
guard let paymentHash = invoicePaidDetails["paymentHash"] as? String else { throw SdkError.Generic(message: "Missing mandatory field paymentHash for type InvoicePaidDetails") }
guard let bolt11 = invoicePaidDetails["bolt11"] as? String else { throw SdkError.Generic(message: "Missing mandatory field bolt11 for type InvoicePaidDetails") }
var payment: Payment?
if let paymentTmp = invoicePaidDetails["payment"] as? [String: Any?] {
payment = try asPayment(payment: paymentTmp)
}

return InvoicePaidDetails(
paymentHash: paymentHash,
bolt11: bolt11
bolt11: bolt11,
payment: payment
)
}

static func dictionaryOf(invoicePaidDetails: InvoicePaidDetails) -> [String: Any?] {
return [
"paymentHash": invoicePaidDetails.paymentHash,
"bolt11": invoicePaidDetails.bolt11,
"payment": invoicePaidDetails.payment == nil ? nil : dictionaryOf(payment: invoicePaidDetails.payment!),
]
}

Expand Down
1 change: 1 addition & 0 deletions libs/sdk-react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export type GreenlightNodeConfig = {
export type InvoicePaidDetails = {
paymentHash: string
bolt11: string
payment?: Payment
}

export type LnInvoice = {
Expand Down

0 comments on commit af67ee9

Please sign in to comment.