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