+/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
+/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum RecentPaymentDetails {
+ /// When an invoice was requested and thus a payment has not yet been sent.
+ AwaitingInvoice {
+ /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
+ /// a payment and ensure idempotency in LDK.
+ payment_id: crate::c_types::ThirtyTwoBytes,
+ },
+ /// When a payment is still being sent and awaiting successful delivery.
+ Pending {
+ /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
+ /// a payment and ensure idempotency in LDK.
+ payment_id: crate::c_types::ThirtyTwoBytes,
+ /// Hash of the payment that is currently being sent but has yet to be fulfilled or
+ /// abandoned.
+ payment_hash: crate::c_types::ThirtyTwoBytes,
+ /// Total amount (in msat, excluding fees) across all paths for this payment,
+ /// not just the amount currently inflight.
+ total_msat: u64,
+ },
+ /// When a pending payment is fulfilled, we continue tracking it until all pending HTLCs have
+ /// been resolved. Upon receiving [`Event::PaymentSent`], we delay for a few minutes before the
+ /// payment is removed from tracking.
+ Fulfilled {
+ /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
+ /// a payment and ensure idempotency in LDK.
+ payment_id: crate::c_types::ThirtyTwoBytes,
+ /// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
+ /// made before LDK version 0.0.104.
+ payment_hash: crate::c_types::derived::COption_ThirtyTwoBytesZ,
+ },
+ /// After a payment's retries are exhausted per the provided [`Retry`], or it is explicitly
+ /// abandoned via [`ChannelManager::abandon_payment`], it is marked as abandoned until all
+ /// pending HTLCs for this payment resolve and an [`Event::PaymentFailed`] is generated.
+ Abandoned {
+ /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify
+ /// a payment and ensure idempotency in LDK.
+ payment_id: crate::c_types::ThirtyTwoBytes,
+ /// Hash of the payment that we have given up trying to send.
+ payment_hash: crate::c_types::ThirtyTwoBytes,
+ },
+}
+use lightning::ln::channelmanager::RecentPaymentDetails as RecentPaymentDetailsImport;
+pub(crate) type nativeRecentPaymentDetails = RecentPaymentDetailsImport;
+
+impl RecentPaymentDetails {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeRecentPaymentDetails {
+ match self {
+ RecentPaymentDetails::AwaitingInvoice {ref payment_id, } => {
+ let mut payment_id_nonref = Clone::clone(payment_id);
+ nativeRecentPaymentDetails::AwaitingInvoice {
+ payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
+ }
+ },
+ RecentPaymentDetails::Pending {ref payment_id, ref payment_hash, ref total_msat, } => {
+ let mut payment_id_nonref = Clone::clone(payment_id);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ let mut total_msat_nonref = Clone::clone(total_msat);
+ nativeRecentPaymentDetails::Pending {
+ payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
+ total_msat: total_msat_nonref,
+ }
+ },
+ RecentPaymentDetails::Fulfilled {ref payment_id, ref payment_hash, } => {
+ let mut payment_id_nonref = Clone::clone(payment_id);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ let mut local_payment_hash_nonref = { /*payment_hash_nonref*/ let payment_hash_nonref_opt = payment_hash_nonref; if payment_hash_nonref_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentHash({ payment_hash_nonref_opt.take() }.data) }})} };
+ nativeRecentPaymentDetails::Fulfilled {
+ payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
+ payment_hash: local_payment_hash_nonref,
+ }
+ },
+ RecentPaymentDetails::Abandoned {ref payment_id, ref payment_hash, } => {
+ let mut payment_id_nonref = Clone::clone(payment_id);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ nativeRecentPaymentDetails::Abandoned {
+ payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeRecentPaymentDetails {
+ match self {
+ RecentPaymentDetails::AwaitingInvoice {mut payment_id, } => {
+ nativeRecentPaymentDetails::AwaitingInvoice {
+ payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
+ }
+ },
+ RecentPaymentDetails::Pending {mut payment_id, mut payment_hash, mut total_msat, } => {
+ nativeRecentPaymentDetails::Pending {
+ payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
+ total_msat: total_msat,
+ }
+ },
+ RecentPaymentDetails::Fulfilled {mut payment_id, mut payment_hash, } => {
+ let mut local_payment_hash = { /*payment_hash*/ let payment_hash_opt = payment_hash; if payment_hash_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentHash({ payment_hash_opt.take() }.data) }})} };
+ nativeRecentPaymentDetails::Fulfilled {
+ payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
+ payment_hash: local_payment_hash,
+ }
+ },
+ RecentPaymentDetails::Abandoned {mut payment_id, mut payment_hash, } => {
+ nativeRecentPaymentDetails::Abandoned {
+ payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeRecentPaymentDetails) -> Self {
+ match native {
+ nativeRecentPaymentDetails::AwaitingInvoice {ref payment_id, } => {
+ let mut payment_id_nonref = Clone::clone(payment_id);
+ RecentPaymentDetails::AwaitingInvoice {
+ payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
+ }
+ },
+ nativeRecentPaymentDetails::Pending {ref payment_id, ref payment_hash, ref total_msat, } => {
+ let mut payment_id_nonref = Clone::clone(payment_id);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ let mut total_msat_nonref = Clone::clone(total_msat);
+ RecentPaymentDetails::Pending {
+ payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
+ total_msat: total_msat_nonref,
+ }
+ },
+ nativeRecentPaymentDetails::Fulfilled {ref payment_id, ref payment_hash, } => {
+ let mut payment_id_nonref = Clone::clone(payment_id);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ let mut local_payment_hash_nonref = if payment_hash_nonref.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some( { crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.unwrap().0 } }) };
+ RecentPaymentDetails::Fulfilled {
+ payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
+ payment_hash: local_payment_hash_nonref,
+ }
+ },
+ nativeRecentPaymentDetails::Abandoned {ref payment_id, ref payment_hash, } => {
+ let mut payment_id_nonref = Clone::clone(payment_id);
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ RecentPaymentDetails::Abandoned {
+ payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeRecentPaymentDetails) -> Self {
+ match native {
+ nativeRecentPaymentDetails::AwaitingInvoice {mut payment_id, } => {
+ RecentPaymentDetails::AwaitingInvoice {
+ payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
+ }
+ },
+ nativeRecentPaymentDetails::Pending {mut payment_id, mut payment_hash, mut total_msat, } => {
+ RecentPaymentDetails::Pending {
+ payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
+ total_msat: total_msat,
+ }
+ },
+ nativeRecentPaymentDetails::Fulfilled {mut payment_id, mut payment_hash, } => {
+ let mut local_payment_hash = if payment_hash.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some( { crate::c_types::ThirtyTwoBytes { data: payment_hash.unwrap().0 } }) };
+ RecentPaymentDetails::Fulfilled {
+ payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
+ payment_hash: local_payment_hash,
+ }
+ },
+ nativeRecentPaymentDetails::Abandoned {mut payment_id, mut payment_hash, } => {
+ RecentPaymentDetails::Abandoned {
+ payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
+ }
+ },
+ }
+ }
+}
+/// Frees any resources used by the RecentPaymentDetails
+#[no_mangle]
+pub extern "C" fn RecentPaymentDetails_free(this_ptr: RecentPaymentDetails) { }
+/// Creates a copy of the RecentPaymentDetails
+#[no_mangle]
+pub extern "C" fn RecentPaymentDetails_clone(orig: &RecentPaymentDetails) -> RecentPaymentDetails {
+ orig.clone()
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn RecentPaymentDetails_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const RecentPaymentDetails)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn RecentPaymentDetails_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut RecentPaymentDetails) };
+}
+#[no_mangle]
+/// Utility method to constructs a new AwaitingInvoice-variant RecentPaymentDetails
+pub extern "C" fn RecentPaymentDetails_awaiting_invoice(payment_id: crate::c_types::ThirtyTwoBytes) -> RecentPaymentDetails {
+ RecentPaymentDetails::AwaitingInvoice {
+ payment_id,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new Pending-variant RecentPaymentDetails
+pub extern "C" fn RecentPaymentDetails_pending(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, total_msat: u64) -> RecentPaymentDetails {
+ RecentPaymentDetails::Pending {
+ payment_id,
+ payment_hash,
+ total_msat,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new Fulfilled-variant RecentPaymentDetails
+pub extern "C" fn RecentPaymentDetails_fulfilled(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::derived::COption_ThirtyTwoBytesZ) -> RecentPaymentDetails {
+ RecentPaymentDetails::Fulfilled {
+ payment_id,
+ payment_hash,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new Abandoned-variant RecentPaymentDetails
+pub extern "C" fn RecentPaymentDetails_abandoned(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> RecentPaymentDetails {
+ RecentPaymentDetails::Abandoned {
+ payment_id,
+ payment_hash,
+ }
+}
+
+use lightning::ln::channelmanager::PhantomRouteHints as nativePhantomRouteHintsImport;
+pub(crate) type nativePhantomRouteHints = nativePhantomRouteHintsImport;
+
+/// Route hints used in constructing invoices for [phantom node payents].
+///
+/// [phantom node payments]: crate::sign::PhantomKeysManager
+#[must_use]
+#[repr(C)]
+pub struct PhantomRouteHints {
+ /// A pointer to the opaque Rust object.
+
+ /// Nearly everywhere, inner must be non-null, however in places where
+ /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+ pub inner: *mut nativePhantomRouteHints,
+ /// Indicates that this is the only struct which contains the same pointer.
+
+ /// Rust functions which take ownership of an object provided via an argument require
+ /// this to be true and invalidate the object pointed to by inner.
+ pub is_owned: bool,
+}
+
+impl Drop for PhantomRouteHints {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativePhantomRouteHints>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the PhantomRouteHints, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn PhantomRouteHints_free(this_obj: PhantomRouteHints) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn PhantomRouteHints_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomRouteHints) };
+}
+#[allow(unused)]
+impl PhantomRouteHints {
+ pub(crate) fn get_native_ref(&self) -> &'static nativePhantomRouteHints {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomRouteHints {
+ unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
+ }
+ /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+ pub(crate) fn take_inner(mut self) -> *mut nativePhantomRouteHints {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+}
+/// The list of channels to be included in the invoice route hints.
+#[no_mangle]
+pub extern "C" fn PhantomRouteHints_get_channels(this_ptr: &PhantomRouteHints) -> crate::c_types::derived::CVec_ChannelDetailsZ {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().channels;
+ let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); };
+ local_inner_val.into()
+}
+/// The list of channels to be included in the invoice route hints.
+#[no_mangle]
+pub extern "C" fn PhantomRouteHints_set_channels(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::derived::CVec_ChannelDetailsZ) {
+ let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
+}
+/// A fake scid used for representing the phantom node's fake channel in generating the invoice
+/// route hints.
+#[no_mangle]
+pub extern "C" fn PhantomRouteHints_get_phantom_scid(this_ptr: &PhantomRouteHints) -> u64 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().phantom_scid;
+ *inner_val
+}
+/// A fake scid used for representing the phantom node's fake channel in generating the invoice
+/// route hints.
+#[no_mangle]
+pub extern "C" fn PhantomRouteHints_set_phantom_scid(this_ptr: &mut PhantomRouteHints, mut val: u64) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.phantom_scid = val;
+}
+/// The pubkey of the real backing node that would ultimately receive the payment.
+#[no_mangle]
+pub extern "C" fn PhantomRouteHints_get_real_node_pubkey(this_ptr: &PhantomRouteHints) -> crate::c_types::PublicKey {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().real_node_pubkey;
+ crate::c_types::PublicKey::from_rust(&inner_val)
+}
+/// The pubkey of the real backing node that would ultimately receive the payment.
+#[no_mangle]
+pub extern "C" fn PhantomRouteHints_set_real_node_pubkey(this_ptr: &mut PhantomRouteHints, mut val: crate::c_types::PublicKey) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.real_node_pubkey = val.into_rust();
+}
+/// Constructs a new PhantomRouteHints given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn PhantomRouteHints_new(mut channels_arg: crate::c_types::derived::CVec_ChannelDetailsZ, mut phantom_scid_arg: u64, mut real_node_pubkey_arg: crate::c_types::PublicKey) -> PhantomRouteHints {
+ let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ PhantomRouteHints { inner: ObjOps::heap_alloc(nativePhantomRouteHints {
+ channels: local_channels_arg,
+ phantom_scid: phantom_scid_arg,
+ real_node_pubkey: real_node_pubkey_arg.into_rust(),
+ }), is_owned: true }
+}
+impl Clone for PhantomRouteHints {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativePhantomRouteHints>::is_null(self.inner) { core::ptr::null_mut() } else {
+ ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
+ is_owned: true,
+ }
+ }
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn PhantomRouteHints_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePhantomRouteHints)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the PhantomRouteHints
+pub extern "C" fn PhantomRouteHints_clone(orig: &PhantomRouteHints) -> PhantomRouteHints {
+ orig.clone()
+}
+/// Constructs a new `ChannelManager` to hold several channels and route between them.
+///
+/// The current time or latest block header time can be provided as the `current_timestamp`.
+///