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