Skip to content

Commit 04cdc07

Browse files
committed
Expose pending payments through ChannelManager
1 parent 53eb0d7 commit 04cdc07

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lightning/src/ln/channelmanager.rs

+40
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,14 @@ impl PendingOutboundPayment {
485485
_ => false,
486486
}
487487
}
488+
489+
fn is_legacy(&self) -> bool {
490+
match self {
491+
PendingOutboundPayment::Legacy { .. } => true,
492+
_ => false,
493+
}
494+
}
495+
488496
fn abandoned(&self) -> bool {
489497
match self {
490498
PendingOutboundPayment::Abandoned { .. } => true,
@@ -1203,6 +1211,17 @@ impl ChannelDetails {
12031211
}
12041212
}
12051213

1214+
pub enum PendingPaymentStatus {
1215+
Retryable,
1216+
Fulfilled,
1217+
Abandoned,
1218+
}
1219+
1220+
pub struct PendingPaymentDetails {
1221+
status: PendingPaymentStatus,
1222+
total_msat: Option<u64>,
1223+
}
1224+
12061225
/// If a payment fails to send, it can be in one of several states. This enum is returned as the
12071226
/// Err() type describing which state the payment is in, see the description of individual enum
12081227
/// states for more.
@@ -1770,6 +1789,27 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
17701789
self.list_channels_with_filter(|&(_, ref channel)| channel.is_live())
17711790
}
17721791

1792+
pub fn list_pending_payments(&self) -> Vec<PendingPaymentDetails> {
1793+
self.pending_outbound_payments.lock().unwrap().iter()
1794+
.filter(|&(_, value)| { !value.is_legacy() } )
1795+
.map(|(_, pending_outbound_payment)| {
1796+
match pending_outbound_payment {
1797+
PendingOutboundPayment::Retryable { total_msat, .. } => {
1798+
PendingPaymentDetails { status: PendingPaymentStatus::Retryable, total_msat: Some(*total_msat) }
1799+
},
1800+
PendingOutboundPayment::Abandoned { .. } => {
1801+
PendingPaymentDetails { status: PendingPaymentStatus::Abandoned, total_msat: None }
1802+
},
1803+
PendingOutboundPayment::Fulfilled { .. } => {
1804+
PendingPaymentDetails { status: PendingPaymentStatus::Fulfilled, total_msat: None }
1805+
},
1806+
_ => { unreachable!() }
1807+
}
1808+
1809+
})
1810+
.collect()
1811+
}
1812+
17731813
/// Helper function that issues the channel close events
17741814
fn issue_channel_close_events(&self, channel: &Channel<<K::Target as KeysInterface>::Signer>, closure_reason: ClosureReason) {
17751815
let mut pending_events_lock = self.pending_events.lock().unwrap();

0 commit comments

Comments
 (0)