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