Skip to content

Commit dabb827

Browse files
committed
payments: Add unknown to Payment[Kind,Rail]
1 parent adb87dc commit dabb827

File tree

16 files changed

+765
-203
lines changed

16 files changed

+765
-203
lines changed

app-rs/src/ffi/types.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,15 @@ impl From<PaymentStatusRs> for PaymentStatus {
272272
}
273273
}
274274

275-
#[derive(Copy, Clone)]
275+
#[derive(Clone)]
276276
pub enum PaymentKind {
277277
Onchain,
278278
Invoice,
279279
Offer,
280280
Spontaneous,
281281
WaivedChannelFee,
282282
WaivedLiquidityFee,
283+
Unknown(String),
283284
}
284285

285286
impl From<PaymentKindRs> for PaymentKind {
@@ -291,6 +292,7 @@ impl From<PaymentKindRs> for PaymentKind {
291292
PaymentKindRs::Spontaneous => Self::Spontaneous,
292293
PaymentKindRs::WaivedChannelFee => Self::WaivedChannelFee,
293294
PaymentKindRs::WaivedLiquidityFee => Self::WaivedLiquidityFee,
295+
PaymentKindRs::Unknown(s) => Self::Unknown(String::from(s)),
294296
}
295297
}
296298
}
@@ -335,11 +337,13 @@ pub struct ShortPayment {
335337
impl From<&BasicPaymentV1Rs> for ShortPayment {
336338
fn from(payment: &BasicPaymentV1Rs) -> Self {
337339
// V1 payments don't have kind; derive from rail
338-
let kind = match payment.rail {
340+
let kind = match &payment.rail {
339341
PaymentRailRs::Onchain => PaymentKind::Onchain,
340342
PaymentRailRs::Invoice => PaymentKind::Invoice,
341343
PaymentRailRs::Offer => PaymentKind::Offer,
342344
PaymentRailRs::Spontaneous => PaymentKind::Spontaneous,
345+
// V1 doesn't have an unknown variant
346+
PaymentRailRs::Unknown(_) => unreachable!(),
343347
// These rails don't exist in v1
344348
PaymentRailRs::WaivedFee => unreachable!(),
345349
};
@@ -367,7 +371,7 @@ impl From<&BasicPaymentV2Rs> for ShortPayment {
367371
Self {
368372
index: PaymentCreatedIndex::from(payment.created_index()),
369373

370-
kind: PaymentKind::from(payment.kind),
374+
kind: PaymentKind::from(payment.kind.clone()),
371375

372376
direction: PaymentDirection::from(payment.direction),
373377

@@ -415,11 +419,13 @@ pub struct Payment {
415419
impl From<&BasicPaymentV1Rs> for Payment {
416420
fn from(payment: &BasicPaymentV1Rs) -> Self {
417421
// V1 payments don't have kind; derive from rail
418-
let kind = match payment.rail {
422+
let kind = match &payment.rail {
419423
PaymentRailRs::Onchain => PaymentKind::Onchain,
420424
PaymentRailRs::Invoice => PaymentKind::Invoice,
421425
PaymentRailRs::Offer => PaymentKind::Offer,
422426
PaymentRailRs::Spontaneous => PaymentKind::Spontaneous,
427+
// V1 doesn't have an unknown variant
428+
PaymentRailRs::Unknown(_) => unreachable!(),
423429
// These rails don't exist in v1
424430
PaymentRailRs::WaivedFee => unreachable!(),
425431
};
@@ -457,7 +463,7 @@ impl From<&BasicPaymentV2Rs> for Payment {
457463
Self {
458464
index: PaymentCreatedIndex::from(payment.created_index()),
459465

460-
kind: PaymentKind::from(payment.kind),
466+
kind: PaymentKind::from(payment.kind.clone()),
461467
direction: PaymentDirection::from(payment.direction),
462468

463469
invoice: payment.invoice.as_deref().map(Invoice::from),

app-rs/src/frb_generated.rs

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,16 +2516,34 @@ impl SseDecode for crate::ffi::types::PaymentKind {
25162516
fn sse_decode(
25172517
deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer,
25182518
) -> Self {
2519-
let mut inner = <i32>::sse_decode(deserializer);
2520-
return match inner {
2521-
0 => crate::ffi::types::PaymentKind::Onchain,
2522-
1 => crate::ffi::types::PaymentKind::Invoice,
2523-
2 => crate::ffi::types::PaymentKind::Offer,
2524-
3 => crate::ffi::types::PaymentKind::Spontaneous,
2525-
4 => crate::ffi::types::PaymentKind::WaivedChannelFee,
2526-
5 => crate::ffi::types::PaymentKind::WaivedLiquidityFee,
2527-
_ => unreachable!("Invalid variant for PaymentKind: {}", inner),
2528-
};
2519+
let mut tag_ = <i32>::sse_decode(deserializer);
2520+
match tag_ {
2521+
0 => {
2522+
return crate::ffi::types::PaymentKind::Onchain;
2523+
}
2524+
1 => {
2525+
return crate::ffi::types::PaymentKind::Invoice;
2526+
}
2527+
2 => {
2528+
return crate::ffi::types::PaymentKind::Offer;
2529+
}
2530+
3 => {
2531+
return crate::ffi::types::PaymentKind::Spontaneous;
2532+
}
2533+
4 => {
2534+
return crate::ffi::types::PaymentKind::WaivedChannelFee;
2535+
}
2536+
5 => {
2537+
return crate::ffi::types::PaymentKind::WaivedLiquidityFee;
2538+
}
2539+
6 => {
2540+
let mut var_field0 = <String>::sse_decode(deserializer);
2541+
return crate::ffi::types::PaymentKind::Unknown(var_field0);
2542+
}
2543+
_ => {
2544+
unimplemented!("");
2545+
}
2546+
}
25292547
}
25302548
}
25312549

@@ -4083,13 +4101,23 @@ impl flutter_rust_bridge::IntoIntoDart<crate::ffi::types::PaymentDirection>
40834101
impl flutter_rust_bridge::IntoDart for crate::ffi::types::PaymentKind {
40844102
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
40854103
match self {
4086-
Self::Onchain => 0.into_dart(),
4087-
Self::Invoice => 1.into_dart(),
4088-
Self::Offer => 2.into_dart(),
4089-
Self::Spontaneous => 3.into_dart(),
4090-
Self::WaivedChannelFee => 4.into_dart(),
4091-
Self::WaivedLiquidityFee => 5.into_dart(),
4092-
_ => unreachable!(),
4104+
crate::ffi::types::PaymentKind::Onchain =>
4105+
[0.into_dart()].into_dart(),
4106+
crate::ffi::types::PaymentKind::Invoice =>
4107+
[1.into_dart()].into_dart(),
4108+
crate::ffi::types::PaymentKind::Offer =>
4109+
[2.into_dart()].into_dart(),
4110+
crate::ffi::types::PaymentKind::Spontaneous =>
4111+
[3.into_dart()].into_dart(),
4112+
crate::ffi::types::PaymentKind::WaivedChannelFee =>
4113+
[4.into_dart()].into_dart(),
4114+
crate::ffi::types::PaymentKind::WaivedLiquidityFee =>
4115+
[5.into_dart()].into_dart(),
4116+
crate::ffi::types::PaymentKind::Unknown(field0) =>
4117+
[6.into_dart(), field0.into_into_dart().into_dart()].into_dart(),
4118+
_ => {
4119+
unimplemented!("");
4120+
}
40934121
}
40944122
}
40954123
}
@@ -5724,20 +5752,33 @@ impl SseEncode for crate::ffi::types::PaymentKind {
57245752
self,
57255753
serializer: &mut flutter_rust_bridge::for_generated::SseSerializer,
57265754
) {
5727-
<i32>::sse_encode(
5728-
match self {
5729-
crate::ffi::types::PaymentKind::Onchain => 0,
5730-
crate::ffi::types::PaymentKind::Invoice => 1,
5731-
crate::ffi::types::PaymentKind::Offer => 2,
5732-
crate::ffi::types::PaymentKind::Spontaneous => 3,
5733-
crate::ffi::types::PaymentKind::WaivedChannelFee => 4,
5734-
crate::ffi::types::PaymentKind::WaivedLiquidityFee => 5,
5735-
_ => {
5736-
unimplemented!("");
5737-
}
5738-
},
5739-
serializer,
5740-
);
5755+
match self {
5756+
crate::ffi::types::PaymentKind::Onchain => {
5757+
<i32>::sse_encode(0, serializer);
5758+
}
5759+
crate::ffi::types::PaymentKind::Invoice => {
5760+
<i32>::sse_encode(1, serializer);
5761+
}
5762+
crate::ffi::types::PaymentKind::Offer => {
5763+
<i32>::sse_encode(2, serializer);
5764+
}
5765+
crate::ffi::types::PaymentKind::Spontaneous => {
5766+
<i32>::sse_encode(3, serializer);
5767+
}
5768+
crate::ffi::types::PaymentKind::WaivedChannelFee => {
5769+
<i32>::sse_encode(4, serializer);
5770+
}
5771+
crate::ffi::types::PaymentKind::WaivedLiquidityFee => {
5772+
<i32>::sse_encode(5, serializer);
5773+
}
5774+
crate::ffi::types::PaymentKind::Unknown(field0) => {
5775+
<i32>::sse_encode(6, serializer);
5776+
<String>::sse_encode(field0, serializer);
5777+
}
5778+
_ => {
5779+
unimplemented!("");
5780+
}
5781+
}
57415782
}
57425783
}
57435784

app/lib/design_mode/mocks.dart

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ import 'package:app_rs_dart/ffi/types.dart'
6161
Payment,
6262
PaymentCreatedIndex,
6363
PaymentDirection,
64-
PaymentKind,
64+
PaymentKind_Invoice,
65+
PaymentKind_Offer,
66+
PaymentKind_Onchain,
67+
PaymentKind_Spontaneous,
6568
PaymentMethod,
6669
PaymentMethod_Invoice,
6770
PaymentMethod_LnurlPayRequest,
@@ -943,7 +946,7 @@ const Payment dummyOnchainInboundPending01 = Payment(
943946
field0:
944947
"0000001687309696000-bc_238eb9f1b1db5e39877da642126783e2d6a043e047bbbe8872df3e7fdc3dca68",
945948
),
946-
kind: PaymentKind.onchain,
949+
kind: PaymentKind_Onchain(),
947950
direction: PaymentDirection.inbound,
948951
txid: "238eb9f1b1db5e39877da642126783e2d6a043e047bbbe8872df3e7fdc3dca68",
949952
amountSat: 1469,
@@ -961,7 +964,7 @@ const Payment dummyOnchainInboundCompleted01 = Payment(
961964
field0:
962965
"0000001670090492000-bc_551df4ef3b67b3f2ca53f3e668eb73c2a9b3a77dea84b340fd2407ec5542aa66",
963966
),
964-
kind: PaymentKind.onchain,
967+
kind: PaymentKind_Onchain(),
965968
direction: PaymentDirection.inbound,
966969
txid: "551df4ef3b67b3f2ca53f3e668eb73c2a9b3a77dea84b340fd2407ec5542aa66",
967970
amountSat: 20000,
@@ -979,7 +982,7 @@ const Payment dummyOnchainInboundCompleted02 = Payment(
979982
field0:
980983
"0000001739386001000-bc_70596383fb7dd5c578a5ef348ec77c5979a65ecb4b10bae0ce60e814c35f04f1",
981984
),
982-
kind: PaymentKind.onchain,
985+
kind: PaymentKind_Onchain(),
983986
direction: PaymentDirection.inbound,
984987
txid: "70596383fb7dd5c578a5ef348ec77c5979a65ecb4b10bae0ce60e814c35f04f1",
985988
amountSat: 208505,
@@ -997,7 +1000,7 @@ const Payment dummyOnchainOutboundCompleted01 = Payment(
9971000
field0:
9981001
"0000001687385080000-bc_238eb9f1b1db5e39877da642126783e2d6a043e047bbbe8872df3e7fdc3dca68",
9991002
),
1000-
kind: PaymentKind.onchain,
1003+
kind: PaymentKind_Onchain(),
10011004
direction: PaymentDirection.outbound,
10021005
txid: "0a882813f2bb937a45f18568ff0d09d83d437558e85e369629226d0f7405c52e",
10031006
amountSat: 77000,
@@ -1014,7 +1017,7 @@ const Payment dummyOnchainOutboundFailed01 = Payment(
10141017
field0:
10151018
"0000001671818392000-bc_46e52089b60b00de067c84ce58d34a75ffd71a106f720855bc099f20da11700c",
10161019
),
1017-
kind: PaymentKind.onchain,
1020+
kind: PaymentKind_Onchain(),
10181021
direction: PaymentDirection.outbound,
10191022
txid: "e9e3db092c9b4f94d1c603dd503a0f9bb95f9369897a25aafef2960053f8ccab",
10201023
amountSat: 95000000,
@@ -1032,7 +1035,7 @@ const Payment dummySpontaneousOutboundPending01 = Payment(
10321035
field0:
10331036
"0000001686938392000-ln_6973b3c58738403ceb3fccec470365a44361f34f4c2664ccae04f0f39fe71dc0",
10341037
),
1035-
kind: PaymentKind.spontaneous,
1038+
kind: PaymentKind_Spontaneous(),
10361039
direction: PaymentDirection.outbound,
10371040
amountSat: 123000,
10381041
feesSat: 615,
@@ -1047,7 +1050,7 @@ const Payment dummyInvoiceOutboundPending01 = Payment(
10471050
field0:
10481051
"0000001686744442000-ln_6973b3c58738403ceb3fccec470365a44361f34f4c2664ccae04f0f39fe71dc0",
10491052
),
1050-
kind: PaymentKind.invoice,
1053+
kind: PaymentKind_Invoice(),
10511054
direction: PaymentDirection.outbound,
10521055
invoice: Invoice(
10531056
string:
@@ -1072,7 +1075,7 @@ const Payment dummyInvoiceInboundPending01 = Payment(
10721075
field0:
10731076
"0000001687140003000-ln_bbe27583bf7ee269387bbad48c48fcae10e41537d35e49b14d81cc7306f486cb",
10741077
),
1075-
kind: PaymentKind.invoice,
1078+
kind: PaymentKind_Invoice(),
10761079
direction: PaymentDirection.inbound,
10771080
invoice: Invoice(
10781081
string:
@@ -1099,7 +1102,7 @@ const Payment dummyInvoiceInboundPending02 = Payment(
10991102
field0:
11001103
"0000001714432815000-ln_c6e5e46c59267114f91d64df0e069b0dae176f9a134656820bba1e6164318980",
11011104
),
1102-
kind: PaymentKind.invoice,
1105+
kind: PaymentKind_Invoice(),
11031106
direction: PaymentDirection.inbound,
11041107
invoice: Invoice(
11051108
string:
@@ -1124,7 +1127,7 @@ const Payment dummyInvoiceInboundCompleted01 = Payment(
11241127
field0:
11251128
"0000001687100002000-ln_801ffce9fbe74fecc7ec6fa72716d7de6167cc5607635062b24797b54f9ba4be",
11261129
),
1127-
kind: PaymentKind.invoice,
1130+
kind: PaymentKind_Invoice(),
11281131
direction: PaymentDirection.inbound,
11291132
invoice: Invoice(
11301133
string:
@@ -1150,7 +1153,7 @@ const Payment dummyInvoiceInboundCompleted02 = Payment(
11501153
field0:
11511154
"0000001739490952000-ln_4ca99b7534df3a98afb69757b770faffead8b0794e5d618fbbf9b4cfd1f157cf",
11521155
),
1153-
kind: PaymentKind.invoice,
1156+
kind: PaymentKind_Invoice(),
11541157
direction: PaymentDirection.inbound,
11551158
invoice: Invoice(
11561159
string:
@@ -1177,7 +1180,7 @@ const Payment dummyInvoiceInboundFailed01 = Payment(
11771180
field0:
11781181
"0000001700222815000-ln_034a21eee2bea4288ec9582b10a4abd6bfdca83855b25257279e67dd02f77d43",
11791182
),
1180-
kind: PaymentKind.invoice,
1183+
kind: PaymentKind_Invoice(),
11811184
direction: PaymentDirection.inbound,
11821185
invoice: Invoice(
11831186
string:
@@ -1202,7 +1205,7 @@ const Payment dummyInvoiceOutboundCompleted01 = Payment(
12021205
field0:
12031206
"0000001739487454000-ln_432ec4be62f494b0498c76145fd31b302d0be4ac8cffe7c4102ad1f1c056bec9",
12041207
),
1205-
kind: PaymentKind.invoice,
1208+
kind: PaymentKind_Invoice(),
12061209
direction: PaymentDirection.outbound,
12071210
invoice: Invoice(
12081211
string:
@@ -1228,7 +1231,7 @@ const Payment dummyOfferOutboundPayment01 = Payment(
12281231
field0:
12291232
"0000001748993362000-fs_1a0863b5785d35c34e008e8bd879e78a93b795640c2ad9e941a7d12f44356804",
12301233
),
1231-
kind: PaymentKind.offer,
1234+
kind: PaymentKind_Offer(),
12321235
direction: PaymentDirection.outbound,
12331236
offerId: "7bcb7b222189c07dfa6d55da519bdaf0d06c90597aab5dd5fc919c62db17c218",
12341237
offer: Offer(
@@ -1254,7 +1257,7 @@ const Payment dummyOfferInboundPayment01 = Payment(
12541257
field0:
12551258
"0000001748999074000-fr_016041408597e243d2b7a8fddf2304288f4763809e340b94df32c12deb894927",
12561259
),
1257-
kind: PaymentKind.offer,
1260+
kind: PaymentKind_Offer(),
12581261
direction: PaymentDirection.inbound,
12591262
offerId: "e492e1d9c1919d0f37547abcb05f80ce31dcb0b70dff7433f0a0ebdc1cba8539",
12601263
// NOTE: inbound offer payments currently don't have the `offer` field set

0 commit comments

Comments
 (0)