Skip to content

Commit 1e74787

Browse files
committed
Introduce PaymentKind to payment store
1 parent 6536516 commit 1e74787

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

bindings/ldk_node.udl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ interface ClosureReason {
218218
FundingBatchClosure();
219219
};
220220

221+
[Enum]
222+
interface PaymentKind {
223+
Onchain();
224+
Bolt11();
225+
Bolt12();
226+
Spontaneous();
227+
};
228+
221229
enum PaymentDirection {
222230
"Inbound",
223231
"Outbound",
@@ -235,6 +243,7 @@ dictionary LSPFeeLimits {
235243
};
236244

237245
dictionary PaymentDetails {
246+
PaymentKind? kind;
238247
PaymentHash hash;
239248
PaymentPreimage? preimage;
240249
PaymentSecret? secret;

src/event.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::{
44
};
55

66
use crate::payment::payment_store::{
7-
PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentStatus, PaymentStore,
7+
PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentKind, PaymentStatus,
8+
PaymentStore,
89
};
910

1011
use crate::io::{
@@ -550,6 +551,7 @@ where
550551
},
551552
PaymentPurpose::SpontaneousPayment(preimage) => {
552553
let payment = PaymentDetails {
554+
kind: Some(PaymentKind::Spontaneous),
553555
preimage: Some(preimage),
554556
hash: payment_hash,
555557
secret: None,

src/payment/bolt11.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::error::Error;
88
use crate::liquidity::LiquiditySource;
99
use crate::logger::{log_error, log_info, FilesystemLogger, Logger};
1010
use crate::payment::payment_store::{
11-
LSPFeeLimits, PaymentDetails, PaymentDirection, PaymentStatus, PaymentStore,
11+
LSPFeeLimits, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus, PaymentStore,
1212
};
1313
use crate::peer_store::{PeerInfo, PeerStore};
1414
use crate::types::{ChannelManager, KeysManager};
@@ -103,6 +103,7 @@ impl Bolt11Payment {
103103
log_info!(self.logger, "Initiated sending {}msat to {}", amt_msat, payee_pubkey);
104104

105105
let payment = PaymentDetails {
106+
kind: Some(PaymentKind::Bolt11),
106107
preimage: None,
107108
hash: payment_hash,
108109
secret: payment_secret,
@@ -121,6 +122,7 @@ impl Bolt11Payment {
121122
RetryableSendFailure::DuplicatePayment => Err(Error::DuplicatePayment),
122123
_ => {
123124
let payment = PaymentDetails {
125+
kind: Some(PaymentKind::Bolt11),
124126
preimage: None,
125127
hash: payment_hash,
126128
secret: payment_secret,
@@ -209,6 +211,7 @@ impl Bolt11Payment {
209211
);
210212

211213
let payment = PaymentDetails {
214+
kind: Some(PaymentKind::Bolt11),
212215
hash: payment_hash,
213216
preimage: None,
214217
secret: Some(*payment_secret),
@@ -228,6 +231,7 @@ impl Bolt11Payment {
228231
RetryableSendFailure::DuplicatePayment => Err(Error::DuplicatePayment),
229232
_ => {
230233
let payment = PaymentDetails {
234+
kind: Some(PaymentKind::Bolt11),
231235
hash: payment_hash,
232236
preimage: None,
233237
secret: Some(*payment_secret),
@@ -288,6 +292,7 @@ impl Bolt11Payment {
288292

289293
let payment_hash = PaymentHash(invoice.payment_hash().to_byte_array());
290294
let payment = PaymentDetails {
295+
kind: Some(PaymentKind::Bolt11),
291296
hash: payment_hash,
292297
preimage: None,
293298
secret: Some(invoice.payment_secret().clone()),
@@ -414,6 +419,7 @@ impl Bolt11Payment {
414419
max_proportional_opening_fee_ppm_msat: lsp_prop_opening_fee,
415420
});
416421
let payment = PaymentDetails {
422+
kind: Some(PaymentKind::Bolt11),
417423
hash: payment_hash,
418424
preimage: None,
419425
secret: Some(invoice.payment_secret().clone()),

src/payment/payment_store.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ use std::sync::{Arc, Mutex};
1818
/// Represents a payment.
1919
#[derive(Clone, Debug, PartialEq, Eq)]
2020
pub struct PaymentDetails {
21+
/// The kind of the payment.
22+
///
23+
/// This will be `None` for objects created with LDK Node v0.2.1 and earlier.
24+
pub kind: Option<PaymentKind>,
2125
/// The payment hash, i.e., the hash of the `preimage`.
2226
pub hash: PaymentHash,
2327
/// The pre-image used by the payment.
@@ -45,6 +49,7 @@ impl_writeable_tlv_based!(PaymentDetails, {
4549
(0, hash, required),
4650
(1, lsp_fee_limits, option),
4751
(2, preimage, required),
52+
(3, kind, option),
4853
(4, secret, required),
4954
(6, amount_msat, required),
5055
(8, direction, required),
@@ -82,6 +87,28 @@ impl_writeable_tlv_based_enum!(PaymentStatus,
8287
(4, Failed) => {};
8388
);
8489

90+
/// Represents the kind of a payment.
91+
#[derive(Clone, Debug, PartialEq, Eq)]
92+
pub enum PaymentKind {
93+
/// An on-chain payment.
94+
Onchain,
95+
/// A [BOLT 11] payment.
96+
///
97+
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
98+
// TODO: Bolt11 { invoice: Option<Bolt11Invoice> },
99+
Bolt11,
100+
/// A spontaneous ("keysend") payment.
101+
Spontaneous,
102+
}
103+
104+
impl_writeable_tlv_based_enum!(PaymentKind,
105+
(0, Onchain) => {},
106+
(2, Bolt11) => {
107+
// TODO: (0, invoice, option),
108+
},
109+
(6, Spontaneous) => {};
110+
);
111+
85112
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
86113
///
87114
/// See [`LdkChannelConfig::accept_underpaying_htlcs`] for more information.

src/payment/spontaneous.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::config::{Config, LDK_PAYMENT_RETRY_TIMEOUT};
44
use crate::error::Error;
55
use crate::logger::{log_error, log_info, FilesystemLogger, Logger};
66
use crate::payment::payment_store::{
7-
PaymentDetails, PaymentDirection, PaymentStatus, PaymentStore,
7+
PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus, PaymentStore,
88
};
99
use crate::types::{ChannelManager, KeysManager};
1010

@@ -77,6 +77,7 @@ impl SpontaneousPayment {
7777
log_info!(self.logger, "Initiated sending {}msat to {}.", amount_msat, node_id);
7878

7979
let payment = PaymentDetails {
80+
kind: Some(PaymentKind::Spontaneous),
8081
hash: payment_hash,
8182
preimage: Some(payment_preimage),
8283
secret: None,
@@ -96,6 +97,7 @@ impl SpontaneousPayment {
9697
RetryableSendFailure::DuplicatePayment => Err(Error::DuplicatePayment),
9798
_ => {
9899
let payment = PaymentDetails {
100+
kind: Some(PaymentKind::Spontaneous),
99101
hash: payment_hash,
100102
preimage: Some(payment_preimage),
101103
secret: None,

src/uniffi_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use crate::payment::payment_store::{LSPFeeLimits, PaymentDirection, PaymentStatus};
1+
pub use crate::payment::payment_store::{LSPFeeLimits, PaymentDirection, PaymentStatus, PaymentKind};
22

33
pub use lightning::events::{ClosureReason, PaymentFailureReason};
44
pub use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};

0 commit comments

Comments
 (0)