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