Skip to content

Commit 516fc63

Browse files
committed
Add required fields to PaymentKind::Onchain
Previously, `PaymentKind::Onchain` was simply a placeholder entry we never actually used. Here, we extend it to include fields that are actually useful.
1 parent 6e5e9be commit 516fc63

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

bindings/ldk_node.udl

+7-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ interface ClosureReason {
326326

327327
[Enum]
328328
interface PaymentKind {
329-
Onchain();
329+
Onchain(Txid txid, ConfirmationStatus status);
330330
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret);
331331
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, LSPFeeLimits lsp_fee_limits);
332332
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id, UntrustedString? payer_note, u64? quantity);
@@ -357,6 +357,12 @@ dictionary LSPFeeLimits {
357357
u64? max_proportional_opening_fee_ppm_msat;
358358
};
359359

360+
[Enum]
361+
interface ConfirmationStatus {
362+
Confirmed (BlockHash block_hash, u32 height, u64 timestamp);
363+
Unconfirmed ();
364+
};
365+
360366
dictionary PaymentDetails {
361367
PaymentId id;
362368
PaymentKind kind;

src/payment/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ pub use bolt11::Bolt11Payment;
1818
pub use bolt12::Bolt12Payment;
1919
pub use onchain::OnchainPayment;
2020
pub use spontaneous::SpontaneousPayment;
21-
pub use store::{LSPFeeLimits, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus};
21+
pub use store::{
22+
ConfirmationStatus, LSPFeeLimits, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus,
23+
};
2224
pub use unified_qr::{QrPaymentResult, UnifiedQrPayment};
2325

2426
/// Represents information used to send a payment.

src/payment/store.rs

+54-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ use lightning::{
2525

2626
use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
2727

28+
use bitcoin::{BlockHash, Txid};
29+
2830
use std::collections::hash_map;
2931
use std::collections::HashMap;
3032
use std::ops::Deref;
@@ -148,6 +150,15 @@ impl PaymentDetails {
148150
update_if_necessary!(self.status, status);
149151
}
150152

153+
if let Some(confirmation_status) = update.confirmation_status {
154+
match self.kind {
155+
PaymentKind::Onchain { ref mut status, .. } => {
156+
update_if_necessary!(*status, confirmation_status);
157+
},
158+
_ => {},
159+
}
160+
}
161+
151162
if updated {
152163
self.latest_update_timestamp = SystemTime::now()
153164
.duration_since(UNIX_EPOCH)
@@ -273,7 +284,12 @@ impl_writeable_tlv_based_enum!(PaymentStatus,
273284
#[derive(Clone, Debug, PartialEq, Eq)]
274285
pub enum PaymentKind {
275286
/// An on-chain payment.
276-
Onchain,
287+
Onchain {
288+
/// The transaction identifier of this payment.
289+
txid: Txid,
290+
/// The confirmation status of this payment.
291+
status: ConfirmationStatus,
292+
},
277293
/// A [BOLT 11] payment.
278294
///
279295
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
@@ -362,7 +378,10 @@ pub enum PaymentKind {
362378
}
363379

364380
impl_writeable_tlv_based_enum!(PaymentKind,
365-
(0, Onchain) => {},
381+
(0, Onchain) => {
382+
(0, txid, required),
383+
(2, status, required),
384+
},
366385
(2, Bolt11) => {
367386
(0, hash, required),
368387
(2, preimage, option),
@@ -395,6 +414,31 @@ impl_writeable_tlv_based_enum!(PaymentKind,
395414
}
396415
);
397416

417+
/// Represents the confirmation status of a transaction.
418+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
419+
pub enum ConfirmationStatus {
420+
/// The transaction is confirmed in the best chain.
421+
Confirmed {
422+
/// The hash of the block in which the transaction was confirmed.
423+
block_hash: BlockHash,
424+
/// The height under which the block was confirmed.
425+
height: u32,
426+
/// The time at which the block was confirmed.
427+
timestamp: u64,
428+
},
429+
/// The transaction is unconfirmed.
430+
Unconfirmed,
431+
}
432+
433+
impl_writeable_tlv_based_enum!(ConfirmationStatus,
434+
(0, Confirmed) => {
435+
(0, block_hash, required),
436+
(2, height, required),
437+
(4, timestamp, required),
438+
},
439+
(2, Unconfirmed) => {},
440+
);
441+
398442
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
399443
///
400444
/// See [`LdkChannelConfig::accept_underpaying_htlcs`] for more information.
@@ -424,6 +468,7 @@ pub(crate) struct PaymentDetailsUpdate {
424468
pub amount_msat: Option<Option<u64>>,
425469
pub direction: Option<PaymentDirection>,
426470
pub status: Option<PaymentStatus>,
471+
pub confirmation_status: Option<ConfirmationStatus>,
427472
}
428473

429474
impl PaymentDetailsUpdate {
@@ -436,6 +481,7 @@ impl PaymentDetailsUpdate {
436481
amount_msat: None,
437482
direction: None,
438483
status: None,
484+
confirmation_status: None,
439485
}
440486
}
441487
}
@@ -451,6 +497,11 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
451497
_ => (None, None, None),
452498
};
453499

500+
let confirmation_status = match value.kind {
501+
PaymentKind::Onchain { status, .. } => Some(status),
502+
_ => None,
503+
};
504+
454505
Self {
455506
id: value.id,
456507
hash: Some(hash),
@@ -459,6 +510,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
459510
amount_msat: Some(value.amount_msat),
460511
direction: Some(value.direction),
461512
status: Some(value.status),
513+
confirmation_status,
462514
}
463515
}
464516
}

src/uniffi_types.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ pub use crate::config::{
1414
default_config, AnchorChannelsConfig, EsploraSyncConfig, MaxDustHTLCExposure,
1515
};
1616
pub use crate::graph::{ChannelInfo, ChannelUpdateInfo, NodeAnnouncementInfo, NodeInfo};
17-
pub use crate::payment::store::{LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus};
17+
pub use crate::payment::store::{
18+
ConfirmationStatus, LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus,
19+
};
1820
pub use crate::payment::{MaxTotalRoutingFeeLimit, QrPaymentResult, SendingParameters};
1921

2022
pub use lightning::chain::channelmonitor::BalanceSource;

0 commit comments

Comments
 (0)