+#[cfg(feature="no-std")]
+use alloc::{vec::Vec, boxed::Box};
+
+/// Information about where a received HTLC('s onion) has indicated the HTLC should go.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum PendingHTLCRouting {
+ /// An HTLC which should be forwarded on to another node.
+ Forward {
+ /// The onion which should be included in the forwarded HTLC, telling the next hop what to
+ /// do with the HTLC.
+ onion_packet: crate::lightning::ln::msgs::OnionPacket,
+ /// The short channel ID of the channel which we were instructed to forward this HTLC to.
+ ///
+ /// This could be a real on-chain SCID, an SCID alias, or some other SCID which has meaning
+ /// to the receiving node, such as one returned from
+ /// [`ChannelManager::get_intercept_scid`] or [`ChannelManager::get_phantom_scid`].
+ short_channel_id: u64,
+ /// Set if this HTLC is being forwarded within a blinded path.
+ ///
+ /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ blinded: crate::lightning::ln::channelmanager::BlindedForward,
+ },
+ /// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
+ ///
+ /// Note that at this point, we have not checked that the invoice being paid was actually
+ /// generated by us, but rather it's claiming to pay an invoice of ours.
+ Receive {
+ /// Information about the amount the sender intended to pay and (potential) proof that this
+ /// is a payment for an invoice we generated. This proof of payment is is also used for
+ /// linking MPP parts of a larger payment.
+ payment_data: crate::lightning::ln::msgs::FinalOnionHopData,
+ /// Additional data which we (allegedly) instructed the sender to include in the onion.
+ ///
+ /// For HTLCs received by LDK, this will ultimately be exposed in
+ /// [`Event::PaymentClaimable::onion_fields`] as
+ /// [`RecipientOnionFields::payment_metadata`].
+ payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ,
+ /// CLTV expiry of the received HTLC.
+ ///
+ /// Used to track when we should expire pending HTLCs that go unclaimed.
+ incoming_cltv_expiry: u32,
+ /// If the onion had forwarding instructions to one of our phantom node SCIDs, this will
+ /// provide the onion shared secret used to decrypt the next level of forwarding
+ /// instructions.
+ ///
+ /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ phantom_shared_secret: crate::c_types::ThirtyTwoBytes,
+ /// Custom TLVs which were set by the sender.
+ ///
+ /// For HTLCs received by LDK, this will ultimately be exposed in
+ /// [`Event::PaymentClaimable::onion_fields`] as
+ /// [`RecipientOnionFields::custom_tlvs`].
+ custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ,
+ /// Set if this HTLC is the final hop in a multi-hop blinded path.
+ requires_blinded_error: bool,
+ },
+ /// The onion indicates that this is for payment to us but which contains the preimage for
+ /// claiming included, and is unrelated to any invoice we'd previously generated (aka a
+ /// \"keysend\" or \"spontaneous\" payment).
+ ReceiveKeysend {
+ /// Information about the amount the sender intended to pay and possibly a token to
+ /// associate MPP parts of a larger payment.
+ ///
+ /// This will only be filled in if receiving MPP keysend payments is enabled, and it being
+ /// present will cause deserialization to fail on versions of LDK prior to 0.0.116.
+ ///
+ /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ payment_data: crate::lightning::ln::msgs::FinalOnionHopData,
+ /// Preimage for this onion payment. This preimage is provided by the sender and will be
+ /// used to settle the spontaneous payment.
+ payment_preimage: crate::c_types::ThirtyTwoBytes,
+ /// Additional data which we (allegedly) instructed the sender to include in the onion.
+ ///
+ /// For HTLCs received by LDK, this will ultimately bubble back up as
+ /// [`RecipientOnionFields::payment_metadata`].
+ payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ,
+ /// CLTV expiry of the received HTLC.
+ ///
+ /// Used to track when we should expire pending HTLCs that go unclaimed.
+ incoming_cltv_expiry: u32,
+ /// Custom TLVs which were set by the sender.
+ ///
+ /// For HTLCs received by LDK, these will ultimately bubble back up as
+ /// [`RecipientOnionFields::custom_tlvs`].
+ custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ,
+ },
+}
+use lightning::ln::channelmanager::PendingHTLCRouting as PendingHTLCRoutingImport;
+pub(crate) type nativePendingHTLCRouting = PendingHTLCRoutingImport;
+
+impl PendingHTLCRouting {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativePendingHTLCRouting {
+ match self {
+ PendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, } => {
+ let mut onion_packet_nonref = Clone::clone(onion_packet);
+ let mut short_channel_id_nonref = Clone::clone(short_channel_id);
+ let mut blinded_nonref = Clone::clone(blinded);
+ let mut local_blinded_nonref = if blinded_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded_nonref.take_inner()) } }) };
+ nativePendingHTLCRouting::Forward {
+ onion_packet: *unsafe { Box::from_raw(onion_packet_nonref.take_inner()) },
+ short_channel_id: short_channel_id_nonref,
+ blinded: local_blinded_nonref,
+ }
+ },
+ PendingHTLCRouting::Receive {ref payment_data, ref payment_metadata, ref incoming_cltv_expiry, ref phantom_shared_secret, ref custom_tlvs, ref requires_blinded_error, } => {
+ let mut payment_data_nonref = Clone::clone(payment_data);
+ let mut payment_metadata_nonref = Clone::clone(payment_metadata);
+ let mut local_payment_metadata_nonref = { /*payment_metadata_nonref*/ let payment_metadata_nonref_opt = payment_metadata_nonref; if payment_metadata_nonref_opt.is_none() { None } else { Some({ { let mut local_payment_metadata_nonref_0 = Vec::new(); for mut item in { payment_metadata_nonref_opt.take() }.into_rust().drain(..) { local_payment_metadata_nonref_0.push( { item }); }; local_payment_metadata_nonref_0 }})} };
+ let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
+ let mut phantom_shared_secret_nonref = Clone::clone(phantom_shared_secret);
+ let mut local_phantom_shared_secret_nonref = if phantom_shared_secret_nonref.data == [0; 32] { None } else { Some( { phantom_shared_secret_nonref.data }) };
+ let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
+ let mut local_custom_tlvs_nonref = Vec::new(); for mut item in custom_tlvs_nonref.into_rust().drain(..) { local_custom_tlvs_nonref.push( { let (mut orig_custom_tlvs_nonref_0_0, mut orig_custom_tlvs_nonref_0_1) = item.to_rust(); let mut local_orig_custom_tlvs_nonref_0_1 = Vec::new(); for mut item in orig_custom_tlvs_nonref_0_1.into_rust().drain(..) { local_orig_custom_tlvs_nonref_0_1.push( { item }); }; let mut local_custom_tlvs_nonref_0 = (orig_custom_tlvs_nonref_0_0, local_orig_custom_tlvs_nonref_0_1); local_custom_tlvs_nonref_0 }); };
+ let mut requires_blinded_error_nonref = Clone::clone(requires_blinded_error);
+ nativePendingHTLCRouting::Receive {
+ payment_data: *unsafe { Box::from_raw(payment_data_nonref.take_inner()) },
+ payment_metadata: local_payment_metadata_nonref,
+ incoming_cltv_expiry: incoming_cltv_expiry_nonref,
+ phantom_shared_secret: local_phantom_shared_secret_nonref,
+ custom_tlvs: local_custom_tlvs_nonref,
+ requires_blinded_error: requires_blinded_error_nonref,
+ }
+ },
+ PendingHTLCRouting::ReceiveKeysend {ref payment_data, ref payment_preimage, ref payment_metadata, ref incoming_cltv_expiry, ref custom_tlvs, } => {
+ let mut payment_data_nonref = Clone::clone(payment_data);
+ let mut local_payment_data_nonref = if payment_data_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payment_data_nonref.take_inner()) } }) };
+ let mut payment_preimage_nonref = Clone::clone(payment_preimage);
+ let mut payment_metadata_nonref = Clone::clone(payment_metadata);
+ let mut local_payment_metadata_nonref = { /*payment_metadata_nonref*/ let payment_metadata_nonref_opt = payment_metadata_nonref; if payment_metadata_nonref_opt.is_none() { None } else { Some({ { let mut local_payment_metadata_nonref_0 = Vec::new(); for mut item in { payment_metadata_nonref_opt.take() }.into_rust().drain(..) { local_payment_metadata_nonref_0.push( { item }); }; local_payment_metadata_nonref_0 }})} };
+ let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
+ let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
+ let mut local_custom_tlvs_nonref = Vec::new(); for mut item in custom_tlvs_nonref.into_rust().drain(..) { local_custom_tlvs_nonref.push( { let (mut orig_custom_tlvs_nonref_0_0, mut orig_custom_tlvs_nonref_0_1) = item.to_rust(); let mut local_orig_custom_tlvs_nonref_0_1 = Vec::new(); for mut item in orig_custom_tlvs_nonref_0_1.into_rust().drain(..) { local_orig_custom_tlvs_nonref_0_1.push( { item }); }; let mut local_custom_tlvs_nonref_0 = (orig_custom_tlvs_nonref_0_0, local_orig_custom_tlvs_nonref_0_1); local_custom_tlvs_nonref_0 }); };
+ nativePendingHTLCRouting::ReceiveKeysend {
+ payment_data: local_payment_data_nonref,
+ payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
+ payment_metadata: local_payment_metadata_nonref,
+ incoming_cltv_expiry: incoming_cltv_expiry_nonref,
+ custom_tlvs: local_custom_tlvs_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativePendingHTLCRouting {
+ match self {
+ PendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, } => {
+ let mut local_blinded = if blinded.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded.take_inner()) } }) };
+ nativePendingHTLCRouting::Forward {
+ onion_packet: *unsafe { Box::from_raw(onion_packet.take_inner()) },
+ short_channel_id: short_channel_id,
+ blinded: local_blinded,
+ }
+ },
+ PendingHTLCRouting::Receive {mut payment_data, mut payment_metadata, mut incoming_cltv_expiry, mut phantom_shared_secret, mut custom_tlvs, mut requires_blinded_error, } => {
+ let mut local_payment_metadata = { /*payment_metadata*/ let payment_metadata_opt = payment_metadata; if payment_metadata_opt.is_none() { None } else { Some({ { let mut local_payment_metadata_0 = Vec::new(); for mut item in { payment_metadata_opt.take() }.into_rust().drain(..) { local_payment_metadata_0.push( { item }); }; local_payment_metadata_0 }})} };
+ let mut local_phantom_shared_secret = if phantom_shared_secret.data == [0; 32] { None } else { Some( { phantom_shared_secret.data }) };
+ let mut local_custom_tlvs = Vec::new(); for mut item in custom_tlvs.into_rust().drain(..) { local_custom_tlvs.push( { let (mut orig_custom_tlvs_0_0, mut orig_custom_tlvs_0_1) = item.to_rust(); let mut local_orig_custom_tlvs_0_1 = Vec::new(); for mut item in orig_custom_tlvs_0_1.into_rust().drain(..) { local_orig_custom_tlvs_0_1.push( { item }); }; let mut local_custom_tlvs_0 = (orig_custom_tlvs_0_0, local_orig_custom_tlvs_0_1); local_custom_tlvs_0 }); };
+ nativePendingHTLCRouting::Receive {
+ payment_data: *unsafe { Box::from_raw(payment_data.take_inner()) },
+ payment_metadata: local_payment_metadata,
+ incoming_cltv_expiry: incoming_cltv_expiry,
+ phantom_shared_secret: local_phantom_shared_secret,
+ custom_tlvs: local_custom_tlvs,
+ requires_blinded_error: requires_blinded_error,
+ }
+ },
+ PendingHTLCRouting::ReceiveKeysend {mut payment_data, mut payment_preimage, mut payment_metadata, mut incoming_cltv_expiry, mut custom_tlvs, } => {
+ let mut local_payment_data = if payment_data.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payment_data.take_inner()) } }) };
+ let mut local_payment_metadata = { /*payment_metadata*/ let payment_metadata_opt = payment_metadata; if payment_metadata_opt.is_none() { None } else { Some({ { let mut local_payment_metadata_0 = Vec::new(); for mut item in { payment_metadata_opt.take() }.into_rust().drain(..) { local_payment_metadata_0.push( { item }); }; local_payment_metadata_0 }})} };
+ let mut local_custom_tlvs = Vec::new(); for mut item in custom_tlvs.into_rust().drain(..) { local_custom_tlvs.push( { let (mut orig_custom_tlvs_0_0, mut orig_custom_tlvs_0_1) = item.to_rust(); let mut local_orig_custom_tlvs_0_1 = Vec::new(); for mut item in orig_custom_tlvs_0_1.into_rust().drain(..) { local_orig_custom_tlvs_0_1.push( { item }); }; let mut local_custom_tlvs_0 = (orig_custom_tlvs_0_0, local_orig_custom_tlvs_0_1); local_custom_tlvs_0 }); };
+ nativePendingHTLCRouting::ReceiveKeysend {
+ payment_data: local_payment_data,
+ payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
+ payment_metadata: local_payment_metadata,
+ incoming_cltv_expiry: incoming_cltv_expiry,
+ custom_tlvs: local_custom_tlvs,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &PendingHTLCRoutingImport) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativePendingHTLCRouting) };
+ match native {
+ nativePendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, } => {
+ let mut onion_packet_nonref = Clone::clone(onion_packet);
+ let mut short_channel_id_nonref = Clone::clone(short_channel_id);
+ let mut blinded_nonref = Clone::clone(blinded);
+ let mut local_blinded_nonref = crate::lightning::ln::channelmanager::BlindedForward { inner: if blinded_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((blinded_nonref.unwrap())) } }, is_owned: true };
+ PendingHTLCRouting::Forward {
+ onion_packet: crate::lightning::ln::msgs::OnionPacket { inner: ObjOps::heap_alloc(onion_packet_nonref), is_owned: true },
+ short_channel_id: short_channel_id_nonref,
+ blinded: local_blinded_nonref,
+ }
+ },
+ nativePendingHTLCRouting::Receive {ref payment_data, ref payment_metadata, ref incoming_cltv_expiry, ref phantom_shared_secret, ref custom_tlvs, ref requires_blinded_error, } => {
+ let mut payment_data_nonref = Clone::clone(payment_data);
+ let mut payment_metadata_nonref = Clone::clone(payment_metadata);
+ let mut local_payment_metadata_nonref = if payment_metadata_nonref.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_payment_metadata_nonref_0 = Vec::new(); for mut item in payment_metadata_nonref.unwrap().drain(..) { local_payment_metadata_nonref_0.push( { item }); }; local_payment_metadata_nonref_0.into() }) };
+ let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
+ let mut phantom_shared_secret_nonref = Clone::clone(phantom_shared_secret);
+ let mut local_phantom_shared_secret_nonref = if phantom_shared_secret_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (phantom_shared_secret_nonref.unwrap()) } } };
+ let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
+ let mut local_custom_tlvs_nonref = Vec::new(); for mut item in custom_tlvs_nonref.drain(..) { local_custom_tlvs_nonref.push( { let (mut orig_custom_tlvs_nonref_0_0, mut orig_custom_tlvs_nonref_0_1) = item; let mut local_orig_custom_tlvs_nonref_0_1 = Vec::new(); for mut item in orig_custom_tlvs_nonref_0_1.drain(..) { local_orig_custom_tlvs_nonref_0_1.push( { item }); }; let mut local_custom_tlvs_nonref_0 = (orig_custom_tlvs_nonref_0_0, local_orig_custom_tlvs_nonref_0_1.into()).into(); local_custom_tlvs_nonref_0 }); };
+ let mut requires_blinded_error_nonref = Clone::clone(requires_blinded_error);
+ PendingHTLCRouting::Receive {
+ payment_data: crate::lightning::ln::msgs::FinalOnionHopData { inner: ObjOps::heap_alloc(payment_data_nonref), is_owned: true },
+ payment_metadata: local_payment_metadata_nonref,
+ incoming_cltv_expiry: incoming_cltv_expiry_nonref,
+ phantom_shared_secret: local_phantom_shared_secret_nonref,
+ custom_tlvs: local_custom_tlvs_nonref.into(),
+ requires_blinded_error: requires_blinded_error_nonref,
+ }
+ },
+ nativePendingHTLCRouting::ReceiveKeysend {ref payment_data, ref payment_preimage, ref payment_metadata, ref incoming_cltv_expiry, ref custom_tlvs, } => {
+ let mut payment_data_nonref = Clone::clone(payment_data);
+ let mut local_payment_data_nonref = crate::lightning::ln::msgs::FinalOnionHopData { inner: if payment_data_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((payment_data_nonref.unwrap())) } }, is_owned: true };
+ let mut payment_preimage_nonref = Clone::clone(payment_preimage);
+ let mut payment_metadata_nonref = Clone::clone(payment_metadata);
+ let mut local_payment_metadata_nonref = if payment_metadata_nonref.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_payment_metadata_nonref_0 = Vec::new(); for mut item in payment_metadata_nonref.unwrap().drain(..) { local_payment_metadata_nonref_0.push( { item }); }; local_payment_metadata_nonref_0.into() }) };
+ let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
+ let mut custom_tlvs_nonref = Clone::clone(custom_tlvs);
+ let mut local_custom_tlvs_nonref = Vec::new(); for mut item in custom_tlvs_nonref.drain(..) { local_custom_tlvs_nonref.push( { let (mut orig_custom_tlvs_nonref_0_0, mut orig_custom_tlvs_nonref_0_1) = item; let mut local_orig_custom_tlvs_nonref_0_1 = Vec::new(); for mut item in orig_custom_tlvs_nonref_0_1.drain(..) { local_orig_custom_tlvs_nonref_0_1.push( { item }); }; let mut local_custom_tlvs_nonref_0 = (orig_custom_tlvs_nonref_0_0, local_orig_custom_tlvs_nonref_0_1.into()).into(); local_custom_tlvs_nonref_0 }); };
+ PendingHTLCRouting::ReceiveKeysend {
+ payment_data: local_payment_data_nonref,
+ payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
+ payment_metadata: local_payment_metadata_nonref,
+ incoming_cltv_expiry: incoming_cltv_expiry_nonref,
+ custom_tlvs: local_custom_tlvs_nonref.into(),
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativePendingHTLCRouting) -> Self {
+ match native {
+ nativePendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, } => {
+ let mut local_blinded = crate::lightning::ln::channelmanager::BlindedForward { inner: if blinded.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((blinded.unwrap())) } }, is_owned: true };
+ PendingHTLCRouting::Forward {
+ onion_packet: crate::lightning::ln::msgs::OnionPacket { inner: ObjOps::heap_alloc(onion_packet), is_owned: true },
+ short_channel_id: short_channel_id,
+ blinded: local_blinded,
+ }
+ },
+ nativePendingHTLCRouting::Receive {mut payment_data, mut payment_metadata, mut incoming_cltv_expiry, mut phantom_shared_secret, mut custom_tlvs, mut requires_blinded_error, } => {
+ let mut local_payment_metadata = if payment_metadata.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_payment_metadata_0 = Vec::new(); for mut item in payment_metadata.unwrap().drain(..) { local_payment_metadata_0.push( { item }); }; local_payment_metadata_0.into() }) };
+ let mut local_phantom_shared_secret = if phantom_shared_secret.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (phantom_shared_secret.unwrap()) } } };
+ let mut local_custom_tlvs = Vec::new(); for mut item in custom_tlvs.drain(..) { local_custom_tlvs.push( { let (mut orig_custom_tlvs_0_0, mut orig_custom_tlvs_0_1) = item; let mut local_orig_custom_tlvs_0_1 = Vec::new(); for mut item in orig_custom_tlvs_0_1.drain(..) { local_orig_custom_tlvs_0_1.push( { item }); }; let mut local_custom_tlvs_0 = (orig_custom_tlvs_0_0, local_orig_custom_tlvs_0_1.into()).into(); local_custom_tlvs_0 }); };
+ PendingHTLCRouting::Receive {
+ payment_data: crate::lightning::ln::msgs::FinalOnionHopData { inner: ObjOps::heap_alloc(payment_data), is_owned: true },
+ payment_metadata: local_payment_metadata,
+ incoming_cltv_expiry: incoming_cltv_expiry,
+ phantom_shared_secret: local_phantom_shared_secret,
+ custom_tlvs: local_custom_tlvs.into(),
+ requires_blinded_error: requires_blinded_error,
+ }
+ },
+ nativePendingHTLCRouting::ReceiveKeysend {mut payment_data, mut payment_preimage, mut payment_metadata, mut incoming_cltv_expiry, mut custom_tlvs, } => {
+ let mut local_payment_data = crate::lightning::ln::msgs::FinalOnionHopData { inner: if payment_data.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((payment_data.unwrap())) } }, is_owned: true };
+ let mut local_payment_metadata = if payment_metadata.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_payment_metadata_0 = Vec::new(); for mut item in payment_metadata.unwrap().drain(..) { local_payment_metadata_0.push( { item }); }; local_payment_metadata_0.into() }) };
+ let mut local_custom_tlvs = Vec::new(); for mut item in custom_tlvs.drain(..) { local_custom_tlvs.push( { let (mut orig_custom_tlvs_0_0, mut orig_custom_tlvs_0_1) = item; let mut local_orig_custom_tlvs_0_1 = Vec::new(); for mut item in orig_custom_tlvs_0_1.drain(..) { local_orig_custom_tlvs_0_1.push( { item }); }; let mut local_custom_tlvs_0 = (orig_custom_tlvs_0_0, local_orig_custom_tlvs_0_1.into()).into(); local_custom_tlvs_0 }); };
+ PendingHTLCRouting::ReceiveKeysend {
+ payment_data: local_payment_data,
+ payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
+ payment_metadata: local_payment_metadata,
+ incoming_cltv_expiry: incoming_cltv_expiry,
+ custom_tlvs: local_custom_tlvs.into(),
+ }
+ },
+ }
+ }
+}
+/// Frees any resources used by the PendingHTLCRouting
+#[no_mangle]
+pub extern "C" fn PendingHTLCRouting_free(this_ptr: PendingHTLCRouting) { }
+/// Creates a copy of the PendingHTLCRouting
+#[no_mangle]
+pub extern "C" fn PendingHTLCRouting_clone(orig: &PendingHTLCRouting) -> PendingHTLCRouting {
+ 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 PendingHTLCRouting_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PendingHTLCRouting)).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 PendingHTLCRouting_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut PendingHTLCRouting) };
+}
+#[no_mangle]
+/// Utility method to constructs a new Forward-variant PendingHTLCRouting
+pub extern "C" fn PendingHTLCRouting_forward(onion_packet: crate::lightning::ln::msgs::OnionPacket, short_channel_id: u64, blinded: crate::lightning::ln::channelmanager::BlindedForward) -> PendingHTLCRouting {
+ PendingHTLCRouting::Forward {
+ onion_packet,
+ short_channel_id,
+ blinded,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new Receive-variant PendingHTLCRouting
+pub extern "C" fn PendingHTLCRouting_receive(payment_data: crate::lightning::ln::msgs::FinalOnionHopData, payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ, incoming_cltv_expiry: u32, phantom_shared_secret: crate::c_types::ThirtyTwoBytes, custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ, requires_blinded_error: bool) -> PendingHTLCRouting {
+ PendingHTLCRouting::Receive {
+ payment_data,
+ payment_metadata,
+ incoming_cltv_expiry,
+ phantom_shared_secret,
+ custom_tlvs,
+ requires_blinded_error,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new ReceiveKeysend-variant PendingHTLCRouting
+pub extern "C" fn PendingHTLCRouting_receive_keysend(payment_data: crate::lightning::ln::msgs::FinalOnionHopData, payment_preimage: crate::c_types::ThirtyTwoBytes, payment_metadata: crate::c_types::derived::COption_CVec_u8ZZ, incoming_cltv_expiry: u32, custom_tlvs: crate::c_types::derived::CVec_C2Tuple_u64CVec_u8ZZZ) -> PendingHTLCRouting {
+ PendingHTLCRouting::ReceiveKeysend {
+ payment_data,
+ payment_preimage,
+ payment_metadata,
+ incoming_cltv_expiry,
+ custom_tlvs,
+ }
+}
+
+use lightning::ln::channelmanager::BlindedForward as nativeBlindedForwardImport;
+pub(crate) type nativeBlindedForward = nativeBlindedForwardImport;
+
+/// Information used to forward or fail this HTLC that is being forwarded within a blinded path.
+#[must_use]
+#[repr(C)]
+pub struct BlindedForward {
+ /// 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 nativeBlindedForward,
+ /// 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 BlindedForward {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeBlindedForward>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the BlindedForward, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn BlindedForward_free(this_obj: BlindedForward) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn BlindedForward_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedForward) };
+}
+#[allow(unused)]
+impl BlindedForward {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedForward {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedForward {
+ 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 nativeBlindedForward {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+}
+/// The `blinding_point` that was set in the inbound [`msgs::UpdateAddHTLC`], or in the inbound
+/// onion payload if we're the introduction node. Useful for calculating the next hop's
+/// [`msgs::UpdateAddHTLC::blinding_point`].
+#[no_mangle]
+pub extern "C" fn BlindedForward_get_inbound_blinding_point(this_ptr: &BlindedForward) -> crate::c_types::PublicKey {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().inbound_blinding_point;
+ crate::c_types::PublicKey::from_rust(&inner_val)
+}
+/// The `blinding_point` that was set in the inbound [`msgs::UpdateAddHTLC`], or in the inbound
+/// onion payload if we're the introduction node. Useful for calculating the next hop's
+/// [`msgs::UpdateAddHTLC::blinding_point`].
+#[no_mangle]
+pub extern "C" fn BlindedForward_set_inbound_blinding_point(this_ptr: &mut BlindedForward, mut val: crate::c_types::PublicKey) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inbound_blinding_point = val.into_rust();
+}
+/// If needed, this determines how this HTLC should be failed backwards, based on whether we are
+/// the introduction node.
+#[no_mangle]
+pub extern "C" fn BlindedForward_get_failure(this_ptr: &BlindedForward) -> crate::lightning::ln::channelmanager::BlindedFailure {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().failure;
+ crate::lightning::ln::channelmanager::BlindedFailure::from_native(inner_val)
+}
+/// If needed, this determines how this HTLC should be failed backwards, based on whether we are
+/// the introduction node.
+#[no_mangle]
+pub extern "C" fn BlindedForward_set_failure(this_ptr: &mut BlindedForward, mut val: crate::lightning::ln::channelmanager::BlindedFailure) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure = val.into_native();
+}
+/// Constructs a new BlindedForward given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn BlindedForward_new(mut inbound_blinding_point_arg: crate::c_types::PublicKey, mut failure_arg: crate::lightning::ln::channelmanager::BlindedFailure) -> BlindedForward {
+ BlindedForward { inner: ObjOps::heap_alloc(nativeBlindedForward {
+ inbound_blinding_point: inbound_blinding_point_arg.into_rust(),
+ failure: failure_arg.into_native(),
+ }), is_owned: true }
+}
+impl Clone for BlindedForward {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeBlindedForward>::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 BlindedForward_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedForward)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the BlindedForward
+pub extern "C" fn BlindedForward_clone(orig: &BlindedForward) -> BlindedForward {
+ orig.clone()
+}
+/// Get a string which allows debug introspection of a BlindedForward object
+pub extern "C" fn BlindedForward_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channelmanager::BlindedForward }).into()}
+/// Generates a non-cryptographic 64-bit hash of the BlindedForward.
+#[no_mangle]
+pub extern "C" fn BlindedForward_hash(o: &BlindedForward) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
+/// Checks if two BlindedForwards contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+/// Two objects with NULL inner values will be considered "equal" here.
+#[no_mangle]
+pub extern "C" fn BlindedForward_eq(a: &BlindedForward, b: &BlindedForward) -> bool {
+ if a.inner == b.inner { return true; }
+ if a.inner.is_null() || b.inner.is_null() { return false; }
+ if a.get_native_ref() == b.get_native_ref() { true } else { false }
+}
+
+use lightning::ln::channelmanager::PendingHTLCInfo as nativePendingHTLCInfoImport;
+pub(crate) type nativePendingHTLCInfo = nativePendingHTLCInfoImport;