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