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