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