+#[no_mangle]
+/// Read a ClosureReason from a byte array, created by ClosureReason_write
+pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_ClosureReasonZDecodeErrorZ {
+ let res: Result<Option<lightning::util::events::ClosureReason>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_ClosureReasonZ::None } else { crate::c_types::derived::COption_ClosureReasonZ::Some( { crate::lightning::util::events::ClosureReason::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
+ local_res
+}
+/// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum HTLCDestination {
+ /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
+ /// there is insufficient capacity in our outbound channel.
+ NextHopChannel {
+ /// The `node_id` of the next node. For backwards compatibility, this field is
+ /// marked as optional, versions prior to 0.0.110 may not always be able to provide
+ /// counterparty node information.
+ ///
+ /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ node_id: crate::c_types::PublicKey,
+ /// The outgoing `channel_id` between us and the next node.
+ channel_id: crate::c_types::ThirtyTwoBytes,
+ },
+ /// Scenario where we are unsure of the next node to forward the HTLC to.
+ UnknownNextHop {
+ /// Short channel id we are requesting to forward an HTLC to.
+ requested_forward_scid: u64,
+ },
+ /// Failure scenario where an HTLC may have been forwarded to be intended for us,
+ /// but is invalid for some reason, so we reject it.
+ ///
+ /// Some of the reasons may include:
+ /// * HTLC Timeouts
+ /// * Expected MPP amount to claim does not equal HTLC total
+ /// * Claimable amount does not match expected amount
+ FailedPayment {
+ /// The payment hash of the payment we attempted to process.
+ payment_hash: crate::c_types::ThirtyTwoBytes,
+ },
+}
+use lightning::util::events::HTLCDestination as HTLCDestinationImport;
+pub(crate) type nativeHTLCDestination = HTLCDestinationImport;
+
+impl HTLCDestination {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeHTLCDestination {
+ match self {
+ HTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
+ let mut node_id_nonref = (*node_id).clone();
+ let mut local_node_id_nonref = if node_id_nonref.is_null() { None } else { Some( { node_id_nonref.into_rust() }) };
+ let mut channel_id_nonref = (*channel_id).clone();
+ nativeHTLCDestination::NextHopChannel {
+ node_id: local_node_id_nonref,
+ channel_id: channel_id_nonref.data,
+ }
+ },
+ HTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
+ let mut requested_forward_scid_nonref = (*requested_forward_scid).clone();
+ nativeHTLCDestination::UnknownNextHop {
+ requested_forward_scid: requested_forward_scid_nonref,
+ }
+ },
+ HTLCDestination::FailedPayment {ref payment_hash, } => {
+ let mut payment_hash_nonref = (*payment_hash).clone();
+ nativeHTLCDestination::FailedPayment {
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeHTLCDestination {
+ match self {
+ HTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
+ let mut local_node_id = if node_id.is_null() { None } else { Some( { node_id.into_rust() }) };
+ nativeHTLCDestination::NextHopChannel {
+ node_id: local_node_id,
+ channel_id: channel_id.data,
+ }
+ },
+ HTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
+ nativeHTLCDestination::UnknownNextHop {
+ requested_forward_scid: requested_forward_scid,
+ }
+ },
+ HTLCDestination::FailedPayment {mut payment_hash, } => {
+ nativeHTLCDestination::FailedPayment {
+ payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeHTLCDestination) -> Self {
+ match native {
+ nativeHTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
+ let mut node_id_nonref = (*node_id).clone();
+ let mut local_node_id_nonref = if node_id_nonref.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(node_id_nonref.unwrap())) } };
+ let mut channel_id_nonref = (*channel_id).clone();
+ HTLCDestination::NextHopChannel {
+ node_id: local_node_id_nonref,
+ channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
+ }
+ },
+ nativeHTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
+ let mut requested_forward_scid_nonref = (*requested_forward_scid).clone();
+ HTLCDestination::UnknownNextHop {
+ requested_forward_scid: requested_forward_scid_nonref,
+ }
+ },
+ nativeHTLCDestination::FailedPayment {ref payment_hash, } => {
+ let mut payment_hash_nonref = (*payment_hash).clone();
+ HTLCDestination::FailedPayment {
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeHTLCDestination) -> Self {
+ match native {
+ nativeHTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
+ let mut local_node_id = if node_id.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(node_id.unwrap())) } };
+ HTLCDestination::NextHopChannel {
+ node_id: local_node_id,
+ channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
+ }
+ },
+ nativeHTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
+ HTLCDestination::UnknownNextHop {
+ requested_forward_scid: requested_forward_scid,
+ }
+ },
+ nativeHTLCDestination::FailedPayment {mut payment_hash, } => {
+ HTLCDestination::FailedPayment {
+ payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
+ }
+ },
+ }
+ }
+}
+/// Frees any resources used by the HTLCDestination
+#[no_mangle]
+pub extern "C" fn HTLCDestination_free(this_ptr: HTLCDestination) { }
+/// Creates a copy of the HTLCDestination
+#[no_mangle]
+pub extern "C" fn HTLCDestination_clone(orig: &HTLCDestination) -> HTLCDestination {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new NextHopChannel-variant HTLCDestination
+pub extern "C" fn HTLCDestination_next_hop_channel(node_id: crate::c_types::PublicKey, channel_id: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
+ HTLCDestination::NextHopChannel {
+ node_id,
+ channel_id,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new UnknownNextHop-variant HTLCDestination
+pub extern "C" fn HTLCDestination_unknown_next_hop(requested_forward_scid: u64) -> HTLCDestination {
+ HTLCDestination::UnknownNextHop {
+ requested_forward_scid,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new FailedPayment-variant HTLCDestination
+pub extern "C" fn HTLCDestination_failed_payment(payment_hash: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
+ HTLCDestination::FailedPayment {
+ payment_hash,
+ }
+}
+/// Checks if two HTLCDestinations contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn HTLCDestination_eq(a: &HTLCDestination, b: &HTLCDestination) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+#[no_mangle]
+/// Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
+pub extern "C" fn HTLCDestination_write(obj: &crate::lightning::util::events::HTLCDestination) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
+}
+#[no_mangle]
+/// Read a HTLCDestination from a byte array, created by HTLCDestination_write
+pub extern "C" fn HTLCDestination_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_HTLCDestinationZDecodeErrorZ {
+ let res: Result<Option<lightning::util::events::HTLCDestination>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_HTLCDestinationZ::None } else { crate::c_types::derived::COption_HTLCDestinationZ::Some( { crate::lightning::util::events::HTLCDestination::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
+ local_res
+}