+#[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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).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.
+ ///
+ /// 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.
+ DisconnectedPeer,
+ /// Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than
+ /// the ChannelManager deserialized.
+ 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}
+#[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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
+ local_res
+}