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