970499534027394bd20e3fffe62dd02d14f2321c
[ldk-c-bindings] / lightning-c-bindings / src / lightning / util / events.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! Events are returned from various bits in the library which indicate some action must be taken
10 //! by the client.
11 //!
12 //! Because we don't have a built-in runtime, it's up to the client to call events at a time in the
13 //! future, as well as generate and broadcast funding transactions handle payment preimages and a
14 //! few other things.
15
16 use alloc::str::FromStr;
17 use core::ffi::c_void;
18 use core::convert::Infallible;
19 use bitcoin::hashes::Hash;
20 use crate::c_types::*;
21 #[cfg(feature="no-std")]
22 use alloc::{vec::Vec, boxed::Box};
23
24 /// Some information provided on receipt of payment depends on whether the payment received is a
25 /// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
26 #[derive(Clone)]
27 #[must_use]
28 #[repr(C)]
29 pub enum PaymentPurpose {
30         /// Information for receiving a payment that we generated an invoice for.
31         InvoicePayment {
32                 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
33                 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
34                 /// [`ChannelManager::claim_funds`].
35                 ///
36                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
37                 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
38                 ///
39                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
40                 payment_preimage: crate::c_types::ThirtyTwoBytes,
41                 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
42                 /// number of deanonymization attacks during the routing process.
43                 /// It is provided here for your reference, however its accuracy is enforced directly by
44                 /// [`ChannelManager`] using the values you previously provided to
45                 /// [`ChannelManager::create_inbound_payment`] or
46                 /// [`ChannelManager::create_inbound_payment_for_hash`].
47                 ///
48                 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
49                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
50                 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
51                 payment_secret: crate::c_types::ThirtyTwoBytes,
52         },
53         /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
54         /// (the payee) providing a preimage.
55         SpontaneousPayment(
56                 crate::c_types::ThirtyTwoBytes),
57 }
58 use lightning::util::events::PaymentPurpose as PaymentPurposeImport;
59 pub(crate) type nativePaymentPurpose = PaymentPurposeImport;
60
61 impl PaymentPurpose {
62         #[allow(unused)]
63         pub(crate) fn to_native(&self) -> nativePaymentPurpose {
64                 match self {
65                         PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
66                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
67                                 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
68                                 let mut payment_secret_nonref = (*payment_secret).clone();
69                                 nativePaymentPurpose::InvoicePayment {
70                                         payment_preimage: local_payment_preimage_nonref,
71                                         payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
72                                 }
73                         },
74                         PaymentPurpose::SpontaneousPayment (ref a, ) => {
75                                 let mut a_nonref = (*a).clone();
76                                 nativePaymentPurpose::SpontaneousPayment (
77                                         ::lightning::ln::PaymentPreimage(a_nonref.data),
78                                 )
79                         },
80                 }
81         }
82         #[allow(unused)]
83         pub(crate) fn into_native(self) -> nativePaymentPurpose {
84                 match self {
85                         PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
86                                 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
87                                 nativePaymentPurpose::InvoicePayment {
88                                         payment_preimage: local_payment_preimage,
89                                         payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
90                                 }
91                         },
92                         PaymentPurpose::SpontaneousPayment (mut a, ) => {
93                                 nativePaymentPurpose::SpontaneousPayment (
94                                         ::lightning::ln::PaymentPreimage(a.data),
95                                 )
96                         },
97                 }
98         }
99         #[allow(unused)]
100         pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
101                 match native {
102                         nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
103                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
104                                 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 } } };
105                                 let mut payment_secret_nonref = (*payment_secret).clone();
106                                 PaymentPurpose::InvoicePayment {
107                                         payment_preimage: local_payment_preimage_nonref,
108                                         payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
109                                 }
110                         },
111                         nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
112                                 let mut a_nonref = (*a).clone();
113                                 PaymentPurpose::SpontaneousPayment (
114                                         crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
115                                 )
116                         },
117                 }
118         }
119         #[allow(unused)]
120         pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
121                 match native {
122                         nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
123                                 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 } } };
124                                 PaymentPurpose::InvoicePayment {
125                                         payment_preimage: local_payment_preimage,
126                                         payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
127                                 }
128                         },
129                         nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
130                                 PaymentPurpose::SpontaneousPayment (
131                                         crate::c_types::ThirtyTwoBytes { data: a.0 },
132                                 )
133                         },
134                 }
135         }
136 }
137 /// Frees any resources used by the PaymentPurpose
138 #[no_mangle]
139 pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
140 /// Creates a copy of the PaymentPurpose
141 #[no_mangle]
142 pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
143         orig.clone()
144 }
145 #[no_mangle]
146 /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
147 pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
148         PaymentPurpose::InvoicePayment {
149                 payment_preimage,
150                 payment_secret,
151         }
152 }
153 #[no_mangle]
154 /// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
155 pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
156         PaymentPurpose::SpontaneousPayment(a, )
157 }
158 #[no_mangle]
159 /// Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
160 pub extern "C" fn PaymentPurpose_write(obj: &crate::lightning::util::events::PaymentPurpose) -> crate::c_types::derived::CVec_u8Z {
161         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
162 }
163 #[no_mangle]
164 /// Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
165 pub extern "C" fn PaymentPurpose_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentPurposeDecodeErrorZ {
166         let res: Result<lightning::util::events::PaymentPurpose, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
167         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() };
168         local_res
169 }
170 /// The reason the channel was closed. See individual variants more details.
171 #[derive(Clone)]
172 #[must_use]
173 #[repr(C)]
174 pub enum ClosureReason {
175         /// Closure generated from receiving a peer error message.
176         ///
177         /// Our counterparty may have broadcasted their latest commitment state, and we have
178         /// as well.
179         CounterpartyForceClosed {
180                 /// The error which the peer sent us.
181                 ///
182                 /// The string should be sanitized before it is used (e.g emitted to logs
183                 /// or printed to stdout). Otherwise, a well crafted error message may exploit
184                 /// a security vulnerability in the terminal emulator or the logging subsystem.
185                 peer_msg: crate::c_types::Str,
186         },
187         /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
188         ///
189         /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
190         HolderForceClosed,
191         /// The channel was closed after negotiating a cooperative close and we've now broadcasted
192         /// the cooperative close transaction. Note the shutdown may have been initiated by us.
193         CooperativeClosure,
194         /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
195         /// commitment transaction came from our counterparty, but it may also have come from
196         /// a copy of our own `ChannelMonitor`.
197         CommitmentTxConfirmed,
198         /// The funding transaction failed to confirm in a timely manner on an inbound channel.
199         FundingTimedOut,
200         /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
201         ProcessingError {
202                 /// A developer-readable error message which we generated.
203                 err: crate::c_types::Str,
204         },
205         /// The peer disconnected prior to funding completing. In this case the spec mandates that we
206         /// forget the channel entirely - we can attempt again if the peer reconnects.
207         ///
208         /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
209         /// peer because of mutual incompatibility between us and our channel counterparty.
210         DisconnectedPeer,
211         /// Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than
212         /// the ChannelManager deserialized.
213         OutdatedChannelManager,
214 }
215 use lightning::util::events::ClosureReason as ClosureReasonImport;
216 pub(crate) type nativeClosureReason = ClosureReasonImport;
217
218 impl ClosureReason {
219         #[allow(unused)]
220         pub(crate) fn to_native(&self) -> nativeClosureReason {
221                 match self {
222                         ClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
223                                 let mut peer_msg_nonref = (*peer_msg).clone();
224                                 nativeClosureReason::CounterpartyForceClosed {
225                                         peer_msg: peer_msg_nonref.into_string(),
226                                 }
227                         },
228                         ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
229                         ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
230                         ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
231                         ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
232                         ClosureReason::ProcessingError {ref err, } => {
233                                 let mut err_nonref = (*err).clone();
234                                 nativeClosureReason::ProcessingError {
235                                         err: err_nonref.into_string(),
236                                 }
237                         },
238                         ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
239                         ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
240                 }
241         }
242         #[allow(unused)]
243         pub(crate) fn into_native(self) -> nativeClosureReason {
244                 match self {
245                         ClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
246                                 nativeClosureReason::CounterpartyForceClosed {
247                                         peer_msg: peer_msg.into_string(),
248                                 }
249                         },
250                         ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
251                         ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
252                         ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
253                         ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
254                         ClosureReason::ProcessingError {mut err, } => {
255                                 nativeClosureReason::ProcessingError {
256                                         err: err.into_string(),
257                                 }
258                         },
259                         ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
260                         ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
261                 }
262         }
263         #[allow(unused)]
264         pub(crate) fn from_native(native: &nativeClosureReason) -> Self {
265                 match native {
266                         nativeClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
267                                 let mut peer_msg_nonref = (*peer_msg).clone();
268                                 ClosureReason::CounterpartyForceClosed {
269                                         peer_msg: peer_msg_nonref.into(),
270                                 }
271                         },
272                         nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
273                         nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
274                         nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
275                         nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
276                         nativeClosureReason::ProcessingError {ref err, } => {
277                                 let mut err_nonref = (*err).clone();
278                                 ClosureReason::ProcessingError {
279                                         err: err_nonref.into(),
280                                 }
281                         },
282                         nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
283                         nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
284                 }
285         }
286         #[allow(unused)]
287         pub(crate) fn native_into(native: nativeClosureReason) -> Self {
288                 match native {
289                         nativeClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
290                                 ClosureReason::CounterpartyForceClosed {
291                                         peer_msg: peer_msg.into(),
292                                 }
293                         },
294                         nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
295                         nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
296                         nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
297                         nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
298                         nativeClosureReason::ProcessingError {mut err, } => {
299                                 ClosureReason::ProcessingError {
300                                         err: err.into(),
301                                 }
302                         },
303                         nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
304                         nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
305                 }
306         }
307 }
308 /// Frees any resources used by the ClosureReason
309 #[no_mangle]
310 pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { }
311 /// Creates a copy of the ClosureReason
312 #[no_mangle]
313 pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason {
314         orig.clone()
315 }
316 #[no_mangle]
317 /// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
318 pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::c_types::Str) -> ClosureReason {
319         ClosureReason::CounterpartyForceClosed {
320                 peer_msg,
321         }
322 }
323 #[no_mangle]
324 /// Utility method to constructs a new HolderForceClosed-variant ClosureReason
325 pub extern "C" fn ClosureReason_holder_force_closed() -> ClosureReason {
326         ClosureReason::HolderForceClosed}
327 #[no_mangle]
328 /// Utility method to constructs a new CooperativeClosure-variant ClosureReason
329 pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason {
330         ClosureReason::CooperativeClosure}
331 #[no_mangle]
332 /// Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
333 pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason {
334         ClosureReason::CommitmentTxConfirmed}
335 #[no_mangle]
336 /// Utility method to constructs a new FundingTimedOut-variant ClosureReason
337 pub extern "C" fn ClosureReason_funding_timed_out() -> ClosureReason {
338         ClosureReason::FundingTimedOut}
339 #[no_mangle]
340 /// Utility method to constructs a new ProcessingError-variant ClosureReason
341 pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason {
342         ClosureReason::ProcessingError {
343                 err,
344         }
345 }
346 #[no_mangle]
347 /// Utility method to constructs a new DisconnectedPeer-variant ClosureReason
348 pub extern "C" fn ClosureReason_disconnected_peer() -> ClosureReason {
349         ClosureReason::DisconnectedPeer}
350 #[no_mangle]
351 /// Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
352 pub extern "C" fn ClosureReason_outdated_channel_manager() -> ClosureReason {
353         ClosureReason::OutdatedChannelManager}
354 #[no_mangle]
355 /// Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
356 pub extern "C" fn ClosureReason_write(obj: &crate::lightning::util::events::ClosureReason) -> crate::c_types::derived::CVec_u8Z {
357         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
358 }
359 #[no_mangle]
360 /// Read a ClosureReason from a byte array, created by ClosureReason_write
361 pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_ClosureReasonZDecodeErrorZ {
362         let res: Result<Option<lightning::util::events::ClosureReason>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
363         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() };
364         local_res
365 }
366 /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
367 #[derive(Clone)]
368 #[must_use]
369 #[repr(C)]
370 pub enum HTLCDestination {
371         /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
372         /// there is insufficient capacity in our outbound channel.
373         NextHopChannel {
374                 /// The `node_id` of the next node. For backwards compatibility, this field is
375                 /// marked as optional, versions prior to 0.0.110 may not always be able to provide
376                 /// counterparty node information.
377                 ///
378                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
379                 node_id: crate::c_types::PublicKey,
380                 /// The outgoing `channel_id` between us and the next node.
381                 channel_id: crate::c_types::ThirtyTwoBytes,
382         },
383         /// Scenario where we are unsure of the next node to forward the HTLC to.
384         UnknownNextHop {
385                 /// Short channel id we are requesting to forward an HTLC to.
386                 requested_forward_scid: u64,
387         },
388         /// Failure scenario where an HTLC may have been forwarded to be intended for us,
389         /// but is invalid for some reason, so we reject it.
390         ///
391         /// Some of the reasons may include:
392         /// * HTLC Timeouts
393         /// * Expected MPP amount to claim does not equal HTLC total
394         /// * Claimable amount does not match expected amount
395         FailedPayment {
396                 /// The payment hash of the payment we attempted to process.
397                 payment_hash: crate::c_types::ThirtyTwoBytes,
398         },
399 }
400 use lightning::util::events::HTLCDestination as HTLCDestinationImport;
401 pub(crate) type nativeHTLCDestination = HTLCDestinationImport;
402
403 impl HTLCDestination {
404         #[allow(unused)]
405         pub(crate) fn to_native(&self) -> nativeHTLCDestination {
406                 match self {
407                         HTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
408                                 let mut node_id_nonref = (*node_id).clone();
409                                 let mut local_node_id_nonref = if node_id_nonref.is_null() { None } else { Some( { node_id_nonref.into_rust() }) };
410                                 let mut channel_id_nonref = (*channel_id).clone();
411                                 nativeHTLCDestination::NextHopChannel {
412                                         node_id: local_node_id_nonref,
413                                         channel_id: channel_id_nonref.data,
414                                 }
415                         },
416                         HTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
417                                 let mut requested_forward_scid_nonref = (*requested_forward_scid).clone();
418                                 nativeHTLCDestination::UnknownNextHop {
419                                         requested_forward_scid: requested_forward_scid_nonref,
420                                 }
421                         },
422                         HTLCDestination::FailedPayment {ref payment_hash, } => {
423                                 let mut payment_hash_nonref = (*payment_hash).clone();
424                                 nativeHTLCDestination::FailedPayment {
425                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
426                                 }
427                         },
428                 }
429         }
430         #[allow(unused)]
431         pub(crate) fn into_native(self) -> nativeHTLCDestination {
432                 match self {
433                         HTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
434                                 let mut local_node_id = if node_id.is_null() { None } else { Some( { node_id.into_rust() }) };
435                                 nativeHTLCDestination::NextHopChannel {
436                                         node_id: local_node_id,
437                                         channel_id: channel_id.data,
438                                 }
439                         },
440                         HTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
441                                 nativeHTLCDestination::UnknownNextHop {
442                                         requested_forward_scid: requested_forward_scid,
443                                 }
444                         },
445                         HTLCDestination::FailedPayment {mut payment_hash, } => {
446                                 nativeHTLCDestination::FailedPayment {
447                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
448                                 }
449                         },
450                 }
451         }
452         #[allow(unused)]
453         pub(crate) fn from_native(native: &nativeHTLCDestination) -> Self {
454                 match native {
455                         nativeHTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
456                                 let mut node_id_nonref = (*node_id).clone();
457                                 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())) } };
458                                 let mut channel_id_nonref = (*channel_id).clone();
459                                 HTLCDestination::NextHopChannel {
460                                         node_id: local_node_id_nonref,
461                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
462                                 }
463                         },
464                         nativeHTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
465                                 let mut requested_forward_scid_nonref = (*requested_forward_scid).clone();
466                                 HTLCDestination::UnknownNextHop {
467                                         requested_forward_scid: requested_forward_scid_nonref,
468                                 }
469                         },
470                         nativeHTLCDestination::FailedPayment {ref payment_hash, } => {
471                                 let mut payment_hash_nonref = (*payment_hash).clone();
472                                 HTLCDestination::FailedPayment {
473                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
474                                 }
475                         },
476                 }
477         }
478         #[allow(unused)]
479         pub(crate) fn native_into(native: nativeHTLCDestination) -> Self {
480                 match native {
481                         nativeHTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
482                                 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())) } };
483                                 HTLCDestination::NextHopChannel {
484                                         node_id: local_node_id,
485                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
486                                 }
487                         },
488                         nativeHTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
489                                 HTLCDestination::UnknownNextHop {
490                                         requested_forward_scid: requested_forward_scid,
491                                 }
492                         },
493                         nativeHTLCDestination::FailedPayment {mut payment_hash, } => {
494                                 HTLCDestination::FailedPayment {
495                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
496                                 }
497                         },
498                 }
499         }
500 }
501 /// Frees any resources used by the HTLCDestination
502 #[no_mangle]
503 pub extern "C" fn HTLCDestination_free(this_ptr: HTLCDestination) { }
504 /// Creates a copy of the HTLCDestination
505 #[no_mangle]
506 pub extern "C" fn HTLCDestination_clone(orig: &HTLCDestination) -> HTLCDestination {
507         orig.clone()
508 }
509 #[no_mangle]
510 /// Utility method to constructs a new NextHopChannel-variant HTLCDestination
511 pub extern "C" fn HTLCDestination_next_hop_channel(node_id: crate::c_types::PublicKey, channel_id: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
512         HTLCDestination::NextHopChannel {
513                 node_id,
514                 channel_id,
515         }
516 }
517 #[no_mangle]
518 /// Utility method to constructs a new UnknownNextHop-variant HTLCDestination
519 pub extern "C" fn HTLCDestination_unknown_next_hop(requested_forward_scid: u64) -> HTLCDestination {
520         HTLCDestination::UnknownNextHop {
521                 requested_forward_scid,
522         }
523 }
524 #[no_mangle]
525 /// Utility method to constructs a new FailedPayment-variant HTLCDestination
526 pub extern "C" fn HTLCDestination_failed_payment(payment_hash: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
527         HTLCDestination::FailedPayment {
528                 payment_hash,
529         }
530 }
531 #[no_mangle]
532 /// Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
533 pub extern "C" fn HTLCDestination_write(obj: &crate::lightning::util::events::HTLCDestination) -> crate::c_types::derived::CVec_u8Z {
534         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
535 }
536 #[no_mangle]
537 /// Read a HTLCDestination from a byte array, created by HTLCDestination_write
538 pub extern "C" fn HTLCDestination_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_HTLCDestinationZDecodeErrorZ {
539         let res: Result<Option<lightning::util::events::HTLCDestination>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
540         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
541         local_res
542 }
543 /// An Event which you should probably take some action in response to.
544 ///
545 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
546 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
547 /// written as it makes no sense to respond to it after reconnecting to peers).
548 #[derive(Clone)]
549 #[must_use]
550 #[repr(C)]
551 pub enum Event {
552         /// Used to indicate that the client should generate a funding transaction with the given
553         /// parameters and then call [`ChannelManager::funding_transaction_generated`].
554         /// Generated in [`ChannelManager`] message handling.
555         /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
556         /// counterparty can steal your funds!
557         ///
558         /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
559         /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
560         FundingGenerationReady {
561                 /// The random channel_id we picked which you'll need to pass into
562                 /// [`ChannelManager::funding_transaction_generated`].
563                 ///
564                 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
565                 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
566                 /// The counterparty's node_id, which you'll need to pass back into
567                 /// [`ChannelManager::funding_transaction_generated`].
568                 ///
569                 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
570                 counterparty_node_id: crate::c_types::PublicKey,
571                 /// The value, in satoshis, that the output should have.
572                 channel_value_satoshis: u64,
573                 /// The script which should be used in the transaction output.
574                 output_script: crate::c_types::derived::CVec_u8Z,
575                 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
576                 /// an inbound channel.
577                 ///
578                 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
579                 user_channel_id: u64,
580         },
581         /// Indicates we've received (an offer of) money! Just gotta dig out that payment preimage and
582         /// feed it to [`ChannelManager::claim_funds`] to get it....
583         ///
584         /// Note that if the preimage is not known, you should call
585         /// [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid
586         /// network congestion.
587         /// If you fail to call either [`ChannelManager::claim_funds`] or
588         /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be
589         /// automatically failed.
590         ///
591         /// # Note
592         /// LDK will not stop an inbound payment from being paid multiple times, so multiple
593         /// `PaymentReceived` events may be generated for the same payment.
594         ///
595         /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
596         /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
597         PaymentReceived {
598                 /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
599                 /// not stop you from registering duplicate payment hashes for inbound payments.
600                 payment_hash: crate::c_types::ThirtyTwoBytes,
601                 /// The value, in thousandths of a satoshi, that this payment is for.
602                 amount_msat: u64,
603                 /// Information for claiming this received payment, based on whether the purpose of the
604                 /// payment is to pay an invoice or to send a spontaneous payment.
605                 purpose: crate::lightning::util::events::PaymentPurpose,
606         },
607         /// Indicates a payment has been claimed and we've received money!
608         ///
609         /// This most likely occurs when [`ChannelManager::claim_funds`] has been called in response
610         /// to an [`Event::PaymentReceived`]. However, if we previously crashed during a
611         /// [`ChannelManager::claim_funds`] call you may see this event without a corresponding
612         /// [`Event::PaymentReceived`] event.
613         ///
614         /// # Note
615         /// LDK will not stop an inbound payment from being paid multiple times, so multiple
616         /// `PaymentReceived` events may be generated for the same payment. If you then call
617         /// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentReceived`] you may get
618         /// multiple `PaymentClaimed` events.
619         ///
620         /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
621         PaymentClaimed {
622                 /// The payment hash of the claimed payment. Note that LDK will not stop you from
623                 /// registering duplicate payment hashes for inbound payments.
624                 payment_hash: crate::c_types::ThirtyTwoBytes,
625                 /// The value, in thousandths of a satoshi, that this payment is for.
626                 amount_msat: u64,
627                 /// The purpose of this claimed payment, i.e. whether the payment was for an invoice or a
628                 /// spontaneous payment.
629                 purpose: crate::lightning::util::events::PaymentPurpose,
630         },
631         /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
632         /// and we got back the payment preimage for it).
633         ///
634         /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
635         /// event. In this situation, you SHOULD treat this payment as having succeeded.
636         PaymentSent {
637                 /// The id returned by [`ChannelManager::send_payment`] and used with
638                 /// [`ChannelManager::retry_payment`].
639                 ///
640                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
641                 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
642                 ///
643                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
644                 payment_id: crate::c_types::ThirtyTwoBytes,
645                 /// The preimage to the hash given to ChannelManager::send_payment.
646                 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
647                 /// store it somehow!
648                 payment_preimage: crate::c_types::ThirtyTwoBytes,
649                 /// The hash that was given to [`ChannelManager::send_payment`].
650                 ///
651                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
652                 payment_hash: crate::c_types::ThirtyTwoBytes,
653                 /// The total fee which was spent at intermediate hops in this payment, across all paths.
654                 ///
655                 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
656                 /// overpayment to the recipient node.
657                 ///
658                 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
659                 /// overstate the amount paid, though this is unlikely.
660                 ///
661                 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
662                 fee_paid_msat: crate::c_types::derived::COption_u64Z,
663         },
664         /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
665         /// provide failure information for each MPP part in the payment.
666         ///
667         /// This event is provided once there are no further pending HTLCs for the payment and the
668         /// payment is no longer retryable, either due to a several-block timeout or because
669         /// [`ChannelManager::abandon_payment`] was previously called for the corresponding payment.
670         ///
671         /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
672         PaymentFailed {
673                 /// The id returned by [`ChannelManager::send_payment`] and used with
674                 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
675                 ///
676                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
677                 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
678                 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
679                 payment_id: crate::c_types::ThirtyTwoBytes,
680                 /// The hash that was given to [`ChannelManager::send_payment`].
681                 ///
682                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
683                 payment_hash: crate::c_types::ThirtyTwoBytes,
684         },
685         /// Indicates that a path for an outbound payment was successful.
686         ///
687         /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
688         /// [`Event::PaymentSent`] for obtaining the payment preimage.
689         PaymentPathSuccessful {
690                 /// The id returned by [`ChannelManager::send_payment`] and used with
691                 /// [`ChannelManager::retry_payment`].
692                 ///
693                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
694                 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
695                 payment_id: crate::c_types::ThirtyTwoBytes,
696                 /// The hash that was given to [`ChannelManager::send_payment`].
697                 ///
698                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
699                 ///
700                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
701                 payment_hash: crate::c_types::ThirtyTwoBytes,
702                 /// The payment path that was successful.
703                 ///
704                 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
705                 path: crate::c_types::derived::CVec_RouteHopZ,
706         },
707         /// Indicates an outbound HTLC we sent failed. Probably some intermediary node dropped
708         /// something. You may wish to retry with a different route.
709         ///
710         /// Note that this does *not* indicate that all paths for an MPP payment have failed, see
711         /// [`Event::PaymentFailed`] and [`all_paths_failed`].
712         ///
713         /// [`all_paths_failed`]: Self::PaymentPathFailed::all_paths_failed
714         PaymentPathFailed {
715                 /// The id returned by [`ChannelManager::send_payment`] and used with
716                 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
717                 ///
718                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
719                 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
720                 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
721                 ///
722                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
723                 payment_id: crate::c_types::ThirtyTwoBytes,
724                 /// The hash that was given to [`ChannelManager::send_payment`].
725                 ///
726                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
727                 payment_hash: crate::c_types::ThirtyTwoBytes,
728                 /// Indicates the payment was rejected for some reason by the recipient. This implies that
729                 /// the payment has failed, not just the route in question. If this is not set, you may
730                 /// retry the payment via a different route.
731                 rejected_by_dest: bool,
732                 /// Any failure information conveyed via the Onion return packet by a node along the failed
733                 /// payment route.
734                 ///
735                 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
736                 /// account the update.
737                 ///
738                 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
739                 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
740                 /// For both single-path and multi-path payments, this is set if all paths of the payment have
741                 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
742                 /// larger MPP payment were still in flight when this event was generated.
743                 ///
744                 /// Note that if you are retrying individual MPP parts, using this value to determine if a
745                 /// payment has fully failed is race-y. Because multiple failures can happen prior to events
746                 /// being processed, you may retry in response to a first failure, with a second failure
747                 /// (with `all_paths_failed` set) still pending. Then, when the second failure is processed
748                 /// you will see `all_paths_failed` set even though the retry of the first failure still
749                 /// has an associated in-flight HTLC. See (1) for an example of such a failure.
750                 ///
751                 /// If you wish to retry individual MPP parts and learn when a payment has failed, you must
752                 /// call [`ChannelManager::abandon_payment`] and wait for a [`Event::PaymentFailed`] event.
753                 ///
754                 /// (1) <https://github.com/lightningdevkit/rust-lightning/issues/1164>
755                 ///
756                 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
757                 all_paths_failed: bool,
758                 /// The payment path that failed.
759                 path: crate::c_types::derived::CVec_RouteHopZ,
760                 /// The channel responsible for the failed payment path.
761                 ///
762                 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
763                 /// may not refer to a channel in the public network graph. These aliases may also collide
764                 /// with channels in the public network graph.
765                 ///
766                 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
767                 /// retried. May be `None` for older [`Event`] serializations.
768                 short_channel_id: crate::c_types::derived::COption_u64Z,
769                 /// Parameters needed to compute a new [`Route`] when retrying the failed payment path.
770                 ///
771                 /// See [`find_route`] for details.
772                 ///
773                 /// [`Route`]: crate::routing::router::Route
774                 /// [`find_route`]: crate::routing::router::find_route
775                 ///
776                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
777                 retry: crate::lightning::routing::router::RouteParameters,
778         },
779         /// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
780         ProbeSuccessful {
781                 /// The id returned by [`ChannelManager::send_probe`].
782                 ///
783                 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
784                 payment_id: crate::c_types::ThirtyTwoBytes,
785                 /// The hash generated by [`ChannelManager::send_probe`].
786                 ///
787                 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
788                 payment_hash: crate::c_types::ThirtyTwoBytes,
789                 /// The payment path that was successful.
790                 path: crate::c_types::derived::CVec_RouteHopZ,
791         },
792         /// Indicates that a probe payment we sent failed at an intermediary node on the path.
793         ProbeFailed {
794                 /// The id returned by [`ChannelManager::send_probe`].
795                 ///
796                 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
797                 payment_id: crate::c_types::ThirtyTwoBytes,
798                 /// The hash generated by [`ChannelManager::send_probe`].
799                 ///
800                 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
801                 payment_hash: crate::c_types::ThirtyTwoBytes,
802                 /// The payment path that failed.
803                 path: crate::c_types::derived::CVec_RouteHopZ,
804                 /// The channel responsible for the failed probe.
805                 ///
806                 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
807                 /// may not refer to a channel in the public network graph. These aliases may also collide
808                 /// with channels in the public network graph.
809                 short_channel_id: crate::c_types::derived::COption_u64Z,
810         },
811         /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
812         /// a time in the future.
813         ///
814         /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
815         PendingHTLCsForwardable {
816                 /// The minimum amount of time that should be waited prior to calling
817                 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
818                 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
819                 /// now + 5*time_forwardable).
820                 time_forwardable: u64,
821         },
822         /// Used to indicate that an output which you should know how to spend was confirmed on chain
823         /// and is now spendable.
824         /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
825         /// counterparty spending them due to some kind of timeout. Thus, you need to store them
826         /// somewhere and spend them when you create on-chain transactions.
827         SpendableOutputs {
828                 /// The outputs which you should store as spendable by you.
829                 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
830         },
831         /// This event is generated when a payment has been successfully forwarded through us and a
832         /// forwarding fee earned.
833         PaymentForwarded {
834                 /// The incoming channel between the previous node and us. This is only `None` for events
835                 /// generated or serialized by versions prior to 0.0.107.
836                 ///
837                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
838                 prev_channel_id: crate::c_types::ThirtyTwoBytes,
839                 /// The outgoing channel between the next node and us. This is only `None` for events
840                 /// generated or serialized by versions prior to 0.0.107.
841                 ///
842                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
843                 next_channel_id: crate::c_types::ThirtyTwoBytes,
844                 /// The fee, in milli-satoshis, which was earned as a result of the payment.
845                 ///
846                 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
847                 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
848                 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
849                 /// claimed the full value in millisatoshis from the source. In this case,
850                 /// `claim_from_onchain_tx` will be set.
851                 ///
852                 /// If the channel which sent us the payment has been force-closed, we will claim the funds
853                 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
854                 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
855                 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
856                 /// `None`.
857                 fee_earned_msat: crate::c_types::derived::COption_u64Z,
858                 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
859                 /// transaction.
860                 claim_from_onchain_tx: bool,
861         },
862         /// Used to indicate that a previously opened channel with the given `channel_id` is in the
863         /// process of closure.
864         ChannelClosed {
865                 /// The channel_id of the channel which has been closed. Note that on-chain transactions
866                 /// resolving the channel are likely still awaiting confirmation.
867                 channel_id: crate::c_types::ThirtyTwoBytes,
868                 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
869                 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
870                 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
871                 /// `user_channel_id` will be 0 for an inbound channel.
872                 /// This will always be zero for objects serialized with LDK versions prior to 0.0.102.
873                 ///
874                 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
875                 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
876                 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
877                 user_channel_id: u64,
878                 /// The reason the channel was closed.
879                 reason: crate::lightning::util::events::ClosureReason,
880         },
881         /// Used to indicate to the user that they can abandon the funding transaction and recycle the
882         /// inputs for another purpose.
883         DiscardFunding {
884                 /// The channel_id of the channel which has been closed.
885                 channel_id: crate::c_types::ThirtyTwoBytes,
886                 /// The full transaction received from the user
887                 transaction: crate::c_types::Transaction,
888         },
889         /// Indicates a request to open a new channel by a peer.
890         ///
891         /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the
892         /// request, call [`ChannelManager::force_close_without_broadcasting_txn`].
893         ///
894         /// The event is only triggered when a new open channel request is received and the
895         /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
896         ///
897         /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
898         /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
899         /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
900         OpenChannelRequest {
901                 /// The temporary channel ID of the channel requested to be opened.
902                 ///
903                 /// When responding to the request, the `temporary_channel_id` should be passed
904                 /// back to the ChannelManager through [`ChannelManager::accept_inbound_channel`] to accept,
905                 /// or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject.
906                 ///
907                 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
908                 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
909                 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
910                 /// The node_id of the counterparty requesting to open the channel.
911                 ///
912                 /// When responding to the request, the `counterparty_node_id` should be passed
913                 /// back to the `ChannelManager` through [`ChannelManager::accept_inbound_channel`] to
914                 /// accept the request, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject the
915                 /// request.
916                 ///
917                 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
918                 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
919                 counterparty_node_id: crate::c_types::PublicKey,
920                 /// The channel value of the requested channel.
921                 funding_satoshis: u64,
922                 /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
923                 push_msat: u64,
924                 /// The features that this channel will operate with. If you reject the channel, a
925                 /// well-behaved counterparty may automatically re-attempt the channel with a new set of
926                 /// feature flags.
927                 ///
928                 /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
929                 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
930                 /// 0.0.106.
931                 ///
932                 /// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
933                 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
934                 /// 0.0.107. Channels setting this type also need to get manually accepted via
935                 /// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
936                 /// or will be rejected otherwise.
937                 ///
938                 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
939                 channel_type: crate::lightning::ln::features::ChannelTypeFeatures,
940         },
941         /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
942         /// forward it.
943         ///
944         /// Some scenarios where this event may be sent include:
945         /// * Insufficient capacity in the outbound channel
946         /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
947         /// * When an unknown SCID is requested for forwarding a payment.
948         /// * Claiming an amount for an MPP payment that exceeds the HTLC total
949         /// * The HTLC has timed out
950         ///
951         /// This event, however, does not get generated if an HTLC fails to meet the forwarding
952         /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
953         HTLCHandlingFailed {
954                 /// The channel over which the HTLC was received.
955                 prev_channel_id: crate::c_types::ThirtyTwoBytes,
956                 /// Destination of the HTLC that failed to be processed.
957                 failed_next_destination: crate::lightning::util::events::HTLCDestination,
958         },
959 }
960 use lightning::util::events::Event as EventImport;
961 pub(crate) type nativeEvent = EventImport;
962
963 impl Event {
964         #[allow(unused)]
965         pub(crate) fn to_native(&self) -> nativeEvent {
966                 match self {
967                         Event::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
968                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
969                                 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
970                                 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
971                                 let mut output_script_nonref = (*output_script).clone();
972                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
973                                 nativeEvent::FundingGenerationReady {
974                                         temporary_channel_id: temporary_channel_id_nonref.data,
975                                         counterparty_node_id: counterparty_node_id_nonref.into_rust(),
976                                         channel_value_satoshis: channel_value_satoshis_nonref,
977                                         output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
978                                         user_channel_id: user_channel_id_nonref,
979                                 }
980                         },
981                         Event::PaymentReceived {ref payment_hash, ref amount_msat, ref purpose, } => {
982                                 let mut payment_hash_nonref = (*payment_hash).clone();
983                                 let mut amount_msat_nonref = (*amount_msat).clone();
984                                 let mut purpose_nonref = (*purpose).clone();
985                                 nativeEvent::PaymentReceived {
986                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
987                                         amount_msat: amount_msat_nonref,
988                                         purpose: purpose_nonref.into_native(),
989                                 }
990                         },
991                         Event::PaymentClaimed {ref payment_hash, ref amount_msat, ref purpose, } => {
992                                 let mut payment_hash_nonref = (*payment_hash).clone();
993                                 let mut amount_msat_nonref = (*amount_msat).clone();
994                                 let mut purpose_nonref = (*purpose).clone();
995                                 nativeEvent::PaymentClaimed {
996                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
997                                         amount_msat: amount_msat_nonref,
998                                         purpose: purpose_nonref.into_native(),
999                                 }
1000                         },
1001                         Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1002                                 let mut payment_id_nonref = (*payment_id).clone();
1003                                 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1004                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
1005                                 let mut payment_hash_nonref = (*payment_hash).clone();
1006                                 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
1007                                 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
1008                                 nativeEvent::PaymentSent {
1009                                         payment_id: local_payment_id_nonref,
1010                                         payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
1011                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1012                                         fee_paid_msat: local_fee_paid_msat_nonref,
1013                                 }
1014                         },
1015                         Event::PaymentFailed {ref payment_id, ref payment_hash, } => {
1016                                 let mut payment_id_nonref = (*payment_id).clone();
1017                                 let mut payment_hash_nonref = (*payment_hash).clone();
1018                                 nativeEvent::PaymentFailed {
1019                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1020                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1021                                 }
1022                         },
1023                         Event::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1024                                 let mut payment_id_nonref = (*payment_id).clone();
1025                                 let mut payment_hash_nonref = (*payment_hash).clone();
1026                                 let mut local_payment_hash_nonref = if payment_hash_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash_nonref.data) }) };
1027                                 let mut path_nonref = (*path).clone();
1028                                 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1029                                 nativeEvent::PaymentPathSuccessful {
1030                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1031                                         payment_hash: local_payment_hash_nonref,
1032                                         path: local_path_nonref,
1033                                 }
1034                         },
1035                         Event::PaymentPathFailed {ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, ref retry, } => {
1036                                 let mut payment_id_nonref = (*payment_id).clone();
1037                                 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1038                                 let mut payment_hash_nonref = (*payment_hash).clone();
1039                                 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
1040                                 let mut network_update_nonref = (*network_update).clone();
1041                                 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() }) } };
1042                                 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
1043                                 let mut path_nonref = (*path).clone();
1044                                 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1045                                 let mut short_channel_id_nonref = (*short_channel_id).clone();
1046                                 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1047                                 let mut retry_nonref = (*retry).clone();
1048                                 let mut local_retry_nonref = if retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry_nonref.take_inner()) } }) };
1049                                 nativeEvent::PaymentPathFailed {
1050                                         payment_id: local_payment_id_nonref,
1051                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1052                                         rejected_by_dest: rejected_by_dest_nonref,
1053                                         network_update: local_network_update_nonref,
1054                                         all_paths_failed: all_paths_failed_nonref,
1055                                         path: local_path_nonref,
1056                                         short_channel_id: local_short_channel_id_nonref,
1057                                         retry: local_retry_nonref,
1058                                 }
1059                         },
1060                         Event::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1061                                 let mut payment_id_nonref = (*payment_id).clone();
1062                                 let mut payment_hash_nonref = (*payment_hash).clone();
1063                                 let mut path_nonref = (*path).clone();
1064                                 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1065                                 nativeEvent::ProbeSuccessful {
1066                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1067                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1068                                         path: local_path_nonref,
1069                                 }
1070                         },
1071                         Event::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1072                                 let mut payment_id_nonref = (*payment_id).clone();
1073                                 let mut payment_hash_nonref = (*payment_hash).clone();
1074                                 let mut path_nonref = (*path).clone();
1075                                 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1076                                 let mut short_channel_id_nonref = (*short_channel_id).clone();
1077                                 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1078                                 nativeEvent::ProbeFailed {
1079                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1080                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1081                                         path: local_path_nonref,
1082                                         short_channel_id: local_short_channel_id_nonref,
1083                                 }
1084                         },
1085                         Event::PendingHTLCsForwardable {ref time_forwardable, } => {
1086                                 let mut time_forwardable_nonref = (*time_forwardable).clone();
1087                                 nativeEvent::PendingHTLCsForwardable {
1088                                         time_forwardable: core::time::Duration::from_secs(time_forwardable_nonref),
1089                                 }
1090                         },
1091                         Event::SpendableOutputs {ref outputs, } => {
1092                                 let mut outputs_nonref = (*outputs).clone();
1093                                 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
1094                                 nativeEvent::SpendableOutputs {
1095                                         outputs: local_outputs_nonref,
1096                                 }
1097                         },
1098                         Event::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, } => {
1099                                 let mut prev_channel_id_nonref = (*prev_channel_id).clone();
1100                                 let mut local_prev_channel_id_nonref = if prev_channel_id_nonref.data == [0; 32] { None } else { Some( { prev_channel_id_nonref.data }) };
1101                                 let mut next_channel_id_nonref = (*next_channel_id).clone();
1102                                 let mut local_next_channel_id_nonref = if next_channel_id_nonref.data == [0; 32] { None } else { Some( { next_channel_id_nonref.data }) };
1103                                 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
1104                                 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
1105                                 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
1106                                 nativeEvent::PaymentForwarded {
1107                                         prev_channel_id: local_prev_channel_id_nonref,
1108                                         next_channel_id: local_next_channel_id_nonref,
1109                                         fee_earned_msat: local_fee_earned_msat_nonref,
1110                                         claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1111                                 }
1112                         },
1113                         Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
1114                                 let mut channel_id_nonref = (*channel_id).clone();
1115                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
1116                                 let mut reason_nonref = (*reason).clone();
1117                                 nativeEvent::ChannelClosed {
1118                                         channel_id: channel_id_nonref.data,
1119                                         user_channel_id: user_channel_id_nonref,
1120                                         reason: reason_nonref.into_native(),
1121                                 }
1122                         },
1123                         Event::DiscardFunding {ref channel_id, ref transaction, } => {
1124                                 let mut channel_id_nonref = (*channel_id).clone();
1125                                 let mut transaction_nonref = (*transaction).clone();
1126                                 nativeEvent::DiscardFunding {
1127                                         channel_id: channel_id_nonref.data,
1128                                         transaction: transaction_nonref.into_bitcoin(),
1129                                 }
1130                         },
1131                         Event::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1132                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
1133                                 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
1134                                 let mut funding_satoshis_nonref = (*funding_satoshis).clone();
1135                                 let mut push_msat_nonref = (*push_msat).clone();
1136                                 let mut channel_type_nonref = (*channel_type).clone();
1137                                 nativeEvent::OpenChannelRequest {
1138                                         temporary_channel_id: temporary_channel_id_nonref.data,
1139                                         counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1140                                         funding_satoshis: funding_satoshis_nonref,
1141                                         push_msat: push_msat_nonref,
1142                                         channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) },
1143                                 }
1144                         },
1145                         Event::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
1146                                 let mut prev_channel_id_nonref = (*prev_channel_id).clone();
1147                                 let mut failed_next_destination_nonref = (*failed_next_destination).clone();
1148                                 nativeEvent::HTLCHandlingFailed {
1149                                         prev_channel_id: prev_channel_id_nonref.data,
1150                                         failed_next_destination: failed_next_destination_nonref.into_native(),
1151                                 }
1152                         },
1153                 }
1154         }
1155         #[allow(unused)]
1156         pub(crate) fn into_native(self) -> nativeEvent {
1157                 match self {
1158                         Event::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1159                                 nativeEvent::FundingGenerationReady {
1160                                         temporary_channel_id: temporary_channel_id.data,
1161                                         counterparty_node_id: counterparty_node_id.into_rust(),
1162                                         channel_value_satoshis: channel_value_satoshis,
1163                                         output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
1164                                         user_channel_id: user_channel_id,
1165                                 }
1166                         },
1167                         Event::PaymentReceived {mut payment_hash, mut amount_msat, mut purpose, } => {
1168                                 nativeEvent::PaymentReceived {
1169                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1170                                         amount_msat: amount_msat,
1171                                         purpose: purpose.into_native(),
1172                                 }
1173                         },
1174                         Event::PaymentClaimed {mut payment_hash, mut amount_msat, mut purpose, } => {
1175                                 nativeEvent::PaymentClaimed {
1176                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1177                                         amount_msat: amount_msat,
1178                                         purpose: purpose.into_native(),
1179                                 }
1180                         },
1181                         Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1182                                 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1183                                 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
1184                                 nativeEvent::PaymentSent {
1185                                         payment_id: local_payment_id,
1186                                         payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
1187                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1188                                         fee_paid_msat: local_fee_paid_msat,
1189                                 }
1190                         },
1191                         Event::PaymentFailed {mut payment_id, mut payment_hash, } => {
1192                                 nativeEvent::PaymentFailed {
1193                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1194                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1195                                 }
1196                         },
1197                         Event::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1198                                 let mut local_payment_hash = if payment_hash.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash.data) }) };
1199                                 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1200                                 nativeEvent::PaymentPathSuccessful {
1201                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1202                                         payment_hash: local_payment_hash,
1203                                         path: local_path,
1204                                 }
1205                         },
1206                         Event::PaymentPathFailed {mut payment_id, mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, mut retry, } => {
1207                                 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1208                                 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() }) } };
1209                                 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1210                                 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1211                                 let mut local_retry = if retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry.take_inner()) } }) };
1212                                 nativeEvent::PaymentPathFailed {
1213                                         payment_id: local_payment_id,
1214                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1215                                         rejected_by_dest: rejected_by_dest,
1216                                         network_update: local_network_update,
1217                                         all_paths_failed: all_paths_failed,
1218                                         path: local_path,
1219                                         short_channel_id: local_short_channel_id,
1220                                         retry: local_retry,
1221                                 }
1222                         },
1223                         Event::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1224                                 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1225                                 nativeEvent::ProbeSuccessful {
1226                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1227                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1228                                         path: local_path,
1229                                 }
1230                         },
1231                         Event::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
1232                                 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1233                                 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1234                                 nativeEvent::ProbeFailed {
1235                                         payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1236                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1237                                         path: local_path,
1238                                         short_channel_id: local_short_channel_id,
1239                                 }
1240                         },
1241                         Event::PendingHTLCsForwardable {mut time_forwardable, } => {
1242                                 nativeEvent::PendingHTLCsForwardable {
1243                                         time_forwardable: core::time::Duration::from_secs(time_forwardable),
1244                                 }
1245                         },
1246                         Event::SpendableOutputs {mut outputs, } => {
1247                                 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
1248                                 nativeEvent::SpendableOutputs {
1249                                         outputs: local_outputs,
1250                                 }
1251                         },
1252                         Event::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1253                                 let mut local_prev_channel_id = if prev_channel_id.data == [0; 32] { None } else { Some( { prev_channel_id.data }) };
1254                                 let mut local_next_channel_id = if next_channel_id.data == [0; 32] { None } else { Some( { next_channel_id.data }) };
1255                                 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
1256                                 nativeEvent::PaymentForwarded {
1257                                         prev_channel_id: local_prev_channel_id,
1258                                         next_channel_id: local_next_channel_id,
1259                                         fee_earned_msat: local_fee_earned_msat,
1260                                         claim_from_onchain_tx: claim_from_onchain_tx,
1261                                 }
1262                         },
1263                         Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1264                                 nativeEvent::ChannelClosed {
1265                                         channel_id: channel_id.data,
1266                                         user_channel_id: user_channel_id,
1267                                         reason: reason.into_native(),
1268                                 }
1269                         },
1270                         Event::DiscardFunding {mut channel_id, mut transaction, } => {
1271                                 nativeEvent::DiscardFunding {
1272                                         channel_id: channel_id.data,
1273                                         transaction: transaction.into_bitcoin(),
1274                                 }
1275                         },
1276                         Event::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1277                                 nativeEvent::OpenChannelRequest {
1278                                         temporary_channel_id: temporary_channel_id.data,
1279                                         counterparty_node_id: counterparty_node_id.into_rust(),
1280                                         funding_satoshis: funding_satoshis,
1281                                         push_msat: push_msat,
1282                                         channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) },
1283                                 }
1284                         },
1285                         Event::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
1286                                 nativeEvent::HTLCHandlingFailed {
1287                                         prev_channel_id: prev_channel_id.data,
1288                                         failed_next_destination: failed_next_destination.into_native(),
1289                                 }
1290                         },
1291                 }
1292         }
1293         #[allow(unused)]
1294         pub(crate) fn from_native(native: &nativeEvent) -> Self {
1295                 match native {
1296                         nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
1297                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
1298                                 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
1299                                 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
1300                                 let mut output_script_nonref = (*output_script).clone();
1301                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
1302                                 Event::FundingGenerationReady {
1303                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1304                                         counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1305                                         channel_value_satoshis: channel_value_satoshis_nonref,
1306                                         output_script: output_script_nonref.into_bytes().into(),
1307                                         user_channel_id: user_channel_id_nonref,
1308                                 }
1309                         },
1310                         nativeEvent::PaymentReceived {ref payment_hash, ref amount_msat, ref purpose, } => {
1311                                 let mut payment_hash_nonref = (*payment_hash).clone();
1312                                 let mut amount_msat_nonref = (*amount_msat).clone();
1313                                 let mut purpose_nonref = (*purpose).clone();
1314                                 Event::PaymentReceived {
1315                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1316                                         amount_msat: amount_msat_nonref,
1317                                         purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
1318                                 }
1319                         },
1320                         nativeEvent::PaymentClaimed {ref payment_hash, ref amount_msat, ref purpose, } => {
1321                                 let mut payment_hash_nonref = (*payment_hash).clone();
1322                                 let mut amount_msat_nonref = (*amount_msat).clone();
1323                                 let mut purpose_nonref = (*purpose).clone();
1324                                 Event::PaymentClaimed {
1325                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1326                                         amount_msat: amount_msat_nonref,
1327                                         purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
1328                                 }
1329                         },
1330                         nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1331                                 let mut payment_id_nonref = (*payment_id).clone();
1332                                 let mut local_payment_id_nonref = if payment_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else {  { crate::c_types::ThirtyTwoBytes { data: (payment_id_nonref.unwrap()).0 } } };
1333                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
1334                                 let mut payment_hash_nonref = (*payment_hash).clone();
1335                                 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
1336                                 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_paid_msat_nonref.unwrap() }) };
1337                                 Event::PaymentSent {
1338                                         payment_id: local_payment_id_nonref,
1339                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
1340                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1341                                         fee_paid_msat: local_fee_paid_msat_nonref,
1342                                 }
1343                         },
1344                         nativeEvent::PaymentFailed {ref payment_id, ref payment_hash, } => {
1345                                 let mut payment_id_nonref = (*payment_id).clone();
1346                                 let mut payment_hash_nonref = (*payment_hash).clone();
1347                                 Event::PaymentFailed {
1348                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1349                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1350                                 }
1351                         },
1352                         nativeEvent::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1353                                 let mut payment_id_nonref = (*payment_id).clone();
1354                                 let mut payment_hash_nonref = (*payment_hash).clone();
1355                                 let mut local_payment_hash_nonref = if payment_hash_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else {  { crate::c_types::ThirtyTwoBytes { data: (payment_hash_nonref.unwrap()).0 } } };
1356                                 let mut path_nonref = (*path).clone();
1357                                 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1358                                 Event::PaymentPathSuccessful {
1359                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1360                                         payment_hash: local_payment_hash_nonref,
1361                                         path: local_path_nonref.into(),
1362                                 }
1363                         },
1364                         nativeEvent::PaymentPathFailed {ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, ref retry, } => {
1365                                 let mut payment_id_nonref = (*payment_id).clone();
1366                                 let mut local_payment_id_nonref = if payment_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else {  { crate::c_types::ThirtyTwoBytes { data: (payment_id_nonref.unwrap()).0 } } };
1367                                 let mut payment_hash_nonref = (*payment_hash).clone();
1368                                 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
1369                                 let mut network_update_nonref = (*network_update).clone();
1370                                 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()) }) };
1371                                 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
1372                                 let mut path_nonref = (*path).clone();
1373                                 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1374                                 let mut short_channel_id_nonref = (*short_channel_id).clone();
1375                                 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id_nonref.unwrap() }) };
1376                                 let mut retry_nonref = (*retry).clone();
1377                                 let mut local_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if retry_nonref.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((retry_nonref.unwrap())) } }, is_owned: true };
1378                                 Event::PaymentPathFailed {
1379                                         payment_id: local_payment_id_nonref,
1380                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1381                                         rejected_by_dest: rejected_by_dest_nonref,
1382                                         network_update: local_network_update_nonref,
1383                                         all_paths_failed: all_paths_failed_nonref,
1384                                         path: local_path_nonref.into(),
1385                                         short_channel_id: local_short_channel_id_nonref,
1386                                         retry: local_retry_nonref,
1387                                 }
1388                         },
1389                         nativeEvent::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1390                                 let mut payment_id_nonref = (*payment_id).clone();
1391                                 let mut payment_hash_nonref = (*payment_hash).clone();
1392                                 let mut path_nonref = (*path).clone();
1393                                 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1394                                 Event::ProbeSuccessful {
1395                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1396                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1397                                         path: local_path_nonref.into(),
1398                                 }
1399                         },
1400                         nativeEvent::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1401                                 let mut payment_id_nonref = (*payment_id).clone();
1402                                 let mut payment_hash_nonref = (*payment_hash).clone();
1403                                 let mut path_nonref = (*path).clone();
1404                                 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1405                                 let mut short_channel_id_nonref = (*short_channel_id).clone();
1406                                 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id_nonref.unwrap() }) };
1407                                 Event::ProbeFailed {
1408                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1409                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1410                                         path: local_path_nonref.into(),
1411                                         short_channel_id: local_short_channel_id_nonref,
1412                                 }
1413                         },
1414                         nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
1415                                 let mut time_forwardable_nonref = (*time_forwardable).clone();
1416                                 Event::PendingHTLCsForwardable {
1417                                         time_forwardable: time_forwardable_nonref.as_secs(),
1418                                 }
1419                         },
1420                         nativeEvent::SpendableOutputs {ref outputs, } => {
1421                                 let mut outputs_nonref = (*outputs).clone();
1422                                 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.drain(..) { local_outputs_nonref.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
1423                                 Event::SpendableOutputs {
1424                                         outputs: local_outputs_nonref.into(),
1425                                 }
1426                         },
1427                         nativeEvent::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, } => {
1428                                 let mut prev_channel_id_nonref = (*prev_channel_id).clone();
1429                                 let mut local_prev_channel_id_nonref = if prev_channel_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else {  { crate::c_types::ThirtyTwoBytes { data: (prev_channel_id_nonref.unwrap()) } } };
1430                                 let mut next_channel_id_nonref = (*next_channel_id).clone();
1431                                 let mut local_next_channel_id_nonref = if next_channel_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else {  { crate::c_types::ThirtyTwoBytes { data: (next_channel_id_nonref.unwrap()) } } };
1432                                 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
1433                                 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_earned_msat_nonref.unwrap() }) };
1434                                 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
1435                                 Event::PaymentForwarded {
1436                                         prev_channel_id: local_prev_channel_id_nonref,
1437                                         next_channel_id: local_next_channel_id_nonref,
1438                                         fee_earned_msat: local_fee_earned_msat_nonref,
1439                                         claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1440                                 }
1441                         },
1442                         nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
1443                                 let mut channel_id_nonref = (*channel_id).clone();
1444                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
1445                                 let mut reason_nonref = (*reason).clone();
1446                                 Event::ChannelClosed {
1447                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1448                                         user_channel_id: user_channel_id_nonref,
1449                                         reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
1450                                 }
1451                         },
1452                         nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
1453                                 let mut channel_id_nonref = (*channel_id).clone();
1454                                 let mut transaction_nonref = (*transaction).clone();
1455                                 Event::DiscardFunding {
1456                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1457                                         transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
1458                                 }
1459                         },
1460                         nativeEvent::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1461                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
1462                                 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
1463                                 let mut funding_satoshis_nonref = (*funding_satoshis).clone();
1464                                 let mut push_msat_nonref = (*push_msat).clone();
1465                                 let mut channel_type_nonref = (*channel_type).clone();
1466                                 Event::OpenChannelRequest {
1467                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1468                                         counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1469                                         funding_satoshis: funding_satoshis_nonref,
1470                                         push_msat: push_msat_nonref,
1471                                         channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true },
1472                                 }
1473                         },
1474                         nativeEvent::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
1475                                 let mut prev_channel_id_nonref = (*prev_channel_id).clone();
1476                                 let mut failed_next_destination_nonref = (*failed_next_destination).clone();
1477                                 Event::HTLCHandlingFailed {
1478                                         prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id_nonref },
1479                                         failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination_nonref),
1480                                 }
1481                         },
1482                 }
1483         }
1484         #[allow(unused)]
1485         pub(crate) fn native_into(native: nativeEvent) -> Self {
1486                 match native {
1487                         nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1488                                 Event::FundingGenerationReady {
1489                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1490                                         counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1491                                         channel_value_satoshis: channel_value_satoshis,
1492                                         output_script: output_script.into_bytes().into(),
1493                                         user_channel_id: user_channel_id,
1494                                 }
1495                         },
1496                         nativeEvent::PaymentReceived {mut payment_hash, mut amount_msat, mut purpose, } => {
1497                                 Event::PaymentReceived {
1498                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1499                                         amount_msat: amount_msat,
1500                                         purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
1501                                 }
1502                         },
1503                         nativeEvent::PaymentClaimed {mut payment_hash, mut amount_msat, mut purpose, } => {
1504                                 Event::PaymentClaimed {
1505                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1506                                         amount_msat: amount_msat,
1507                                         purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
1508                                 }
1509                         },
1510                         nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1511                                 let mut local_payment_id = if payment_id.is_none() { crate::c_types::ThirtyTwoBytes::null() } else {  { crate::c_types::ThirtyTwoBytes { data: (payment_id.unwrap()).0 } } };
1512                                 let mut local_fee_paid_msat = if fee_paid_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_paid_msat.unwrap() }) };
1513                                 Event::PaymentSent {
1514                                         payment_id: local_payment_id,
1515                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
1516                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1517                                         fee_paid_msat: local_fee_paid_msat,
1518                                 }
1519                         },
1520                         nativeEvent::PaymentFailed {mut payment_id, mut payment_hash, } => {
1521                                 Event::PaymentFailed {
1522                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1523                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1524                                 }
1525                         },
1526                         nativeEvent::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1527                                 let mut local_payment_hash = if payment_hash.is_none() { crate::c_types::ThirtyTwoBytes::null() } else {  { crate::c_types::ThirtyTwoBytes { data: (payment_hash.unwrap()).0 } } };
1528                                 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1529                                 Event::PaymentPathSuccessful {
1530                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1531                                         payment_hash: local_payment_hash,
1532                                         path: local_path.into(),
1533                                 }
1534                         },
1535                         nativeEvent::PaymentPathFailed {mut payment_id, mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, mut retry, } => {
1536                                 let mut local_payment_id = if payment_id.is_none() { crate::c_types::ThirtyTwoBytes::null() } else {  { crate::c_types::ThirtyTwoBytes { data: (payment_id.unwrap()).0 } } };
1537                                 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()) }) };
1538                                 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1539                                 let mut local_short_channel_id = if short_channel_id.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id.unwrap() }) };
1540                                 let mut local_retry = crate::lightning::routing::router::RouteParameters { inner: if retry.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((retry.unwrap())) } }, is_owned: true };
1541                                 Event::PaymentPathFailed {
1542                                         payment_id: local_payment_id,
1543                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1544                                         rejected_by_dest: rejected_by_dest,
1545                                         network_update: local_network_update,
1546                                         all_paths_failed: all_paths_failed,
1547                                         path: local_path.into(),
1548                                         short_channel_id: local_short_channel_id,
1549                                         retry: local_retry,
1550                                 }
1551                         },
1552                         nativeEvent::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1553                                 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1554                                 Event::ProbeSuccessful {
1555                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1556                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1557                                         path: local_path.into(),
1558                                 }
1559                         },
1560                         nativeEvent::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
1561                                 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1562                                 let mut local_short_channel_id = if short_channel_id.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id.unwrap() }) };
1563                                 Event::ProbeFailed {
1564                                         payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1565                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1566                                         path: local_path.into(),
1567                                         short_channel_id: local_short_channel_id,
1568                                 }
1569                         },
1570                         nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
1571                                 Event::PendingHTLCsForwardable {
1572                                         time_forwardable: time_forwardable.as_secs(),
1573                                 }
1574                         },
1575                         nativeEvent::SpendableOutputs {mut outputs, } => {
1576                                 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
1577                                 Event::SpendableOutputs {
1578                                         outputs: local_outputs.into(),
1579                                 }
1580                         },
1581                         nativeEvent::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1582                                 let mut local_prev_channel_id = if prev_channel_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else {  { crate::c_types::ThirtyTwoBytes { data: (prev_channel_id.unwrap()) } } };
1583                                 let mut local_next_channel_id = if next_channel_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else {  { crate::c_types::ThirtyTwoBytes { data: (next_channel_id.unwrap()) } } };
1584                                 let mut local_fee_earned_msat = if fee_earned_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_earned_msat.unwrap() }) };
1585                                 Event::PaymentForwarded {
1586                                         prev_channel_id: local_prev_channel_id,
1587                                         next_channel_id: local_next_channel_id,
1588                                         fee_earned_msat: local_fee_earned_msat,
1589                                         claim_from_onchain_tx: claim_from_onchain_tx,
1590                                 }
1591                         },
1592                         nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1593                                 Event::ChannelClosed {
1594                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1595                                         user_channel_id: user_channel_id,
1596                                         reason: crate::lightning::util::events::ClosureReason::native_into(reason),
1597                                 }
1598                         },
1599                         nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
1600                                 Event::DiscardFunding {
1601                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1602                                         transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
1603                                 }
1604                         },
1605                         nativeEvent::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1606                                 Event::OpenChannelRequest {
1607                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1608                                         counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1609                                         funding_satoshis: funding_satoshis,
1610                                         push_msat: push_msat,
1611                                         channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true },
1612                                 }
1613                         },
1614                         nativeEvent::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
1615                                 Event::HTLCHandlingFailed {
1616                                         prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id },
1617                                         failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination),
1618                                 }
1619                         },
1620                 }
1621         }
1622 }
1623 /// Frees any resources used by the Event
1624 #[no_mangle]
1625 pub extern "C" fn Event_free(this_ptr: Event) { }
1626 /// Creates a copy of the Event
1627 #[no_mangle]
1628 pub extern "C" fn Event_clone(orig: &Event) -> Event {
1629         orig.clone()
1630 }
1631 #[no_mangle]
1632 /// Utility method to constructs a new FundingGenerationReady-variant Event
1633 pub extern "C" fn Event_funding_generation_ready(temporary_channel_id: crate::c_types::ThirtyTwoBytes, counterparty_node_id: crate::c_types::PublicKey, channel_value_satoshis: u64, output_script: crate::c_types::derived::CVec_u8Z, user_channel_id: u64) -> Event {
1634         Event::FundingGenerationReady {
1635                 temporary_channel_id,
1636                 counterparty_node_id,
1637                 channel_value_satoshis,
1638                 output_script,
1639                 user_channel_id,
1640         }
1641 }
1642 #[no_mangle]
1643 /// Utility method to constructs a new PaymentReceived-variant Event
1644 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amount_msat: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
1645         Event::PaymentReceived {
1646                 payment_hash,
1647                 amount_msat,
1648                 purpose,
1649         }
1650 }
1651 #[no_mangle]
1652 /// Utility method to constructs a new PaymentClaimed-variant Event
1653 pub extern "C" fn Event_payment_claimed(payment_hash: crate::c_types::ThirtyTwoBytes, amount_msat: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
1654         Event::PaymentClaimed {
1655                 payment_hash,
1656                 amount_msat,
1657                 purpose,
1658         }
1659 }
1660 #[no_mangle]
1661 /// Utility method to constructs a new PaymentSent-variant Event
1662 pub extern "C" fn Event_payment_sent(payment_id: crate::c_types::ThirtyTwoBytes, payment_preimage: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, fee_paid_msat: crate::c_types::derived::COption_u64Z) -> Event {
1663         Event::PaymentSent {
1664                 payment_id,
1665                 payment_preimage,
1666                 payment_hash,
1667                 fee_paid_msat,
1668         }
1669 }
1670 #[no_mangle]
1671 /// Utility method to constructs a new PaymentFailed-variant Event
1672 pub extern "C" fn Event_payment_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> Event {
1673         Event::PaymentFailed {
1674                 payment_id,
1675                 payment_hash,
1676         }
1677 }
1678 #[no_mangle]
1679 /// Utility method to constructs a new PaymentPathSuccessful-variant Event
1680 pub extern "C" fn Event_payment_path_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event {
1681         Event::PaymentPathSuccessful {
1682                 payment_id,
1683                 payment_hash,
1684                 path,
1685         }
1686 }
1687 #[no_mangle]
1688 /// Utility method to constructs a new PaymentPathFailed-variant Event
1689 pub extern "C" fn Event_payment_path_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, rejected_by_dest: bool, network_update: crate::c_types::derived::COption_NetworkUpdateZ, all_paths_failed: bool, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z, retry: crate::lightning::routing::router::RouteParameters) -> Event {
1690         Event::PaymentPathFailed {
1691                 payment_id,
1692                 payment_hash,
1693                 rejected_by_dest,
1694                 network_update,
1695                 all_paths_failed,
1696                 path,
1697                 short_channel_id,
1698                 retry,
1699         }
1700 }
1701 #[no_mangle]
1702 /// Utility method to constructs a new ProbeSuccessful-variant Event
1703 pub extern "C" fn Event_probe_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event {
1704         Event::ProbeSuccessful {
1705                 payment_id,
1706                 payment_hash,
1707                 path,
1708         }
1709 }
1710 #[no_mangle]
1711 /// Utility method to constructs a new ProbeFailed-variant Event
1712 pub extern "C" fn Event_probe_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z) -> Event {
1713         Event::ProbeFailed {
1714                 payment_id,
1715                 payment_hash,
1716                 path,
1717                 short_channel_id,
1718         }
1719 }
1720 #[no_mangle]
1721 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
1722 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
1723         Event::PendingHTLCsForwardable {
1724                 time_forwardable,
1725         }
1726 }
1727 #[no_mangle]
1728 /// Utility method to constructs a new SpendableOutputs-variant Event
1729 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
1730         Event::SpendableOutputs {
1731                 outputs,
1732         }
1733 }
1734 #[no_mangle]
1735 /// Utility method to constructs a new PaymentForwarded-variant Event
1736 pub extern "C" fn Event_payment_forwarded(prev_channel_id: crate::c_types::ThirtyTwoBytes, next_channel_id: crate::c_types::ThirtyTwoBytes, fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
1737         Event::PaymentForwarded {
1738                 prev_channel_id,
1739                 next_channel_id,
1740                 fee_earned_msat,
1741                 claim_from_onchain_tx,
1742         }
1743 }
1744 #[no_mangle]
1745 /// Utility method to constructs a new ChannelClosed-variant Event
1746 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: u64, reason: crate::lightning::util::events::ClosureReason) -> Event {
1747         Event::ChannelClosed {
1748                 channel_id,
1749                 user_channel_id,
1750                 reason,
1751         }
1752 }
1753 #[no_mangle]
1754 /// Utility method to constructs a new DiscardFunding-variant Event
1755 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
1756         Event::DiscardFunding {
1757                 channel_id,
1758                 transaction,
1759         }
1760 }
1761 #[no_mangle]
1762 /// Utility method to constructs a new OpenChannelRequest-variant Event
1763 pub extern "C" fn Event_open_channel_request(temporary_channel_id: crate::c_types::ThirtyTwoBytes, counterparty_node_id: crate::c_types::PublicKey, funding_satoshis: u64, push_msat: u64, channel_type: crate::lightning::ln::features::ChannelTypeFeatures) -> Event {
1764         Event::OpenChannelRequest {
1765                 temporary_channel_id,
1766                 counterparty_node_id,
1767                 funding_satoshis,
1768                 push_msat,
1769                 channel_type,
1770         }
1771 }
1772 #[no_mangle]
1773 /// Utility method to constructs a new HTLCHandlingFailed-variant Event
1774 pub extern "C" fn Event_htlchandling_failed(prev_channel_id: crate::c_types::ThirtyTwoBytes, failed_next_destination: crate::lightning::util::events::HTLCDestination) -> Event {
1775         Event::HTLCHandlingFailed {
1776                 prev_channel_id,
1777                 failed_next_destination,
1778         }
1779 }
1780 #[no_mangle]
1781 /// Serialize the Event object into a byte array which can be read by Event_read
1782 pub extern "C" fn Event_write(obj: &crate::lightning::util::events::Event) -> crate::c_types::derived::CVec_u8Z {
1783         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
1784 }
1785 #[no_mangle]
1786 /// Read a Event from a byte array, created by Event_write
1787 pub extern "C" fn Event_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_EventZDecodeErrorZ {
1788         let res: Result<Option<lightning::util::events::Event>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
1789         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_EventZ::None } else { crate::c_types::derived::COption_EventZ::Some( { crate::lightning::util::events::Event::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() };
1790         local_res
1791 }
1792 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1793 /// broadcast to most peers).
1794 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1795 #[derive(Clone)]
1796 #[must_use]
1797 #[repr(C)]
1798 pub enum MessageSendEvent {
1799         /// Used to indicate that we've accepted a channel open and should send the accept_channel
1800         /// message provided to the given peer.
1801         SendAcceptChannel {
1802                 /// The node_id of the node which should receive this message
1803                 node_id: crate::c_types::PublicKey,
1804                 /// The message which should be sent.
1805                 msg: crate::lightning::ln::msgs::AcceptChannel,
1806         },
1807         /// Used to indicate that we've initiated a channel open and should send the open_channel
1808         /// message provided to the given peer.
1809         SendOpenChannel {
1810                 /// The node_id of the node which should receive this message
1811                 node_id: crate::c_types::PublicKey,
1812                 /// The message which should be sent.
1813                 msg: crate::lightning::ln::msgs::OpenChannel,
1814         },
1815         /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1816         SendFundingCreated {
1817                 /// The node_id of the node which should receive this message
1818                 node_id: crate::c_types::PublicKey,
1819                 /// The message which should be sent.
1820                 msg: crate::lightning::ln::msgs::FundingCreated,
1821         },
1822         /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
1823         SendFundingSigned {
1824                 /// The node_id of the node which should receive this message
1825                 node_id: crate::c_types::PublicKey,
1826                 /// The message which should be sent.
1827                 msg: crate::lightning::ln::msgs::FundingSigned,
1828         },
1829         /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
1830         SendChannelReady {
1831                 /// The node_id of the node which should receive these message(s)
1832                 node_id: crate::c_types::PublicKey,
1833                 /// The channel_ready message which should be sent.
1834                 msg: crate::lightning::ln::msgs::ChannelReady,
1835         },
1836         /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1837         SendAnnouncementSignatures {
1838                 /// The node_id of the node which should receive these message(s)
1839                 node_id: crate::c_types::PublicKey,
1840                 /// The announcement_signatures message which should be sent.
1841                 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
1842         },
1843         /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1844         /// message should be sent to the peer with the given node_id.
1845         UpdateHTLCs {
1846                 /// The node_id of the node which should receive these message(s)
1847                 node_id: crate::c_types::PublicKey,
1848                 /// The update messages which should be sent. ALL messages in the struct should be sent!
1849                 updates: crate::lightning::ln::msgs::CommitmentUpdate,
1850         },
1851         /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1852         SendRevokeAndACK {
1853                 /// The node_id of the node which should receive this message
1854                 node_id: crate::c_types::PublicKey,
1855                 /// The message which should be sent.
1856                 msg: crate::lightning::ln::msgs::RevokeAndACK,
1857         },
1858         /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1859         SendClosingSigned {
1860                 /// The node_id of the node which should receive this message
1861                 node_id: crate::c_types::PublicKey,
1862                 /// The message which should be sent.
1863                 msg: crate::lightning::ln::msgs::ClosingSigned,
1864         },
1865         /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
1866         SendShutdown {
1867                 /// The node_id of the node which should receive this message
1868                 node_id: crate::c_types::PublicKey,
1869                 /// The message which should be sent.
1870                 msg: crate::lightning::ln::msgs::Shutdown,
1871         },
1872         /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1873         SendChannelReestablish {
1874                 /// The node_id of the node which should receive this message
1875                 node_id: crate::c_types::PublicKey,
1876                 /// The message which should be sent.
1877                 msg: crate::lightning::ln::msgs::ChannelReestablish,
1878         },
1879         /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1880         /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1881         ///
1882         /// Note that after doing so, you very likely (unless you did so very recently) want to call
1883         /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
1884         /// This ensures that any nodes which see our channel_announcement also have a relevant
1885         /// node_announcement, including relevant feature flags which may be important for routing
1886         /// through or to us.
1887         BroadcastChannelAnnouncement {
1888                 /// The channel_announcement which should be sent.
1889                 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
1890                 /// The followup channel_update which should be sent.
1891                 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
1892         },
1893         /// Used to indicate that a node_announcement should be broadcast to all peers.
1894         BroadcastNodeAnnouncement {
1895                 /// The node_announcement which should be sent.
1896                 msg: crate::lightning::ln::msgs::NodeAnnouncement,
1897         },
1898         /// Used to indicate that a channel_update should be broadcast to all peers.
1899         BroadcastChannelUpdate {
1900                 /// The channel_update which should be sent.
1901                 msg: crate::lightning::ln::msgs::ChannelUpdate,
1902         },
1903         /// Used to indicate that a channel_update should be sent to a single peer.
1904         /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1905         /// private channel and we shouldn't be informing all of our peers of channel parameters.
1906         SendChannelUpdate {
1907                 /// The node_id of the node which should receive this message
1908                 node_id: crate::c_types::PublicKey,
1909                 /// The channel_update which should be sent.
1910                 msg: crate::lightning::ln::msgs::ChannelUpdate,
1911         },
1912         /// Broadcast an error downstream to be handled
1913         HandleError {
1914                 /// The node_id of the node which should receive this message
1915                 node_id: crate::c_types::PublicKey,
1916                 /// The action which should be taken.
1917                 action: crate::lightning::ln::msgs::ErrorAction,
1918         },
1919         /// Query a peer for channels with funding transaction UTXOs in a block range.
1920         SendChannelRangeQuery {
1921                 /// The node_id of this message recipient
1922                 node_id: crate::c_types::PublicKey,
1923                 /// The query_channel_range which should be sent.
1924                 msg: crate::lightning::ln::msgs::QueryChannelRange,
1925         },
1926         /// Request routing gossip messages from a peer for a list of channels identified by
1927         /// their short_channel_ids.
1928         SendShortIdsQuery {
1929                 /// The node_id of this message recipient
1930                 node_id: crate::c_types::PublicKey,
1931                 /// The query_short_channel_ids which should be sent.
1932                 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
1933         },
1934         /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1935         /// emitted during processing of the query.
1936         SendReplyChannelRange {
1937                 /// The node_id of this message recipient
1938                 node_id: crate::c_types::PublicKey,
1939                 /// The reply_channel_range which should be sent.
1940                 msg: crate::lightning::ln::msgs::ReplyChannelRange,
1941         },
1942         /// Sends a timestamp filter for inbound gossip. This should be sent on each new connection to
1943         /// enable receiving gossip messages from the peer.
1944         SendGossipTimestampFilter {
1945                 /// The node_id of this message recipient
1946                 node_id: crate::c_types::PublicKey,
1947                 /// The gossip_timestamp_filter which should be sent.
1948                 msg: crate::lightning::ln::msgs::GossipTimestampFilter,
1949         },
1950 }
1951 use lightning::util::events::MessageSendEvent as MessageSendEventImport;
1952 pub(crate) type nativeMessageSendEvent = MessageSendEventImport;
1953
1954 impl MessageSendEvent {
1955         #[allow(unused)]
1956         pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
1957                 match self {
1958                         MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1959                                 let mut node_id_nonref = (*node_id).clone();
1960                                 let mut msg_nonref = (*msg).clone();
1961                                 nativeMessageSendEvent::SendAcceptChannel {
1962                                         node_id: node_id_nonref.into_rust(),
1963                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1964                                 }
1965                         },
1966                         MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1967                                 let mut node_id_nonref = (*node_id).clone();
1968                                 let mut msg_nonref = (*msg).clone();
1969                                 nativeMessageSendEvent::SendOpenChannel {
1970                                         node_id: node_id_nonref.into_rust(),
1971                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1972                                 }
1973                         },
1974                         MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1975                                 let mut node_id_nonref = (*node_id).clone();
1976                                 let mut msg_nonref = (*msg).clone();
1977                                 nativeMessageSendEvent::SendFundingCreated {
1978                                         node_id: node_id_nonref.into_rust(),
1979                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1980                                 }
1981                         },
1982                         MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1983                                 let mut node_id_nonref = (*node_id).clone();
1984                                 let mut msg_nonref = (*msg).clone();
1985                                 nativeMessageSendEvent::SendFundingSigned {
1986                                         node_id: node_id_nonref.into_rust(),
1987                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1988                                 }
1989                         },
1990                         MessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
1991                                 let mut node_id_nonref = (*node_id).clone();
1992                                 let mut msg_nonref = (*msg).clone();
1993                                 nativeMessageSendEvent::SendChannelReady {
1994                                         node_id: node_id_nonref.into_rust(),
1995                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1996                                 }
1997                         },
1998                         MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1999                                 let mut node_id_nonref = (*node_id).clone();
2000                                 let mut msg_nonref = (*msg).clone();
2001                                 nativeMessageSendEvent::SendAnnouncementSignatures {
2002                                         node_id: node_id_nonref.into_rust(),
2003                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2004                                 }
2005                         },
2006                         MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2007                                 let mut node_id_nonref = (*node_id).clone();
2008                                 let mut updates_nonref = (*updates).clone();
2009                                 nativeMessageSendEvent::UpdateHTLCs {
2010                                         node_id: node_id_nonref.into_rust(),
2011                                         updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
2012                                 }
2013                         },
2014                         MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2015                                 let mut node_id_nonref = (*node_id).clone();
2016                                 let mut msg_nonref = (*msg).clone();
2017                                 nativeMessageSendEvent::SendRevokeAndACK {
2018                                         node_id: node_id_nonref.into_rust(),
2019                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2020                                 }
2021                         },
2022                         MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2023                                 let mut node_id_nonref = (*node_id).clone();
2024                                 let mut msg_nonref = (*msg).clone();
2025                                 nativeMessageSendEvent::SendClosingSigned {
2026                                         node_id: node_id_nonref.into_rust(),
2027                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2028                                 }
2029                         },
2030                         MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
2031                                 let mut node_id_nonref = (*node_id).clone();
2032                                 let mut msg_nonref = (*msg).clone();
2033                                 nativeMessageSendEvent::SendShutdown {
2034                                         node_id: node_id_nonref.into_rust(),
2035                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2036                                 }
2037                         },
2038                         MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
2039                                 let mut node_id_nonref = (*node_id).clone();
2040                                 let mut msg_nonref = (*msg).clone();
2041                                 nativeMessageSendEvent::SendChannelReestablish {
2042                                         node_id: node_id_nonref.into_rust(),
2043                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2044                                 }
2045                         },
2046                         MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
2047                                 let mut msg_nonref = (*msg).clone();
2048                                 let mut update_msg_nonref = (*update_msg).clone();
2049                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2050                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2051                                         update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
2052                                 }
2053                         },
2054                         MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
2055                                 let mut msg_nonref = (*msg).clone();
2056                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
2057                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2058                                 }
2059                         },
2060                         MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
2061                                 let mut msg_nonref = (*msg).clone();
2062                                 nativeMessageSendEvent::BroadcastChannelUpdate {
2063                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2064                                 }
2065                         },
2066                         MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
2067                                 let mut node_id_nonref = (*node_id).clone();
2068                                 let mut msg_nonref = (*msg).clone();
2069                                 nativeMessageSendEvent::SendChannelUpdate {
2070                                         node_id: node_id_nonref.into_rust(),
2071                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2072                                 }
2073                         },
2074                         MessageSendEvent::HandleError {ref node_id, ref action, } => {
2075                                 let mut node_id_nonref = (*node_id).clone();
2076                                 let mut action_nonref = (*action).clone();
2077                                 nativeMessageSendEvent::HandleError {
2078                                         node_id: node_id_nonref.into_rust(),
2079                                         action: action_nonref.into_native(),
2080                                 }
2081                         },
2082                         MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
2083                                 let mut node_id_nonref = (*node_id).clone();
2084                                 let mut msg_nonref = (*msg).clone();
2085                                 nativeMessageSendEvent::SendChannelRangeQuery {
2086                                         node_id: node_id_nonref.into_rust(),
2087                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2088                                 }
2089                         },
2090                         MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
2091                                 let mut node_id_nonref = (*node_id).clone();
2092                                 let mut msg_nonref = (*msg).clone();
2093                                 nativeMessageSendEvent::SendShortIdsQuery {
2094                                         node_id: node_id_nonref.into_rust(),
2095                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2096                                 }
2097                         },
2098                         MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
2099                                 let mut node_id_nonref = (*node_id).clone();
2100                                 let mut msg_nonref = (*msg).clone();
2101                                 nativeMessageSendEvent::SendReplyChannelRange {
2102                                         node_id: node_id_nonref.into_rust(),
2103                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2104                                 }
2105                         },
2106                         MessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
2107                                 let mut node_id_nonref = (*node_id).clone();
2108                                 let mut msg_nonref = (*msg).clone();
2109                                 nativeMessageSendEvent::SendGossipTimestampFilter {
2110                                         node_id: node_id_nonref.into_rust(),
2111                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2112                                 }
2113                         },
2114                 }
2115         }
2116         #[allow(unused)]
2117         pub(crate) fn into_native(self) -> nativeMessageSendEvent {
2118                 match self {
2119                         MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
2120                                 nativeMessageSendEvent::SendAcceptChannel {
2121                                         node_id: node_id.into_rust(),
2122                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2123                                 }
2124                         },
2125                         MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
2126                                 nativeMessageSendEvent::SendOpenChannel {
2127                                         node_id: node_id.into_rust(),
2128                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2129                                 }
2130                         },
2131                         MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
2132                                 nativeMessageSendEvent::SendFundingCreated {
2133                                         node_id: node_id.into_rust(),
2134                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2135                                 }
2136                         },
2137                         MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
2138                                 nativeMessageSendEvent::SendFundingSigned {
2139                                         node_id: node_id.into_rust(),
2140                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2141                                 }
2142                         },
2143                         MessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
2144                                 nativeMessageSendEvent::SendChannelReady {
2145                                         node_id: node_id.into_rust(),
2146                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2147                                 }
2148                         },
2149                         MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
2150                                 nativeMessageSendEvent::SendAnnouncementSignatures {
2151                                         node_id: node_id.into_rust(),
2152                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2153                                 }
2154                         },
2155                         MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
2156                                 nativeMessageSendEvent::UpdateHTLCs {
2157                                         node_id: node_id.into_rust(),
2158                                         updates: *unsafe { Box::from_raw(updates.take_inner()) },
2159                                 }
2160                         },
2161                         MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
2162                                 nativeMessageSendEvent::SendRevokeAndACK {
2163                                         node_id: node_id.into_rust(),
2164                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2165                                 }
2166                         },
2167                         MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
2168                                 nativeMessageSendEvent::SendClosingSigned {
2169                                         node_id: node_id.into_rust(),
2170                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2171                                 }
2172                         },
2173                         MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
2174                                 nativeMessageSendEvent::SendShutdown {
2175                                         node_id: node_id.into_rust(),
2176                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2177                                 }
2178                         },
2179                         MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
2180                                 nativeMessageSendEvent::SendChannelReestablish {
2181                                         node_id: node_id.into_rust(),
2182                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2183                                 }
2184                         },
2185                         MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
2186                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2187                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2188                                         update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
2189                                 }
2190                         },
2191                         MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
2192                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
2193                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2194                                 }
2195                         },
2196                         MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
2197                                 nativeMessageSendEvent::BroadcastChannelUpdate {
2198                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2199                                 }
2200                         },
2201                         MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
2202                                 nativeMessageSendEvent::SendChannelUpdate {
2203                                         node_id: node_id.into_rust(),
2204                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2205                                 }
2206                         },
2207                         MessageSendEvent::HandleError {mut node_id, mut action, } => {
2208                                 nativeMessageSendEvent::HandleError {
2209                                         node_id: node_id.into_rust(),
2210                                         action: action.into_native(),
2211                                 }
2212                         },
2213                         MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
2214                                 nativeMessageSendEvent::SendChannelRangeQuery {
2215                                         node_id: node_id.into_rust(),
2216                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2217                                 }
2218                         },
2219                         MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
2220                                 nativeMessageSendEvent::SendShortIdsQuery {
2221                                         node_id: node_id.into_rust(),
2222                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2223                                 }
2224                         },
2225                         MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
2226                                 nativeMessageSendEvent::SendReplyChannelRange {
2227                                         node_id: node_id.into_rust(),
2228                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2229                                 }
2230                         },
2231                         MessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
2232                                 nativeMessageSendEvent::SendGossipTimestampFilter {
2233                                         node_id: node_id.into_rust(),
2234                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
2235                                 }
2236                         },
2237                 }
2238         }
2239         #[allow(unused)]
2240         pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
2241                 match native {
2242                         nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
2243                                 let mut node_id_nonref = (*node_id).clone();
2244                                 let mut msg_nonref = (*msg).clone();
2245                                 MessageSendEvent::SendAcceptChannel {
2246                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2247                                         msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2248                                 }
2249                         },
2250                         nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
2251                                 let mut node_id_nonref = (*node_id).clone();
2252                                 let mut msg_nonref = (*msg).clone();
2253                                 MessageSendEvent::SendOpenChannel {
2254                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2255                                         msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2256                                 }
2257                         },
2258                         nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
2259                                 let mut node_id_nonref = (*node_id).clone();
2260                                 let mut msg_nonref = (*msg).clone();
2261                                 MessageSendEvent::SendFundingCreated {
2262                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2263                                         msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2264                                 }
2265                         },
2266                         nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
2267                                 let mut node_id_nonref = (*node_id).clone();
2268                                 let mut msg_nonref = (*msg).clone();
2269                                 MessageSendEvent::SendFundingSigned {
2270                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2271                                         msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2272                                 }
2273                         },
2274                         nativeMessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
2275                                 let mut node_id_nonref = (*node_id).clone();
2276                                 let mut msg_nonref = (*msg).clone();
2277                                 MessageSendEvent::SendChannelReady {
2278                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2279                                         msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2280                                 }
2281                         },
2282                         nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
2283                                 let mut node_id_nonref = (*node_id).clone();
2284                                 let mut msg_nonref = (*msg).clone();
2285                                 MessageSendEvent::SendAnnouncementSignatures {
2286                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2287                                         msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2288                                 }
2289                         },
2290                         nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2291                                 let mut node_id_nonref = (*node_id).clone();
2292                                 let mut updates_nonref = (*updates).clone();
2293                                 MessageSendEvent::UpdateHTLCs {
2294                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2295                                         updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
2296                                 }
2297                         },
2298                         nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2299                                 let mut node_id_nonref = (*node_id).clone();
2300                                 let mut msg_nonref = (*msg).clone();
2301                                 MessageSendEvent::SendRevokeAndACK {
2302                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2303                                         msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2304                                 }
2305                         },
2306                         nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2307                                 let mut node_id_nonref = (*node_id).clone();
2308                                 let mut msg_nonref = (*msg).clone();
2309                                 MessageSendEvent::SendClosingSigned {
2310                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2311                                         msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2312                                 }
2313                         },
2314                         nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
2315                                 let mut node_id_nonref = (*node_id).clone();
2316                                 let mut msg_nonref = (*msg).clone();
2317                                 MessageSendEvent::SendShutdown {
2318                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2319                                         msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2320                                 }
2321                         },
2322                         nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
2323                                 let mut node_id_nonref = (*node_id).clone();
2324                                 let mut msg_nonref = (*msg).clone();
2325                                 MessageSendEvent::SendChannelReestablish {
2326                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2327                                         msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2328                                 }
2329                         },
2330                         nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
2331                                 let mut msg_nonref = (*msg).clone();
2332                                 let mut update_msg_nonref = (*update_msg).clone();
2333                                 MessageSendEvent::BroadcastChannelAnnouncement {
2334                                         msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2335                                         update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
2336                                 }
2337                         },
2338                         nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
2339                                 let mut msg_nonref = (*msg).clone();
2340                                 MessageSendEvent::BroadcastNodeAnnouncement {
2341                                         msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2342                                 }
2343                         },
2344                         nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
2345                                 let mut msg_nonref = (*msg).clone();
2346                                 MessageSendEvent::BroadcastChannelUpdate {
2347                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2348                                 }
2349                         },
2350                         nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
2351                                 let mut node_id_nonref = (*node_id).clone();
2352                                 let mut msg_nonref = (*msg).clone();
2353                                 MessageSendEvent::SendChannelUpdate {
2354                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2355                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2356                                 }
2357                         },
2358                         nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
2359                                 let mut node_id_nonref = (*node_id).clone();
2360                                 let mut action_nonref = (*action).clone();
2361                                 MessageSendEvent::HandleError {
2362                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2363                                         action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
2364                                 }
2365                         },
2366                         nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
2367                                 let mut node_id_nonref = (*node_id).clone();
2368                                 let mut msg_nonref = (*msg).clone();
2369                                 MessageSendEvent::SendChannelRangeQuery {
2370                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2371                                         msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2372                                 }
2373                         },
2374                         nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
2375                                 let mut node_id_nonref = (*node_id).clone();
2376                                 let mut msg_nonref = (*msg).clone();
2377                                 MessageSendEvent::SendShortIdsQuery {
2378                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2379                                         msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2380                                 }
2381                         },
2382                         nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
2383                                 let mut node_id_nonref = (*node_id).clone();
2384                                 let mut msg_nonref = (*msg).clone();
2385                                 MessageSendEvent::SendReplyChannelRange {
2386                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2387                                         msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2388                                 }
2389                         },
2390                         nativeMessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
2391                                 let mut node_id_nonref = (*node_id).clone();
2392                                 let mut msg_nonref = (*msg).clone();
2393                                 MessageSendEvent::SendGossipTimestampFilter {
2394                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2395                                         msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2396                                 }
2397                         },
2398                 }
2399         }
2400         #[allow(unused)]
2401         pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
2402                 match native {
2403                         nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
2404                                 MessageSendEvent::SendAcceptChannel {
2405                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2406                                         msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
2407                                 }
2408                         },
2409                         nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
2410                                 MessageSendEvent::SendOpenChannel {
2411                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2412                                         msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
2413                                 }
2414                         },
2415                         nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
2416                                 MessageSendEvent::SendFundingCreated {
2417                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2418                                         msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
2419                                 }
2420                         },
2421                         nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
2422                                 MessageSendEvent::SendFundingSigned {
2423                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2424                                         msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
2425                                 }
2426                         },
2427                         nativeMessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
2428                                 MessageSendEvent::SendChannelReady {
2429                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2430                                         msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg), is_owned: true },
2431                                 }
2432                         },
2433                         nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
2434                                 MessageSendEvent::SendAnnouncementSignatures {
2435                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2436                                         msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
2437                                 }
2438                         },
2439                         nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
2440                                 MessageSendEvent::UpdateHTLCs {
2441                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2442                                         updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
2443                                 }
2444                         },
2445                         nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
2446                                 MessageSendEvent::SendRevokeAndACK {
2447                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2448                                         msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
2449                                 }
2450                         },
2451                         nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
2452                                 MessageSendEvent::SendClosingSigned {
2453                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2454                                         msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
2455                                 }
2456                         },
2457                         nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
2458                                 MessageSendEvent::SendShutdown {
2459                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2460                                         msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
2461                                 }
2462                         },
2463                         nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
2464                                 MessageSendEvent::SendChannelReestablish {
2465                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2466                                         msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
2467                                 }
2468                         },
2469                         nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
2470                                 MessageSendEvent::BroadcastChannelAnnouncement {
2471                                         msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
2472                                         update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
2473                                 }
2474                         },
2475                         nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
2476                                 MessageSendEvent::BroadcastNodeAnnouncement {
2477                                         msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
2478                                 }
2479                         },
2480                         nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
2481                                 MessageSendEvent::BroadcastChannelUpdate {
2482                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
2483                                 }
2484                         },
2485                         nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
2486                                 MessageSendEvent::SendChannelUpdate {
2487                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2488                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
2489                                 }
2490                         },
2491                         nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
2492                                 MessageSendEvent::HandleError {
2493                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2494                                         action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
2495                                 }
2496                         },
2497                         nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
2498                                 MessageSendEvent::SendChannelRangeQuery {
2499                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2500                                         msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
2501                                 }
2502                         },
2503                         nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
2504                                 MessageSendEvent::SendShortIdsQuery {
2505                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2506                                         msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
2507                                 }
2508                         },
2509                         nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
2510                                 MessageSendEvent::SendReplyChannelRange {
2511                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2512                                         msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
2513                                 }
2514                         },
2515                         nativeMessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
2516                                 MessageSendEvent::SendGossipTimestampFilter {
2517                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
2518                                         msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg), is_owned: true },
2519                                 }
2520                         },
2521                 }
2522         }
2523 }
2524 /// Frees any resources used by the MessageSendEvent
2525 #[no_mangle]
2526 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
2527 /// Creates a copy of the MessageSendEvent
2528 #[no_mangle]
2529 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
2530         orig.clone()
2531 }
2532 #[no_mangle]
2533 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
2534 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
2535         MessageSendEvent::SendAcceptChannel {
2536                 node_id,
2537                 msg,
2538         }
2539 }
2540 #[no_mangle]
2541 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
2542 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
2543         MessageSendEvent::SendOpenChannel {
2544                 node_id,
2545                 msg,
2546         }
2547 }
2548 #[no_mangle]
2549 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
2550 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
2551         MessageSendEvent::SendFundingCreated {
2552                 node_id,
2553                 msg,
2554         }
2555 }
2556 #[no_mangle]
2557 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
2558 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
2559         MessageSendEvent::SendFundingSigned {
2560                 node_id,
2561                 msg,
2562         }
2563 }
2564 #[no_mangle]
2565 /// Utility method to constructs a new SendChannelReady-variant MessageSendEvent
2566 pub extern "C" fn MessageSendEvent_send_channel_ready(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReady) -> MessageSendEvent {
2567         MessageSendEvent::SendChannelReady {
2568                 node_id,
2569                 msg,
2570         }
2571 }
2572 #[no_mangle]
2573 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
2574 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
2575         MessageSendEvent::SendAnnouncementSignatures {
2576                 node_id,
2577                 msg,
2578         }
2579 }
2580 #[no_mangle]
2581 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
2582 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
2583         MessageSendEvent::UpdateHTLCs {
2584                 node_id,
2585                 updates,
2586         }
2587 }
2588 #[no_mangle]
2589 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
2590 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
2591         MessageSendEvent::SendRevokeAndACK {
2592                 node_id,
2593                 msg,
2594         }
2595 }
2596 #[no_mangle]
2597 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
2598 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
2599         MessageSendEvent::SendClosingSigned {
2600                 node_id,
2601                 msg,
2602         }
2603 }
2604 #[no_mangle]
2605 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
2606 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
2607         MessageSendEvent::SendShutdown {
2608                 node_id,
2609                 msg,
2610         }
2611 }
2612 #[no_mangle]
2613 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
2614 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
2615         MessageSendEvent::SendChannelReestablish {
2616                 node_id,
2617                 msg,
2618         }
2619 }
2620 #[no_mangle]
2621 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
2622 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2623         MessageSendEvent::BroadcastChannelAnnouncement {
2624                 msg,
2625                 update_msg,
2626         }
2627 }
2628 #[no_mangle]
2629 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
2630 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
2631         MessageSendEvent::BroadcastNodeAnnouncement {
2632                 msg,
2633         }
2634 }
2635 #[no_mangle]
2636 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
2637 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2638         MessageSendEvent::BroadcastChannelUpdate {
2639                 msg,
2640         }
2641 }
2642 #[no_mangle]
2643 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
2644 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2645         MessageSendEvent::SendChannelUpdate {
2646                 node_id,
2647                 msg,
2648         }
2649 }
2650 #[no_mangle]
2651 /// Utility method to constructs a new HandleError-variant MessageSendEvent
2652 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
2653         MessageSendEvent::HandleError {
2654                 node_id,
2655                 action,
2656         }
2657 }
2658 #[no_mangle]
2659 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
2660 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
2661         MessageSendEvent::SendChannelRangeQuery {
2662                 node_id,
2663                 msg,
2664         }
2665 }
2666 #[no_mangle]
2667 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
2668 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
2669         MessageSendEvent::SendShortIdsQuery {
2670                 node_id,
2671                 msg,
2672         }
2673 }
2674 #[no_mangle]
2675 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
2676 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
2677         MessageSendEvent::SendReplyChannelRange {
2678                 node_id,
2679                 msg,
2680         }
2681 }
2682 #[no_mangle]
2683 /// Utility method to constructs a new SendGossipTimestampFilter-variant MessageSendEvent
2684 pub extern "C" fn MessageSendEvent_send_gossip_timestamp_filter(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::GossipTimestampFilter) -> MessageSendEvent {
2685         MessageSendEvent::SendGossipTimestampFilter {
2686                 node_id,
2687                 msg,
2688         }
2689 }
2690 /// A trait indicating an object may generate message send events
2691 #[repr(C)]
2692 pub struct MessageSendEventsProvider {
2693         /// An opaque pointer which is passed to your function implementations as an argument.
2694         /// This has no meaning in the LDK, and can be NULL or any other value.
2695         pub this_arg: *mut c_void,
2696         /// Gets the list of pending events which were generated by previous actions, clearing the list
2697         /// in the process.
2698         #[must_use]
2699         pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
2700         /// Frees any resources associated with this object given its this_arg pointer.
2701         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2702         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2703 }
2704 unsafe impl Send for MessageSendEventsProvider {}
2705 unsafe impl Sync for MessageSendEventsProvider {}
2706 #[no_mangle]
2707 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
2708         MessageSendEventsProvider {
2709                 this_arg: orig.this_arg,
2710                 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
2711                 free: Clone::clone(&orig.free),
2712         }
2713 }
2714
2715 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
2716 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
2717         fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
2718                 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
2719                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
2720                 local_ret
2721         }
2722 }
2723
2724 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2725 // directly as a Deref trait in higher-level structs:
2726 impl core::ops::Deref for MessageSendEventsProvider {
2727         type Target = Self;
2728         fn deref(&self) -> &Self {
2729                 self
2730         }
2731 }
2732 /// Calls the free function if one is set
2733 #[no_mangle]
2734 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
2735 impl Drop for MessageSendEventsProvider {
2736         fn drop(&mut self) {
2737                 if let Some(f) = self.free {
2738                         f(self.this_arg);
2739                 }
2740         }
2741 }
2742 /// A trait indicating an object may generate events.
2743 ///
2744 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
2745 ///
2746 /// # Requirements
2747 ///
2748 /// See [`process_pending_events`] for requirements around event processing.
2749 ///
2750 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
2751 /// event since the last invocation. The handler must either act upon the event immediately
2752 /// or preserve it for later handling.
2753 ///
2754 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
2755 /// consult the provider's documentation on the implication of processing events and how a handler
2756 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
2757 /// [`ChainMonitor::process_pending_events`]).
2758 ///
2759 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
2760 /// own type(s).
2761 ///
2762 /// [`process_pending_events`]: Self::process_pending_events
2763 /// [`handle_event`]: EventHandler::handle_event
2764 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
2765 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
2766 #[repr(C)]
2767 pub struct EventsProvider {
2768         /// An opaque pointer which is passed to your function implementations as an argument.
2769         /// This has no meaning in the LDK, and can be NULL or any other value.
2770         pub this_arg: *mut c_void,
2771         /// Processes any events generated since the last call using the given event handler.
2772         ///
2773         /// Subsequent calls must only process new events. However, handlers must be capable of handling
2774         /// duplicate events across process restarts. This may occur if the provider was recovered from
2775         /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
2776         pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
2777         /// Frees any resources associated with this object given its this_arg pointer.
2778         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2779         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2780 }
2781 unsafe impl Send for EventsProvider {}
2782 unsafe impl Sync for EventsProvider {}
2783 #[no_mangle]
2784 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
2785         EventsProvider {
2786                 this_arg: orig.this_arg,
2787                 process_pending_events: Clone::clone(&orig.process_pending_events),
2788                 free: Clone::clone(&orig.free),
2789         }
2790 }
2791
2792 use lightning::util::events::EventsProvider as rustEventsProvider;
2793 /// Calls the free function if one is set
2794 #[no_mangle]
2795 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
2796 impl Drop for EventsProvider {
2797         fn drop(&mut self) {
2798                 if let Some(f) = self.free {
2799                         f(self.this_arg);
2800                 }
2801         }
2802 }
2803 /// A trait implemented for objects handling events from [`EventsProvider`].
2804 #[repr(C)]
2805 pub struct EventHandler {
2806         /// An opaque pointer which is passed to your function implementations as an argument.
2807         /// This has no meaning in the LDK, and can be NULL or any other value.
2808         pub this_arg: *mut c_void,
2809         /// Handles the given [`Event`].
2810         ///
2811         /// See [`EventsProvider`] for details that must be considered when implementing this method.
2812         pub handle_event: extern "C" fn (this_arg: *const c_void, event: &crate::lightning::util::events::Event),
2813         /// Frees any resources associated with this object given its this_arg pointer.
2814         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2815         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2816 }
2817 unsafe impl Send for EventHandler {}
2818 unsafe impl Sync for EventHandler {}
2819 #[no_mangle]
2820 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
2821         EventHandler {
2822                 this_arg: orig.this_arg,
2823                 handle_event: Clone::clone(&orig.handle_event),
2824                 free: Clone::clone(&orig.free),
2825         }
2826 }
2827
2828 use lightning::util::events::EventHandler as rustEventHandler;
2829 impl rustEventHandler for EventHandler {
2830         fn handle_event(&self, mut event: &lightning::util::events::Event) {
2831                 (self.handle_event)(self.this_arg, &crate::lightning::util::events::Event::from_native(event))
2832         }
2833 }
2834
2835 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2836 // directly as a Deref trait in higher-level structs:
2837 impl core::ops::Deref for EventHandler {
2838         type Target = Self;
2839         fn deref(&self) -> &Self {
2840                 self
2841         }
2842 }
2843 /// Calls the free function if one is set
2844 #[no_mangle]
2845 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
2846 impl Drop for EventHandler {
2847         fn drop(&mut self) {
2848                 if let Some(f) = self.free {
2849                         f(self.this_arg);
2850                 }
2851         }
2852 }