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