+#[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
+}
+/// 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 = (*peer_msg).clone();
+ 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 = (*err).clone();
+ 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 = (*peer_msg).clone();
+ 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 = (*err).clone();
+ 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,
+ },
+ /// 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
+}