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