Rebuild against current RL main
[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                 /// The random channel_id we picked which you'll need to pass into
28                 /// ChannelManager::funding_transaction_generated.
29                 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
30                 /// The value, in satoshis, that the output should have.
31                 channel_value_satoshis: u64,
32                 /// The script which should be used in the transaction output.
33                 output_script: crate::c_types::derived::CVec_u8Z,
34                 /// The value passed in to ChannelManager::create_channel
35                 user_channel_id: u64,
36         },
37         /// Used to indicate that the client may now broadcast the funding transaction it created for a
38         /// channel. Broadcasting such a transaction prior to this event may lead to our counterparty
39         /// trivially stealing all funds in the funding transaction!
40         FundingBroadcastSafe {
41                 /// The output, which was passed to ChannelManager::funding_transaction_generated, which is
42                 /// now safe to broadcast.
43                 funding_txo: crate::chain::transaction::OutPoint,
44                 /// The value passed in to ChannelManager::create_channel
45                 user_channel_id: u64,
46         },
47         /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
48         /// ChannelManager::claim_funds to get it....
49         /// Note that if the preimage is not known or the amount paid is incorrect, you should call
50         /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid
51         /// network congestion.
52         /// The amount paid should be considered 'incorrect' when it is less than or more than twice
53         /// the amount expected.
54         /// If you fail to call either ChannelManager::claim_funds or
55         /// ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be
56         /// automatically failed.
57         PaymentReceived {
58                 /// The hash for which the preimage should be handed to the ChannelManager.
59                 payment_hash: crate::c_types::ThirtyTwoBytes,
60                 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
61                 /// number of deanonymization attacks during the routing process.
62                 /// As nodes upgrade, the invoices you provide should likely migrate to setting the
63                 /// payment_secret feature to required, at which point you should fail_backwards any HTLCs
64                 /// which have a None here.
65                 /// Until then, however, values of None should be ignored, and only incorrect Some values
66                 /// should result in an HTLC fail_backwards.
67                 /// Note that, in any case, this value must be passed as-is to any fail or claim calls as
68                 /// the HTLC index includes this value.
69                 payment_secret: crate::c_types::ThirtyTwoBytes,
70                 /// The value, in thousandths of a satoshi, that this payment is for. Note that you must
71                 /// compare this to the expected value before accepting the payment (as otherwise you are
72                 /// providing proof-of-payment for less than the value you expected!).
73                 amt: u64,
74         },
75         /// Indicates an outbound payment we made succeeded (ie it made it all the way to its target
76         /// and we got back the payment preimage for it).
77         /// Note that duplicative PaymentSent Events may be generated - it is your responsibility to
78         /// deduplicate them by payment_preimage (which MUST be unique)!
79         PaymentSent {
80                 /// The preimage to the hash given to ChannelManager::send_payment.
81                 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
82                 /// store it somehow!
83                 payment_preimage: crate::c_types::ThirtyTwoBytes,
84         },
85         /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
86         /// something. You may wish to retry with a different route.
87         /// Note that duplicative PaymentFailed Events may be generated - it is your responsibility to
88         /// deduplicate them by payment_hash (which MUST be unique)!
89         PaymentFailed {
90                 /// The hash which was given to ChannelManager::send_payment.
91                 payment_hash: crate::c_types::ThirtyTwoBytes,
92                 /// Indicates the payment was rejected for some reason by the recipient. This implies that
93                 /// the payment has failed, not just the route in question. If this is not set, you may
94                 /// retry the payment via a different route.
95                 rejected_by_dest: bool,
96         },
97         /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
98         /// time in the future.
99         PendingHTLCsForwardable {
100                 /// The minimum amount of time that should be waited prior to calling
101                 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
102                 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
103                 /// now + 5*time_forwardable).
104                 time_forwardable: u64,
105         },
106         /// Used to indicate that an output was generated on-chain which you should know how to spend.
107         /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
108         /// counterparty spending them due to some kind of timeout. Thus, you need to store them
109         /// somewhere and spend them when you create on-chain transactions.
110         SpendableOutputs {
111                 /// The outputs which you should store as spendable by you.
112                 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
113         },
114 }
115 use lightning::util::events::Event as nativeEvent;
116 impl Event {
117         #[allow(unused)]
118         pub(crate) fn to_native(&self) -> nativeEvent {
119                 match self {
120                         Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
121                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
122                                 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
123                                 let mut output_script_nonref = (*output_script).clone();
124                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
125                                 nativeEvent::FundingGenerationReady {
126                                         temporary_channel_id: temporary_channel_id_nonref.data,
127                                         channel_value_satoshis: channel_value_satoshis_nonref,
128                                         output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
129                                         user_channel_id: user_channel_id_nonref,
130                                 }
131                         },
132                         Event::FundingBroadcastSafe {ref funding_txo, ref user_channel_id, } => {
133                                 let mut funding_txo_nonref = (*funding_txo).clone();
134                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
135                                 nativeEvent::FundingBroadcastSafe {
136                                         funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
137                                         user_channel_id: user_channel_id_nonref,
138                                 }
139                         },
140                         Event::PaymentReceived {ref payment_hash, ref payment_secret, ref amt, } => {
141                                 let mut payment_hash_nonref = (*payment_hash).clone();
142                                 let mut payment_secret_nonref = (*payment_secret).clone();
143                                 let mut local_payment_secret_nonref = if payment_secret_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret_nonref.data) }) };
144                                 let mut amt_nonref = (*amt).clone();
145                                 nativeEvent::PaymentReceived {
146                                         payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash_nonref.data),
147                                         payment_secret: local_payment_secret_nonref,
148                                         amt: amt_nonref,
149                                 }
150                         },
151                         Event::PaymentSent {ref payment_preimage, } => {
152                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
153                                 nativeEvent::PaymentSent {
154                                         payment_preimage: ::lightning::ln::channelmanager::PaymentPreimage(payment_preimage_nonref.data),
155                                 }
156                         },
157                         Event::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
158                                 let mut payment_hash_nonref = (*payment_hash).clone();
159                                 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
160                                 nativeEvent::PaymentFailed {
161                                         payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash_nonref.data),
162                                         rejected_by_dest: rejected_by_dest_nonref,
163                                 }
164                         },
165                         Event::PendingHTLCsForwardable {ref time_forwardable, } => {
166                                 let mut time_forwardable_nonref = (*time_forwardable).clone();
167                                 nativeEvent::PendingHTLCsForwardable {
168                                         time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
169                                 }
170                         },
171                         Event::SpendableOutputs {ref outputs, } => {
172                                 let mut outputs_nonref = (*outputs).clone();
173                                 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
174                                 nativeEvent::SpendableOutputs {
175                                         outputs: local_outputs_nonref,
176                                 }
177                         },
178                 }
179         }
180         #[allow(unused)]
181         pub(crate) fn into_native(self) -> nativeEvent {
182                 match self {
183                         Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
184                                 nativeEvent::FundingGenerationReady {
185                                         temporary_channel_id: temporary_channel_id.data,
186                                         channel_value_satoshis: channel_value_satoshis,
187                                         output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
188                                         user_channel_id: user_channel_id,
189                                 }
190                         },
191                         Event::FundingBroadcastSafe {mut funding_txo, mut user_channel_id, } => {
192                                 nativeEvent::FundingBroadcastSafe {
193                                         funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
194                                         user_channel_id: user_channel_id,
195                                 }
196                         },
197                         Event::PaymentReceived {mut payment_hash, mut payment_secret, mut amt, } => {
198                                 let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
199                                 nativeEvent::PaymentReceived {
200                                         payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash.data),
201                                         payment_secret: local_payment_secret,
202                                         amt: amt,
203                                 }
204                         },
205                         Event::PaymentSent {mut payment_preimage, } => {
206                                 nativeEvent::PaymentSent {
207                                         payment_preimage: ::lightning::ln::channelmanager::PaymentPreimage(payment_preimage.data),
208                                 }
209                         },
210                         Event::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
211                                 nativeEvent::PaymentFailed {
212                                         payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash.data),
213                                         rejected_by_dest: rejected_by_dest,
214                                 }
215                         },
216                         Event::PendingHTLCsForwardable {mut time_forwardable, } => {
217                                 nativeEvent::PendingHTLCsForwardable {
218                                         time_forwardable: std::time::Duration::from_secs(time_forwardable),
219                                 }
220                         },
221                         Event::SpendableOutputs {mut outputs, } => {
222                                 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
223                                 nativeEvent::SpendableOutputs {
224                                         outputs: local_outputs,
225                                 }
226                         },
227                 }
228         }
229         #[allow(unused)]
230         pub(crate) fn from_native(native: &nativeEvent) -> Self {
231                 match native {
232                         nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
233                                 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
234                                 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
235                                 let mut output_script_nonref = (*output_script).clone();
236                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
237                                 Event::FundingGenerationReady {
238                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
239                                         channel_value_satoshis: channel_value_satoshis_nonref,
240                                         output_script: output_script_nonref.into_bytes().into(),
241                                         user_channel_id: user_channel_id_nonref,
242                                 }
243                         },
244                         nativeEvent::FundingBroadcastSafe {ref funding_txo, ref user_channel_id, } => {
245                                 let mut funding_txo_nonref = (*funding_txo).clone();
246                                 let mut user_channel_id_nonref = (*user_channel_id).clone();
247                                 Event::FundingBroadcastSafe {
248                                         funding_txo: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo_nonref)), is_owned: true },
249                                         user_channel_id: user_channel_id_nonref,
250                                 }
251                         },
252                         nativeEvent::PaymentReceived {ref payment_hash, ref payment_secret, ref amt, } => {
253                                 let mut payment_hash_nonref = (*payment_hash).clone();
254                                 let mut payment_secret_nonref = (*payment_secret).clone();
255                                 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 } } };
256                                 let mut amt_nonref = (*amt).clone();
257                                 Event::PaymentReceived {
258                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
259                                         payment_secret: local_payment_secret_nonref,
260                                         amt: amt_nonref,
261                                 }
262                         },
263                         nativeEvent::PaymentSent {ref payment_preimage, } => {
264                                 let mut payment_preimage_nonref = (*payment_preimage).clone();
265                                 Event::PaymentSent {
266                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
267                                 }
268                         },
269                         nativeEvent::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
270                                 let mut payment_hash_nonref = (*payment_hash).clone();
271                                 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
272                                 Event::PaymentFailed {
273                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
274                                         rejected_by_dest: rejected_by_dest_nonref,
275                                 }
276                         },
277                         nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
278                                 let mut time_forwardable_nonref = (*time_forwardable).clone();
279                                 Event::PendingHTLCsForwardable {
280                                         time_forwardable: time_forwardable_nonref.as_secs(),
281                                 }
282                         },
283                         nativeEvent::SpendableOutputs {ref outputs, } => {
284                                 let mut outputs_nonref = (*outputs).clone();
285                                 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) }); };
286                                 Event::SpendableOutputs {
287                                         outputs: local_outputs_nonref.into(),
288                                 }
289                         },
290                 }
291         }
292         #[allow(unused)]
293         pub(crate) fn native_into(native: nativeEvent) -> Self {
294                 match native {
295                         nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
296                                 Event::FundingGenerationReady {
297                                         temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
298                                         channel_value_satoshis: channel_value_satoshis,
299                                         output_script: output_script.into_bytes().into(),
300                                         user_channel_id: user_channel_id,
301                                 }
302                         },
303                         nativeEvent::FundingBroadcastSafe {mut funding_txo, mut user_channel_id, } => {
304                                 Event::FundingBroadcastSafe {
305                                         funding_txo: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true },
306                                         user_channel_id: user_channel_id,
307                                 }
308                         },
309                         nativeEvent::PaymentReceived {mut payment_hash, mut payment_secret, mut amt, } => {
310                                 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 } } };
311                                 Event::PaymentReceived {
312                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
313                                         payment_secret: local_payment_secret,
314                                         amt: amt,
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::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::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::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::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::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::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::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::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::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::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::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::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::ln::msgs::ChannelAnnouncement,
453                 /// The followup channel_update which should be sent.
454                 update_msg: crate::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::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::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::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::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::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::ln::msgs::QueryShortChannelIds,
493         },
494 }
495 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
496 impl MessageSendEvent {
497         #[allow(unused)]
498         pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
499                 match self {
500                         MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
501                                 let mut node_id_nonref = (*node_id).clone();
502                                 let mut msg_nonref = (*msg).clone();
503                                 nativeMessageSendEvent::SendAcceptChannel {
504                                         node_id: node_id_nonref.into_rust(),
505                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
506                                 }
507                         },
508                         MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
509                                 let mut node_id_nonref = (*node_id).clone();
510                                 let mut msg_nonref = (*msg).clone();
511                                 nativeMessageSendEvent::SendOpenChannel {
512                                         node_id: node_id_nonref.into_rust(),
513                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
514                                 }
515                         },
516                         MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
517                                 let mut node_id_nonref = (*node_id).clone();
518                                 let mut msg_nonref = (*msg).clone();
519                                 nativeMessageSendEvent::SendFundingCreated {
520                                         node_id: node_id_nonref.into_rust(),
521                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
522                                 }
523                         },
524                         MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
525                                 let mut node_id_nonref = (*node_id).clone();
526                                 let mut msg_nonref = (*msg).clone();
527                                 nativeMessageSendEvent::SendFundingSigned {
528                                         node_id: node_id_nonref.into_rust(),
529                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
530                                 }
531                         },
532                         MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
533                                 let mut node_id_nonref = (*node_id).clone();
534                                 let mut msg_nonref = (*msg).clone();
535                                 nativeMessageSendEvent::SendFundingLocked {
536                                         node_id: node_id_nonref.into_rust(),
537                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
538                                 }
539                         },
540                         MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
541                                 let mut node_id_nonref = (*node_id).clone();
542                                 let mut msg_nonref = (*msg).clone();
543                                 nativeMessageSendEvent::SendAnnouncementSignatures {
544                                         node_id: node_id_nonref.into_rust(),
545                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
546                                 }
547                         },
548                         MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
549                                 let mut node_id_nonref = (*node_id).clone();
550                                 let mut updates_nonref = (*updates).clone();
551                                 nativeMessageSendEvent::UpdateHTLCs {
552                                         node_id: node_id_nonref.into_rust(),
553                                         updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
554                                 }
555                         },
556                         MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
557                                 let mut node_id_nonref = (*node_id).clone();
558                                 let mut msg_nonref = (*msg).clone();
559                                 nativeMessageSendEvent::SendRevokeAndACK {
560                                         node_id: node_id_nonref.into_rust(),
561                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
562                                 }
563                         },
564                         MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
565                                 let mut node_id_nonref = (*node_id).clone();
566                                 let mut msg_nonref = (*msg).clone();
567                                 nativeMessageSendEvent::SendClosingSigned {
568                                         node_id: node_id_nonref.into_rust(),
569                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
570                                 }
571                         },
572                         MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
573                                 let mut node_id_nonref = (*node_id).clone();
574                                 let mut msg_nonref = (*msg).clone();
575                                 nativeMessageSendEvent::SendShutdown {
576                                         node_id: node_id_nonref.into_rust(),
577                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
578                                 }
579                         },
580                         MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
581                                 let mut node_id_nonref = (*node_id).clone();
582                                 let mut msg_nonref = (*msg).clone();
583                                 nativeMessageSendEvent::SendChannelReestablish {
584                                         node_id: node_id_nonref.into_rust(),
585                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
586                                 }
587                         },
588                         MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
589                                 let mut msg_nonref = (*msg).clone();
590                                 let mut update_msg_nonref = (*update_msg).clone();
591                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
592                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
593                                         update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
594                                 }
595                         },
596                         MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
597                                 let mut msg_nonref = (*msg).clone();
598                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
599                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
600                                 }
601                         },
602                         MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
603                                 let mut msg_nonref = (*msg).clone();
604                                 nativeMessageSendEvent::BroadcastChannelUpdate {
605                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
606                                 }
607                         },
608                         MessageSendEvent::HandleError {ref node_id, ref action, } => {
609                                 let mut node_id_nonref = (*node_id).clone();
610                                 let mut action_nonref = (*action).clone();
611                                 nativeMessageSendEvent::HandleError {
612                                         node_id: node_id_nonref.into_rust(),
613                                         action: action_nonref.into_native(),
614                                 }
615                         },
616                         MessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
617                                 let mut update_nonref = (*update).clone();
618                                 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
619                                         update: update_nonref.into_native(),
620                                 }
621                         },
622                         MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
623                                 let mut node_id_nonref = (*node_id).clone();
624                                 let mut msg_nonref = (*msg).clone();
625                                 nativeMessageSendEvent::SendChannelRangeQuery {
626                                         node_id: node_id_nonref.into_rust(),
627                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
628                                 }
629                         },
630                         MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
631                                 let mut node_id_nonref = (*node_id).clone();
632                                 let mut msg_nonref = (*msg).clone();
633                                 nativeMessageSendEvent::SendShortIdsQuery {
634                                         node_id: node_id_nonref.into_rust(),
635                                         msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
636                                 }
637                         },
638                 }
639         }
640         #[allow(unused)]
641         pub(crate) fn into_native(self) -> nativeMessageSendEvent {
642                 match self {
643                         MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
644                                 nativeMessageSendEvent::SendAcceptChannel {
645                                         node_id: node_id.into_rust(),
646                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
647                                 }
648                         },
649                         MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
650                                 nativeMessageSendEvent::SendOpenChannel {
651                                         node_id: node_id.into_rust(),
652                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
653                                 }
654                         },
655                         MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
656                                 nativeMessageSendEvent::SendFundingCreated {
657                                         node_id: node_id.into_rust(),
658                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
659                                 }
660                         },
661                         MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
662                                 nativeMessageSendEvent::SendFundingSigned {
663                                         node_id: node_id.into_rust(),
664                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
665                                 }
666                         },
667                         MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
668                                 nativeMessageSendEvent::SendFundingLocked {
669                                         node_id: node_id.into_rust(),
670                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
671                                 }
672                         },
673                         MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
674                                 nativeMessageSendEvent::SendAnnouncementSignatures {
675                                         node_id: node_id.into_rust(),
676                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
677                                 }
678                         },
679                         MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
680                                 nativeMessageSendEvent::UpdateHTLCs {
681                                         node_id: node_id.into_rust(),
682                                         updates: *unsafe { Box::from_raw(updates.take_inner()) },
683                                 }
684                         },
685                         MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
686                                 nativeMessageSendEvent::SendRevokeAndACK {
687                                         node_id: node_id.into_rust(),
688                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
689                                 }
690                         },
691                         MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
692                                 nativeMessageSendEvent::SendClosingSigned {
693                                         node_id: node_id.into_rust(),
694                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
695                                 }
696                         },
697                         MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
698                                 nativeMessageSendEvent::SendShutdown {
699                                         node_id: node_id.into_rust(),
700                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
701                                 }
702                         },
703                         MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
704                                 nativeMessageSendEvent::SendChannelReestablish {
705                                         node_id: node_id.into_rust(),
706                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
707                                 }
708                         },
709                         MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
710                                 nativeMessageSendEvent::BroadcastChannelAnnouncement {
711                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
712                                         update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
713                                 }
714                         },
715                         MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
716                                 nativeMessageSendEvent::BroadcastNodeAnnouncement {
717                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
718                                 }
719                         },
720                         MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
721                                 nativeMessageSendEvent::BroadcastChannelUpdate {
722                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
723                                 }
724                         },
725                         MessageSendEvent::HandleError {mut node_id, mut action, } => {
726                                 nativeMessageSendEvent::HandleError {
727                                         node_id: node_id.into_rust(),
728                                         action: action.into_native(),
729                                 }
730                         },
731                         MessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
732                                 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
733                                         update: update.into_native(),
734                                 }
735                         },
736                         MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
737                                 nativeMessageSendEvent::SendChannelRangeQuery {
738                                         node_id: node_id.into_rust(),
739                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
740                                 }
741                         },
742                         MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
743                                 nativeMessageSendEvent::SendShortIdsQuery {
744                                         node_id: node_id.into_rust(),
745                                         msg: *unsafe { Box::from_raw(msg.take_inner()) },
746                                 }
747                         },
748                 }
749         }
750         #[allow(unused)]
751         pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
752                 match native {
753                         nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
754                                 let mut node_id_nonref = (*node_id).clone();
755                                 let mut msg_nonref = (*msg).clone();
756                                 MessageSendEvent::SendAcceptChannel {
757                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
758                                         msg: crate::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
759                                 }
760                         },
761                         nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
762                                 let mut node_id_nonref = (*node_id).clone();
763                                 let mut msg_nonref = (*msg).clone();
764                                 MessageSendEvent::SendOpenChannel {
765                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
766                                         msg: crate::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
767                                 }
768                         },
769                         nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
770                                 let mut node_id_nonref = (*node_id).clone();
771                                 let mut msg_nonref = (*msg).clone();
772                                 MessageSendEvent::SendFundingCreated {
773                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
774                                         msg: crate::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
775                                 }
776                         },
777                         nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
778                                 let mut node_id_nonref = (*node_id).clone();
779                                 let mut msg_nonref = (*msg).clone();
780                                 MessageSendEvent::SendFundingSigned {
781                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
782                                         msg: crate::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
783                                 }
784                         },
785                         nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
786                                 let mut node_id_nonref = (*node_id).clone();
787                                 let mut msg_nonref = (*msg).clone();
788                                 MessageSendEvent::SendFundingLocked {
789                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
790                                         msg: crate::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
791                                 }
792                         },
793                         nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
794                                 let mut node_id_nonref = (*node_id).clone();
795                                 let mut msg_nonref = (*msg).clone();
796                                 MessageSendEvent::SendAnnouncementSignatures {
797                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
798                                         msg: crate::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
799                                 }
800                         },
801                         nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
802                                 let mut node_id_nonref = (*node_id).clone();
803                                 let mut updates_nonref = (*updates).clone();
804                                 MessageSendEvent::UpdateHTLCs {
805                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
806                                         updates: crate::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates_nonref)), is_owned: true },
807                                 }
808                         },
809                         nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
810                                 let mut node_id_nonref = (*node_id).clone();
811                                 let mut msg_nonref = (*msg).clone();
812                                 MessageSendEvent::SendRevokeAndACK {
813                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
814                                         msg: crate::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
815                                 }
816                         },
817                         nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
818                                 let mut node_id_nonref = (*node_id).clone();
819                                 let mut msg_nonref = (*msg).clone();
820                                 MessageSendEvent::SendClosingSigned {
821                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
822                                         msg: crate::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
823                                 }
824                         },
825                         nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
826                                 let mut node_id_nonref = (*node_id).clone();
827                                 let mut msg_nonref = (*msg).clone();
828                                 MessageSendEvent::SendShutdown {
829                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
830                                         msg: crate::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
831                                 }
832                         },
833                         nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
834                                 let mut node_id_nonref = (*node_id).clone();
835                                 let mut msg_nonref = (*msg).clone();
836                                 MessageSendEvent::SendChannelReestablish {
837                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
838                                         msg: crate::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
839                                 }
840                         },
841                         nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
842                                 let mut msg_nonref = (*msg).clone();
843                                 let mut update_msg_nonref = (*update_msg).clone();
844                                 MessageSendEvent::BroadcastChannelAnnouncement {
845                                         msg: crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
846                                         update_msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg_nonref)), is_owned: true },
847                                 }
848                         },
849                         nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
850                                 let mut msg_nonref = (*msg).clone();
851                                 MessageSendEvent::BroadcastNodeAnnouncement {
852                                         msg: crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
853                                 }
854                         },
855                         nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
856                                 let mut msg_nonref = (*msg).clone();
857                                 MessageSendEvent::BroadcastChannelUpdate {
858                                         msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
859                                 }
860                         },
861                         nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
862                                 let mut node_id_nonref = (*node_id).clone();
863                                 let mut action_nonref = (*action).clone();
864                                 MessageSendEvent::HandleError {
865                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
866                                         action: crate::ln::msgs::ErrorAction::native_into(action_nonref),
867                                 }
868                         },
869                         nativeMessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
870                                 let mut update_nonref = (*update).clone();
871                                 MessageSendEvent::PaymentFailureNetworkUpdate {
872                                         update: crate::ln::msgs::HTLCFailChannelUpdate::native_into(update_nonref),
873                                 }
874                         },
875                         nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
876                                 let mut node_id_nonref = (*node_id).clone();
877                                 let mut msg_nonref = (*msg).clone();
878                                 MessageSendEvent::SendChannelRangeQuery {
879                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
880                                         msg: crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
881                                 }
882                         },
883                         nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
884                                 let mut node_id_nonref = (*node_id).clone();
885                                 let mut msg_nonref = (*msg).clone();
886                                 MessageSendEvent::SendShortIdsQuery {
887                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
888                                         msg: crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
889                                 }
890                         },
891                 }
892         }
893         #[allow(unused)]
894         pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
895                 match native {
896                         nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
897                                 MessageSendEvent::SendAcceptChannel {
898                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
899                                         msg: crate::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
900                                 }
901                         },
902                         nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
903                                 MessageSendEvent::SendOpenChannel {
904                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
905                                         msg: crate::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
906                                 }
907                         },
908                         nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
909                                 MessageSendEvent::SendFundingCreated {
910                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
911                                         msg: crate::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg)), is_owned: true },
912                                 }
913                         },
914                         nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
915                                 MessageSendEvent::SendFundingSigned {
916                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
917                                         msg: crate::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
918                                 }
919                         },
920                         nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
921                                 MessageSendEvent::SendFundingLocked {
922                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
923                                         msg: crate::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg)), is_owned: true },
924                                 }
925                         },
926                         nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
927                                 MessageSendEvent::SendAnnouncementSignatures {
928                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
929                                         msg: crate::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg)), is_owned: true },
930                                 }
931                         },
932                         nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
933                                 MessageSendEvent::UpdateHTLCs {
934                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
935                                         updates: crate::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates)), is_owned: true },
936                                 }
937                         },
938                         nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
939                                 MessageSendEvent::SendRevokeAndACK {
940                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
941                                         msg: crate::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg)), is_owned: true },
942                                 }
943                         },
944                         nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
945                                 MessageSendEvent::SendClosingSigned {
946                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
947                                         msg: crate::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
948                                 }
949                         },
950                         nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
951                                 MessageSendEvent::SendShutdown {
952                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
953                                         msg: crate::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg)), is_owned: true },
954                                 }
955                         },
956                         nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
957                                 MessageSendEvent::SendChannelReestablish {
958                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
959                                         msg: crate::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg)), is_owned: true },
960                                 }
961                         },
962                         nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
963                                 MessageSendEvent::BroadcastChannelAnnouncement {
964                                         msg: crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
965                                         update_msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg)), is_owned: true },
966                                 }
967                         },
968                         nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
969                                 MessageSendEvent::BroadcastNodeAnnouncement {
970                                         msg: crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
971                                 }
972                         },
973                         nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
974                                 MessageSendEvent::BroadcastChannelUpdate {
975                                         msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg)), is_owned: true },
976                                 }
977                         },
978                         nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
979                                 MessageSendEvent::HandleError {
980                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
981                                         action: crate::ln::msgs::ErrorAction::native_into(action),
982                                 }
983                         },
984                         nativeMessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
985                                 MessageSendEvent::PaymentFailureNetworkUpdate {
986                                         update: crate::ln::msgs::HTLCFailChannelUpdate::native_into(update),
987                                 }
988                         },
989                         nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
990                                 MessageSendEvent::SendChannelRangeQuery {
991                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
992                                         msg: crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true },
993                                 }
994                         },
995                         nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
996                                 MessageSendEvent::SendShortIdsQuery {
997                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
998                                         msg: crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg)), is_owned: true },
999                                 }
1000                         },
1001                 }
1002         }
1003 }
1004 /// Frees any resources used by the MessageSendEvent
1005 #[no_mangle]
1006 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1007 /// Creates a copy of the MessageSendEvent
1008 #[no_mangle]
1009 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1010         orig.clone()
1011 }
1012 /// A trait indicating an object may generate message send events
1013 #[repr(C)]
1014 pub struct MessageSendEventsProvider {
1015         /// An opaque pointer which is passed to your function implementations as an argument.
1016         /// This has no meaning in the LDK, and can be NULL or any other value.
1017         pub this_arg: *mut c_void,
1018         /// Gets the list of pending events which were generated by previous actions, clearing the list
1019         /// in the process.
1020         #[must_use]
1021         pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1022 /// Frees any resources associated with this object given its this_arg pointer.
1023 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1024         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1025 }
1026
1027 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1028 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1029         fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1030                 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1031                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1032                 local_ret
1033         }
1034 }
1035
1036 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1037 // directly as a Deref trait in higher-level structs:
1038 impl std::ops::Deref for MessageSendEventsProvider {
1039         type Target = Self;
1040         fn deref(&self) -> &Self {
1041                 self
1042         }
1043 }
1044 /// Calls the free function if one is set
1045 #[no_mangle]
1046 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1047 impl Drop for MessageSendEventsProvider {
1048         fn drop(&mut self) {
1049                 if let Some(f) = self.free {
1050                         f(self.this_arg);
1051                 }
1052         }
1053 }
1054 /// A trait indicating an object may generate events
1055 #[repr(C)]
1056 pub struct EventsProvider {
1057         /// An opaque pointer which is passed to your function implementations as an argument.
1058         /// This has no meaning in the LDK, and can be NULL or any other value.
1059         pub this_arg: *mut c_void,
1060         /// Gets the list of pending events which were generated by previous actions, clearing the list
1061         /// in the process.
1062         #[must_use]
1063         pub get_and_clear_pending_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_EventZ,
1064 /// Frees any resources associated with this object given its this_arg pointer.
1065 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1066         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1067 }
1068
1069 use lightning::util::events::EventsProvider as rustEventsProvider;
1070 impl rustEventsProvider for EventsProvider {
1071         fn get_and_clear_pending_events(&self) -> Vec<lightning::util::events::Event> {
1072                 let mut ret = (self.get_and_clear_pending_events)(self.this_arg);
1073                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1074                 local_ret
1075         }
1076 }
1077
1078 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1079 // directly as a Deref trait in higher-level structs:
1080 impl std::ops::Deref for EventsProvider {
1081         type Target = Self;
1082         fn deref(&self) -> &Self {
1083                 self
1084         }
1085 }
1086 /// Calls the free function if one is set
1087 #[no_mangle]
1088 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1089 impl Drop for EventsProvider {
1090         fn drop(&mut self) {
1091                 if let Some(f) = self.free {
1092                         f(self.this_arg);
1093                 }
1094         }
1095 }