diff --git a/lib/bindings/langs/flutter/breez_liquid_sdk/include/breez_liquid_sdk.h b/lib/bindings/langs/flutter/breez_liquid_sdk/include/breez_liquid_sdk.h index f60de32..b92de84 100644 --- a/lib/bindings/langs/flutter/breez_liquid_sdk/include/breez_liquid_sdk.h +++ b/lib/bindings/langs/flutter/breez_liquid_sdk/include/breez_liquid_sdk.h @@ -68,6 +68,7 @@ typedef struct wire_cst_payment { uint64_t amount_sat; uint64_t fees_sat; struct wire_cst_list_prim_u_8_strict *preimage; + struct wire_cst_list_prim_u_8_strict *bolt11; struct wire_cst_list_prim_u_8_strict *refund_tx_id; uint64_t *refund_tx_amount_sat; int32_t payment_type; diff --git a/lib/bindings/src/breez_liquid_sdk.udl b/lib/bindings/src/breez_liquid_sdk.udl index 4bc8150..843beb2 100644 --- a/lib/bindings/src/breez_liquid_sdk.udl +++ b/lib/bindings/src/breez_liquid_sdk.udl @@ -125,6 +125,7 @@ dictionary Payment { u64 amount_sat; u64 fees_sat; string? preimage = null; + string? bolt11 = null; string? refund_tx_id = null; u64? refund_tx_amount_sat = null; PaymentType payment_type; diff --git a/lib/core/src/frb_generated.io.rs b/lib/core/src/frb_generated.io.rs index 9a594ef..8c496da 100644 --- a/lib/core/src/frb_generated.io.rs +++ b/lib/core/src/frb_generated.io.rs @@ -345,6 +345,7 @@ impl CstDecode for wire_cst_payment { amount_sat: self.amount_sat.cst_decode(), fees_sat: self.fees_sat.cst_decode(), preimage: self.preimage.cst_decode(), + bolt11: self.bolt11.cst_decode(), refund_tx_id: self.refund_tx_id.cst_decode(), refund_tx_amount_sat: self.refund_tx_amount_sat.cst_decode(), payment_type: self.payment_type.cst_decode(), @@ -636,6 +637,7 @@ impl NewWithNullPtr for wire_cst_payment { amount_sat: Default::default(), fees_sat: Default::default(), preimage: core::ptr::null_mut(), + bolt11: core::ptr::null_mut(), refund_tx_id: core::ptr::null_mut(), refund_tx_amount_sat: core::ptr::null_mut(), payment_type: Default::default(), @@ -1223,6 +1225,7 @@ pub struct wire_cst_payment { amount_sat: u64, fees_sat: u64, preimage: *mut wire_cst_list_prim_u_8_strict, + bolt11: *mut wire_cst_list_prim_u_8_strict, refund_tx_id: *mut wire_cst_list_prim_u_8_strict, refund_tx_amount_sat: *mut u64, payment_type: i32, diff --git a/lib/core/src/frb_generated.rs b/lib/core/src/frb_generated.rs index a61e7e7..5424603 100644 --- a/lib/core/src/frb_generated.rs +++ b/lib/core/src/frb_generated.rs @@ -1051,6 +1051,7 @@ impl SseDecode for crate::model::Payment { let mut var_amountSat = ::sse_decode(deserializer); let mut var_feesSat = ::sse_decode(deserializer); let mut var_preimage = >::sse_decode(deserializer); + let mut var_bolt11 = >::sse_decode(deserializer); let mut var_refundTxId = >::sse_decode(deserializer); let mut var_refundTxAmountSat = >::sse_decode(deserializer); let mut var_paymentType = ::sse_decode(deserializer); @@ -1062,6 +1063,7 @@ impl SseDecode for crate::model::Payment { amount_sat: var_amountSat, fees_sat: var_feesSat, preimage: var_preimage, + bolt11: var_bolt11, refund_tx_id: var_refundTxId, refund_tx_amount_sat: var_refundTxAmountSat, payment_type: var_paymentType, @@ -1582,6 +1584,7 @@ impl flutter_rust_bridge::IntoDart for crate::model::Payment { self.amount_sat.into_into_dart().into_dart(), self.fees_sat.into_into_dart().into_dart(), self.preimage.into_into_dart().into_dart(), + self.bolt11.into_into_dart().into_dart(), self.refund_tx_id.into_into_dart().into_dart(), self.refund_tx_amount_sat.into_into_dart().into_dart(), self.payment_type.into_into_dart().into_dart(), @@ -2125,6 +2128,7 @@ impl SseEncode for crate::model::Payment { ::sse_encode(self.amount_sat, serializer); ::sse_encode(self.fees_sat, serializer); >::sse_encode(self.preimage, serializer); + >::sse_encode(self.bolt11, serializer); >::sse_encode(self.refund_tx_id, serializer); >::sse_encode(self.refund_tx_amount_sat, serializer); ::sse_encode(self.payment_type, serializer); diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index 1e04f08..5d1538b 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -533,6 +533,8 @@ pub struct PaymentSwapData { pub preimage: Option, + pub bolt11: String, + /// Amount sent by the swap payer pub payer_amount_sat: u64, @@ -586,6 +588,11 @@ pub struct Payment { /// In case of a Send swap, this is the preimage of the paid invoice (proof of payment). pub preimage: Option, + /// Represents the invoice associated with a payment + /// In the case of a Send payment, this is the invoice paid by the swapper + /// In the case of a Receive payment, this is the invoice paid by the user + pub bolt11: Option, + /// For a Send swap which was refunded, this is the refund tx id pub refund_tx_id: Option, @@ -615,6 +622,7 @@ impl Payment { amount_sat, fees_sat: swap.payer_amount_sat - swap.receiver_amount_sat, preimage: swap.preimage, + bolt11: Some(swap.bolt11), refund_tx_id: swap.refund_tx_id, refund_tx_amount_sat: swap.refund_tx_amount_sat, payment_type, @@ -639,6 +647,7 @@ impl Payment { }, }, preimage: swap.as_ref().and_then(|s| s.preimage.clone()), + bolt11: swap.as_ref().map(|s| s.bolt11.clone()), refund_tx_id: swap.as_ref().and_then(|s| s.refund_tx_id.clone()), refund_tx_amount_sat: swap.as_ref().and_then(|s| s.refund_tx_amount_sat), payment_type: tx.payment_type, diff --git a/lib/core/src/persist/mod.rs b/lib/core/src/persist/mod.rs index 89ac649..cea6c8b 100644 --- a/lib/core/src/persist/mod.rs +++ b/lib/core/src/persist/mod.rs @@ -106,11 +106,13 @@ impl Persister { ptx.is_confirmed, rs.id, rs.created_at, + rs.invoice, rs.payer_amount_sat, rs.receiver_amount_sat, rs.state, ss.id, ss.created_at, + ss.invoice, ss.preimage, ss.refund_tx_id, ss.payer_amount_sat, @@ -151,18 +153,20 @@ impl Persister { let maybe_receive_swap_id: Option = row.get(6)?; let maybe_receive_swap_created_at: Option = row.get(7)?; - let maybe_receive_swap_payer_amount_sat: Option = row.get(8)?; - let maybe_receive_swap_receiver_amount_sat: Option = row.get(9)?; - let maybe_receive_swap_receiver_state: Option = row.get(10)?; + let maybe_receive_swap_invoice: Option = row.get(8)?; + let maybe_receive_swap_payer_amount_sat: Option = row.get(9)?; + let maybe_receive_swap_receiver_amount_sat: Option = row.get(10)?; + let maybe_receive_swap_receiver_state: Option = row.get(11)?; - let maybe_send_swap_id: Option = row.get(11)?; - let maybe_send_swap_created_at: Option = row.get(12)?; - let maybe_send_swap_preimage: Option = row.get(13)?; - let maybe_send_swap_refund_tx_id: Option = row.get(14)?; - let maybe_send_swap_payer_amount_sat: Option = row.get(15)?; - let maybe_send_swap_receiver_amount_sat: Option = row.get(16)?; - let maybe_send_swap_state: Option = row.get(17)?; - let maybe_send_swap_refund_tx_amount_sat: Option = row.get(18)?; + let maybe_send_swap_id: Option = row.get(12)?; + let maybe_send_swap_created_at: Option = row.get(13)?; + let maybe_send_swap_invoice: Option = row.get(14)?; + let maybe_send_swap_preimage: Option = row.get(15)?; + let maybe_send_swap_refund_tx_id: Option = row.get(16)?; + let maybe_send_swap_payer_amount_sat: Option = row.get(17)?; + let maybe_send_swap_receiver_amount_sat: Option = row.get(18)?; + let maybe_send_swap_state: Option = row.get(19)?; + let maybe_send_swap_refund_tx_amount_sat: Option = row.get(20)?; let (swap, payment_type) = match maybe_receive_swap_id { Some(receive_swap_id) => ( @@ -170,6 +174,7 @@ impl Persister { swap_id: receive_swap_id, created_at: maybe_receive_swap_created_at.unwrap_or(utils::now()), preimage: None, + bolt11: maybe_receive_swap_invoice.unwrap_or("".to_string()), payer_amount_sat: maybe_receive_swap_payer_amount_sat.unwrap_or(0), receiver_amount_sat: maybe_receive_swap_receiver_amount_sat.unwrap_or(0), refund_tx_id: None, @@ -183,6 +188,7 @@ impl Persister { swap_id: send_swap_id, created_at: maybe_send_swap_created_at.unwrap_or(utils::now()), preimage: maybe_send_swap_preimage, + bolt11: maybe_send_swap_invoice.unwrap_or("".to_string()), payer_amount_sat: maybe_send_swap_payer_amount_sat.unwrap_or(0), receiver_amount_sat: maybe_send_swap_receiver_amount_sat.unwrap_or(0), refund_tx_id: maybe_send_swap_refund_tx_id, diff --git a/packages/dart/lib/src/frb_generated.dart b/packages/dart/lib/src/frb_generated.dart index 0913b7a..d14a1e7 100644 --- a/packages/dart/lib/src/frb_generated.dart +++ b/packages/dart/lib/src/frb_generated.dart @@ -855,7 +855,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { Payment dco_decode_payment(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs final arr = raw as List; - if (arr.length != 10) throw Exception('unexpected arr length: expect 10 but see ${arr.length}'); + if (arr.length != 11) throw Exception('unexpected arr length: expect 11 but see ${arr.length}'); return Payment( txId: dco_decode_opt_String(arr[0]), swapId: dco_decode_opt_String(arr[1]), @@ -863,10 +863,11 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { amountSat: dco_decode_u_64(arr[3]), feesSat: dco_decode_u_64(arr[4]), preimage: dco_decode_opt_String(arr[5]), - refundTxId: dco_decode_opt_String(arr[6]), - refundTxAmountSat: dco_decode_opt_box_autoadd_u_64(arr[7]), - paymentType: dco_decode_payment_type(arr[8]), - status: dco_decode_payment_state(arr[9]), + bolt11: dco_decode_opt_String(arr[6]), + refundTxId: dco_decode_opt_String(arr[7]), + refundTxAmountSat: dco_decode_opt_box_autoadd_u_64(arr[8]), + paymentType: dco_decode_payment_type(arr[9]), + status: dco_decode_payment_state(arr[10]), ); } @@ -1425,6 +1426,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { var var_amountSat = sse_decode_u_64(deserializer); var var_feesSat = sse_decode_u_64(deserializer); var var_preimage = sse_decode_opt_String(deserializer); + var var_bolt11 = sse_decode_opt_String(deserializer); var var_refundTxId = sse_decode_opt_String(deserializer); var var_refundTxAmountSat = sse_decode_opt_box_autoadd_u_64(deserializer); var var_paymentType = sse_decode_payment_type(deserializer); @@ -1436,6 +1438,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { amountSat: var_amountSat, feesSat: var_feesSat, preimage: var_preimage, + bolt11: var_bolt11, refundTxId: var_refundTxId, refundTxAmountSat: var_refundTxAmountSat, paymentType: var_paymentType, @@ -2006,6 +2009,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_u_64(self.amountSat, serializer); sse_encode_u_64(self.feesSat, serializer); sse_encode_opt_String(self.preimage, serializer); + sse_encode_opt_String(self.bolt11, serializer); sse_encode_opt_String(self.refundTxId, serializer); sse_encode_opt_box_autoadd_u_64(self.refundTxAmountSat, serializer); sse_encode_payment_type(self.paymentType, serializer); diff --git a/packages/dart/lib/src/frb_generated.io.dart b/packages/dart/lib/src/frb_generated.io.dart index 52f4fc4..6086054 100644 --- a/packages/dart/lib/src/frb_generated.io.dart +++ b/packages/dart/lib/src/frb_generated.io.dart @@ -728,6 +728,7 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { wireObj.amount_sat = cst_encode_u_64(apiObj.amountSat); wireObj.fees_sat = cst_encode_u_64(apiObj.feesSat); wireObj.preimage = cst_encode_opt_String(apiObj.preimage); + wireObj.bolt11 = cst_encode_opt_String(apiObj.bolt11); wireObj.refund_tx_id = cst_encode_opt_String(apiObj.refundTxId); wireObj.refund_tx_amount_sat = cst_encode_opt_box_autoadd_u_64(apiObj.refundTxAmountSat); wireObj.payment_type = cst_encode_payment_type(apiObj.paymentType); @@ -1636,12 +1637,9 @@ class RustLibWire implements BaseWire { _dummy_method_to_enforce_bundlingPtr.asFunction(); } -typedef DartPostCObjectFnType = ffi.Pointer>; -typedef DartPostCObjectFnTypeFunction = ffi.Bool Function(DartPort port_id, ffi.Pointer message); -typedef DartDartPostCObjectFnTypeFunction = bool Function( - DartDartPort port_id, ffi.Pointer message); +typedef DartPostCObjectFnType + = ffi.Pointer message)>>; typedef DartPort = ffi.Int64; -typedef DartDartPort = int; final class wire_cst_list_prim_u_8_strict extends ffi.Struct { external ffi.Pointer ptr; @@ -1702,6 +1700,8 @@ final class wire_cst_payment extends ffi.Struct { external ffi.Pointer preimage; + external ffi.Pointer bolt11; + external ffi.Pointer refund_tx_id; external ffi.Pointer refund_tx_amount_sat; diff --git a/packages/dart/lib/src/model.dart b/packages/dart/lib/src/model.dart index d0e125f..4720ef0 100644 --- a/packages/dart/lib/src/model.dart +++ b/packages/dart/lib/src/model.dart @@ -293,6 +293,11 @@ class Payment { /// In case of a Send swap, this is the preimage of the paid invoice (proof of payment). final String? preimage; + /// Represents the invoice associated with a payment + /// In the case of a Send payment, this is the invoice paid by the swapper + /// In the case of a Receive payment, this is the invoice paid by the user + final String? bolt11; + /// For a Send swap which was refunded, this is the refund tx id final String? refundTxId; @@ -314,6 +319,7 @@ class Payment { required this.amountSat, required this.feesSat, this.preimage, + this.bolt11, this.refundTxId, this.refundTxAmountSat, required this.paymentType, @@ -328,6 +334,7 @@ class Payment { amountSat.hashCode ^ feesSat.hashCode ^ preimage.hashCode ^ + bolt11.hashCode ^ refundTxId.hashCode ^ refundTxAmountSat.hashCode ^ paymentType.hashCode ^ @@ -344,6 +351,7 @@ class Payment { amountSat == other.amountSat && feesSat == other.feesSat && preimage == other.preimage && + bolt11 == other.bolt11 && refundTxId == other.refundTxId && refundTxAmountSat == other.refundTxAmountSat && paymentType == other.paymentType && diff --git a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart index 0db2d7f..7710755 100644 --- a/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart +++ b/packages/flutter/lib/flutter_breez_liquid_bindings_generated.dart @@ -648,6 +648,8 @@ final class wire_cst_payment extends ffi.Struct { external ffi.Pointer preimage; + external ffi.Pointer bolt11; + external ffi.Pointer refund_tx_id; external ffi.Pointer refund_tx_amount_sat; diff --git a/packages/react-native/android/src/main/java/com/breezliquidsdk/BreezLiquidSDKMapper.kt b/packages/react-native/android/src/main/java/com/breezliquidsdk/BreezLiquidSDKMapper.kt index 9ab9fbb..b06b687 100644 --- a/packages/react-native/android/src/main/java/com/breezliquidsdk/BreezLiquidSDKMapper.kt +++ b/packages/react-native/android/src/main/java/com/breezliquidsdk/BreezLiquidSDKMapper.kt @@ -306,6 +306,7 @@ fun asPayment(payment: ReadableMap): Payment? { val amountSat = payment.getDouble("amountSat").toULong() val feesSat = payment.getDouble("feesSat").toULong() val preimage = if (hasNonNullKey(payment, "preimage")) payment.getString("preimage") else null + val bolt11 = if (hasNonNullKey(payment, "bolt11")) payment.getString("bolt11") else null val refundTxId = if (hasNonNullKey(payment, "refundTxId")) payment.getString("refundTxId") else null val refundTxAmountSat = if (hasNonNullKey(payment, "refundTxAmountSat")) payment.getDouble("refundTxAmountSat").toULong() else null val paymentType = payment.getString("paymentType")?.let { asPaymentType(it) }!! @@ -317,6 +318,7 @@ fun asPayment(payment: ReadableMap): Payment? { amountSat, feesSat, preimage, + bolt11, refundTxId, refundTxAmountSat, paymentType, @@ -332,6 +334,7 @@ fun readableMapOf(payment: Payment): ReadableMap = "amountSat" to payment.amountSat, "feesSat" to payment.feesSat, "preimage" to payment.preimage, + "bolt11" to payment.bolt11, "refundTxId" to payment.refundTxId, "refundTxAmountSat" to payment.refundTxAmountSat, "paymentType" to payment.paymentType.name.lowercase(), diff --git a/packages/react-native/ios/BreezLiquidSDKMapper.swift b/packages/react-native/ios/BreezLiquidSDKMapper.swift index 881fdc6..ea427fd 100644 --- a/packages/react-native/ios/BreezLiquidSDKMapper.swift +++ b/packages/react-native/ios/BreezLiquidSDKMapper.swift @@ -368,6 +368,13 @@ enum BreezLiquidSDKMapper { } preimage = preimageTmp } + var bolt11: String? + if hasNonNilKey(data: payment, key: "bolt11") { + guard let bolt11Tmp = payment["bolt11"] as? String else { + throw LiquidSdkError.Generic(message: errUnexpectedValue(fieldName: "bolt11")) + } + bolt11 = bolt11Tmp + } var refundTxId: String? if hasNonNilKey(data: payment, key: "refundTxId") { guard let refundTxIdTmp = payment["refundTxId"] as? String else { @@ -399,6 +406,7 @@ enum BreezLiquidSDKMapper { amountSat: amountSat, feesSat: feesSat, preimage: preimage, + bolt11: bolt11, refundTxId: refundTxId, refundTxAmountSat: refundTxAmountSat, paymentType: paymentType, @@ -414,6 +422,7 @@ enum BreezLiquidSDKMapper { "amountSat": payment.amountSat, "feesSat": payment.feesSat, "preimage": payment.preimage == nil ? nil : payment.preimage, + "bolt11": payment.bolt11 == nil ? nil : payment.bolt11, "refundTxId": payment.refundTxId == nil ? nil : payment.refundTxId, "refundTxAmountSat": payment.refundTxAmountSat == nil ? nil : payment.refundTxAmountSat, "paymentType": valueOf(paymentType: payment.paymentType), diff --git a/packages/react-native/src/index.ts b/packages/react-native/src/index.ts index 657d062..970c6a2 100644 --- a/packages/react-native/src/index.ts +++ b/packages/react-native/src/index.ts @@ -72,6 +72,7 @@ export interface Payment { amountSat: number feesSat: number preimage?: string + bolt11?: string refundTxId?: string refundTxAmountSat?: number paymentType: PaymentType