+/// Some information provided on receipt of payment depends on whether the payment received is a
+/// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum PaymentPurpose {
+ /// Information for receiving a payment that we generated an invoice for.
+ InvoicePayment {
+ /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
+ /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
+ /// [`ChannelManager::claim_funds`].
+ ///
+ /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
+ /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
+ ///
+ /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ payment_preimage: crate::c_types::ThirtyTwoBytes,
+ /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
+ /// number of deanonymization attacks during the routing process.
+ /// It is provided here for your reference, however its accuracy is enforced directly by
+ /// [`ChannelManager`] using the values you previously provided to
+ /// [`ChannelManager::create_inbound_payment`] or
+ /// [`ChannelManager::create_inbound_payment_for_hash`].
+ ///
+ /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
+ /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
+ /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
+ payment_secret: crate::c_types::ThirtyTwoBytes,
+ },
+ /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
+ /// (the payee) providing a preimage.
+ SpontaneousPayment(
+ crate::c_types::ThirtyTwoBytes),
+}
+use lightning::util::events::PaymentPurpose as PaymentPurposeImport;
+pub(crate) type nativePaymentPurpose = PaymentPurposeImport;
+
+impl PaymentPurpose {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativePaymentPurpose {
+ match self {
+ PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
+ let mut payment_preimage_nonref = Clone::clone(payment_preimage);
+ let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
+ let mut payment_secret_nonref = Clone::clone(payment_secret);
+ nativePaymentPurpose::InvoicePayment {
+ payment_preimage: local_payment_preimage_nonref,
+ payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
+ }
+ },
+ PaymentPurpose::SpontaneousPayment (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativePaymentPurpose::SpontaneousPayment (
+ ::lightning::ln::PaymentPreimage(a_nonref.data),
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativePaymentPurpose {
+ match self {
+ PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
+ let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
+ nativePaymentPurpose::InvoicePayment {
+ payment_preimage: local_payment_preimage,
+ payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
+ }
+ },
+ PaymentPurpose::SpontaneousPayment (mut a, ) => {
+ nativePaymentPurpose::SpontaneousPayment (
+ ::lightning::ln::PaymentPreimage(a.data),
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
+ match native {
+ nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
+ let mut payment_preimage_nonref = Clone::clone(payment_preimage);
+ let mut local_payment_preimage_nonref = if payment_preimage_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_preimage_nonref.unwrap()).0 } } };
+ let mut payment_secret_nonref = Clone::clone(payment_secret);
+ PaymentPurpose::InvoicePayment {
+ payment_preimage: local_payment_preimage_nonref,
+ payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
+ }
+ },
+ nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ PaymentPurpose::SpontaneousPayment (
+ crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
+ match native {
+ nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
+ let mut local_payment_preimage = if payment_preimage.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_preimage.unwrap()).0 } } };
+ PaymentPurpose::InvoicePayment {
+ payment_preimage: local_payment_preimage,
+ payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
+ }
+ },
+ nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
+ PaymentPurpose::SpontaneousPayment (
+ crate::c_types::ThirtyTwoBytes { data: a.0 },
+ )
+ },
+ }
+ }
+}
+/// Frees any resources used by the PaymentPurpose
+#[no_mangle]
+pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
+/// Creates a copy of the PaymentPurpose
+#[no_mangle]
+pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
+pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
+ PaymentPurpose::InvoicePayment {
+ payment_preimage,
+ payment_secret,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
+pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
+ PaymentPurpose::SpontaneousPayment(a, )
+}
+/// Checks if two PaymentPurposes contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn PaymentPurpose_eq(a: &PaymentPurpose, b: &PaymentPurpose) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+#[no_mangle]
+/// Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
+pub extern "C" fn PaymentPurpose_write(obj: &crate::lightning::util::events::PaymentPurpose) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
+}
+#[no_mangle]
+/// Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
+pub extern "C" fn PaymentPurpose_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentPurposeDecodeErrorZ {
+ let res: Result<lightning::util::events::PaymentPurpose, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::events::PaymentPurpose::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
+ local_res
+}
+/// When the payment path failure took place and extra details about it. [`PathFailure::OnPath`] may
+/// contain a [`NetworkUpdate`] that needs to be applied to the [`NetworkGraph`].
+///
+/// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
+/// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum PathFailure {
+ /// We failed to initially send the payment and no HTLC was committed to. Contains the relevant
+ /// error.
+ InitialSend {
+ /// The error surfaced from initial send.
+ err: crate::lightning::util::errors::APIError,
+ },
+ /// A hop on the path failed to forward our payment.
+ OnPath {
+ /// If present, this [`NetworkUpdate`] should be applied to the [`NetworkGraph`] so that routing
+ /// decisions can take into account the update.
+ ///
+ /// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
+ /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
+ network_update: crate::c_types::derived::COption_NetworkUpdateZ,
+ },
+}
+use lightning::util::events::PathFailure as PathFailureImport;
+pub(crate) type nativePathFailure = PathFailureImport;
+
+impl PathFailure {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativePathFailure {
+ match self {
+ PathFailure::InitialSend {ref err, } => {
+ let mut err_nonref = Clone::clone(err);
+ nativePathFailure::InitialSend {
+ err: err_nonref.into_native(),
+ }
+ },
+ PathFailure::OnPath {ref network_update, } => {
+ let mut network_update_nonref = Clone::clone(network_update);
+ let mut local_network_update_nonref = { /* network_update_nonref*/ let network_update_nonref_opt = network_update_nonref; { } if network_update_nonref_opt.is_none() { None } else { Some({ network_update_nonref_opt.take().into_native() }) } };
+ nativePathFailure::OnPath {
+ network_update: local_network_update_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativePathFailure {
+ match self {
+ PathFailure::InitialSend {mut err, } => {
+ nativePathFailure::InitialSend {
+ err: err.into_native(),
+ }
+ },
+ PathFailure::OnPath {mut network_update, } => {
+ let mut local_network_update = { /* network_update*/ let network_update_opt = network_update; { } if network_update_opt.is_none() { None } else { Some({ network_update_opt.take().into_native() }) } };
+ nativePathFailure::OnPath {
+ network_update: local_network_update,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativePathFailure) -> Self {
+ match native {
+ nativePathFailure::InitialSend {ref err, } => {
+ let mut err_nonref = Clone::clone(err);
+ PathFailure::InitialSend {
+ err: crate::lightning::util::errors::APIError::native_into(err_nonref),
+ }
+ },
+ nativePathFailure::OnPath {ref network_update, } => {
+ let mut network_update_nonref = Clone::clone(network_update);
+ let mut local_network_update_nonref = if network_update_nonref.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::gossip::NetworkUpdate::native_into(network_update_nonref.unwrap()) }) };
+ PathFailure::OnPath {
+ network_update: local_network_update_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativePathFailure) -> Self {
+ match native {
+ nativePathFailure::InitialSend {mut err, } => {
+ PathFailure::InitialSend {
+ err: crate::lightning::util::errors::APIError::native_into(err),
+ }
+ },
+ nativePathFailure::OnPath {mut network_update, } => {
+ let mut local_network_update = if network_update.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::gossip::NetworkUpdate::native_into(network_update.unwrap()) }) };
+ PathFailure::OnPath {
+ network_update: local_network_update,
+ }
+ },
+ }
+ }
+}
+/// Frees any resources used by the PathFailure
+#[no_mangle]
+pub extern "C" fn PathFailure_free(this_ptr: PathFailure) { }
+/// Creates a copy of the PathFailure
+#[no_mangle]
+pub extern "C" fn PathFailure_clone(orig: &PathFailure) -> PathFailure {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new InitialSend-variant PathFailure
+pub extern "C" fn PathFailure_initial_send(err: crate::lightning::util::errors::APIError) -> PathFailure {
+ PathFailure::InitialSend {
+ err,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new OnPath-variant PathFailure
+pub extern "C" fn PathFailure_on_path(network_update: crate::c_types::derived::COption_NetworkUpdateZ) -> PathFailure {
+ PathFailure::OnPath {
+ network_update,
+ }
+}
+/// Checks if two PathFailures contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn PathFailure_eq(a: &PathFailure, b: &PathFailure) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+#[no_mangle]
+/// Serialize the PathFailure object into a byte array which can be read by PathFailure_read
+pub extern "C" fn PathFailure_write(obj: &crate::lightning::util::events::PathFailure) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
+}
+#[no_mangle]
+/// Read a PathFailure from a byte array, created by PathFailure_write
+pub extern "C" fn PathFailure_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_PathFailureZDecodeErrorZ {
+ let res: Result<Option<lightning::util::events::PathFailure>, 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_PathFailureZ::None } else { crate::c_types::derived::COption_PathFailureZ::Some( { crate::lightning::util::events::PathFailure::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
+}
+/// The reason the channel was closed. See individual variants more details.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum ClosureReason {
+ /// Closure generated from receiving a peer error message.
+ ///
+ /// Our counterparty may have broadcasted their latest commitment state, and we have
+ /// as well.
+ CounterpartyForceClosed {
+ /// The error which the peer sent us.
+ ///
+ /// The string should be sanitized before it is used (e.g emitted to logs
+ /// or printed to stdout). Otherwise, a well crafted error message may exploit
+ /// a security vulnerability in the terminal emulator or the logging subsystem.
+ peer_msg: crate::c_types::Str,
+ },
+ /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
+ ///
+ /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
+ HolderForceClosed,
+ /// The channel was closed after negotiating a cooperative close and we've now broadcasted
+ /// the cooperative close transaction. Note the shutdown may have been initiated by us.
+ CooperativeClosure,
+ /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
+ /// commitment transaction came from our counterparty, but it may also have come from
+ /// a copy of our own `ChannelMonitor`.
+ CommitmentTxConfirmed,
+ /// The funding transaction failed to confirm in a timely manner on an inbound channel.
+ FundingTimedOut,
+ /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
+ ProcessingError {
+ /// A developer-readable error message which we generated.
+ err: crate::c_types::Str,
+ },
+ /// The peer disconnected prior to funding completing. In this case the spec mandates that we
+ /// forget the channel entirely - we can attempt again if the peer reconnects.
+ ///
+ /// This includes cases where we restarted prior to funding completion, including prior to the
+ /// initial [`ChannelMonitor`] persistence completing.
+ ///
+ /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
+ /// peer because of mutual incompatibility between us and our channel counterparty.
+ ///
+ /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
+ DisconnectedPeer,
+ /// Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
+ /// the [`ChannelManager`] deserialized.
+ ///
+ /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
+ /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
+ OutdatedChannelManager,
+}
+use lightning::util::events::ClosureReason as ClosureReasonImport;
+pub(crate) type nativeClosureReason = ClosureReasonImport;
+
+impl ClosureReason {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeClosureReason {
+ match self {
+ ClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
+ let mut peer_msg_nonref = Clone::clone(peer_msg);
+ nativeClosureReason::CounterpartyForceClosed {
+ peer_msg: peer_msg_nonref.into_string(),
+ }
+ },
+ ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
+ ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
+ ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
+ ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
+ ClosureReason::ProcessingError {ref err, } => {
+ let mut err_nonref = Clone::clone(err);
+ nativeClosureReason::ProcessingError {
+ err: err_nonref.into_string(),
+ }
+ },
+ ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
+ ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeClosureReason {
+ match self {
+ ClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
+ nativeClosureReason::CounterpartyForceClosed {
+ peer_msg: peer_msg.into_string(),
+ }
+ },
+ ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
+ ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
+ ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
+ ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
+ ClosureReason::ProcessingError {mut err, } => {
+ nativeClosureReason::ProcessingError {
+ err: err.into_string(),
+ }
+ },
+ ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
+ ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeClosureReason) -> Self {
+ match native {
+ nativeClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
+ let mut peer_msg_nonref = Clone::clone(peer_msg);
+ ClosureReason::CounterpartyForceClosed {
+ peer_msg: peer_msg_nonref.into(),
+ }
+ },
+ nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
+ nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
+ nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
+ nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
+ nativeClosureReason::ProcessingError {ref err, } => {
+ let mut err_nonref = Clone::clone(err);
+ ClosureReason::ProcessingError {
+ err: err_nonref.into(),
+ }
+ },
+ nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
+ nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeClosureReason) -> Self {
+ match native {
+ nativeClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
+ ClosureReason::CounterpartyForceClosed {
+ peer_msg: peer_msg.into(),
+ }
+ },
+ nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
+ nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
+ nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
+ nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
+ nativeClosureReason::ProcessingError {mut err, } => {
+ ClosureReason::ProcessingError {
+ err: err.into(),
+ }
+ },
+ nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
+ nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
+ }
+ }
+}
+/// Frees any resources used by the ClosureReason
+#[no_mangle]
+pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { }
+/// Creates a copy of the ClosureReason
+#[no_mangle]
+pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
+pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::c_types::Str) -> ClosureReason {
+ ClosureReason::CounterpartyForceClosed {
+ peer_msg,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new HolderForceClosed-variant ClosureReason
+pub extern "C" fn ClosureReason_holder_force_closed() -> ClosureReason {
+ ClosureReason::HolderForceClosed}
+#[no_mangle]
+/// Utility method to constructs a new CooperativeClosure-variant ClosureReason
+pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason {
+ ClosureReason::CooperativeClosure}
+#[no_mangle]
+/// Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
+pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason {
+ ClosureReason::CommitmentTxConfirmed}
+#[no_mangle]
+/// Utility method to constructs a new FundingTimedOut-variant ClosureReason
+pub extern "C" fn ClosureReason_funding_timed_out() -> ClosureReason {
+ ClosureReason::FundingTimedOut}
+#[no_mangle]
+/// Utility method to constructs a new ProcessingError-variant ClosureReason
+pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason {
+ ClosureReason::ProcessingError {
+ err,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new DisconnectedPeer-variant ClosureReason
+pub extern "C" fn ClosureReason_disconnected_peer() -> ClosureReason {
+ ClosureReason::DisconnectedPeer}
+#[no_mangle]
+/// Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
+pub extern "C" fn ClosureReason_outdated_channel_manager() -> ClosureReason {
+ ClosureReason::OutdatedChannelManager}
+/// Checks if two ClosureReasons contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn ClosureReason_eq(a: &ClosureReason, b: &ClosureReason) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+#[no_mangle]
+/// Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
+pub extern "C" fn ClosureReason_write(obj: &crate::lightning::util::events::ClosureReason) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
+}
+#[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,
+ },
+ /// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
+ /// intercept HTLC.
+ InvalidForward {
+ /// 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 = Clone::clone(node_id);
+ 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 = Clone::clone(channel_id);
+ 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 = Clone::clone(requested_forward_scid);
+ nativeHTLCDestination::UnknownNextHop {
+ requested_forward_scid: requested_forward_scid_nonref,
+ }
+ },
+ HTLCDestination::InvalidForward {ref requested_forward_scid, } => {
+ let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
+ nativeHTLCDestination::InvalidForward {
+ requested_forward_scid: requested_forward_scid_nonref,
+ }
+ },
+ HTLCDestination::FailedPayment {ref payment_hash, } => {
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ 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::InvalidForward {mut requested_forward_scid, } => {
+ nativeHTLCDestination::InvalidForward {
+ 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 = Clone::clone(node_id);
+ 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 = Clone::clone(channel_id);
+ 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 = Clone::clone(requested_forward_scid);
+ HTLCDestination::UnknownNextHop {
+ requested_forward_scid: requested_forward_scid_nonref,
+ }
+ },
+ nativeHTLCDestination::InvalidForward {ref requested_forward_scid, } => {
+ let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
+ HTLCDestination::InvalidForward {
+ requested_forward_scid: requested_forward_scid_nonref,
+ }
+ },
+ nativeHTLCDestination::FailedPayment {ref payment_hash, } => {
+ let mut payment_hash_nonref = Clone::clone(payment_hash);
+ 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::InvalidForward {mut requested_forward_scid, } => {
+ HTLCDestination::InvalidForward {
+ 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 InvalidForward-variant HTLCDestination
+pub extern "C" fn HTLCDestination_invalid_forward(requested_forward_scid: u64) -> HTLCDestination {
+ HTLCDestination::InvalidForward {
+ 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
+}