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 std::str::FromStr;
17 use std::ffi::c_void;
18 use core::convert::Infallible;
19 use bitcoin::hashes::Hash;
20 use crate::c_types::*;
21
22 /// Some information provided on receipt of payment depends on whether the payment received is a
23 /// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
24 #[must_use]
25 #[derive(Clone)]
26 #[repr(C)]
27 pub enum PaymentPurpose {
28         /// Information for receiving a payment that we generated an invoice for.
29         InvoicePayment {
30                 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
31                 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
32                 /// [`ChannelManager::claim_funds`].
33                 ///
34                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
35                 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
36                 ///
37                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
38                 payment_preimage: crate::c_types::ThirtyTwoBytes,
39                 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
40                 /// number of deanonymization attacks during the routing process.
41                 /// It is provided here for your reference, however its accuracy is enforced directly by
42                 /// [`ChannelManager`] using the values you previously provided to
43                 /// [`ChannelManager::create_inbound_payment`] or
44                 /// [`ChannelManager::create_inbound_payment_for_hash`].
45                 ///
46                 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
47                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
48                 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
49                 payment_secret: crate::c_types::ThirtyTwoBytes,
50                 /// This is the `user_payment_id` which was provided to
51                 /// [`ChannelManager::create_inbound_payment_for_hash`] or
52                 /// [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is
53                 /// simply copied here. It may be used to correlate PaymentReceived events with invoice
54                 /// metadata stored elsewhere.
55                 ///
56                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
57                 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
58                 user_payment_id: u64,
59         },
60         /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
61         /// (the payee) providing a preimage.
62         SpontaneousPayment(crate::c_types::ThirtyTwoBytes),
63 }
64 use lightning::util::events::PaymentPurpose as nativePaymentPurpose;
65 impl PaymentPurpose {
66         #[allow(unused)]
67         pub(crate) fn to_native(&self) -> nativePaymentPurpose {
68                 match self {
69                         PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
70                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
71                                 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
72                                 let mut payment_secret_nonref = (*payment_secret).clone();
73                                 let mut user_payment_id_nonref = (*user_payment_id).clone();
74                                 nativePaymentPurpose::InvoicePayment {
75                                         payment_preimage: local_payment_preimage_nonref,
76                                         payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
77                                         user_payment_id: user_payment_id_nonref,
78                                 }
79                         },
80                         PaymentPurpose::SpontaneousPayment (ref a, ) => {
81                                 let mut a_nonref = (*a).clone();
82                                 nativePaymentPurpose::SpontaneousPayment (
83                                         ::lightning::ln::PaymentPreimage(a_nonref.data),
84                                 )
85                         },
86                 }
87         }
88         #[allow(unused)]
89         pub(crate) fn into_native(self) -> nativePaymentPurpose {
90                 match self {
91                         PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
92                                 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
93                                 nativePaymentPurpose::InvoicePayment {
94                                         payment_preimage: local_payment_preimage,
95                                         payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
96                                         user_payment_id: user_payment_id,
97                                 }
98                         },
99                         PaymentPurpose::SpontaneousPayment (mut a, ) => {
100                                 nativePaymentPurpose::SpontaneousPayment (
101                                         ::lightning::ln::PaymentPreimage(a.data),
102                                 )
103                         },
104                 }
105         }
106         #[allow(unused)]
107         pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
108                 match native {
109                         nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
110                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
111                                 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 } } };
112                                 let mut payment_secret_nonref = (*payment_secret).clone();
113                                 let mut user_payment_id_nonref = (*user_payment_id).clone();
114                                 PaymentPurpose::InvoicePayment {
115                                         payment_preimage: local_payment_preimage_nonref,
116                                         payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
117                                         user_payment_id: user_payment_id_nonref,
118                                 }
119                         },
120                         nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
121                                 let mut a_nonref = (*a).clone();
122                                 PaymentPurpose::SpontaneousPayment (
123                                         crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
124                                 )
125                         },
126                 }
127         }
128         #[allow(unused)]
129         pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
130                 match native {
131                         nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
132                                 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 } } };
133                                 PaymentPurpose::InvoicePayment {
134                                         payment_preimage: local_payment_preimage,
135                                         payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
136                                         user_payment_id: user_payment_id,
137                                 }
138                         },
139                         nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
140                                 PaymentPurpose::SpontaneousPayment (
141                                         crate::c_types::ThirtyTwoBytes { data: a.0 },
142                                 )
143                         },
144                 }
145         }
146 }
147 /// Frees any resources used by the PaymentPurpose
148 #[no_mangle]
149 pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
150 /// Creates a copy of the PaymentPurpose
151 #[no_mangle]
152 pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
153         orig.clone()
154 }
155 #[no_mangle]
156 /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
157 pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes, user_payment_id: u64) -> PaymentPurpose {
158         PaymentPurpose::InvoicePayment {
159                 payment_preimage,
160                 payment_secret,
161                 user_payment_id,
162         }
163 }
164 #[no_mangle]
165 /// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
166 pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
167         PaymentPurpose::SpontaneousPayment(a, )
168 }
169 /// The reason the channel was closed. See individual variants more details.
170 #[must_use]
171 #[derive(Clone)]
172 #[repr(C)]
173 pub enum ClosureReason {
174         /// Closure generated from receiving a peer error message.
175         ///
176         /// Our counterparty may have broadcasted their latest commitment state, and we have
177         /// as well.
178         CounterpartyForceClosed {
179                 /// The error which the peer sent us.
180                 ///
181                 /// The string should be sanitized before it is used (e.g emitted to logs
182                 /// or printed to stdout). Otherwise, a well crafted error message may exploit
183                 /// a security vulnerability in the terminal emulator or the logging subsystem.
184                 peer_msg: crate::c_types::Str,
185         },
186         /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
187         ///
188         /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
189         HolderForceClosed,
190         /// The channel was closed after negotiating a cooperative close and we've now broadcasted
191         /// the cooperative close transaction. Note the shutdown may have been initiated by us.
192         CooperativeClosure,
193         /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
194         /// commitment transaction came from our counterparty, but it may also have come from
195         /// a copy of our own `ChannelMonitor`.
196         CommitmentTxConfirmed,
197         /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
198         ProcessingError {
199                 /// A developer-readable error message which we generated.
200                 err: crate::c_types::Str,
201         },
202         /// The `PeerManager` informed us that we've disconnected from the peer. We close channels
203         /// if the `PeerManager` informed us that it is unlikely we'll be able to connect to the
204         /// peer again in the future or if the peer disconnected before we finished negotiating
205         /// the channel open. The first case may be caused by incompatible features which our
206         /// counterparty, or we, require.
207         DisconnectedPeer,
208         /// Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than
209         /// the ChannelManager deserialized.
210         OutdatedChannelManager,
211 }
212 use lightning::util::events::ClosureReason as nativeClosureReason;
213 impl ClosureReason {
214         #[allow(unused)]
215         pub(crate) fn to_native(&self) -> nativeClosureReason {
216                 match self {
217                         ClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
218                                 let mut peer_msg_nonref = (*peer_msg).clone();
219                                 nativeClosureReason::CounterpartyForceClosed {
220                                         peer_msg: peer_msg_nonref.into_string(),
221                                 }
222                         },
223                         ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
224                         ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
225                         ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
226                         ClosureReason::ProcessingError {ref err, } => {
227                                 let mut err_nonref = (*err).clone();
228                                 nativeClosureReason::ProcessingError {
229                                         err: err_nonref.into_string(),
230                                 }
231                         },
232                         ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
233                         ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
234                 }
235         }
236         #[allow(unused)]
237         pub(crate) fn into_native(self) -> nativeClosureReason {
238                 match self {
239                         ClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
240                                 nativeClosureReason::CounterpartyForceClosed {
241                                         peer_msg: peer_msg.into_string(),
242                                 }
243                         },
244                         ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
245                         ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
246                         ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
247                         ClosureReason::ProcessingError {mut err, } => {
248                                 nativeClosureReason::ProcessingError {
249                                         err: err.into_string(),
250                                 }
251                         },
252                         ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
253                         ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
254                 }
255         }
256         #[allow(unused)]
257         pub(crate) fn from_native(native: &nativeClosureReason) -> Self {
258                 match native {
259                         nativeClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
260                                 let mut peer_msg_nonref = (*peer_msg).clone();
261                                 ClosureReason::CounterpartyForceClosed {
262                                         peer_msg: peer_msg_nonref.into(),
263                                 }
264                         },
265                         nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
266                         nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
267                         nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
268                         nativeClosureReason::ProcessingError {ref err, } => {
269                                 let mut err_nonref = (*err).clone();
270                                 ClosureReason::ProcessingError {
271                                         err: err_nonref.into(),
272                                 }
273                         },
274                         nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
275                         nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
276                 }
277         }
278         #[allow(unused)]
279         pub(crate) fn native_into(native: nativeClosureReason) -> Self {
280                 match native {
281                         nativeClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
282                                 ClosureReason::CounterpartyForceClosed {
283                                         peer_msg: peer_msg.into(),
284                                 }
285                         },
286                         nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
287                         nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
288                         nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
289                         nativeClosureReason::ProcessingError {mut err, } => {
290                                 ClosureReason::ProcessingError {
291                                         err: err.into(),
292                                 }
293                         },
294                         nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
295                         nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
296                 }
297         }
298 }
299 /// Frees any resources used by the ClosureReason
300 #[no_mangle]
301 pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { }
302 /// Creates a copy of the ClosureReason
303 #[no_mangle]
304 pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason {
305         orig.clone()
306 }
307 #[no_mangle]
308 /// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
309 pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::c_types::Str) -> ClosureReason {
310         ClosureReason::CounterpartyForceClosed {
311                 peer_msg,
312         }
313 }
314 #[no_mangle]
315 /// Utility method to constructs a new HolderForceClosed-variant ClosureReason
316 pub extern "C" fn ClosureReason_holder_force_closed() -> ClosureReason {
317         ClosureReason::HolderForceClosed}
318 #[no_mangle]
319 /// Utility method to constructs a new CooperativeClosure-variant ClosureReason
320 pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason {
321         ClosureReason::CooperativeClosure}
322 #[no_mangle]
323 /// Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
324 pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason {
325         ClosureReason::CommitmentTxConfirmed}
326 #[no_mangle]
327 /// Utility method to constructs a new ProcessingError-variant ClosureReason
328 pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason {
329         ClosureReason::ProcessingError {
330                 err,
331         }
332 }
333 #[no_mangle]
334 /// Utility method to constructs a new DisconnectedPeer-variant ClosureReason
335 pub extern "C" fn ClosureReason_disconnected_peer() -> ClosureReason {
336         ClosureReason::DisconnectedPeer}
337 #[no_mangle]
338 /// Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
339 pub extern "C" fn ClosureReason_outdated_channel_manager() -> ClosureReason {
340         ClosureReason::OutdatedChannelManager}
341 #[no_mangle]
342 /// Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
343 pub extern "C" fn ClosureReason_write(obj: &ClosureReason) -> crate::c_types::derived::CVec_u8Z {
344         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
345 }
346 /// An Event which you should probably take some action in response to.
347 ///
348 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
349 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
350 /// written as it makes no sense to respond to it after reconnecting to peers).
351 #[must_use]
352 #[derive(Clone)]
353 #[repr(C)]
354 pub enum Event {
355         /// Used to indicate that the client should generate a funding transaction with the given
356         /// parameters and then call ChannelManager::funding_transaction_generated.
357         /// Generated in ChannelManager message handling.
358         /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
359         /// counterparty can steal your funds!
360         FundingGenerationReady {
361                 /// The random channel_id we picked which you'll need to pass into
362                 /// ChannelManager::funding_transaction_generated.
363                 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
364                 /// The value, in satoshis, that the output should have.
365                 channel_value_satoshis: u64,
366                 /// The script which should be used in the transaction output.
367                 output_script: crate::c_types::derived::CVec_u8Z,
368                 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
369                 /// an inbound channel.
370                 ///
371                 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
372                 user_channel_id: u64,
373         },
374         /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
375         /// [`ChannelManager::claim_funds`] to get it....
376         /// Note that if the preimage is not known, you should call
377         /// [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid
378         /// network congestion.
379         /// If you fail to call either [`ChannelManager::claim_funds`] or
380         /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be
381         /// automatically failed.
382         ///
383         /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
384         /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
385         PaymentReceived {
386                 /// The hash for which the preimage should be handed to the ChannelManager.
387                 payment_hash: crate::c_types::ThirtyTwoBytes,
388                 /// The value, in thousandths of a satoshi, that this payment is for.
389                 amt: u64,
390                 /// Information for claiming this received payment, based on whether the purpose of the
391                 /// payment is to pay an invoice or to send a spontaneous payment.
392                 purpose: crate::lightning::util::events::PaymentPurpose,
393         },
394         /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
395         /// and we got back the payment preimage for it).
396         ///
397         /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
398         /// event. In this situation, you SHOULD treat this payment as having succeeded.
399         PaymentSent {
400                 /// The id returned by [`ChannelManager::send_payment`] and used with
401                 /// [`ChannelManager::retry_payment`].
402                 ///
403                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
404                 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
405                 ///
406                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
407                 payment_id: crate::c_types::ThirtyTwoBytes,
408                 /// The preimage to the hash given to ChannelManager::send_payment.
409                 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
410                 /// store it somehow!
411                 payment_preimage: crate::c_types::ThirtyTwoBytes,
412                 /// The hash which was given to [`ChannelManager::send_payment`].
413                 ///
414                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
415                 payment_hash: crate::c_types::ThirtyTwoBytes,
416                 /// The total fee which was spent at intermediate hops in this payment, across all paths.
417                 ///
418                 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
419                 /// overpayment to the recipient node.
420                 ///
421                 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
422                 /// overstate the amount paid, though this is unlikely.
423                 ///
424                 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
425                 fee_paid_msat: crate::c_types::derived::COption_u64Z,
426         },
427         /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
428         /// something. You may wish to retry with a different route.
429         PaymentPathFailed {
430                 /// The id returned by [`ChannelManager::send_payment`] and used with
431                 /// [`ChannelManager::retry_payment`].
432                 ///
433                 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
434                 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
435                 ///
436                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
437                 payment_id: crate::c_types::ThirtyTwoBytes,
438                 /// The hash which was given to ChannelManager::send_payment.
439                 payment_hash: crate::c_types::ThirtyTwoBytes,
440                 /// Indicates the payment was rejected for some reason by the recipient. This implies that
441                 /// the payment has failed, not just the route in question. If this is not set, you may
442                 /// retry the payment via a different route.
443                 rejected_by_dest: bool,
444                 /// Any failure information conveyed via the Onion return packet by a node along the failed
445                 /// payment route.
446                 ///
447                 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
448                 /// account the update. [`NetGraphMsgHandler`] is capable of doing this.
449                 ///
450                 /// [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph
451                 /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
452                 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
453                 /// For both single-path and multi-path payments, this is set if all paths of the payment have
454                 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
455                 /// larger MPP payment were still in flight when this event was generated.
456                 all_paths_failed: bool,
457                 /// The payment path that failed.
458                 path: crate::c_types::derived::CVec_RouteHopZ,
459                 /// The channel responsible for the failed payment path.
460                 ///
461                 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
462                 /// retried. May be `None` for older [`Event`] serializations.
463                 short_channel_id: crate::c_types::derived::COption_u64Z,
464                 /// Parameters needed to compute a new [`Route`] when retrying the failed payment path.
465                 ///
466                 /// See [`find_route`] for details.
467                 ///
468                 /// [`Route`]: crate::routing::router::Route
469                 /// [`find_route`]: crate::routing::router::find_route
470                 ///
471                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
472                 retry: crate::lightning::routing::router::RouteParameters,
473         },
474         /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
475         /// time in the future.
476         PendingHTLCsForwardable {
477                 /// The minimum amount of time that should be waited prior to calling
478                 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
479                 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
480                 /// now + 5*time_forwardable).
481                 time_forwardable: u64,
482         },
483         /// Used to indicate that an output which you should know how to spend was confirmed on chain
484         /// and is now spendable.
485         /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
486         /// counterparty spending them due to some kind of timeout. Thus, you need to store them
487         /// somewhere and spend them when you create on-chain transactions.
488         SpendableOutputs {
489                 /// The outputs which you should store as spendable by you.
490                 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
491         },
492         /// This event is generated when a payment has been successfully forwarded through us and a
493         /// forwarding fee earned.
494         PaymentForwarded {
495                 /// The fee, in milli-satoshis, which was earned as a result of the payment.
496                 ///
497                 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
498                 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
499                 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
500                 /// claimed the full value in millisatoshis from the source. In this case,
501                 /// `claim_from_onchain_tx` will be set.
502                 ///
503                 /// If the channel which sent us the payment has been force-closed, we will claim the funds
504                 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
505                 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
506                 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
507                 /// `None`.
508                 fee_earned_msat: crate::c_types::derived::COption_u64Z,
509                 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
510                 /// transaction.
511                 claim_from_onchain_tx: bool,
512         },
513         /// Used to indicate that a channel with the given `channel_id` is in the process of closure.
514         ChannelClosed {
515                 /// The channel_id of the channel which has been closed. Note that on-chain transactions
516                 /// resolving the channel are likely still awaiting confirmation.
517                 channel_id: crate::c_types::ThirtyTwoBytes,
518                 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
519                 /// an inbound channel. This will always be zero for objects serialized with LDK versions
520                 /// prior to 0.0.102.
521                 ///
522                 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
523                 user_channel_id: u64,
524                 /// The reason the channel was closed.
525                 reason: crate::lightning::util::events::ClosureReason,
526         },
527         /// Used to indicate to the user that they can abandon the funding transaction and recycle the
528         /// inputs for another purpose.
529         DiscardFunding {
530                 /// The channel_id of the channel which has been closed.
531                 channel_id: crate::c_types::ThirtyTwoBytes,
532                 /// The full transaction received from the user
533                 transaction: crate::c_types::Transaction,
534         },
535 }
536 use lightning::util::events::Event as nativeEvent;
537 impl Event {
538         #[allow(unused)]
539         pub(crate) fn to_native(&self) -> nativeEvent {
540                 match self {
541                         Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
542                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
543                                 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
544                                 let mut output_script_nonref = (*output_script).clone();
545                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
546                                 nativeEvent::FundingGenerationReady {
547                                         temporary_channel_id: temporary_channel_id_nonref.data,
548                                         channel_value_satoshis: channel_value_satoshis_nonref,
549                                         output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
550                                         user_channel_id: user_channel_id_nonref,
551                                 }
552                         },
553                         Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
554                                 let mut payment_hash_nonref = (*payment_hash).clone();
555                                 let mut amt_nonref = (*amt).clone();
556                                 let mut purpose_nonref = (*purpose).clone();
557                                 nativeEvent::PaymentReceived {
558                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
559                                         amt: amt_nonref,
560                                         purpose: purpose_nonref.into_native(),
561                                 }
562                         },
563                         Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
564                                 let mut payment_id_nonref = (*payment_id).clone();
565                                 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
566                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
567                                 let mut payment_hash_nonref = (*payment_hash).clone();
568                                 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
569                                 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
570                                 nativeEvent::PaymentSent {
571                                         payment_id: local_payment_id_nonref,
572                                         payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
573                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
574                                         fee_paid_msat: local_fee_paid_msat_nonref,
575                                 }
576                         },
577                         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, } => {
578                                 let mut payment_id_nonref = (*payment_id).clone();
579                                 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
580                                 let mut payment_hash_nonref = (*payment_hash).clone();
581                                 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
582                                 let mut network_update_nonref = (*network_update).clone();
583                                 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() }) } };
584                                 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
585                                 let mut path_nonref = (*path).clone();
586                                 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()) } }); };
587                                 let mut short_channel_id_nonref = (*short_channel_id).clone();
588                                 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
589                                 let mut retry_nonref = (*retry).clone();
590                                 let mut local_retry_nonref = if retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry_nonref.take_inner()) } }) };
591                                 nativeEvent::PaymentPathFailed {
592                                         payment_id: local_payment_id_nonref,
593                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
594                                         rejected_by_dest: rejected_by_dest_nonref,
595                                         network_update: local_network_update_nonref,
596                                         all_paths_failed: all_paths_failed_nonref,
597                                         path: local_path_nonref,
598                                         short_channel_id: local_short_channel_id_nonref,
599                                         retry: local_retry_nonref,
600                                 }
601                         },
602                         Event::PendingHTLCsForwardable {ref time_forwardable, } => {
603                                 let mut time_forwardable_nonref = (*time_forwardable).clone();
604                                 nativeEvent::PendingHTLCsForwardable {
605                                         time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
606                                 }
607                         },
608                         Event::SpendableOutputs {ref outputs, } => {
609                                 let mut outputs_nonref = (*outputs).clone();
610                                 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
611                                 nativeEvent::SpendableOutputs {
612                                         outputs: local_outputs_nonref,
613                                 }
614                         },
615                         Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
616                                 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
617                                 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
618                                 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
619                                 nativeEvent::PaymentForwarded {
620                                         fee_earned_msat: local_fee_earned_msat_nonref,
621                                         claim_from_onchain_tx: claim_from_onchain_tx_nonref,
622                                 }
623                         },
624                         Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
625                                 let mut channel_id_nonref = (*channel_id).clone();
626                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
627                                 let mut reason_nonref = (*reason).clone();
628                                 nativeEvent::ChannelClosed {
629                                         channel_id: channel_id_nonref.data,
630                                         user_channel_id: user_channel_id_nonref,
631                                         reason: reason_nonref.into_native(),
632                                 }
633                         },
634                         Event::DiscardFunding {ref channel_id, ref transaction, } => {
635                                 let mut channel_id_nonref = (*channel_id).clone();
636                                 let mut transaction_nonref = (*transaction).clone();
637                                 nativeEvent::DiscardFunding {
638                                         channel_id: channel_id_nonref.data,
639                                         transaction: transaction_nonref.into_bitcoin(),
640                                 }
641                         },
642                 }
643         }
644         #[allow(unused)]
645         pub(crate) fn into_native(self) -> nativeEvent {
646                 match self {
647                         Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
648                                 nativeEvent::FundingGenerationReady {
649                                         temporary_channel_id: temporary_channel_id.data,
650                                         channel_value_satoshis: channel_value_satoshis,
651                                         output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
652                                         user_channel_id: user_channel_id,
653                                 }
654                         },
655                         Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
656                                 nativeEvent::PaymentReceived {
657                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
658                                         amt: amt,
659                                         purpose: purpose.into_native(),
660                                 }
661                         },
662                         Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
663                                 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
664                                 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
665                                 nativeEvent::PaymentSent {
666                                         payment_id: local_payment_id,
667                                         payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
668                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
669                                         fee_paid_msat: local_fee_paid_msat,
670                                 }
671                         },
672                         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, } => {
673                                 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
674                                 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() }) } };
675                                 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
676                                 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
677                                 let mut local_retry = if retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry.take_inner()) } }) };
678                                 nativeEvent::PaymentPathFailed {
679                                         payment_id: local_payment_id,
680                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
681                                         rejected_by_dest: rejected_by_dest,
682                                         network_update: local_network_update,
683                                         all_paths_failed: all_paths_failed,
684                                         path: local_path,
685                                         short_channel_id: local_short_channel_id,
686                                         retry: local_retry,
687                                 }
688                         },
689                         Event::PendingHTLCsForwardable {mut time_forwardable, } => {
690                                 nativeEvent::PendingHTLCsForwardable {
691                                         time_forwardable: std::time::Duration::from_secs(time_forwardable),
692                                 }
693                         },
694                         Event::SpendableOutputs {mut outputs, } => {
695                                 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
696                                 nativeEvent::SpendableOutputs {
697                                         outputs: local_outputs,
698                                 }
699                         },
700                         Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
701                                 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
702                                 nativeEvent::PaymentForwarded {
703                                         fee_earned_msat: local_fee_earned_msat,
704                                         claim_from_onchain_tx: claim_from_onchain_tx,
705                                 }
706                         },
707                         Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
708                                 nativeEvent::ChannelClosed {
709                                         channel_id: channel_id.data,
710                                         user_channel_id: user_channel_id,
711                                         reason: reason.into_native(),
712                                 }
713                         },
714                         Event::DiscardFunding {mut channel_id, mut transaction, } => {
715                                 nativeEvent::DiscardFunding {
716                                         channel_id: channel_id.data,
717                                         transaction: transaction.into_bitcoin(),
718                                 }
719                         },
720                 }
721         }
722         #[allow(unused)]
723         pub(crate) fn from_native(native: &nativeEvent) -> Self {
724                 match native {
725                         nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
726                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
727                                 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
728                                 let mut output_script_nonref = (*output_script).clone();
729                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
730                                 Event::FundingGenerationReady {
731                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
732                                         channel_value_satoshis: channel_value_satoshis_nonref,
733                                         output_script: output_script_nonref.into_bytes().into(),
734                                         user_channel_id: user_channel_id_nonref,
735                                 }
736                         },
737                         nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
738                                 let mut payment_hash_nonref = (*payment_hash).clone();
739                                 let mut amt_nonref = (*amt).clone();
740                                 let mut purpose_nonref = (*purpose).clone();
741                                 Event::PaymentReceived {
742                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
743                                         amt: amt_nonref,
744                                         purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
745                                 }
746                         },
747                         nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
748                                 let mut payment_id_nonref = (*payment_id).clone();
749                                 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 } } };
750                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
751                                 let mut payment_hash_nonref = (*payment_hash).clone();
752                                 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
753                                 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() }) };
754                                 Event::PaymentSent {
755                                         payment_id: local_payment_id_nonref,
756                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
757                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
758                                         fee_paid_msat: local_fee_paid_msat_nonref,
759                                 }
760                         },
761                         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, } => {
762                                 let mut payment_id_nonref = (*payment_id).clone();
763                                 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 } } };
764                                 let mut payment_hash_nonref = (*payment_hash).clone();
765                                 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
766                                 let mut network_update_nonref = (*network_update).clone();
767                                 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::network_graph::NetworkUpdate::native_into(network_update_nonref.unwrap()) }) };
768                                 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
769                                 let mut path_nonref = (*path).clone();
770                                 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 } }); };
771                                 let mut short_channel_id_nonref = (*short_channel_id).clone();
772                                 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() }) };
773                                 let mut retry_nonref = (*retry).clone();
774                                 let mut local_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if retry_nonref.is_none() { std::ptr::null_mut() } else {  { ObjOps::heap_alloc((retry_nonref.unwrap())) } }, is_owned: true };
775                                 Event::PaymentPathFailed {
776                                         payment_id: local_payment_id_nonref,
777                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
778                                         rejected_by_dest: rejected_by_dest_nonref,
779                                         network_update: local_network_update_nonref,
780                                         all_paths_failed: all_paths_failed_nonref,
781                                         path: local_path_nonref.into(),
782                                         short_channel_id: local_short_channel_id_nonref,
783                                         retry: local_retry_nonref,
784                                 }
785                         },
786                         nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
787                                 let mut time_forwardable_nonref = (*time_forwardable).clone();
788                                 Event::PendingHTLCsForwardable {
789                                         time_forwardable: time_forwardable_nonref.as_secs(),
790                                 }
791                         },
792                         nativeEvent::SpendableOutputs {ref outputs, } => {
793                                 let mut outputs_nonref = (*outputs).clone();
794                                 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) }); };
795                                 Event::SpendableOutputs {
796                                         outputs: local_outputs_nonref.into(),
797                                 }
798                         },
799                         nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
800                                 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
801                                 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() }) };
802                                 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
803                                 Event::PaymentForwarded {
804                                         fee_earned_msat: local_fee_earned_msat_nonref,
805                                         claim_from_onchain_tx: claim_from_onchain_tx_nonref,
806                                 }
807                         },
808                         nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
809                                 let mut channel_id_nonref = (*channel_id).clone();
810                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
811                                 let mut reason_nonref = (*reason).clone();
812                                 Event::ChannelClosed {
813                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
814                                         user_channel_id: user_channel_id_nonref,
815                                         reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
816                                 }
817                         },
818                         nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
819                                 let mut channel_id_nonref = (*channel_id).clone();
820                                 let mut transaction_nonref = (*transaction).clone();
821                                 Event::DiscardFunding {
822                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
823                                         transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
824                                 }
825                         },
826                 }
827         }
828         #[allow(unused)]
829         pub(crate) fn native_into(native: nativeEvent) -> Self {
830                 match native {
831                         nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
832                                 Event::FundingGenerationReady {
833                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
834                                         channel_value_satoshis: channel_value_satoshis,
835                                         output_script: output_script.into_bytes().into(),
836                                         user_channel_id: user_channel_id,
837                                 }
838                         },
839                         nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
840                                 Event::PaymentReceived {
841                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
842                                         amt: amt,
843                                         purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
844                                 }
845                         },
846                         nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
847                                 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 } } };
848                                 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() }) };
849                                 Event::PaymentSent {
850                                         payment_id: local_payment_id,
851                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
852                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
853                                         fee_paid_msat: local_fee_paid_msat,
854                                 }
855                         },
856                         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, } => {
857                                 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 } } };
858                                 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::network_graph::NetworkUpdate::native_into(network_update.unwrap()) }) };
859                                 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 } }); };
860                                 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() }) };
861                                 let mut local_retry = crate::lightning::routing::router::RouteParameters { inner: if retry.is_none() { std::ptr::null_mut() } else {  { ObjOps::heap_alloc((retry.unwrap())) } }, is_owned: true };
862                                 Event::PaymentPathFailed {
863                                         payment_id: local_payment_id,
864                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
865                                         rejected_by_dest: rejected_by_dest,
866                                         network_update: local_network_update,
867                                         all_paths_failed: all_paths_failed,
868                                         path: local_path.into(),
869                                         short_channel_id: local_short_channel_id,
870                                         retry: local_retry,
871                                 }
872                         },
873                         nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
874                                 Event::PendingHTLCsForwardable {
875                                         time_forwardable: time_forwardable.as_secs(),
876                                 }
877                         },
878                         nativeEvent::SpendableOutputs {mut outputs, } => {
879                                 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
880                                 Event::SpendableOutputs {
881                                         outputs: local_outputs.into(),
882                                 }
883                         },
884                         nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
885                                 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() }) };
886                                 Event::PaymentForwarded {
887                                         fee_earned_msat: local_fee_earned_msat,
888                                         claim_from_onchain_tx: claim_from_onchain_tx,
889                                 }
890                         },
891                         nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
892                                 Event::ChannelClosed {
893                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
894                                         user_channel_id: user_channel_id,
895                                         reason: crate::lightning::util::events::ClosureReason::native_into(reason),
896                                 }
897                         },
898                         nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
899                                 Event::DiscardFunding {
900                                         channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
901                                         transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
902                                 }
903                         },
904                 }
905         }
906 }
907 /// Frees any resources used by the Event
908 #[no_mangle]
909 pub extern "C" fn Event_free(this_ptr: Event) { }
910 /// Creates a copy of the Event
911 #[no_mangle]
912 pub extern "C" fn Event_clone(orig: &Event) -> Event {
913         orig.clone()
914 }
915 #[no_mangle]
916 /// Utility method to constructs a new FundingGenerationReady-variant Event
917 pub extern "C" fn Event_funding_generation_ready(temporary_channel_id: crate::c_types::ThirtyTwoBytes, channel_value_satoshis: u64, output_script: crate::c_types::derived::CVec_u8Z, user_channel_id: u64) -> Event {
918         Event::FundingGenerationReady {
919                 temporary_channel_id,
920                 channel_value_satoshis,
921                 output_script,
922                 user_channel_id,
923         }
924 }
925 #[no_mangle]
926 /// Utility method to constructs a new PaymentReceived-variant Event
927 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
928         Event::PaymentReceived {
929                 payment_hash,
930                 amt,
931                 purpose,
932         }
933 }
934 #[no_mangle]
935 /// Utility method to constructs a new PaymentSent-variant Event
936 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 {
937         Event::PaymentSent {
938                 payment_id,
939                 payment_preimage,
940                 payment_hash,
941                 fee_paid_msat,
942         }
943 }
944 #[no_mangle]
945 /// Utility method to constructs a new PaymentPathFailed-variant Event
946 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 {
947         Event::PaymentPathFailed {
948                 payment_id,
949                 payment_hash,
950                 rejected_by_dest,
951                 network_update,
952                 all_paths_failed,
953                 path,
954                 short_channel_id,
955                 retry,
956         }
957 }
958 #[no_mangle]
959 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
960 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
961         Event::PendingHTLCsForwardable {
962                 time_forwardable,
963         }
964 }
965 #[no_mangle]
966 /// Utility method to constructs a new SpendableOutputs-variant Event
967 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
968         Event::SpendableOutputs {
969                 outputs,
970         }
971 }
972 #[no_mangle]
973 /// Utility method to constructs a new PaymentForwarded-variant Event
974 pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
975         Event::PaymentForwarded {
976                 fee_earned_msat,
977                 claim_from_onchain_tx,
978         }
979 }
980 #[no_mangle]
981 /// Utility method to constructs a new ChannelClosed-variant Event
982 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: u64, reason: crate::lightning::util::events::ClosureReason) -> Event {
983         Event::ChannelClosed {
984                 channel_id,
985                 user_channel_id,
986                 reason,
987         }
988 }
989 #[no_mangle]
990 /// Utility method to constructs a new DiscardFunding-variant Event
991 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
992         Event::DiscardFunding {
993                 channel_id,
994                 transaction,
995         }
996 }
997 #[no_mangle]
998 /// Serialize the Event object into a byte array which can be read by Event_read
999 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
1000         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
1001 }
1002 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1003 /// broadcast to most peers).
1004 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1005 #[must_use]
1006 #[derive(Clone)]
1007 #[repr(C)]
1008 pub enum MessageSendEvent {
1009         /// Used to indicate that we've accepted a channel open and should send the accept_channel
1010         /// message provided to the given peer.
1011         SendAcceptChannel {
1012                 /// The node_id of the node which should receive this message
1013                 node_id: crate::c_types::PublicKey,
1014                 /// The message which should be sent.
1015                 msg: crate::lightning::ln::msgs::AcceptChannel,
1016         },
1017         /// Used to indicate that we've initiated a channel open and should send the open_channel
1018         /// message provided to the given peer.
1019         SendOpenChannel {
1020                 /// The node_id of the node which should receive this message
1021                 node_id: crate::c_types::PublicKey,
1022                 /// The message which should be sent.
1023                 msg: crate::lightning::ln::msgs::OpenChannel,
1024         },
1025         /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1026         SendFundingCreated {
1027                 /// The node_id of the node which should receive this message
1028                 node_id: crate::c_types::PublicKey,
1029                 /// The message which should be sent.
1030                 msg: crate::lightning::ln::msgs::FundingCreated,
1031         },
1032         /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
1033         SendFundingSigned {
1034                 /// The node_id of the node which should receive this message
1035                 node_id: crate::c_types::PublicKey,
1036                 /// The message which should be sent.
1037                 msg: crate::lightning::ln::msgs::FundingSigned,
1038         },
1039         /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
1040         SendFundingLocked {
1041                 /// The node_id of the node which should receive these message(s)
1042                 node_id: crate::c_types::PublicKey,
1043                 /// The funding_locked message which should be sent.
1044                 msg: crate::lightning::ln::msgs::FundingLocked,
1045         },
1046         /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1047         SendAnnouncementSignatures {
1048                 /// The node_id of the node which should receive these message(s)
1049                 node_id: crate::c_types::PublicKey,
1050                 /// The announcement_signatures message which should be sent.
1051                 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
1052         },
1053         /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1054         /// message should be sent to the peer with the given node_id.
1055         UpdateHTLCs {
1056                 /// The node_id of the node which should receive these message(s)
1057                 node_id: crate::c_types::PublicKey,
1058                 /// The update messages which should be sent. ALL messages in the struct should be sent!
1059                 updates: crate::lightning::ln::msgs::CommitmentUpdate,
1060         },
1061         /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1062         SendRevokeAndACK {
1063                 /// The node_id of the node which should receive this message
1064                 node_id: crate::c_types::PublicKey,
1065                 /// The message which should be sent.
1066                 msg: crate::lightning::ln::msgs::RevokeAndACK,
1067         },
1068         /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1069         SendClosingSigned {
1070                 /// The node_id of the node which should receive this message
1071                 node_id: crate::c_types::PublicKey,
1072                 /// The message which should be sent.
1073                 msg: crate::lightning::ln::msgs::ClosingSigned,
1074         },
1075         /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
1076         SendShutdown {
1077                 /// The node_id of the node which should receive this message
1078                 node_id: crate::c_types::PublicKey,
1079                 /// The message which should be sent.
1080                 msg: crate::lightning::ln::msgs::Shutdown,
1081         },
1082         /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1083         SendChannelReestablish {
1084                 /// The node_id of the node which should receive this message
1085                 node_id: crate::c_types::PublicKey,
1086                 /// The message which should be sent.
1087                 msg: crate::lightning::ln::msgs::ChannelReestablish,
1088         },
1089         /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1090         /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1091         ///
1092         /// Note that after doing so, you very likely (unless you did so very recently) want to call
1093         /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
1094         /// This ensures that any nodes which see our channel_announcement also have a relevant
1095         /// node_announcement, including relevant feature flags which may be important for routing
1096         /// through or to us.
1097         BroadcastChannelAnnouncement {
1098                 /// The channel_announcement which should be sent.
1099                 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
1100                 /// The followup channel_update which should be sent.
1101                 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
1102         },
1103         /// Used to indicate that a node_announcement should be broadcast to all peers.
1104         BroadcastNodeAnnouncement {
1105                 /// The node_announcement which should be sent.
1106                 msg: crate::lightning::ln::msgs::NodeAnnouncement,
1107         },
1108         /// Used to indicate that a channel_update should be broadcast to all peers.
1109         BroadcastChannelUpdate {
1110                 /// The channel_update which should be sent.
1111                 msg: crate::lightning::ln::msgs::ChannelUpdate,
1112         },
1113         /// Used to indicate that a channel_update should be sent to a single peer.
1114         /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1115         /// private channel and we shouldn't be informing all of our peers of channel parameters.
1116         SendChannelUpdate {
1117                 /// The node_id of the node which should receive this message
1118                 node_id: crate::c_types::PublicKey,
1119                 /// The channel_update which should be sent.
1120                 msg: crate::lightning::ln::msgs::ChannelUpdate,
1121         },
1122         /// Broadcast an error downstream to be handled
1123         HandleError {
1124                 /// The node_id of the node which should receive this message
1125                 node_id: crate::c_types::PublicKey,
1126                 /// The action which should be taken.
1127                 action: crate::lightning::ln::msgs::ErrorAction,
1128         },
1129         /// Query a peer for channels with funding transaction UTXOs in a block range.
1130         SendChannelRangeQuery {
1131                 /// The node_id of this message recipient
1132                 node_id: crate::c_types::PublicKey,
1133                 /// The query_channel_range which should be sent.
1134                 msg: crate::lightning::ln::msgs::QueryChannelRange,
1135         },
1136         /// Request routing gossip messages from a peer for a list of channels identified by
1137         /// their short_channel_ids.
1138         SendShortIdsQuery {
1139                 /// The node_id of this message recipient
1140                 node_id: crate::c_types::PublicKey,
1141                 /// The query_short_channel_ids which should be sent.
1142                 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
1143         },
1144         /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1145         /// emitted during processing of the query.
1146         SendReplyChannelRange {
1147                 /// The node_id of this message recipient
1148                 node_id: crate::c_types::PublicKey,
1149                 /// The reply_channel_range which should be sent.
1150                 msg: crate::lightning::ln::msgs::ReplyChannelRange,
1151         },
1152 }
1153 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
1154 impl MessageSendEvent {
1155         #[allow(unused)]
1156         pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
1157                 match self {
1158                         MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1159                                 let mut node_id_nonref = (*node_id).clone();
1160                                 let mut msg_nonref = (*msg).clone();
1161                                 nativeMessageSendEvent::SendAcceptChannel {
1162                                         node_id: node_id_nonref.into_rust(),
1163                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1164                                 }
1165                         },
1166                         MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1167                                 let mut node_id_nonref = (*node_id).clone();
1168                                 let mut msg_nonref = (*msg).clone();
1169                                 nativeMessageSendEvent::SendOpenChannel {
1170                                         node_id: node_id_nonref.into_rust(),
1171                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1172                                 }
1173                         },
1174                         MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1175                                 let mut node_id_nonref = (*node_id).clone();
1176                                 let mut msg_nonref = (*msg).clone();
1177                                 nativeMessageSendEvent::SendFundingCreated {
1178                                         node_id: node_id_nonref.into_rust(),
1179                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1180                                 }
1181                         },
1182                         MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1183                                 let mut node_id_nonref = (*node_id).clone();
1184                                 let mut msg_nonref = (*msg).clone();
1185                                 nativeMessageSendEvent::SendFundingSigned {
1186                                         node_id: node_id_nonref.into_rust(),
1187                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1188                                 }
1189                         },
1190                         MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1191                                 let mut node_id_nonref = (*node_id).clone();
1192                                 let mut msg_nonref = (*msg).clone();
1193                                 nativeMessageSendEvent::SendFundingLocked {
1194                                         node_id: node_id_nonref.into_rust(),
1195                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1196                                 }
1197                         },
1198                         MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1199                                 let mut node_id_nonref = (*node_id).clone();
1200                                 let mut msg_nonref = (*msg).clone();
1201                                 nativeMessageSendEvent::SendAnnouncementSignatures {
1202                                         node_id: node_id_nonref.into_rust(),
1203                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1204                                 }
1205                         },
1206                         MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1207                                 let mut node_id_nonref = (*node_id).clone();
1208                                 let mut updates_nonref = (*updates).clone();
1209                                 nativeMessageSendEvent::UpdateHTLCs {
1210                                         node_id: node_id_nonref.into_rust(),
1211                                         updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
1212                                 }
1213                         },
1214                         MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1215                                 let mut node_id_nonref = (*node_id).clone();
1216                                 let mut msg_nonref = (*msg).clone();
1217                                 nativeMessageSendEvent::SendRevokeAndACK {
1218                                         node_id: node_id_nonref.into_rust(),
1219                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1220                                 }
1221                         },
1222                         MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1223                                 let mut node_id_nonref = (*node_id).clone();
1224                                 let mut msg_nonref = (*msg).clone();
1225                                 nativeMessageSendEvent::SendClosingSigned {
1226                                         node_id: node_id_nonref.into_rust(),
1227                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1228                                 }
1229                         },
1230                         MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1231                                 let mut node_id_nonref = (*node_id).clone();
1232                                 let mut msg_nonref = (*msg).clone();
1233                                 nativeMessageSendEvent::SendShutdown {
1234                                         node_id: node_id_nonref.into_rust(),
1235                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1236                                 }
1237                         },
1238                         MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1239                                 let mut node_id_nonref = (*node_id).clone();
1240                                 let mut msg_nonref = (*msg).clone();
1241                                 nativeMessageSendEvent::SendChannelReestablish {
1242                                         node_id: node_id_nonref.into_rust(),
1243                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1244                                 }
1245                         },
1246                         MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1247                                 let mut msg_nonref = (*msg).clone();
1248                                 let mut update_msg_nonref = (*update_msg).clone();
1249                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1250                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1251                                         update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
1252                                 }
1253                         },
1254                         MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1255                                 let mut msg_nonref = (*msg).clone();
1256                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1257                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1258                                 }
1259                         },
1260                         MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1261                                 let mut msg_nonref = (*msg).clone();
1262                                 nativeMessageSendEvent::BroadcastChannelUpdate {
1263                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1264                                 }
1265                         },
1266                         MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1267                                 let mut node_id_nonref = (*node_id).clone();
1268                                 let mut msg_nonref = (*msg).clone();
1269                                 nativeMessageSendEvent::SendChannelUpdate {
1270                                         node_id: node_id_nonref.into_rust(),
1271                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1272                                 }
1273                         },
1274                         MessageSendEvent::HandleError {ref node_id, ref action, } => {
1275                                 let mut node_id_nonref = (*node_id).clone();
1276                                 let mut action_nonref = (*action).clone();
1277                                 nativeMessageSendEvent::HandleError {
1278                                         node_id: node_id_nonref.into_rust(),
1279                                         action: action_nonref.into_native(),
1280                                 }
1281                         },
1282                         MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1283                                 let mut node_id_nonref = (*node_id).clone();
1284                                 let mut msg_nonref = (*msg).clone();
1285                                 nativeMessageSendEvent::SendChannelRangeQuery {
1286                                         node_id: node_id_nonref.into_rust(),
1287                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1288                                 }
1289                         },
1290                         MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1291                                 let mut node_id_nonref = (*node_id).clone();
1292                                 let mut msg_nonref = (*msg).clone();
1293                                 nativeMessageSendEvent::SendShortIdsQuery {
1294                                         node_id: node_id_nonref.into_rust(),
1295                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1296                                 }
1297                         },
1298                         MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1299                                 let mut node_id_nonref = (*node_id).clone();
1300                                 let mut msg_nonref = (*msg).clone();
1301                                 nativeMessageSendEvent::SendReplyChannelRange {
1302                                         node_id: node_id_nonref.into_rust(),
1303                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1304                                 }
1305                         },
1306                 }
1307         }
1308         #[allow(unused)]
1309         pub(crate) fn into_native(self) -> nativeMessageSendEvent {
1310                 match self {
1311                         MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1312                                 nativeMessageSendEvent::SendAcceptChannel {
1313                                         node_id: node_id.into_rust(),
1314                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1315                                 }
1316                         },
1317                         MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1318                                 nativeMessageSendEvent::SendOpenChannel {
1319                                         node_id: node_id.into_rust(),
1320                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1321                                 }
1322                         },
1323                         MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1324                                 nativeMessageSendEvent::SendFundingCreated {
1325                                         node_id: node_id.into_rust(),
1326                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1327                                 }
1328                         },
1329                         MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1330                                 nativeMessageSendEvent::SendFundingSigned {
1331                                         node_id: node_id.into_rust(),
1332                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1333                                 }
1334                         },
1335                         MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1336                                 nativeMessageSendEvent::SendFundingLocked {
1337                                         node_id: node_id.into_rust(),
1338                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1339                                 }
1340                         },
1341                         MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1342                                 nativeMessageSendEvent::SendAnnouncementSignatures {
1343                                         node_id: node_id.into_rust(),
1344                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1345                                 }
1346                         },
1347                         MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1348                                 nativeMessageSendEvent::UpdateHTLCs {
1349                                         node_id: node_id.into_rust(),
1350                                         updates: *unsafe { Box::from_raw(updates.take_inner()) },
1351                                 }
1352                         },
1353                         MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1354                                 nativeMessageSendEvent::SendRevokeAndACK {
1355                                         node_id: node_id.into_rust(),
1356                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1357                                 }
1358                         },
1359                         MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1360                                 nativeMessageSendEvent::SendClosingSigned {
1361                                         node_id: node_id.into_rust(),
1362                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1363                                 }
1364                         },
1365                         MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1366                                 nativeMessageSendEvent::SendShutdown {
1367                                         node_id: node_id.into_rust(),
1368                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1369                                 }
1370                         },
1371                         MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1372                                 nativeMessageSendEvent::SendChannelReestablish {
1373                                         node_id: node_id.into_rust(),
1374                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1375                                 }
1376                         },
1377                         MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1378                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1379                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1380                                         update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
1381                                 }
1382                         },
1383                         MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1384                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1385                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1386                                 }
1387                         },
1388                         MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1389                                 nativeMessageSendEvent::BroadcastChannelUpdate {
1390                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1391                                 }
1392                         },
1393                         MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1394                                 nativeMessageSendEvent::SendChannelUpdate {
1395                                         node_id: node_id.into_rust(),
1396                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1397                                 }
1398                         },
1399                         MessageSendEvent::HandleError {mut node_id, mut action, } => {
1400                                 nativeMessageSendEvent::HandleError {
1401                                         node_id: node_id.into_rust(),
1402                                         action: action.into_native(),
1403                                 }
1404                         },
1405                         MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1406                                 nativeMessageSendEvent::SendChannelRangeQuery {
1407                                         node_id: node_id.into_rust(),
1408                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1409                                 }
1410                         },
1411                         MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1412                                 nativeMessageSendEvent::SendShortIdsQuery {
1413                                         node_id: node_id.into_rust(),
1414                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1415                                 }
1416                         },
1417                         MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1418                                 nativeMessageSendEvent::SendReplyChannelRange {
1419                                         node_id: node_id.into_rust(),
1420                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1421                                 }
1422                         },
1423                 }
1424         }
1425         #[allow(unused)]
1426         pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
1427                 match native {
1428                         nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1429                                 let mut node_id_nonref = (*node_id).clone();
1430                                 let mut msg_nonref = (*msg).clone();
1431                                 MessageSendEvent::SendAcceptChannel {
1432                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1433                                         msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1434                                 }
1435                         },
1436                         nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1437                                 let mut node_id_nonref = (*node_id).clone();
1438                                 let mut msg_nonref = (*msg).clone();
1439                                 MessageSendEvent::SendOpenChannel {
1440                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1441                                         msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1442                                 }
1443                         },
1444                         nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1445                                 let mut node_id_nonref = (*node_id).clone();
1446                                 let mut msg_nonref = (*msg).clone();
1447                                 MessageSendEvent::SendFundingCreated {
1448                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1449                                         msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1450                                 }
1451                         },
1452                         nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1453                                 let mut node_id_nonref = (*node_id).clone();
1454                                 let mut msg_nonref = (*msg).clone();
1455                                 MessageSendEvent::SendFundingSigned {
1456                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1457                                         msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1458                                 }
1459                         },
1460                         nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1461                                 let mut node_id_nonref = (*node_id).clone();
1462                                 let mut msg_nonref = (*msg).clone();
1463                                 MessageSendEvent::SendFundingLocked {
1464                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1465                                         msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1466                                 }
1467                         },
1468                         nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1469                                 let mut node_id_nonref = (*node_id).clone();
1470                                 let mut msg_nonref = (*msg).clone();
1471                                 MessageSendEvent::SendAnnouncementSignatures {
1472                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1473                                         msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1474                                 }
1475                         },
1476                         nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1477                                 let mut node_id_nonref = (*node_id).clone();
1478                                 let mut updates_nonref = (*updates).clone();
1479                                 MessageSendEvent::UpdateHTLCs {
1480                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1481                                         updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
1482                                 }
1483                         },
1484                         nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1485                                 let mut node_id_nonref = (*node_id).clone();
1486                                 let mut msg_nonref = (*msg).clone();
1487                                 MessageSendEvent::SendRevokeAndACK {
1488                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1489                                         msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1490                                 }
1491                         },
1492                         nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1493                                 let mut node_id_nonref = (*node_id).clone();
1494                                 let mut msg_nonref = (*msg).clone();
1495                                 MessageSendEvent::SendClosingSigned {
1496                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1497                                         msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1498                                 }
1499                         },
1500                         nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1501                                 let mut node_id_nonref = (*node_id).clone();
1502                                 let mut msg_nonref = (*msg).clone();
1503                                 MessageSendEvent::SendShutdown {
1504                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1505                                         msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1506                                 }
1507                         },
1508                         nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1509                                 let mut node_id_nonref = (*node_id).clone();
1510                                 let mut msg_nonref = (*msg).clone();
1511                                 MessageSendEvent::SendChannelReestablish {
1512                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1513                                         msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1514                                 }
1515                         },
1516                         nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1517                                 let mut msg_nonref = (*msg).clone();
1518                                 let mut update_msg_nonref = (*update_msg).clone();
1519                                 MessageSendEvent::BroadcastChannelAnnouncement {
1520                                         msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1521                                         update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
1522                                 }
1523                         },
1524                         nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1525                                 let mut msg_nonref = (*msg).clone();
1526                                 MessageSendEvent::BroadcastNodeAnnouncement {
1527                                         msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1528                                 }
1529                         },
1530                         nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1531                                 let mut msg_nonref = (*msg).clone();
1532                                 MessageSendEvent::BroadcastChannelUpdate {
1533                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1534                                 }
1535                         },
1536                         nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1537                                 let mut node_id_nonref = (*node_id).clone();
1538                                 let mut msg_nonref = (*msg).clone();
1539                                 MessageSendEvent::SendChannelUpdate {
1540                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1541                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1542                                 }
1543                         },
1544                         nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
1545                                 let mut node_id_nonref = (*node_id).clone();
1546                                 let mut action_nonref = (*action).clone();
1547                                 MessageSendEvent::HandleError {
1548                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1549                                         action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
1550                                 }
1551                         },
1552                         nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1553                                 let mut node_id_nonref = (*node_id).clone();
1554                                 let mut msg_nonref = (*msg).clone();
1555                                 MessageSendEvent::SendChannelRangeQuery {
1556                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1557                                         msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1558                                 }
1559                         },
1560                         nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1561                                 let mut node_id_nonref = (*node_id).clone();
1562                                 let mut msg_nonref = (*msg).clone();
1563                                 MessageSendEvent::SendShortIdsQuery {
1564                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1565                                         msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1566                                 }
1567                         },
1568                         nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1569                                 let mut node_id_nonref = (*node_id).clone();
1570                                 let mut msg_nonref = (*msg).clone();
1571                                 MessageSendEvent::SendReplyChannelRange {
1572                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1573                                         msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1574                                 }
1575                         },
1576                 }
1577         }
1578         #[allow(unused)]
1579         pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
1580                 match native {
1581                         nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1582                                 MessageSendEvent::SendAcceptChannel {
1583                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1584                                         msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1585                                 }
1586                         },
1587                         nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1588                                 MessageSendEvent::SendOpenChannel {
1589                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1590                                         msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1591                                 }
1592                         },
1593                         nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1594                                 MessageSendEvent::SendFundingCreated {
1595                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1596                                         msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
1597                                 }
1598                         },
1599                         nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1600                                 MessageSendEvent::SendFundingSigned {
1601                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1602                                         msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1603                                 }
1604                         },
1605                         nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1606                                 MessageSendEvent::SendFundingLocked {
1607                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1608                                         msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg), is_owned: true },
1609                                 }
1610                         },
1611                         nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1612                                 MessageSendEvent::SendAnnouncementSignatures {
1613                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1614                                         msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
1615                                 }
1616                         },
1617                         nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1618                                 MessageSendEvent::UpdateHTLCs {
1619                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1620                                         updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
1621                                 }
1622                         },
1623                         nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1624                                 MessageSendEvent::SendRevokeAndACK {
1625                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1626                                         msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
1627                                 }
1628                         },
1629                         nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1630                                 MessageSendEvent::SendClosingSigned {
1631                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1632                                         msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1633                                 }
1634                         },
1635                         nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1636                                 MessageSendEvent::SendShutdown {
1637                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1638                                         msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
1639                                 }
1640                         },
1641                         nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1642                                 MessageSendEvent::SendChannelReestablish {
1643                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1644                                         msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
1645                                 }
1646                         },
1647                         nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1648                                 MessageSendEvent::BroadcastChannelAnnouncement {
1649                                         msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1650                                         update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
1651                                 }
1652                         },
1653                         nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1654                                 MessageSendEvent::BroadcastNodeAnnouncement {
1655                                         msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1656                                 }
1657                         },
1658                         nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1659                                 MessageSendEvent::BroadcastChannelUpdate {
1660                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1661                                 }
1662                         },
1663                         nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1664                                 MessageSendEvent::SendChannelUpdate {
1665                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1666                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1667                                 }
1668                         },
1669                         nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1670                                 MessageSendEvent::HandleError {
1671                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1672                                         action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1673                                 }
1674                         },
1675                         nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1676                                 MessageSendEvent::SendChannelRangeQuery {
1677                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1678                                         msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1679                                 }
1680                         },
1681                         nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1682                                 MessageSendEvent::SendShortIdsQuery {
1683                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1684                                         msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
1685                                 }
1686                         },
1687                         nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1688                                 MessageSendEvent::SendReplyChannelRange {
1689                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1690                                         msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1691                                 }
1692                         },
1693                 }
1694         }
1695 }
1696 /// Frees any resources used by the MessageSendEvent
1697 #[no_mangle]
1698 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1699 /// Creates a copy of the MessageSendEvent
1700 #[no_mangle]
1701 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1702         orig.clone()
1703 }
1704 #[no_mangle]
1705 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
1706 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
1707         MessageSendEvent::SendAcceptChannel {
1708                 node_id,
1709                 msg,
1710         }
1711 }
1712 #[no_mangle]
1713 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
1714 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
1715         MessageSendEvent::SendOpenChannel {
1716                 node_id,
1717                 msg,
1718         }
1719 }
1720 #[no_mangle]
1721 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
1722 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
1723         MessageSendEvent::SendFundingCreated {
1724                 node_id,
1725                 msg,
1726         }
1727 }
1728 #[no_mangle]
1729 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
1730 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
1731         MessageSendEvent::SendFundingSigned {
1732                 node_id,
1733                 msg,
1734         }
1735 }
1736 #[no_mangle]
1737 /// Utility method to constructs a new SendFundingLocked-variant MessageSendEvent
1738 pub extern "C" fn MessageSendEvent_send_funding_locked(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingLocked) -> MessageSendEvent {
1739         MessageSendEvent::SendFundingLocked {
1740                 node_id,
1741                 msg,
1742         }
1743 }
1744 #[no_mangle]
1745 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
1746 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
1747         MessageSendEvent::SendAnnouncementSignatures {
1748                 node_id,
1749                 msg,
1750         }
1751 }
1752 #[no_mangle]
1753 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
1754 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
1755         MessageSendEvent::UpdateHTLCs {
1756                 node_id,
1757                 updates,
1758         }
1759 }
1760 #[no_mangle]
1761 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
1762 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
1763         MessageSendEvent::SendRevokeAndACK {
1764                 node_id,
1765                 msg,
1766         }
1767 }
1768 #[no_mangle]
1769 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
1770 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
1771         MessageSendEvent::SendClosingSigned {
1772                 node_id,
1773                 msg,
1774         }
1775 }
1776 #[no_mangle]
1777 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
1778 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
1779         MessageSendEvent::SendShutdown {
1780                 node_id,
1781                 msg,
1782         }
1783 }
1784 #[no_mangle]
1785 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
1786 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
1787         MessageSendEvent::SendChannelReestablish {
1788                 node_id,
1789                 msg,
1790         }
1791 }
1792 #[no_mangle]
1793 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
1794 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1795         MessageSendEvent::BroadcastChannelAnnouncement {
1796                 msg,
1797                 update_msg,
1798         }
1799 }
1800 #[no_mangle]
1801 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
1802 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
1803         MessageSendEvent::BroadcastNodeAnnouncement {
1804                 msg,
1805         }
1806 }
1807 #[no_mangle]
1808 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
1809 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1810         MessageSendEvent::BroadcastChannelUpdate {
1811                 msg,
1812         }
1813 }
1814 #[no_mangle]
1815 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
1816 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1817         MessageSendEvent::SendChannelUpdate {
1818                 node_id,
1819                 msg,
1820         }
1821 }
1822 #[no_mangle]
1823 /// Utility method to constructs a new HandleError-variant MessageSendEvent
1824 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
1825         MessageSendEvent::HandleError {
1826                 node_id,
1827                 action,
1828         }
1829 }
1830 #[no_mangle]
1831 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
1832 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
1833         MessageSendEvent::SendChannelRangeQuery {
1834                 node_id,
1835                 msg,
1836         }
1837 }
1838 #[no_mangle]
1839 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
1840 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
1841         MessageSendEvent::SendShortIdsQuery {
1842                 node_id,
1843                 msg,
1844         }
1845 }
1846 #[no_mangle]
1847 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
1848 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
1849         MessageSendEvent::SendReplyChannelRange {
1850                 node_id,
1851                 msg,
1852         }
1853 }
1854 /// A trait indicating an object may generate message send events
1855 #[repr(C)]
1856 pub struct MessageSendEventsProvider {
1857         /// An opaque pointer which is passed to your function implementations as an argument.
1858         /// This has no meaning in the LDK, and can be NULL or any other value.
1859         pub this_arg: *mut c_void,
1860         /// Gets the list of pending events which were generated by previous actions, clearing the list
1861         /// in the process.
1862         #[must_use]
1863         pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1864         /// Frees any resources associated with this object given its this_arg pointer.
1865         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1866         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1867 }
1868 unsafe impl Send for MessageSendEventsProvider {}
1869 unsafe impl Sync for MessageSendEventsProvider {}
1870 #[no_mangle]
1871 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
1872         MessageSendEventsProvider {
1873                 this_arg: orig.this_arg,
1874                 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
1875                 free: Clone::clone(&orig.free),
1876         }
1877 }
1878
1879 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1880 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1881         fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1882                 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1883                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1884                 local_ret
1885         }
1886 }
1887
1888 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1889 // directly as a Deref trait in higher-level structs:
1890 impl std::ops::Deref for MessageSendEventsProvider {
1891         type Target = Self;
1892         fn deref(&self) -> &Self {
1893                 self
1894         }
1895 }
1896 /// Calls the free function if one is set
1897 #[no_mangle]
1898 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1899 impl Drop for MessageSendEventsProvider {
1900         fn drop(&mut self) {
1901                 if let Some(f) = self.free {
1902                         f(self.this_arg);
1903                 }
1904         }
1905 }
1906 /// A trait indicating an object may generate events.
1907 ///
1908 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1909 ///
1910 /// # Requirements
1911 ///
1912 /// See [`process_pending_events`] for requirements around event processing.
1913 ///
1914 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1915 /// event since the last invocation. The handler must either act upon the event immediately
1916 /// or preserve it for later handling.
1917 ///
1918 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1919 /// consult the provider's documentation on the implication of processing events and how a handler
1920 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1921 /// [`ChainMonitor::process_pending_events`]).
1922 ///
1923 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1924 /// own type(s).
1925 ///
1926 /// [`process_pending_events`]: Self::process_pending_events
1927 /// [`handle_event`]: EventHandler::handle_event
1928 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1929 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1930 #[repr(C)]
1931 pub struct EventsProvider {
1932         /// An opaque pointer which is passed to your function implementations as an argument.
1933         /// This has no meaning in the LDK, and can be NULL or any other value.
1934         pub this_arg: *mut c_void,
1935         /// Processes any events generated since the last call using the given event handler.
1936         ///
1937         /// Subsequent calls must only process new events. However, handlers must be capable of handling
1938         /// duplicate events across process restarts. This may occur if the provider was recovered from
1939         /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1940         pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1941         /// Frees any resources associated with this object given its this_arg pointer.
1942         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1943         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1944 }
1945 unsafe impl Send for EventsProvider {}
1946 unsafe impl Sync for EventsProvider {}
1947 #[no_mangle]
1948 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
1949         EventsProvider {
1950                 this_arg: orig.this_arg,
1951                 process_pending_events: Clone::clone(&orig.process_pending_events),
1952                 free: Clone::clone(&orig.free),
1953         }
1954 }
1955
1956 use lightning::util::events::EventsProvider as rustEventsProvider;
1957 /// Calls the free function if one is set
1958 #[no_mangle]
1959 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1960 impl Drop for EventsProvider {
1961         fn drop(&mut self) {
1962                 if let Some(f) = self.free {
1963                         f(self.this_arg);
1964                 }
1965         }
1966 }
1967 /// A trait implemented for objects handling events from [`EventsProvider`].
1968 #[repr(C)]
1969 pub struct EventHandler {
1970         /// An opaque pointer which is passed to your function implementations as an argument.
1971         /// This has no meaning in the LDK, and can be NULL or any other value.
1972         pub this_arg: *mut c_void,
1973         /// Handles the given [`Event`].
1974         ///
1975         /// See [`EventsProvider`] for details that must be considered when implementing this method.
1976         pub handle_event: extern "C" fn (this_arg: *const c_void, event: &crate::lightning::util::events::Event),
1977         /// Frees any resources associated with this object given its this_arg pointer.
1978         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1979         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1980 }
1981 unsafe impl Send for EventHandler {}
1982 unsafe impl Sync for EventHandler {}
1983 #[no_mangle]
1984 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
1985         EventHandler {
1986                 this_arg: orig.this_arg,
1987                 handle_event: Clone::clone(&orig.handle_event),
1988                 free: Clone::clone(&orig.free),
1989         }
1990 }
1991
1992 use lightning::util::events::EventHandler as rustEventHandler;
1993 impl rustEventHandler for EventHandler {
1994         fn handle_event(&self, mut event: &lightning::util::events::Event) {
1995                 (self.handle_event)(self.this_arg, &crate::lightning::util::events::Event::from_native(event))
1996         }
1997 }
1998
1999 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2000 // directly as a Deref trait in higher-level structs:
2001 impl std::ops::Deref for EventHandler {
2002         type Target = Self;
2003         fn deref(&self) -> &Self {
2004                 self
2005         }
2006 }
2007 /// Calls the free function if one is set
2008 #[no_mangle]
2009 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
2010 impl Drop for EventHandler {
2011         fn drop(&mut self) {
2012                 if let Some(f) = self.free {
2013                         f(self.this_arg);
2014                 }
2015         }
2016 }