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