Merge pull request #27 from TheBlueMatt/main
[ldk-c-bindings] / lightning-c-bindings / src / lightning / util / events.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! Events are returned from various bits in the library which indicate some action must be taken
10 //! by the client.
11 //!
12 //! Because we don't have a built-in runtime, it's up to the client to call events at a time in the
13 //! future, as well as generate and broadcast funding transactions handle payment preimages and a
14 //! few other things.
15
16 use std::str::FromStr;
17 use std::ffi::c_void;
18 use bitcoin::hashes::Hash;
19 use crate::c_types::*;
20
21 /// 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         /// Broadcast an error downstream to be handled
464         HandleError {
465                 /// The node_id of the node which should receive this message
466                 node_id: crate::c_types::PublicKey,
467                 /// The action which should be taken.
468                 action: crate::lightning::ln::msgs::ErrorAction,
469         },
470         /// When a payment fails we may receive updates back from the hop where it failed. In such
471         /// cases this event is generated so that we can inform the network graph of this information.
472         PaymentFailureNetworkUpdate {
473                 /// The channel/node update which should be sent to NetGraphMsgHandler
474                 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate,
475         },
476         /// Query a peer for channels with funding transaction UTXOs in a block range.
477         SendChannelRangeQuery {
478                 /// The node_id of this message recipient
479                 node_id: crate::c_types::PublicKey,
480                 /// The query_channel_range which should be sent.
481                 msg: crate::lightning::ln::msgs::QueryChannelRange,
482         },
483         /// Request routing gossip messages from a peer for a list of channels identified by
484         /// their short_channel_ids.
485         SendShortIdsQuery {
486                 /// The node_id of this message recipient
487                 node_id: crate::c_types::PublicKey,
488                 /// The query_short_channel_ids which should be sent.
489                 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
490         },
491         /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
492         /// emitted during processing of the query.
493         SendReplyChannelRange {
494                 /// The node_id of this message recipient
495                 node_id: crate::c_types::PublicKey,
496                 /// The reply_channel_range which should be sent.
497                 msg: crate::lightning::ln::msgs::ReplyChannelRange,
498         },
499 }
500 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
501 impl MessageSendEvent {
502         #[allow(unused)]
503         pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
504                 match self {
505                         MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
506                                 let mut node_id_nonref = (*node_id).clone();
507                                 let mut msg_nonref = (*msg).clone();
508                                 nativeMessageSendEvent::SendAcceptChannel {
509                                         node_id: node_id_nonref.into_rust(),
510                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
511                                 }
512                         },
513                         MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
514                                 let mut node_id_nonref = (*node_id).clone();
515                                 let mut msg_nonref = (*msg).clone();
516                                 nativeMessageSendEvent::SendOpenChannel {
517                                         node_id: node_id_nonref.into_rust(),
518                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
519                                 }
520                         },
521                         MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
522                                 let mut node_id_nonref = (*node_id).clone();
523                                 let mut msg_nonref = (*msg).clone();
524                                 nativeMessageSendEvent::SendFundingCreated {
525                                         node_id: node_id_nonref.into_rust(),
526                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
527                                 }
528                         },
529                         MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
530                                 let mut node_id_nonref = (*node_id).clone();
531                                 let mut msg_nonref = (*msg).clone();
532                                 nativeMessageSendEvent::SendFundingSigned {
533                                         node_id: node_id_nonref.into_rust(),
534                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
535                                 }
536                         },
537                         MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
538                                 let mut node_id_nonref = (*node_id).clone();
539                                 let mut msg_nonref = (*msg).clone();
540                                 nativeMessageSendEvent::SendFundingLocked {
541                                         node_id: node_id_nonref.into_rust(),
542                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
543                                 }
544                         },
545                         MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
546                                 let mut node_id_nonref = (*node_id).clone();
547                                 let mut msg_nonref = (*msg).clone();
548                                 nativeMessageSendEvent::SendAnnouncementSignatures {
549                                         node_id: node_id_nonref.into_rust(),
550                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
551                                 }
552                         },
553                         MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
554                                 let mut node_id_nonref = (*node_id).clone();
555                                 let mut updates_nonref = (*updates).clone();
556                                 nativeMessageSendEvent::UpdateHTLCs {
557                                         node_id: node_id_nonref.into_rust(),
558                                         updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
559                                 }
560                         },
561                         MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
562                                 let mut node_id_nonref = (*node_id).clone();
563                                 let mut msg_nonref = (*msg).clone();
564                                 nativeMessageSendEvent::SendRevokeAndACK {
565                                         node_id: node_id_nonref.into_rust(),
566                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
567                                 }
568                         },
569                         MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
570                                 let mut node_id_nonref = (*node_id).clone();
571                                 let mut msg_nonref = (*msg).clone();
572                                 nativeMessageSendEvent::SendClosingSigned {
573                                         node_id: node_id_nonref.into_rust(),
574                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
575                                 }
576                         },
577                         MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
578                                 let mut node_id_nonref = (*node_id).clone();
579                                 let mut msg_nonref = (*msg).clone();
580                                 nativeMessageSendEvent::SendShutdown {
581                                         node_id: node_id_nonref.into_rust(),
582                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
583                                 }
584                         },
585                         MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
586                                 let mut node_id_nonref = (*node_id).clone();
587                                 let mut msg_nonref = (*msg).clone();
588                                 nativeMessageSendEvent::SendChannelReestablish {
589                                         node_id: node_id_nonref.into_rust(),
590                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
591                                 }
592                         },
593                         MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
594                                 let mut msg_nonref = (*msg).clone();
595                                 let mut update_msg_nonref = (*update_msg).clone();
596                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
597                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
598                                         update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
599                                 }
600                         },
601                         MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
602                                 let mut msg_nonref = (*msg).clone();
603                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
604                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
605                                 }
606                         },
607                         MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
608                                 let mut msg_nonref = (*msg).clone();
609                                 nativeMessageSendEvent::BroadcastChannelUpdate {
610                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
611                                 }
612                         },
613                         MessageSendEvent::HandleError {ref node_id, ref action, } => {
614                                 let mut node_id_nonref = (*node_id).clone();
615                                 let mut action_nonref = (*action).clone();
616                                 nativeMessageSendEvent::HandleError {
617                                         node_id: node_id_nonref.into_rust(),
618                                         action: action_nonref.into_native(),
619                                 }
620                         },
621                         MessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
622                                 let mut update_nonref = (*update).clone();
623                                 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
624                                         update: update_nonref.into_native(),
625                                 }
626                         },
627                         MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
628                                 let mut node_id_nonref = (*node_id).clone();
629                                 let mut msg_nonref = (*msg).clone();
630                                 nativeMessageSendEvent::SendChannelRangeQuery {
631                                         node_id: node_id_nonref.into_rust(),
632                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
633                                 }
634                         },
635                         MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
636                                 let mut node_id_nonref = (*node_id).clone();
637                                 let mut msg_nonref = (*msg).clone();
638                                 nativeMessageSendEvent::SendShortIdsQuery {
639                                         node_id: node_id_nonref.into_rust(),
640                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
641                                 }
642                         },
643                         MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
644                                 let mut node_id_nonref = (*node_id).clone();
645                                 let mut msg_nonref = (*msg).clone();
646                                 nativeMessageSendEvent::SendReplyChannelRange {
647                                         node_id: node_id_nonref.into_rust(),
648                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
649                                 }
650                         },
651                 }
652         }
653         #[allow(unused)]
654         pub(crate) fn into_native(self) -> nativeMessageSendEvent {
655                 match self {
656                         MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
657                                 nativeMessageSendEvent::SendAcceptChannel {
658                                         node_id: node_id.into_rust(),
659                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
660                                 }
661                         },
662                         MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
663                                 nativeMessageSendEvent::SendOpenChannel {
664                                         node_id: node_id.into_rust(),
665                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
666                                 }
667                         },
668                         MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
669                                 nativeMessageSendEvent::SendFundingCreated {
670                                         node_id: node_id.into_rust(),
671                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
672                                 }
673                         },
674                         MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
675                                 nativeMessageSendEvent::SendFundingSigned {
676                                         node_id: node_id.into_rust(),
677                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
678                                 }
679                         },
680                         MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
681                                 nativeMessageSendEvent::SendFundingLocked {
682                                         node_id: node_id.into_rust(),
683                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
684                                 }
685                         },
686                         MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
687                                 nativeMessageSendEvent::SendAnnouncementSignatures {
688                                         node_id: node_id.into_rust(),
689                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
690                                 }
691                         },
692                         MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
693                                 nativeMessageSendEvent::UpdateHTLCs {
694                                         node_id: node_id.into_rust(),
695                                         updates: *unsafe { Box::from_raw(updates.take_inner()) },
696                                 }
697                         },
698                         MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
699                                 nativeMessageSendEvent::SendRevokeAndACK {
700                                         node_id: node_id.into_rust(),
701                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
702                                 }
703                         },
704                         MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
705                                 nativeMessageSendEvent::SendClosingSigned {
706                                         node_id: node_id.into_rust(),
707                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
708                                 }
709                         },
710                         MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
711                                 nativeMessageSendEvent::SendShutdown {
712                                         node_id: node_id.into_rust(),
713                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
714                                 }
715                         },
716                         MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
717                                 nativeMessageSendEvent::SendChannelReestablish {
718                                         node_id: node_id.into_rust(),
719                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
720                                 }
721                         },
722                         MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
723                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
724                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
725                                         update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
726                                 }
727                         },
728                         MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
729                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
730                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
731                                 }
732                         },
733                         MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
734                                 nativeMessageSendEvent::BroadcastChannelUpdate {
735                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
736                                 }
737                         },
738                         MessageSendEvent::HandleError {mut node_id, mut action, } => {
739                                 nativeMessageSendEvent::HandleError {
740                                         node_id: node_id.into_rust(),
741                                         action: action.into_native(),
742                                 }
743                         },
744                         MessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
745                                 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
746                                         update: update.into_native(),
747                                 }
748                         },
749                         MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
750                                 nativeMessageSendEvent::SendChannelRangeQuery {
751                                         node_id: node_id.into_rust(),
752                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
753                                 }
754                         },
755                         MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
756                                 nativeMessageSendEvent::SendShortIdsQuery {
757                                         node_id: node_id.into_rust(),
758                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
759                                 }
760                         },
761                         MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
762                                 nativeMessageSendEvent::SendReplyChannelRange {
763                                         node_id: node_id.into_rust(),
764                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
765                                 }
766                         },
767                 }
768         }
769         #[allow(unused)]
770         pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
771                 match native {
772                         nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
773                                 let mut node_id_nonref = (*node_id).clone();
774                                 let mut msg_nonref = (*msg).clone();
775                                 MessageSendEvent::SendAcceptChannel {
776                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
777                                         msg: crate::lightning::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
778                                 }
779                         },
780                         nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
781                                 let mut node_id_nonref = (*node_id).clone();
782                                 let mut msg_nonref = (*msg).clone();
783                                 MessageSendEvent::SendOpenChannel {
784                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
785                                         msg: crate::lightning::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
786                                 }
787                         },
788                         nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
789                                 let mut node_id_nonref = (*node_id).clone();
790                                 let mut msg_nonref = (*msg).clone();
791                                 MessageSendEvent::SendFundingCreated {
792                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
793                                         msg: crate::lightning::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
794                                 }
795                         },
796                         nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
797                                 let mut node_id_nonref = (*node_id).clone();
798                                 let mut msg_nonref = (*msg).clone();
799                                 MessageSendEvent::SendFundingSigned {
800                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
801                                         msg: crate::lightning::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
802                                 }
803                         },
804                         nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
805                                 let mut node_id_nonref = (*node_id).clone();
806                                 let mut msg_nonref = (*msg).clone();
807                                 MessageSendEvent::SendFundingLocked {
808                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
809                                         msg: crate::lightning::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
810                                 }
811                         },
812                         nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
813                                 let mut node_id_nonref = (*node_id).clone();
814                                 let mut msg_nonref = (*msg).clone();
815                                 MessageSendEvent::SendAnnouncementSignatures {
816                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
817                                         msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
818                                 }
819                         },
820                         nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
821                                 let mut node_id_nonref = (*node_id).clone();
822                                 let mut updates_nonref = (*updates).clone();
823                                 MessageSendEvent::UpdateHTLCs {
824                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
825                                         updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates_nonref)), is_owned: true },
826                                 }
827                         },
828                         nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
829                                 let mut node_id_nonref = (*node_id).clone();
830                                 let mut msg_nonref = (*msg).clone();
831                                 MessageSendEvent::SendRevokeAndACK {
832                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
833                                         msg: crate::lightning::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
834                                 }
835                         },
836                         nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
837                                 let mut node_id_nonref = (*node_id).clone();
838                                 let mut msg_nonref = (*msg).clone();
839                                 MessageSendEvent::SendClosingSigned {
840                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
841                                         msg: crate::lightning::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
842                                 }
843                         },
844                         nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
845                                 let mut node_id_nonref = (*node_id).clone();
846                                 let mut msg_nonref = (*msg).clone();
847                                 MessageSendEvent::SendShutdown {
848                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
849                                         msg: crate::lightning::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
850                                 }
851                         },
852                         nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
853                                 let mut node_id_nonref = (*node_id).clone();
854                                 let mut msg_nonref = (*msg).clone();
855                                 MessageSendEvent::SendChannelReestablish {
856                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
857                                         msg: crate::lightning::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
858                                 }
859                         },
860                         nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
861                                 let mut msg_nonref = (*msg).clone();
862                                 let mut update_msg_nonref = (*update_msg).clone();
863                                 MessageSendEvent::BroadcastChannelAnnouncement {
864                                         msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
865                                         update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg_nonref)), is_owned: true },
866                                 }
867                         },
868                         nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
869                                 let mut msg_nonref = (*msg).clone();
870                                 MessageSendEvent::BroadcastNodeAnnouncement {
871                                         msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
872                                 }
873                         },
874                         nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
875                                 let mut msg_nonref = (*msg).clone();
876                                 MessageSendEvent::BroadcastChannelUpdate {
877                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
878                                 }
879                         },
880                         nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
881                                 let mut node_id_nonref = (*node_id).clone();
882                                 let mut action_nonref = (*action).clone();
883                                 MessageSendEvent::HandleError {
884                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
885                                         action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
886                                 }
887                         },
888                         nativeMessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
889                                 let mut update_nonref = (*update).clone();
890                                 MessageSendEvent::PaymentFailureNetworkUpdate {
891                                         update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update_nonref),
892                                 }
893                         },
894                         nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
895                                 let mut node_id_nonref = (*node_id).clone();
896                                 let mut msg_nonref = (*msg).clone();
897                                 MessageSendEvent::SendChannelRangeQuery {
898                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
899                                         msg: crate::lightning::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
900                                 }
901                         },
902                         nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
903                                 let mut node_id_nonref = (*node_id).clone();
904                                 let mut msg_nonref = (*msg).clone();
905                                 MessageSendEvent::SendShortIdsQuery {
906                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
907                                         msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
908                                 }
909                         },
910                         nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
911                                 let mut node_id_nonref = (*node_id).clone();
912                                 let mut msg_nonref = (*msg).clone();
913                                 MessageSendEvent::SendReplyChannelRange {
914                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
915                                         msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
916                                 }
917                         },
918                 }
919         }
920         #[allow(unused)]
921         pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
922                 match native {
923                         nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
924                                 MessageSendEvent::SendAcceptChannel {
925                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
926                                         msg: crate::lightning::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
927                                 }
928                         },
929                         nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
930                                 MessageSendEvent::SendOpenChannel {
931                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
932                                         msg: crate::lightning::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
933                                 }
934                         },
935                         nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
936                                 MessageSendEvent::SendFundingCreated {
937                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
938                                         msg: crate::lightning::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg)), is_owned: true },
939                                 }
940                         },
941                         nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
942                                 MessageSendEvent::SendFundingSigned {
943                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
944                                         msg: crate::lightning::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
945                                 }
946                         },
947                         nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
948                                 MessageSendEvent::SendFundingLocked {
949                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
950                                         msg: crate::lightning::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg)), is_owned: true },
951                                 }
952                         },
953                         nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
954                                 MessageSendEvent::SendAnnouncementSignatures {
955                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
956                                         msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg)), is_owned: true },
957                                 }
958                         },
959                         nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
960                                 MessageSendEvent::UpdateHTLCs {
961                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
962                                         updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates)), is_owned: true },
963                                 }
964                         },
965                         nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
966                                 MessageSendEvent::SendRevokeAndACK {
967                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
968                                         msg: crate::lightning::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg)), is_owned: true },
969                                 }
970                         },
971                         nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
972                                 MessageSendEvent::SendClosingSigned {
973                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
974                                         msg: crate::lightning::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
975                                 }
976                         },
977                         nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
978                                 MessageSendEvent::SendShutdown {
979                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
980                                         msg: crate::lightning::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg)), is_owned: true },
981                                 }
982                         },
983                         nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
984                                 MessageSendEvent::SendChannelReestablish {
985                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
986                                         msg: crate::lightning::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg)), is_owned: true },
987                                 }
988                         },
989                         nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
990                                 MessageSendEvent::BroadcastChannelAnnouncement {
991                                         msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
992                                         update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg)), is_owned: true },
993                                 }
994                         },
995                         nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
996                                 MessageSendEvent::BroadcastNodeAnnouncement {
997                                         msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
998                                 }
999                         },
1000                         nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1001                                 MessageSendEvent::BroadcastChannelUpdate {
1002                                         msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1003                                 }
1004                         },
1005                         nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1006                                 MessageSendEvent::HandleError {
1007                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1008                                         action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1009                                 }
1010                         },
1011                         nativeMessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
1012                                 MessageSendEvent::PaymentFailureNetworkUpdate {
1013                                         update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update),
1014                                 }
1015                         },
1016                         nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1017                                 MessageSendEvent::SendChannelRangeQuery {
1018                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1019                                         msg: crate::lightning::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1020                                 }
1021                         },
1022                         nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1023                                 MessageSendEvent::SendShortIdsQuery {
1024                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1025                                         msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1026                                 }
1027                         },
1028                         nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1029                                 MessageSendEvent::SendReplyChannelRange {
1030                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1031                                         msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1032                                 }
1033                         },
1034                 }
1035         }
1036 }
1037 /// Frees any resources used by the MessageSendEvent
1038 #[no_mangle]
1039 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1040 /// Creates a copy of the MessageSendEvent
1041 #[no_mangle]
1042 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1043         orig.clone()
1044 }
1045 /// A trait indicating an object may generate message send events
1046 #[repr(C)]
1047 pub struct MessageSendEventsProvider {
1048         /// An opaque pointer which is passed to your function implementations as an argument.
1049         /// This has no meaning in the LDK, and can be NULL or any other value.
1050         pub this_arg: *mut c_void,
1051         /// Gets the list of pending events which were generated by previous actions, clearing the list
1052         /// in the process.
1053         #[must_use]
1054         pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1055         /// Frees any resources associated with this object given its this_arg pointer.
1056         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1057         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1058 }
1059 unsafe impl Send for MessageSendEventsProvider {}
1060 unsafe impl Sync for MessageSendEventsProvider {}
1061
1062 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1063 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1064         fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1065                 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1066                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1067                 local_ret
1068         }
1069 }
1070
1071 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1072 // directly as a Deref trait in higher-level structs:
1073 impl std::ops::Deref for MessageSendEventsProvider {
1074         type Target = Self;
1075         fn deref(&self) -> &Self {
1076                 self
1077         }
1078 }
1079 /// Calls the free function if one is set
1080 #[no_mangle]
1081 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1082 impl Drop for MessageSendEventsProvider {
1083         fn drop(&mut self) {
1084                 if let Some(f) = self.free {
1085                         f(self.this_arg);
1086                 }
1087         }
1088 }
1089 /// A trait indicating an object may generate events.
1090 ///
1091 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1092 ///
1093 /// # Requirements
1094 ///
1095 /// See [`process_pending_events`] for requirements around event processing.
1096 ///
1097 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1098 /// event since the last invocation. The handler must either act upon the event immediately
1099 /// or preserve it for later handling.
1100 ///
1101 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1102 /// consult the provider's documentation on the implication of processing events and how a handler
1103 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1104 /// [`ChainMonitor::process_pending_events`]).
1105 ///
1106 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1107 /// own type(s).
1108 ///
1109 /// [`process_pending_events`]: Self::process_pending_events
1110 /// [`handle_event`]: EventHandler::handle_event
1111 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1112 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1113 #[repr(C)]
1114 pub struct EventsProvider {
1115         /// An opaque pointer which is passed to your function implementations as an argument.
1116         /// This has no meaning in the LDK, and can be NULL or any other value.
1117         pub this_arg: *mut c_void,
1118         /// Processes any events generated since the last call using the given event handler.
1119         ///
1120         /// Subsequent calls must only process new events. However, handlers must be capable of handling
1121         /// duplicate events across process restarts. This may occur if the provider was recovered from
1122         /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1123         pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1124         /// Frees any resources associated with this object given its this_arg pointer.
1125         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1126         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1127 }
1128 unsafe impl Send for EventsProvider {}
1129 unsafe impl Sync for EventsProvider {}
1130
1131 use lightning::util::events::EventsProvider as rustEventsProvider;
1132 /// Calls the free function if one is set
1133 #[no_mangle]
1134 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1135 impl Drop for EventsProvider {
1136         fn drop(&mut self) {
1137                 if let Some(f) = self.free {
1138                         f(self.this_arg);
1139                 }
1140         }
1141 }
1142 /// A trait implemented for objects handling events from [`EventsProvider`].
1143 #[repr(C)]
1144 pub struct EventHandler {
1145         /// An opaque pointer which is passed to your function implementations as an argument.
1146         /// This has no meaning in the LDK, and can be NULL or any other value.
1147         pub this_arg: *mut c_void,
1148         /// Handles the given [`Event`].
1149         ///
1150         /// See [`EventsProvider`] for details that must be considered when implementing this method.
1151         pub handle_event: extern "C" fn (this_arg: *const c_void, event: crate::lightning::util::events::Event),
1152         /// Frees any resources associated with this object given its this_arg pointer.
1153         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1154         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1155 }
1156 unsafe impl Send for EventHandler {}
1157 unsafe impl Sync for EventHandler {}
1158
1159 use lightning::util::events::EventHandler as rustEventHandler;
1160 impl rustEventHandler for EventHandler {
1161         fn handle_event(&self, mut event: lightning::util::events::Event) {
1162                 (self.handle_event)(self.this_arg, crate::lightning::util::events::Event::native_into(event))
1163         }
1164 }
1165
1166 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1167 // directly as a Deref trait in higher-level structs:
1168 impl std::ops::Deref for EventHandler {
1169         type Target = Self;
1170         fn deref(&self) -> &Self {
1171                 self
1172         }
1173 }
1174 /// Calls the free function if one is set
1175 #[no_mangle]
1176 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
1177 impl Drop for EventHandler {
1178         fn drop(&mut self) {
1179                 if let Some(f) = self.free {
1180                         f(self.this_arg);
1181                 }
1182         }
1183 }