Skip to content

Commit 62ff60c

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 c9ddfae commit 62ff60c

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
@@ -358,7 +358,7 @@ interface ClosureReason {
358358

359359
[Enum]
360360
interface PaymentKind {
361-
Onchain();
361+
Onchain(Txid txid, ConfirmationStatus status);
362362
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret);
363363
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, LSPFeeLimits lsp_fee_limits);
364364
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id, UntrustedString? payer_note, u64? quantity);
@@ -389,6 +389,12 @@ dictionary LSPFeeLimits {
389389
u64? max_proportional_opening_fee_ppm_msat;
390390
};
391391

392+
[Enum]
393+
interface ConfirmationStatus {
394+
Confirmed (BlockHash block_hash, u32 height, u64 timestamp);
395+
Unconfirmed ();
396+
};
397+
392398
dictionary PaymentDetails {
393399
PaymentId id;
394400
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;
@@ -156,6 +158,15 @@ impl PaymentDetails {
156158
update_if_necessary!(self.status, status);
157159
}
158160

161+
if let Some(confirmation_status) = update.confirmation_status {
162+
match self.kind {
163+
PaymentKind::Onchain { ref mut status, .. } => {
164+
update_if_necessary!(*status, confirmation_status);
165+
},
166+
_ => {},
167+
}
168+
}
169+
159170
if updated {
160171
self.latest_update_timestamp = SystemTime::now()
161172
.duration_since(UNIX_EPOCH)
@@ -281,7 +292,12 @@ impl_writeable_tlv_based_enum!(PaymentStatus,
281292
#[derive(Clone, Debug, PartialEq, Eq)]
282293
pub enum PaymentKind {
283294
/// An on-chain payment.
284-
Onchain,
295+
Onchain {
296+
/// The transaction identifier of this payment.
297+
txid: Txid,
298+
/// The confirmation status of this payment.
299+
status: ConfirmationStatus,
300+
},
285301
/// A [BOLT 11] payment.
286302
///
287303
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
@@ -370,7 +386,10 @@ pub enum PaymentKind {
370386
}
371387

372388
impl_writeable_tlv_based_enum!(PaymentKind,
373-
(0, Onchain) => {},
389+
(0, Onchain) => {
390+
(0, txid, required),
391+
(2, status, required),
392+
},
374393
(2, Bolt11) => {
375394
(0, hash, required),
376395
(2, preimage, option),
@@ -403,6 +422,31 @@ impl_writeable_tlv_based_enum!(PaymentKind,
403422
}
404423
);
405424

425+
/// Represents the confirmation status of a transaction.
426+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
427+
pub enum ConfirmationStatus {
428+
/// The transaction is confirmed in the best chain.
429+
Confirmed {
430+
/// The hash of the block in which the transaction was confirmed.
431+
block_hash: BlockHash,
432+
/// The height under which the block was confirmed.
433+
height: u32,
434+
/// The timestamp, in seconds since start of the UNIX epoch, when this entry was last updated.
435+
timestamp: u64,
436+
},
437+
/// The transaction is unconfirmed.
438+
Unconfirmed,
439+
}
440+
441+
impl_writeable_tlv_based_enum!(ConfirmationStatus,
442+
(0, Confirmed) => {
443+
(0, block_hash, required),
444+
(2, height, required),
445+
(4, timestamp, required),
446+
},
447+
(2, Unconfirmed) => {},
448+
);
449+
406450
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
407451
///
408452
/// See [`LdkChannelConfig::accept_underpaying_htlcs`] for more information.
@@ -432,6 +476,7 @@ pub(crate) struct PaymentDetailsUpdate {
432476
pub amount_msat: Option<Option<u64>>,
433477
pub direction: Option<PaymentDirection>,
434478
pub status: Option<PaymentStatus>,
479+
pub confirmation_status: Option<ConfirmationStatus>,
435480
}
436481

437482
impl PaymentDetailsUpdate {
@@ -444,6 +489,7 @@ impl PaymentDetailsUpdate {
444489
amount_msat: None,
445490
direction: None,
446491
status: None,
492+
confirmation_status: None,
447493
}
448494
}
449495
}
@@ -459,6 +505,11 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
459505
_ => (None, None, None),
460506
};
461507

508+
let confirmation_status = match value.kind {
509+
PaymentKind::Onchain { status, .. } => Some(status),
510+
_ => None,
511+
};
512+
462513
Self {
463514
id: value.id,
464515
hash: Some(hash),
@@ -467,6 +518,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate {
467518
amount_msat: Some(value.amount_msat),
468519
direction: Some(value.direction),
469520
status: Some(value.status),
521+
confirmation_status,
470522
}
471523
}
472524
}

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)