Merge pull request #40 from TheBlueMatt/main
[ldk-c-bindings] / lightning-c-bindings / src / lightning / util / events.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! Events are returned from various bits in the library which indicate some action must be taken
10 //! by the client.
11 //!
12 //! Because we don't have a built-in runtime, it's up to the client to call events at a time in the
13 //! future, as well as generate and broadcast funding transactions handle payment preimages and a
14 //! few other things.
15
16 use std::str::FromStr;
17 use std::ffi::c_void;
18 use bitcoin::hashes::Hash;
19 use crate::c_types::*;
20
21 /// Some information provided on receipt of payment depends on whether the payment received is a
22 /// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
23 #[must_use]
24 #[derive(Clone)]
25 #[repr(C)]
26 pub enum PaymentPurpose {
27         /// Information for receiving a payment that we generated an invoice for.
28         InvoicePayment {
29                 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
30                 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
31                 /// [`ChannelManager::claim_funds`].
32                 ///
33                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
34                 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
35                 ///
36                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
37                 payment_preimage: crate::c_types::ThirtyTwoBytes,
38                 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
39                 /// number of deanonymization attacks during the routing process.
40                 /// It is provided here for your reference, however its accuracy is enforced directly by
41                 /// [`ChannelManager`] using the values you previously provided to
42                 /// [`ChannelManager::create_inbound_payment`] or
43                 /// [`ChannelManager::create_inbound_payment_for_hash`].
44                 ///
45                 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
46                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
47                 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
48                 payment_secret: crate::c_types::ThirtyTwoBytes,
49                 /// This is the `user_payment_id` which was provided to
50                 /// [`ChannelManager::create_inbound_payment_for_hash`] or
51                 /// [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is
52                 /// simply copied here. It may be used to correlate PaymentReceived events with invoice
53                 /// metadata stored elsewhere.
54                 ///
55                 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
56                 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
57                 user_payment_id: u64,
58         },
59         /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
60         /// (the payee) providing a preimage.
61         SpontaneousPayment(crate::c_types::ThirtyTwoBytes),
62 }
63 use lightning::util::events::PaymentPurpose as nativePaymentPurpose;
64 impl PaymentPurpose {
65         #[allow(unused)]
66         pub(crate) fn to_native(&self) -> nativePaymentPurpose {
67                 match self {
68                         PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
69                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
70                                 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
71                                 let mut payment_secret_nonref = (*payment_secret).clone();
72                                 let mut user_payment_id_nonref = (*user_payment_id).clone();
73                                 nativePaymentPurpose::InvoicePayment {
74                                         payment_preimage: local_payment_preimage_nonref,
75                                         payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
76                                         user_payment_id: user_payment_id_nonref,
77                                 }
78                         },
79                         PaymentPurpose::SpontaneousPayment (ref a, ) => {
80                                 let mut a_nonref = (*a).clone();
81                                 nativePaymentPurpose::SpontaneousPayment (
82                                         ::lightning::ln::PaymentPreimage(a_nonref.data),
83                                 )
84                         },
85                 }
86         }
87         #[allow(unused)]
88         pub(crate) fn into_native(self) -> nativePaymentPurpose {
89                 match self {
90                         PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
91                                 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
92                                 nativePaymentPurpose::InvoicePayment {
93                                         payment_preimage: local_payment_preimage,
94                                         payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
95                                         user_payment_id: user_payment_id,
96                                 }
97                         },
98                         PaymentPurpose::SpontaneousPayment (mut a, ) => {
99                                 nativePaymentPurpose::SpontaneousPayment (
100                                         ::lightning::ln::PaymentPreimage(a.data),
101                                 )
102                         },
103                 }
104         }
105         #[allow(unused)]
106         pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
107                 match native {
108                         nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
109                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
110                                 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 } } };
111                                 let mut payment_secret_nonref = (*payment_secret).clone();
112                                 let mut user_payment_id_nonref = (*user_payment_id).clone();
113                                 PaymentPurpose::InvoicePayment {
114                                         payment_preimage: local_payment_preimage_nonref,
115                                         payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
116                                         user_payment_id: user_payment_id_nonref,
117                                 }
118                         },
119                         nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
120                                 let mut a_nonref = (*a).clone();
121                                 PaymentPurpose::SpontaneousPayment (
122                                         crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
123                                 )
124                         },
125                 }
126         }
127         #[allow(unused)]
128         pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
129                 match native {
130                         nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
131                                 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 } } };
132                                 PaymentPurpose::InvoicePayment {
133                                         payment_preimage: local_payment_preimage,
134                                         payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
135                                         user_payment_id: user_payment_id,
136                                 }
137                         },
138                         nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
139                                 PaymentPurpose::SpontaneousPayment (
140                                         crate::c_types::ThirtyTwoBytes { data: a.0 },
141                                 )
142                         },
143                 }
144         }
145 }
146 /// Frees any resources used by the PaymentPurpose
147 #[no_mangle]
148 pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
149 /// Creates a copy of the PaymentPurpose
150 #[no_mangle]
151 pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
152         orig.clone()
153 }
154 #[no_mangle]
155 /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
156 pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes, user_payment_id: u64) -> PaymentPurpose {
157         PaymentPurpose::InvoicePayment {
158                 payment_preimage,
159                 payment_secret,
160                 user_payment_id,
161         }
162 }
163 #[no_mangle]
164 /// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
165 pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
166         PaymentPurpose::SpontaneousPayment(a, )
167 }
168 /// An Event which you should probably take some action in response to.
169 ///
170 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
171 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
172 /// written as it makes no sense to respond to it after reconnecting to peers).
173 #[must_use]
174 #[derive(Clone)]
175 #[repr(C)]
176 pub enum Event {
177         /// Used to indicate that the client should generate a funding transaction with the given
178         /// parameters and then call ChannelManager::funding_transaction_generated.
179         /// Generated in ChannelManager message handling.
180         /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
181         /// counterparty can steal your funds!
182         FundingGenerationReady {
183                 /// The random channel_id we picked which you'll need to pass into
184                 /// ChannelManager::funding_transaction_generated.
185                 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
186                 /// The value, in satoshis, that the output should have.
187                 channel_value_satoshis: u64,
188                 /// The script which should be used in the transaction output.
189                 output_script: crate::c_types::derived::CVec_u8Z,
190                 /// The value passed in to ChannelManager::create_channel
191                 user_channel_id: u64,
192         },
193         /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
194         /// ChannelManager::claim_funds to get it....
195         /// Note that if the preimage is not known or the amount paid is incorrect, you should call
196         /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid
197         /// network congestion.
198         /// The amount paid should be considered 'incorrect' when it is less than or more than twice
199         /// the amount expected.
200         /// If you fail to call either ChannelManager::claim_funds or
201         /// ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be
202         /// automatically failed.
203         PaymentReceived {
204                 /// The hash for which the preimage should be handed to the ChannelManager.
205                 payment_hash: crate::c_types::ThirtyTwoBytes,
206                 /// The value, in thousandths of a satoshi, that this payment is for. Note that you must
207                 /// compare this to the expected value before accepting the payment (as otherwise you are
208                 /// providing proof-of-payment for less than the value you expected!).
209                 amt: u64,
210                 /// Information for claiming this received payment, based on whether the purpose of the
211                 /// payment is to pay an invoice or to send a spontaneous payment.
212                 purpose: crate::lightning::util::events::PaymentPurpose,
213         },
214         /// Indicates an outbound payment we made succeeded (ie it made it all the way to its target
215         /// and we got back the payment preimage for it).
216         PaymentSent {
217                 /// The preimage to the hash given to ChannelManager::send_payment.
218                 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
219                 /// store it somehow!
220                 payment_preimage: crate::c_types::ThirtyTwoBytes,
221         },
222         /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
223         /// something. You may wish to retry with a different route.
224         PaymentFailed {
225                 /// The hash which was given to ChannelManager::send_payment.
226                 payment_hash: crate::c_types::ThirtyTwoBytes,
227                 /// Indicates the payment was rejected for some reason by the recipient. This implies that
228                 /// the payment has failed, not just the route in question. If this is not set, you may
229                 /// retry the payment via a different route.
230                 rejected_by_dest: bool,
231         },
232         /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
233         /// time in the future.
234         PendingHTLCsForwardable {
235                 /// The minimum amount of time that should be waited prior to calling
236                 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
237                 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
238                 /// now + 5*time_forwardable).
239                 time_forwardable: u64,
240         },
241         /// Used to indicate that an output which you should know how to spend was confirmed on chain
242         /// and is now spendable.
243         /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
244         /// counterparty spending them due to some kind of timeout. Thus, you need to store them
245         /// somewhere and spend them when you create on-chain transactions.
246         SpendableOutputs {
247                 /// The outputs which you should store as spendable by you.
248                 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
249         },
250         /// This event is generated when a payment has been successfully forwarded through us and a
251         /// forwarding fee earned.
252         PaymentForwarded {
253                 /// The fee, in milli-satoshis, which was earned as a result of the payment.
254                 ///
255                 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
256                 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
257                 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
258                 /// claimed the full value in millisatoshis from the source. In this case,
259                 /// `claim_from_onchain_tx` will be set.
260                 ///
261                 /// If the channel which sent us the payment has been force-closed, we will claim the funds
262                 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
263                 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
264                 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
265                 /// `None`.
266                 fee_earned_msat: crate::c_types::derived::COption_u64Z,
267                 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
268                 /// transaction.
269                 claim_from_onchain_tx: bool,
270         },
271 }
272 use lightning::util::events::Event as nativeEvent;
273 impl Event {
274         #[allow(unused)]
275         pub(crate) fn to_native(&self) -> nativeEvent {
276                 match self {
277                         Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
278                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
279                                 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
280                                 let mut output_script_nonref = (*output_script).clone();
281                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
282                                 nativeEvent::FundingGenerationReady {
283                                         temporary_channel_id: temporary_channel_id_nonref.data,
284                                         channel_value_satoshis: channel_value_satoshis_nonref,
285                                         output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
286                                         user_channel_id: user_channel_id_nonref,
287                                 }
288                         },
289                         Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
290                                 let mut payment_hash_nonref = (*payment_hash).clone();
291                                 let mut amt_nonref = (*amt).clone();
292                                 let mut purpose_nonref = (*purpose).clone();
293                                 nativeEvent::PaymentReceived {
294                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
295                                         amt: amt_nonref,
296                                         purpose: purpose_nonref.into_native(),
297                                 }
298                         },
299                         Event::PaymentSent {ref payment_preimage, } => {
300                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
301                                 nativeEvent::PaymentSent {
302                                         payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
303                                 }
304                         },
305                         Event::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
306                                 let mut payment_hash_nonref = (*payment_hash).clone();
307                                 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
308                                 nativeEvent::PaymentFailed {
309                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
310                                         rejected_by_dest: rejected_by_dest_nonref,
311                                 }
312                         },
313                         Event::PendingHTLCsForwardable {ref time_forwardable, } => {
314                                 let mut time_forwardable_nonref = (*time_forwardable).clone();
315                                 nativeEvent::PendingHTLCsForwardable {
316                                         time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
317                                 }
318                         },
319                         Event::SpendableOutputs {ref outputs, } => {
320                                 let mut outputs_nonref = (*outputs).clone();
321                                 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
322                                 nativeEvent::SpendableOutputs {
323                                         outputs: local_outputs_nonref,
324                                 }
325                         },
326                         Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
327                                 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
328                                 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
329                                 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
330                                 nativeEvent::PaymentForwarded {
331                                         fee_earned_msat: local_fee_earned_msat_nonref,
332                                         claim_from_onchain_tx: claim_from_onchain_tx_nonref,
333                                 }
334                         },
335                 }
336         }
337         #[allow(unused)]
338         pub(crate) fn into_native(self) -> nativeEvent {
339                 match self {
340                         Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
341                                 nativeEvent::FundingGenerationReady {
342                                         temporary_channel_id: temporary_channel_id.data,
343                                         channel_value_satoshis: channel_value_satoshis,
344                                         output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
345                                         user_channel_id: user_channel_id,
346                                 }
347                         },
348                         Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
349                                 nativeEvent::PaymentReceived {
350                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
351                                         amt: amt,
352                                         purpose: purpose.into_native(),
353                                 }
354                         },
355                         Event::PaymentSent {mut payment_preimage, } => {
356                                 nativeEvent::PaymentSent {
357                                         payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
358                                 }
359                         },
360                         Event::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
361                                 nativeEvent::PaymentFailed {
362                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
363                                         rejected_by_dest: rejected_by_dest,
364                                 }
365                         },
366                         Event::PendingHTLCsForwardable {mut time_forwardable, } => {
367                                 nativeEvent::PendingHTLCsForwardable {
368                                         time_forwardable: std::time::Duration::from_secs(time_forwardable),
369                                 }
370                         },
371                         Event::SpendableOutputs {mut outputs, } => {
372                                 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
373                                 nativeEvent::SpendableOutputs {
374                                         outputs: local_outputs,
375                                 }
376                         },
377                         Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
378                                 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
379                                 nativeEvent::PaymentForwarded {
380                                         fee_earned_msat: local_fee_earned_msat,
381                                         claim_from_onchain_tx: claim_from_onchain_tx,
382                                 }
383                         },
384                 }
385         }
386         #[allow(unused)]
387         pub(crate) fn from_native(native: &nativeEvent) -> Self {
388                 match native {
389                         nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
390                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
391                                 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
392                                 let mut output_script_nonref = (*output_script).clone();
393                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
394                                 Event::FundingGenerationReady {
395                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
396                                         channel_value_satoshis: channel_value_satoshis_nonref,
397                                         output_script: output_script_nonref.into_bytes().into(),
398                                         user_channel_id: user_channel_id_nonref,
399                                 }
400                         },
401                         nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
402                                 let mut payment_hash_nonref = (*payment_hash).clone();
403                                 let mut amt_nonref = (*amt).clone();
404                                 let mut purpose_nonref = (*purpose).clone();
405                                 Event::PaymentReceived {
406                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
407                                         amt: amt_nonref,
408                                         purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
409                                 }
410                         },
411                         nativeEvent::PaymentSent {ref payment_preimage, } => {
412                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
413                                 Event::PaymentSent {
414                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
415                                 }
416                         },
417                         nativeEvent::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
418                                 let mut payment_hash_nonref = (*payment_hash).clone();
419                                 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
420                                 Event::PaymentFailed {
421                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
422                                         rejected_by_dest: rejected_by_dest_nonref,
423                                 }
424                         },
425                         nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
426                                 let mut time_forwardable_nonref = (*time_forwardable).clone();
427                                 Event::PendingHTLCsForwardable {
428                                         time_forwardable: time_forwardable_nonref.as_secs(),
429                                 }
430                         },
431                         nativeEvent::SpendableOutputs {ref outputs, } => {
432                                 let mut outputs_nonref = (*outputs).clone();
433                                 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) }); };
434                                 Event::SpendableOutputs {
435                                         outputs: local_outputs_nonref.into(),
436                                 }
437                         },
438                         nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
439                                 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
440                                 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()) } };
441                                 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
442                                 Event::PaymentForwarded {
443                                         fee_earned_msat: local_fee_earned_msat_nonref,
444                                         claim_from_onchain_tx: claim_from_onchain_tx_nonref,
445                                 }
446                         },
447                 }
448         }
449         #[allow(unused)]
450         pub(crate) fn native_into(native: nativeEvent) -> Self {
451                 match native {
452                         nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
453                                 Event::FundingGenerationReady {
454                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
455                                         channel_value_satoshis: channel_value_satoshis,
456                                         output_script: output_script.into_bytes().into(),
457                                         user_channel_id: user_channel_id,
458                                 }
459                         },
460                         nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
461                                 Event::PaymentReceived {
462                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
463                                         amt: amt,
464                                         purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
465                                 }
466                         },
467                         nativeEvent::PaymentSent {mut payment_preimage, } => {
468                                 Event::PaymentSent {
469                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
470                                 }
471                         },
472                         nativeEvent::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
473                                 Event::PaymentFailed {
474                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
475                                         rejected_by_dest: rejected_by_dest,
476                                 }
477                         },
478                         nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
479                                 Event::PendingHTLCsForwardable {
480                                         time_forwardable: time_forwardable.as_secs(),
481                                 }
482                         },
483                         nativeEvent::SpendableOutputs {mut outputs, } => {
484                                 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
485                                 Event::SpendableOutputs {
486                                         outputs: local_outputs.into(),
487                                 }
488                         },
489                         nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
490                                 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()) } };
491                                 Event::PaymentForwarded {
492                                         fee_earned_msat: local_fee_earned_msat,
493                                         claim_from_onchain_tx: claim_from_onchain_tx,
494                                 }
495                         },
496                 }
497         }
498 }
499 /// Frees any resources used by the Event
500 #[no_mangle]
501 pub extern "C" fn Event_free(this_ptr: Event) { }
502 /// Creates a copy of the Event
503 #[no_mangle]
504 pub extern "C" fn Event_clone(orig: &Event) -> Event {
505         orig.clone()
506 }
507 #[no_mangle]
508 /// Utility method to constructs a new FundingGenerationReady-variant Event
509 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 {
510         Event::FundingGenerationReady {
511                 temporary_channel_id,
512                 channel_value_satoshis,
513                 output_script,
514                 user_channel_id,
515         }
516 }
517 #[no_mangle]
518 /// Utility method to constructs a new PaymentReceived-variant Event
519 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
520         Event::PaymentReceived {
521                 payment_hash,
522                 amt,
523                 purpose,
524         }
525 }
526 #[no_mangle]
527 /// Utility method to constructs a new PaymentSent-variant Event
528 pub extern "C" fn Event_payment_sent(payment_preimage: crate::c_types::ThirtyTwoBytes) -> Event {
529         Event::PaymentSent {
530                 payment_preimage,
531         }
532 }
533 #[no_mangle]
534 /// Utility method to constructs a new PaymentFailed-variant Event
535 pub extern "C" fn Event_payment_failed(payment_hash: crate::c_types::ThirtyTwoBytes, rejected_by_dest: bool) -> Event {
536         Event::PaymentFailed {
537                 payment_hash,
538                 rejected_by_dest,
539         }
540 }
541 #[no_mangle]
542 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
543 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
544         Event::PendingHTLCsForwardable {
545                 time_forwardable,
546         }
547 }
548 #[no_mangle]
549 /// Utility method to constructs a new SpendableOutputs-variant Event
550 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
551         Event::SpendableOutputs {
552                 outputs,
553         }
554 }
555 #[no_mangle]
556 /// Utility method to constructs a new PaymentForwarded-variant Event
557 pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
558         Event::PaymentForwarded {
559                 fee_earned_msat,
560                 claim_from_onchain_tx,
561         }
562 }
563 #[no_mangle]
564 /// Serialize the Event object into a byte array which can be read by Event_read
565 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
566         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
567 }
568 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
569 /// broadcast to most peers).
570 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
571 #[must_use]
572 #[derive(Clone)]
573 #[repr(C)]
574 pub enum MessageSendEvent {
575         /// Used to indicate that we've accepted a channel open and should send the accept_channel
576         /// message provided to the given peer.
577         SendAcceptChannel {
578                 /// The node_id of the node which should receive this message
579                 node_id: crate::c_types::PublicKey,
580                 /// The message which should be sent.
581                 msg: crate::lightning::ln::msgs::AcceptChannel,
582         },
583         /// Used to indicate that we've initiated a channel open and should send the open_channel
584         /// message provided to the given peer.
585         SendOpenChannel {
586                 /// The node_id of the node which should receive this message
587                 node_id: crate::c_types::PublicKey,
588                 /// The message which should be sent.
589                 msg: crate::lightning::ln::msgs::OpenChannel,
590         },
591         /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
592         SendFundingCreated {
593                 /// The node_id of the node which should receive this message
594                 node_id: crate::c_types::PublicKey,
595                 /// The message which should be sent.
596                 msg: crate::lightning::ln::msgs::FundingCreated,
597         },
598         /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
599         SendFundingSigned {
600                 /// The node_id of the node which should receive this message
601                 node_id: crate::c_types::PublicKey,
602                 /// The message which should be sent.
603                 msg: crate::lightning::ln::msgs::FundingSigned,
604         },
605         /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
606         SendFundingLocked {
607                 /// The node_id of the node which should receive these message(s)
608                 node_id: crate::c_types::PublicKey,
609                 /// The funding_locked message which should be sent.
610                 msg: crate::lightning::ln::msgs::FundingLocked,
611         },
612         /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
613         SendAnnouncementSignatures {
614                 /// The node_id of the node which should receive these message(s)
615                 node_id: crate::c_types::PublicKey,
616                 /// The announcement_signatures message which should be sent.
617                 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
618         },
619         /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
620         /// message should be sent to the peer with the given node_id.
621         UpdateHTLCs {
622                 /// The node_id of the node which should receive these message(s)
623                 node_id: crate::c_types::PublicKey,
624                 /// The update messages which should be sent. ALL messages in the struct should be sent!
625                 updates: crate::lightning::ln::msgs::CommitmentUpdate,
626         },
627         /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
628         SendRevokeAndACK {
629                 /// The node_id of the node which should receive this message
630                 node_id: crate::c_types::PublicKey,
631                 /// The message which should be sent.
632                 msg: crate::lightning::ln::msgs::RevokeAndACK,
633         },
634         /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
635         SendClosingSigned {
636                 /// The node_id of the node which should receive this message
637                 node_id: crate::c_types::PublicKey,
638                 /// The message which should be sent.
639                 msg: crate::lightning::ln::msgs::ClosingSigned,
640         },
641         /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
642         SendShutdown {
643                 /// The node_id of the node which should receive this message
644                 node_id: crate::c_types::PublicKey,
645                 /// The message which should be sent.
646                 msg: crate::lightning::ln::msgs::Shutdown,
647         },
648         /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
649         SendChannelReestablish {
650                 /// The node_id of the node which should receive this message
651                 node_id: crate::c_types::PublicKey,
652                 /// The message which should be sent.
653                 msg: crate::lightning::ln::msgs::ChannelReestablish,
654         },
655         /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
656         /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
657         ///
658         /// Note that after doing so, you very likely (unless you did so very recently) want to call
659         /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
660         /// This ensures that any nodes which see our channel_announcement also have a relevant
661         /// node_announcement, including relevant feature flags which may be important for routing
662         /// through or to us.
663         BroadcastChannelAnnouncement {
664                 /// The channel_announcement which should be sent.
665                 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
666                 /// The followup channel_update which should be sent.
667                 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
668         },
669         /// Used to indicate that a node_announcement should be broadcast to all peers.
670         BroadcastNodeAnnouncement {
671                 /// The node_announcement which should be sent.
672                 msg: crate::lightning::ln::msgs::NodeAnnouncement,
673         },
674         /// Used to indicate that a channel_update should be broadcast to all peers.
675         BroadcastChannelUpdate {
676                 /// The channel_update which should be sent.
677                 msg: crate::lightning::ln::msgs::ChannelUpdate,
678         },
679         /// Used to indicate that a channel_update should be sent to a single peer.
680         /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
681         /// private channel and we shouldn't be informing all of our peers of channel parameters.
682         SendChannelUpdate {
683                 /// The node_id of the node which should receive this message
684                 node_id: crate::c_types::PublicKey,
685                 /// The channel_update which should be sent.
686                 msg: crate::lightning::ln::msgs::ChannelUpdate,
687         },
688         /// Broadcast an error downstream to be handled
689         HandleError {
690                 /// The node_id of the node which should receive this message
691                 node_id: crate::c_types::PublicKey,
692                 /// The action which should be taken.
693                 action: crate::lightning::ln::msgs::ErrorAction,
694         },
695         /// When a payment fails we may receive updates back from the hop where it failed. In such
696         /// cases this event is generated so that we can inform the network graph of this information.
697         PaymentFailureNetworkUpdate {
698                 /// The channel/node update which should be sent to NetGraphMsgHandler
699                 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate,
700         },
701         /// Query a peer for channels with funding transaction UTXOs in a block range.
702         SendChannelRangeQuery {
703                 /// The node_id of this message recipient
704                 node_id: crate::c_types::PublicKey,
705                 /// The query_channel_range which should be sent.
706                 msg: crate::lightning::ln::msgs::QueryChannelRange,
707         },
708         /// Request routing gossip messages from a peer for a list of channels identified by
709         /// their short_channel_ids.
710         SendShortIdsQuery {
711                 /// The node_id of this message recipient
712                 node_id: crate::c_types::PublicKey,
713                 /// The query_short_channel_ids which should be sent.
714                 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
715         },
716         /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
717         /// emitted during processing of the query.
718         SendReplyChannelRange {
719                 /// The node_id of this message recipient
720                 node_id: crate::c_types::PublicKey,
721                 /// The reply_channel_range which should be sent.
722                 msg: crate::lightning::ln::msgs::ReplyChannelRange,
723         },
724 }
725 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
726 impl MessageSendEvent {
727         #[allow(unused)]
728         pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
729                 match self {
730                         MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
731                                 let mut node_id_nonref = (*node_id).clone();
732                                 let mut msg_nonref = (*msg).clone();
733                                 nativeMessageSendEvent::SendAcceptChannel {
734                                         node_id: node_id_nonref.into_rust(),
735                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
736                                 }
737                         },
738                         MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
739                                 let mut node_id_nonref = (*node_id).clone();
740                                 let mut msg_nonref = (*msg).clone();
741                                 nativeMessageSendEvent::SendOpenChannel {
742                                         node_id: node_id_nonref.into_rust(),
743                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
744                                 }
745                         },
746                         MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
747                                 let mut node_id_nonref = (*node_id).clone();
748                                 let mut msg_nonref = (*msg).clone();
749                                 nativeMessageSendEvent::SendFundingCreated {
750                                         node_id: node_id_nonref.into_rust(),
751                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
752                                 }
753                         },
754                         MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
755                                 let mut node_id_nonref = (*node_id).clone();
756                                 let mut msg_nonref = (*msg).clone();
757                                 nativeMessageSendEvent::SendFundingSigned {
758                                         node_id: node_id_nonref.into_rust(),
759                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
760                                 }
761                         },
762                         MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
763                                 let mut node_id_nonref = (*node_id).clone();
764                                 let mut msg_nonref = (*msg).clone();
765                                 nativeMessageSendEvent::SendFundingLocked {
766                                         node_id: node_id_nonref.into_rust(),
767                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
768                                 }
769                         },
770                         MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
771                                 let mut node_id_nonref = (*node_id).clone();
772                                 let mut msg_nonref = (*msg).clone();
773                                 nativeMessageSendEvent::SendAnnouncementSignatures {
774                                         node_id: node_id_nonref.into_rust(),
775                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
776                                 }
777                         },
778                         MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
779                                 let mut node_id_nonref = (*node_id).clone();
780                                 let mut updates_nonref = (*updates).clone();
781                                 nativeMessageSendEvent::UpdateHTLCs {
782                                         node_id: node_id_nonref.into_rust(),
783                                         updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
784                                 }
785                         },
786                         MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
787                                 let mut node_id_nonref = (*node_id).clone();
788                                 let mut msg_nonref = (*msg).clone();
789                                 nativeMessageSendEvent::SendRevokeAndACK {
790                                         node_id: node_id_nonref.into_rust(),
791                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
792                                 }
793                         },
794                         MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
795                                 let mut node_id_nonref = (*node_id).clone();
796                                 let mut msg_nonref = (*msg).clone();
797                                 nativeMessageSendEvent::SendClosingSigned {
798                                         node_id: node_id_nonref.into_rust(),
799                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
800                                 }
801                         },
802                         MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
803                                 let mut node_id_nonref = (*node_id).clone();
804                                 let mut msg_nonref = (*msg).clone();
805                                 nativeMessageSendEvent::SendShutdown {
806                                         node_id: node_id_nonref.into_rust(),
807                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
808                                 }
809                         },
810                         MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
811                                 let mut node_id_nonref = (*node_id).clone();
812                                 let mut msg_nonref = (*msg).clone();
813                                 nativeMessageSendEvent::SendChannelReestablish {
814                                         node_id: node_id_nonref.into_rust(),
815                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
816                                 }
817                         },
818                         MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
819                                 let mut msg_nonref = (*msg).clone();
820                                 let mut update_msg_nonref = (*update_msg).clone();
821                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
822                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
823                                         update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
824                                 }
825                         },
826                         MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
827                                 let mut msg_nonref = (*msg).clone();
828                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
829                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
830                                 }
831                         },
832                         MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
833                                 let mut msg_nonref = (*msg).clone();
834                                 nativeMessageSendEvent::BroadcastChannelUpdate {
835                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
836                                 }
837                         },
838                         MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
839                                 let mut node_id_nonref = (*node_id).clone();
840                                 let mut msg_nonref = (*msg).clone();
841                                 nativeMessageSendEvent::SendChannelUpdate {
842                                         node_id: node_id_nonref.into_rust(),
843                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
844                                 }
845                         },
846                         MessageSendEvent::HandleError {ref node_id, ref action, } => {
847                                 let mut node_id_nonref = (*node_id).clone();
848                                 let mut action_nonref = (*action).clone();
849                                 nativeMessageSendEvent::HandleError {
850                                         node_id: node_id_nonref.into_rust(),
851                                         action: action_nonref.into_native(),
852                                 }
853                         },
854                         MessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
855                                 let mut update_nonref = (*update).clone();
856                                 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
857                                         update: update_nonref.into_native(),
858                                 }
859                         },
860                         MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
861                                 let mut node_id_nonref = (*node_id).clone();
862                                 let mut msg_nonref = (*msg).clone();
863                                 nativeMessageSendEvent::SendChannelRangeQuery {
864                                         node_id: node_id_nonref.into_rust(),
865                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
866                                 }
867                         },
868                         MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
869                                 let mut node_id_nonref = (*node_id).clone();
870                                 let mut msg_nonref = (*msg).clone();
871                                 nativeMessageSendEvent::SendShortIdsQuery {
872                                         node_id: node_id_nonref.into_rust(),
873                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
874                                 }
875                         },
876                         MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
877                                 let mut node_id_nonref = (*node_id).clone();
878                                 let mut msg_nonref = (*msg).clone();
879                                 nativeMessageSendEvent::SendReplyChannelRange {
880                                         node_id: node_id_nonref.into_rust(),
881                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
882                                 }
883                         },
884                 }
885         }
886         #[allow(unused)]
887         pub(crate) fn into_native(self) -> nativeMessageSendEvent {
888                 match self {
889                         MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
890                                 nativeMessageSendEvent::SendAcceptChannel {
891                                         node_id: node_id.into_rust(),
892                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
893                                 }
894                         },
895                         MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
896                                 nativeMessageSendEvent::SendOpenChannel {
897                                         node_id: node_id.into_rust(),
898                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
899                                 }
900                         },
901                         MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
902                                 nativeMessageSendEvent::SendFundingCreated {
903                                         node_id: node_id.into_rust(),
904                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
905                                 }
906                         },
907                         MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
908                                 nativeMessageSendEvent::SendFundingSigned {
909                                         node_id: node_id.into_rust(),
910                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
911                                 }
912                         },
913                         MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
914                                 nativeMessageSendEvent::SendFundingLocked {
915                                         node_id: node_id.into_rust(),
916                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
917                                 }
918                         },
919                         MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
920                                 nativeMessageSendEvent::SendAnnouncementSignatures {
921                                         node_id: node_id.into_rust(),
922                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
923                                 }
924                         },
925                         MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
926                                 nativeMessageSendEvent::UpdateHTLCs {
927                                         node_id: node_id.into_rust(),
928                                         updates: *unsafe { Box::from_raw(updates.take_inner()) },
929                                 }
930                         },
931                         MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
932                                 nativeMessageSendEvent::SendRevokeAndACK {
933                                         node_id: node_id.into_rust(),
934                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
935                                 }
936                         },
937                         MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
938                                 nativeMessageSendEvent::SendClosingSigned {
939                                         node_id: node_id.into_rust(),
940                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
941                                 }
942                         },
943                         MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
944                                 nativeMessageSendEvent::SendShutdown {
945                                         node_id: node_id.into_rust(),
946                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
947                                 }
948                         },
949                         MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
950                                 nativeMessageSendEvent::SendChannelReestablish {
951                                         node_id: node_id.into_rust(),
952                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
953                                 }
954                         },
955                         MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
956                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
957                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
958                                         update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
959                                 }
960                         },
961                         MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
962                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
963                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
964                                 }
965                         },
966                         MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
967                                 nativeMessageSendEvent::BroadcastChannelUpdate {
968                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
969                                 }
970                         },
971                         MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
972                                 nativeMessageSendEvent::SendChannelUpdate {
973                                         node_id: node_id.into_rust(),
974                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
975                                 }
976                         },
977                         MessageSendEvent::HandleError {mut node_id, mut action, } => {
978                                 nativeMessageSendEvent::HandleError {
979                                         node_id: node_id.into_rust(),
980                                         action: action.into_native(),
981                                 }
982                         },
983                         MessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
984                                 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
985                                         update: update.into_native(),
986                                 }
987                         },
988                         MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
989                                 nativeMessageSendEvent::SendChannelRangeQuery {
990                                         node_id: node_id.into_rust(),
991                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
992                                 }
993                         },
994                         MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
995                                 nativeMessageSendEvent::SendShortIdsQuery {
996                                         node_id: node_id.into_rust(),
997                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
998                                 }
999                         },
1000                         MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1001                                 nativeMessageSendEvent::SendReplyChannelRange {
1002                                         node_id: node_id.into_rust(),
1003                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
1004                                 }
1005                         },
1006                 }
1007         }
1008         #[allow(unused)]
1009         pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
1010                 match native {
1011                         nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1012                                 let mut node_id_nonref = (*node_id).clone();
1013                                 let mut msg_nonref = (*msg).clone();
1014                                 MessageSendEvent::SendAcceptChannel {
1015                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1016                                         msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1017                                 }
1018                         },
1019                         nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1020                                 let mut node_id_nonref = (*node_id).clone();
1021                                 let mut msg_nonref = (*msg).clone();
1022                                 MessageSendEvent::SendOpenChannel {
1023                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1024                                         msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1025                                 }
1026                         },
1027                         nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1028                                 let mut node_id_nonref = (*node_id).clone();
1029                                 let mut msg_nonref = (*msg).clone();
1030                                 MessageSendEvent::SendFundingCreated {
1031                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1032                                         msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1033                                 }
1034                         },
1035                         nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1036                                 let mut node_id_nonref = (*node_id).clone();
1037                                 let mut msg_nonref = (*msg).clone();
1038                                 MessageSendEvent::SendFundingSigned {
1039                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1040                                         msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1041                                 }
1042                         },
1043                         nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1044                                 let mut node_id_nonref = (*node_id).clone();
1045                                 let mut msg_nonref = (*msg).clone();
1046                                 MessageSendEvent::SendFundingLocked {
1047                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1048                                         msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1049                                 }
1050                         },
1051                         nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1052                                 let mut node_id_nonref = (*node_id).clone();
1053                                 let mut msg_nonref = (*msg).clone();
1054                                 MessageSendEvent::SendAnnouncementSignatures {
1055                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1056                                         msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1057                                 }
1058                         },
1059                         nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1060                                 let mut node_id_nonref = (*node_id).clone();
1061                                 let mut updates_nonref = (*updates).clone();
1062                                 MessageSendEvent::UpdateHTLCs {
1063                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1064                                         updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
1065                                 }
1066                         },
1067                         nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1068                                 let mut node_id_nonref = (*node_id).clone();
1069                                 let mut msg_nonref = (*msg).clone();
1070                                 MessageSendEvent::SendRevokeAndACK {
1071                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1072                                         msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1073                                 }
1074                         },
1075                         nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1076                                 let mut node_id_nonref = (*node_id).clone();
1077                                 let mut msg_nonref = (*msg).clone();
1078                                 MessageSendEvent::SendClosingSigned {
1079                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1080                                         msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1081                                 }
1082                         },
1083                         nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1084                                 let mut node_id_nonref = (*node_id).clone();
1085                                 let mut msg_nonref = (*msg).clone();
1086                                 MessageSendEvent::SendShutdown {
1087                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1088                                         msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1089                                 }
1090                         },
1091                         nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1092                                 let mut node_id_nonref = (*node_id).clone();
1093                                 let mut msg_nonref = (*msg).clone();
1094                                 MessageSendEvent::SendChannelReestablish {
1095                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1096                                         msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1097                                 }
1098                         },
1099                         nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1100                                 let mut msg_nonref = (*msg).clone();
1101                                 let mut update_msg_nonref = (*update_msg).clone();
1102                                 MessageSendEvent::BroadcastChannelAnnouncement {
1103                                         msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1104                                         update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
1105                                 }
1106                         },
1107                         nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1108                                 let mut msg_nonref = (*msg).clone();
1109                                 MessageSendEvent::BroadcastNodeAnnouncement {
1110                                         msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1111                                 }
1112                         },
1113                         nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1114                                 let mut msg_nonref = (*msg).clone();
1115                                 MessageSendEvent::BroadcastChannelUpdate {
1116                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1117                                 }
1118                         },
1119                         nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1120                                 let mut node_id_nonref = (*node_id).clone();
1121                                 let mut msg_nonref = (*msg).clone();
1122                                 MessageSendEvent::SendChannelUpdate {
1123                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1124                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1125                                 }
1126                         },
1127                         nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
1128                                 let mut node_id_nonref = (*node_id).clone();
1129                                 let mut action_nonref = (*action).clone();
1130                                 MessageSendEvent::HandleError {
1131                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1132                                         action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
1133                                 }
1134                         },
1135                         nativeMessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
1136                                 let mut update_nonref = (*update).clone();
1137                                 MessageSendEvent::PaymentFailureNetworkUpdate {
1138                                         update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update_nonref),
1139                                 }
1140                         },
1141                         nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1142                                 let mut node_id_nonref = (*node_id).clone();
1143                                 let mut msg_nonref = (*msg).clone();
1144                                 MessageSendEvent::SendChannelRangeQuery {
1145                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1146                                         msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1147                                 }
1148                         },
1149                         nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1150                                 let mut node_id_nonref = (*node_id).clone();
1151                                 let mut msg_nonref = (*msg).clone();
1152                                 MessageSendEvent::SendShortIdsQuery {
1153                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1154                                         msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1155                                 }
1156                         },
1157                         nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1158                                 let mut node_id_nonref = (*node_id).clone();
1159                                 let mut msg_nonref = (*msg).clone();
1160                                 MessageSendEvent::SendReplyChannelRange {
1161                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1162                                         msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1163                                 }
1164                         },
1165                 }
1166         }
1167         #[allow(unused)]
1168         pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
1169                 match native {
1170                         nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1171                                 MessageSendEvent::SendAcceptChannel {
1172                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1173                                         msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1174                                 }
1175                         },
1176                         nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1177                                 MessageSendEvent::SendOpenChannel {
1178                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1179                                         msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1180                                 }
1181                         },
1182                         nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1183                                 MessageSendEvent::SendFundingCreated {
1184                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1185                                         msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
1186                                 }
1187                         },
1188                         nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1189                                 MessageSendEvent::SendFundingSigned {
1190                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1191                                         msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1192                                 }
1193                         },
1194                         nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1195                                 MessageSendEvent::SendFundingLocked {
1196                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1197                                         msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg), is_owned: true },
1198                                 }
1199                         },
1200                         nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1201                                 MessageSendEvent::SendAnnouncementSignatures {
1202                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1203                                         msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
1204                                 }
1205                         },
1206                         nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1207                                 MessageSendEvent::UpdateHTLCs {
1208                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1209                                         updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
1210                                 }
1211                         },
1212                         nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1213                                 MessageSendEvent::SendRevokeAndACK {
1214                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1215                                         msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
1216                                 }
1217                         },
1218                         nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1219                                 MessageSendEvent::SendClosingSigned {
1220                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1221                                         msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1222                                 }
1223                         },
1224                         nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1225                                 MessageSendEvent::SendShutdown {
1226                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1227                                         msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
1228                                 }
1229                         },
1230                         nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1231                                 MessageSendEvent::SendChannelReestablish {
1232                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1233                                         msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
1234                                 }
1235                         },
1236                         nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1237                                 MessageSendEvent::BroadcastChannelAnnouncement {
1238                                         msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1239                                         update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
1240                                 }
1241                         },
1242                         nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1243                                 MessageSendEvent::BroadcastNodeAnnouncement {
1244                                         msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1245                                 }
1246                         },
1247                         nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1248                                 MessageSendEvent::BroadcastChannelUpdate {
1249                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1250                                 }
1251                         },
1252                         nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1253                                 MessageSendEvent::SendChannelUpdate {
1254                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1255                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1256                                 }
1257                         },
1258                         nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1259                                 MessageSendEvent::HandleError {
1260                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1261                                         action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1262                                 }
1263                         },
1264                         nativeMessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
1265                                 MessageSendEvent::PaymentFailureNetworkUpdate {
1266                                         update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update),
1267                                 }
1268                         },
1269                         nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1270                                 MessageSendEvent::SendChannelRangeQuery {
1271                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1272                                         msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1273                                 }
1274                         },
1275                         nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1276                                 MessageSendEvent::SendShortIdsQuery {
1277                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1278                                         msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
1279                                 }
1280                         },
1281                         nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1282                                 MessageSendEvent::SendReplyChannelRange {
1283                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1284                                         msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1285                                 }
1286                         },
1287                 }
1288         }
1289 }
1290 /// Frees any resources used by the MessageSendEvent
1291 #[no_mangle]
1292 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1293 /// Creates a copy of the MessageSendEvent
1294 #[no_mangle]
1295 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1296         orig.clone()
1297 }
1298 #[no_mangle]
1299 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
1300 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
1301         MessageSendEvent::SendAcceptChannel {
1302                 node_id,
1303                 msg,
1304         }
1305 }
1306 #[no_mangle]
1307 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
1308 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
1309         MessageSendEvent::SendOpenChannel {
1310                 node_id,
1311                 msg,
1312         }
1313 }
1314 #[no_mangle]
1315 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
1316 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
1317         MessageSendEvent::SendFundingCreated {
1318                 node_id,
1319                 msg,
1320         }
1321 }
1322 #[no_mangle]
1323 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
1324 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
1325         MessageSendEvent::SendFundingSigned {
1326                 node_id,
1327                 msg,
1328         }
1329 }
1330 #[no_mangle]
1331 /// Utility method to constructs a new SendFundingLocked-variant MessageSendEvent
1332 pub extern "C" fn MessageSendEvent_send_funding_locked(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingLocked) -> MessageSendEvent {
1333         MessageSendEvent::SendFundingLocked {
1334                 node_id,
1335                 msg,
1336         }
1337 }
1338 #[no_mangle]
1339 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
1340 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
1341         MessageSendEvent::SendAnnouncementSignatures {
1342                 node_id,
1343                 msg,
1344         }
1345 }
1346 #[no_mangle]
1347 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
1348 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
1349         MessageSendEvent::UpdateHTLCs {
1350                 node_id,
1351                 updates,
1352         }
1353 }
1354 #[no_mangle]
1355 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
1356 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
1357         MessageSendEvent::SendRevokeAndACK {
1358                 node_id,
1359                 msg,
1360         }
1361 }
1362 #[no_mangle]
1363 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
1364 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
1365         MessageSendEvent::SendClosingSigned {
1366                 node_id,
1367                 msg,
1368         }
1369 }
1370 #[no_mangle]
1371 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
1372 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
1373         MessageSendEvent::SendShutdown {
1374                 node_id,
1375                 msg,
1376         }
1377 }
1378 #[no_mangle]
1379 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
1380 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
1381         MessageSendEvent::SendChannelReestablish {
1382                 node_id,
1383                 msg,
1384         }
1385 }
1386 #[no_mangle]
1387 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
1388 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1389         MessageSendEvent::BroadcastChannelAnnouncement {
1390                 msg,
1391                 update_msg,
1392         }
1393 }
1394 #[no_mangle]
1395 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
1396 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
1397         MessageSendEvent::BroadcastNodeAnnouncement {
1398                 msg,
1399         }
1400 }
1401 #[no_mangle]
1402 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
1403 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1404         MessageSendEvent::BroadcastChannelUpdate {
1405                 msg,
1406         }
1407 }
1408 #[no_mangle]
1409 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
1410 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1411         MessageSendEvent::SendChannelUpdate {
1412                 node_id,
1413                 msg,
1414         }
1415 }
1416 #[no_mangle]
1417 /// Utility method to constructs a new HandleError-variant MessageSendEvent
1418 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
1419         MessageSendEvent::HandleError {
1420                 node_id,
1421                 action,
1422         }
1423 }
1424 #[no_mangle]
1425 /// Utility method to constructs a new PaymentFailureNetworkUpdate-variant MessageSendEvent
1426 pub extern "C" fn MessageSendEvent_payment_failure_network_update(update: crate::lightning::ln::msgs::HTLCFailChannelUpdate) -> MessageSendEvent {
1427         MessageSendEvent::PaymentFailureNetworkUpdate {
1428                 update,
1429         }
1430 }
1431 #[no_mangle]
1432 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
1433 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
1434         MessageSendEvent::SendChannelRangeQuery {
1435                 node_id,
1436                 msg,
1437         }
1438 }
1439 #[no_mangle]
1440 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
1441 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
1442         MessageSendEvent::SendShortIdsQuery {
1443                 node_id,
1444                 msg,
1445         }
1446 }
1447 #[no_mangle]
1448 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
1449 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
1450         MessageSendEvent::SendReplyChannelRange {
1451                 node_id,
1452                 msg,
1453         }
1454 }
1455 /// A trait indicating an object may generate message send events
1456 #[repr(C)]
1457 pub struct MessageSendEventsProvider {
1458         /// An opaque pointer which is passed to your function implementations as an argument.
1459         /// This has no meaning in the LDK, and can be NULL or any other value.
1460         pub this_arg: *mut c_void,
1461         /// Gets the list of pending events which were generated by previous actions, clearing the list
1462         /// in the process.
1463         #[must_use]
1464         pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1465         /// Frees any resources associated with this object given its this_arg pointer.
1466         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1467         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1468 }
1469 unsafe impl Send for MessageSendEventsProvider {}
1470 unsafe impl Sync for MessageSendEventsProvider {}
1471 #[no_mangle]
1472 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
1473         MessageSendEventsProvider {
1474                 this_arg: orig.this_arg,
1475                 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
1476                 free: Clone::clone(&orig.free),
1477         }
1478 }
1479
1480 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1481 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1482         fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1483                 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1484                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1485                 local_ret
1486         }
1487 }
1488
1489 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1490 // directly as a Deref trait in higher-level structs:
1491 impl std::ops::Deref for MessageSendEventsProvider {
1492         type Target = Self;
1493         fn deref(&self) -> &Self {
1494                 self
1495         }
1496 }
1497 /// Calls the free function if one is set
1498 #[no_mangle]
1499 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1500 impl Drop for MessageSendEventsProvider {
1501         fn drop(&mut self) {
1502                 if let Some(f) = self.free {
1503                         f(self.this_arg);
1504                 }
1505         }
1506 }
1507 /// A trait indicating an object may generate events.
1508 ///
1509 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1510 ///
1511 /// # Requirements
1512 ///
1513 /// See [`process_pending_events`] for requirements around event processing.
1514 ///
1515 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1516 /// event since the last invocation. The handler must either act upon the event immediately
1517 /// or preserve it for later handling.
1518 ///
1519 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1520 /// consult the provider's documentation on the implication of processing events and how a handler
1521 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1522 /// [`ChainMonitor::process_pending_events`]).
1523 ///
1524 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1525 /// own type(s).
1526 ///
1527 /// [`process_pending_events`]: Self::process_pending_events
1528 /// [`handle_event`]: EventHandler::handle_event
1529 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1530 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1531 #[repr(C)]
1532 pub struct EventsProvider {
1533         /// An opaque pointer which is passed to your function implementations as an argument.
1534         /// This has no meaning in the LDK, and can be NULL or any other value.
1535         pub this_arg: *mut c_void,
1536         /// Processes any events generated since the last call using the given event handler.
1537         ///
1538         /// Subsequent calls must only process new events. However, handlers must be capable of handling
1539         /// duplicate events across process restarts. This may occur if the provider was recovered from
1540         /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1541         pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1542         /// Frees any resources associated with this object given its this_arg pointer.
1543         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1544         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1545 }
1546 unsafe impl Send for EventsProvider {}
1547 unsafe impl Sync for EventsProvider {}
1548 #[no_mangle]
1549 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
1550         EventsProvider {
1551                 this_arg: orig.this_arg,
1552                 process_pending_events: Clone::clone(&orig.process_pending_events),
1553                 free: Clone::clone(&orig.free),
1554         }
1555 }
1556
1557 use lightning::util::events::EventsProvider as rustEventsProvider;
1558 /// Calls the free function if one is set
1559 #[no_mangle]
1560 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1561 impl Drop for EventsProvider {
1562         fn drop(&mut self) {
1563                 if let Some(f) = self.free {
1564                         f(self.this_arg);
1565                 }
1566         }
1567 }
1568 /// A trait implemented for objects handling events from [`EventsProvider`].
1569 #[repr(C)]
1570 pub struct EventHandler {
1571         /// An opaque pointer which is passed to your function implementations as an argument.
1572         /// This has no meaning in the LDK, and can be NULL or any other value.
1573         pub this_arg: *mut c_void,
1574         /// Handles the given [`Event`].
1575         ///
1576         /// See [`EventsProvider`] for details that must be considered when implementing this method.
1577         pub handle_event: extern "C" fn (this_arg: *const c_void, event: crate::lightning::util::events::Event),
1578         /// Frees any resources associated with this object given its this_arg pointer.
1579         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1580         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1581 }
1582 unsafe impl Send for EventHandler {}
1583 unsafe impl Sync for EventHandler {}
1584 #[no_mangle]
1585 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
1586         EventHandler {
1587                 this_arg: orig.this_arg,
1588                 handle_event: Clone::clone(&orig.handle_event),
1589                 free: Clone::clone(&orig.free),
1590         }
1591 }
1592
1593 use lightning::util::events::EventHandler as rustEventHandler;
1594 impl rustEventHandler for EventHandler {
1595         fn handle_event(&self, mut event: lightning::util::events::Event) {
1596                 (self.handle_event)(self.this_arg, crate::lightning::util::events::Event::native_into(event))
1597         }
1598 }
1599
1600 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1601 // directly as a Deref trait in higher-level structs:
1602 impl std::ops::Deref for EventHandler {
1603         type Target = Self;
1604         fn deref(&self) -> &Self {
1605                 self
1606         }
1607 }
1608 /// Calls the free function if one is set
1609 #[no_mangle]
1610 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
1611 impl Drop for EventHandler {
1612         fn drop(&mut self) {
1613                 if let Some(f) = self.free {
1614                         f(self.this_arg);
1615                 }
1616         }
1617 }