feat: invoice details to Payment (#309)

This commit is contained in:
yse
2024-06-18 17:32:51 +02:00
committed by GitHub
parent 78228d8961
commit 4e76e94d26
13 changed files with 72 additions and 21 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -345,6 +345,7 @@ impl CstDecode<crate::model::Payment> 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,

View File

@@ -1051,6 +1051,7 @@ impl SseDecode for crate::model::Payment {
let mut var_amountSat = <u64>::sse_decode(deserializer);
let mut var_feesSat = <u64>::sse_decode(deserializer);
let mut var_preimage = <Option<String>>::sse_decode(deserializer);
let mut var_bolt11 = <Option<String>>::sse_decode(deserializer);
let mut var_refundTxId = <Option<String>>::sse_decode(deserializer);
let mut var_refundTxAmountSat = <Option<u64>>::sse_decode(deserializer);
let mut var_paymentType = <crate::model::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 {
<u64>::sse_encode(self.amount_sat, serializer);
<u64>::sse_encode(self.fees_sat, serializer);
<Option<String>>::sse_encode(self.preimage, serializer);
<Option<String>>::sse_encode(self.bolt11, serializer);
<Option<String>>::sse_encode(self.refund_tx_id, serializer);
<Option<u64>>::sse_encode(self.refund_tx_amount_sat, serializer);
<crate::model::PaymentType>::sse_encode(self.payment_type, serializer);

View File

@@ -533,6 +533,8 @@ pub struct PaymentSwapData {
pub preimage: Option<String>,
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<String>,
/// 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<String>,
/// For a Send swap which was refunded, this is the refund tx id
pub refund_tx_id: Option<String>,
@@ -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,

View File

@@ -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<String> = row.get(6)?;
let maybe_receive_swap_created_at: Option<u32> = row.get(7)?;
let maybe_receive_swap_payer_amount_sat: Option<u64> = row.get(8)?;
let maybe_receive_swap_receiver_amount_sat: Option<u64> = row.get(9)?;
let maybe_receive_swap_receiver_state: Option<PaymentState> = row.get(10)?;
let maybe_receive_swap_invoice: Option<String> = row.get(8)?;
let maybe_receive_swap_payer_amount_sat: Option<u64> = row.get(9)?;
let maybe_receive_swap_receiver_amount_sat: Option<u64> = row.get(10)?;
let maybe_receive_swap_receiver_state: Option<PaymentState> = row.get(11)?;
let maybe_send_swap_id: Option<String> = row.get(11)?;
let maybe_send_swap_created_at: Option<u32> = row.get(12)?;
let maybe_send_swap_preimage: Option<String> = row.get(13)?;
let maybe_send_swap_refund_tx_id: Option<String> = row.get(14)?;
let maybe_send_swap_payer_amount_sat: Option<u64> = row.get(15)?;
let maybe_send_swap_receiver_amount_sat: Option<u64> = row.get(16)?;
let maybe_send_swap_state: Option<PaymentState> = row.get(17)?;
let maybe_send_swap_refund_tx_amount_sat: Option<u64> = row.get(18)?;
let maybe_send_swap_id: Option<String> = row.get(12)?;
let maybe_send_swap_created_at: Option<u32> = row.get(13)?;
let maybe_send_swap_invoice: Option<String> = row.get(14)?;
let maybe_send_swap_preimage: Option<String> = row.get(15)?;
let maybe_send_swap_refund_tx_id: Option<String> = row.get(16)?;
let maybe_send_swap_payer_amount_sat: Option<u64> = row.get(17)?;
let maybe_send_swap_receiver_amount_sat: Option<u64> = row.get(18)?;
let maybe_send_swap_state: Option<PaymentState> = row.get(19)?;
let maybe_send_swap_refund_tx_amount_sat: Option<u64> = 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,

View File

@@ -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<dynamic>;
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);

View File

@@ -728,6 +728,7 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
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<int Function()>();
}
typedef DartPostCObjectFnType = ffi.Pointer<ffi.NativeFunction<DartPostCObjectFnTypeFunction>>;
typedef DartPostCObjectFnTypeFunction = ffi.Bool Function(DartPort port_id, ffi.Pointer<ffi.Void> message);
typedef DartDartPostCObjectFnTypeFunction = bool Function(
DartDartPort port_id, ffi.Pointer<ffi.Void> message);
typedef DartPostCObjectFnType
= ffi.Pointer<ffi.NativeFunction<ffi.Bool Function(DartPort port_id, ffi.Pointer<ffi.Void> message)>>;
typedef DartPort = ffi.Int64;
typedef DartDartPort = int;
final class wire_cst_list_prim_u_8_strict extends ffi.Struct {
external ffi.Pointer<ffi.Uint8> ptr;
@@ -1702,6 +1700,8 @@ final class wire_cst_payment extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> preimage;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> bolt11;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> refund_tx_id;
external ffi.Pointer<ffi.Uint64> refund_tx_amount_sat;

View File

@@ -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 &&

View File

@@ -648,6 +648,8 @@ final class wire_cst_payment extends ffi.Struct {
external ffi.Pointer<wire_cst_list_prim_u_8_strict> preimage;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> bolt11;
external ffi.Pointer<wire_cst_list_prim_u_8_strict> refund_tx_id;
external ffi.Pointer<ffi.Uint64> refund_tx_amount_sat;

View File

@@ -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(),

View File

@@ -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),

View File

@@ -72,6 +72,7 @@ export interface Payment {
amountSat: number
feesSat: number
preimage?: string
bolt11?: string
refundTxId?: string
refundTxAmountSat?: number
paymentType: PaymentType