1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! Events are returned from various bits in the library which indicate some action must be taken
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
16 use std::str::FromStr;
18 use bitcoin::hashes::Hash;
19 use crate::c_types::*;
21 /// An Event which you should probably take some action in response to.
23 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
24 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
25 /// written as it makes no sense to respond to it after reconnecting to peers).
30 /// Used to indicate that the client should generate a funding transaction with the given
31 /// parameters and then call ChannelManager::funding_transaction_generated.
32 /// Generated in ChannelManager message handling.
33 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
34 /// counterparty can steal your funds!
35 FundingGenerationReady {
36 /// The random channel_id we picked which you'll need to pass into
37 /// ChannelManager::funding_transaction_generated.
38 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
39 /// The value, in satoshis, that the output should have.
40 channel_value_satoshis: u64,
41 /// The script which should be used in the transaction output.
42 output_script: crate::c_types::derived::CVec_u8Z,
43 /// The value passed in to ChannelManager::create_channel
46 /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
47 /// ChannelManager::claim_funds to get it....
48 /// Note that if the preimage is not known or the amount paid is incorrect, you should call
49 /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid
50 /// network congestion.
51 /// The amount paid should be considered 'incorrect' when it is less than or more than twice
52 /// the amount expected.
53 /// If you fail to call either ChannelManager::claim_funds or
54 /// ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be
55 /// automatically failed.
57 /// The hash for which the preimage should be handed to the ChannelManager.
58 payment_hash: crate::c_types::ThirtyTwoBytes,
59 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
60 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
61 /// [`ChannelManager::claim_funds`].
63 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
64 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
65 payment_preimage: crate::c_types::ThirtyTwoBytes,
66 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
67 /// number of deanonymization attacks during the routing process.
68 /// It is provided here for your reference, however its accuracy is enforced directly by
69 /// [`ChannelManager`] using the values you previously provided to
70 /// [`ChannelManager::create_inbound_payment`] or
71 /// [`ChannelManager::create_inbound_payment_for_hash`].
73 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
74 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
75 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
76 payment_secret: crate::c_types::ThirtyTwoBytes,
77 /// The value, in thousandths of a satoshi, that this payment is for. Note that you must
78 /// compare this to the expected value before accepting the payment (as otherwise you are
79 /// providing proof-of-payment for less than the value you expected!).
81 /// This is the `user_payment_id` which was provided to
82 /// [`ChannelManager::create_inbound_payment_for_hash`] or
83 /// [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is
84 /// simply copied here. It may be used to correlate PaymentReceived events with invoice
85 /// metadata stored elsewhere.
87 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
88 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
91 /// Indicates an outbound payment we made succeeded (ie it made it all the way to its target
92 /// and we got back the payment preimage for it).
94 /// The preimage to the hash given to ChannelManager::send_payment.
95 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
97 payment_preimage: crate::c_types::ThirtyTwoBytes,
99 /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
100 /// something. You may wish to retry with a different route.
102 /// The hash which was given to ChannelManager::send_payment.
103 payment_hash: crate::c_types::ThirtyTwoBytes,
104 /// Indicates the payment was rejected for some reason by the recipient. This implies that
105 /// the payment has failed, not just the route in question. If this is not set, you may
106 /// retry the payment via a different route.
107 rejected_by_dest: bool,
109 /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
110 /// time in the future.
111 PendingHTLCsForwardable {
112 /// The minimum amount of time that should be waited prior to calling
113 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
114 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
115 /// now + 5*time_forwardable).
116 time_forwardable: u64,
118 /// Used to indicate that an output which you should know how to spend was confirmed on chain
119 /// and is now spendable.
120 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
121 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
122 /// somewhere and spend them when you create on-chain transactions.
124 /// The outputs which you should store as spendable by you.
125 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
128 use lightning::util::events::Event as nativeEvent;
131 pub(crate) fn to_native(&self) -> nativeEvent {
133 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
134 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
135 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
136 let mut output_script_nonref = (*output_script).clone();
137 let mut user_channel_id_nonref = (*user_channel_id).clone();
138 nativeEvent::FundingGenerationReady {
139 temporary_channel_id: temporary_channel_id_nonref.data,
140 channel_value_satoshis: channel_value_satoshis_nonref,
141 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
142 user_channel_id: user_channel_id_nonref,
145 Event::PaymentReceived {ref payment_hash, ref payment_preimage, ref payment_secret, ref amt, ref user_payment_id, } => {
146 let mut payment_hash_nonref = (*payment_hash).clone();
147 let mut payment_preimage_nonref = (*payment_preimage).clone();
148 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
149 let mut payment_secret_nonref = (*payment_secret).clone();
150 let mut amt_nonref = (*amt).clone();
151 let mut user_payment_id_nonref = (*user_payment_id).clone();
152 nativeEvent::PaymentReceived {
153 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
154 payment_preimage: local_payment_preimage_nonref,
155 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
157 user_payment_id: user_payment_id_nonref,
160 Event::PaymentSent {ref payment_preimage, } => {
161 let mut payment_preimage_nonref = (*payment_preimage).clone();
162 nativeEvent::PaymentSent {
163 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
166 Event::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
167 let mut payment_hash_nonref = (*payment_hash).clone();
168 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
169 nativeEvent::PaymentFailed {
170 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
171 rejected_by_dest: rejected_by_dest_nonref,
174 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
175 let mut time_forwardable_nonref = (*time_forwardable).clone();
176 nativeEvent::PendingHTLCsForwardable {
177 time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
180 Event::SpendableOutputs {ref outputs, } => {
181 let mut outputs_nonref = (*outputs).clone();
182 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
183 nativeEvent::SpendableOutputs {
184 outputs: local_outputs_nonref,
190 pub(crate) fn into_native(self) -> nativeEvent {
192 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
193 nativeEvent::FundingGenerationReady {
194 temporary_channel_id: temporary_channel_id.data,
195 channel_value_satoshis: channel_value_satoshis,
196 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
197 user_channel_id: user_channel_id,
200 Event::PaymentReceived {mut payment_hash, mut payment_preimage, mut payment_secret, mut amt, mut user_payment_id, } => {
201 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
202 nativeEvent::PaymentReceived {
203 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
204 payment_preimage: local_payment_preimage,
205 payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
207 user_payment_id: user_payment_id,
210 Event::PaymentSent {mut payment_preimage, } => {
211 nativeEvent::PaymentSent {
212 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
215 Event::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
216 nativeEvent::PaymentFailed {
217 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
218 rejected_by_dest: rejected_by_dest,
221 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
222 nativeEvent::PendingHTLCsForwardable {
223 time_forwardable: std::time::Duration::from_secs(time_forwardable),
226 Event::SpendableOutputs {mut outputs, } => {
227 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
228 nativeEvent::SpendableOutputs {
229 outputs: local_outputs,
235 pub(crate) fn from_native(native: &nativeEvent) -> Self {
237 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
238 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
239 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
240 let mut output_script_nonref = (*output_script).clone();
241 let mut user_channel_id_nonref = (*user_channel_id).clone();
242 Event::FundingGenerationReady {
243 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
244 channel_value_satoshis: channel_value_satoshis_nonref,
245 output_script: output_script_nonref.into_bytes().into(),
246 user_channel_id: user_channel_id_nonref,
249 nativeEvent::PaymentReceived {ref payment_hash, ref payment_preimage, ref payment_secret, ref amt, ref user_payment_id, } => {
250 let mut payment_hash_nonref = (*payment_hash).clone();
251 let mut payment_preimage_nonref = (*payment_preimage).clone();
252 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 } } };
253 let mut payment_secret_nonref = (*payment_secret).clone();
254 let mut amt_nonref = (*amt).clone();
255 let mut user_payment_id_nonref = (*user_payment_id).clone();
256 Event::PaymentReceived {
257 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
258 payment_preimage: local_payment_preimage_nonref,
259 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
261 user_payment_id: user_payment_id_nonref,
264 nativeEvent::PaymentSent {ref payment_preimage, } => {
265 let mut payment_preimage_nonref = (*payment_preimage).clone();
267 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
270 nativeEvent::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
271 let mut payment_hash_nonref = (*payment_hash).clone();
272 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
273 Event::PaymentFailed {
274 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
275 rejected_by_dest: rejected_by_dest_nonref,
278 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
279 let mut time_forwardable_nonref = (*time_forwardable).clone();
280 Event::PendingHTLCsForwardable {
281 time_forwardable: time_forwardable_nonref.as_secs(),
284 nativeEvent::SpendableOutputs {ref outputs, } => {
285 let mut outputs_nonref = (*outputs).clone();
286 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) }); };
287 Event::SpendableOutputs {
288 outputs: local_outputs_nonref.into(),
294 pub(crate) fn native_into(native: nativeEvent) -> Self {
296 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
297 Event::FundingGenerationReady {
298 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
299 channel_value_satoshis: channel_value_satoshis,
300 output_script: output_script.into_bytes().into(),
301 user_channel_id: user_channel_id,
304 nativeEvent::PaymentReceived {mut payment_hash, mut payment_preimage, mut payment_secret, mut amt, mut user_payment_id, } => {
305 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 } } };
306 Event::PaymentReceived {
307 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
308 payment_preimage: local_payment_preimage,
309 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
311 user_payment_id: user_payment_id,
314 nativeEvent::PaymentSent {mut payment_preimage, } => {
316 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
319 nativeEvent::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
320 Event::PaymentFailed {
321 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
322 rejected_by_dest: rejected_by_dest,
325 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
326 Event::PendingHTLCsForwardable {
327 time_forwardable: time_forwardable.as_secs(),
330 nativeEvent::SpendableOutputs {mut outputs, } => {
331 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
332 Event::SpendableOutputs {
333 outputs: local_outputs.into(),
339 /// Frees any resources used by the Event
341 pub extern "C" fn Event_free(this_ptr: Event) { }
342 /// Creates a copy of the Event
344 pub extern "C" fn Event_clone(orig: &Event) -> Event {
348 /// Serialize the Event object into a byte array which can be read by Event_read
349 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
350 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
352 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
353 /// broadcast to most peers).
354 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
358 pub enum MessageSendEvent {
359 /// Used to indicate that we've accepted a channel open and should send the accept_channel
360 /// message provided to the given peer.
362 /// The node_id of the node which should receive this message
363 node_id: crate::c_types::PublicKey,
364 /// The message which should be sent.
365 msg: crate::lightning::ln::msgs::AcceptChannel,
367 /// Used to indicate that we've initiated a channel open and should send the open_channel
368 /// message provided to the given peer.
370 /// The node_id of the node which should receive this message
371 node_id: crate::c_types::PublicKey,
372 /// The message which should be sent.
373 msg: crate::lightning::ln::msgs::OpenChannel,
375 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
377 /// The node_id of the node which should receive this message
378 node_id: crate::c_types::PublicKey,
379 /// The message which should be sent.
380 msg: crate::lightning::ln::msgs::FundingCreated,
382 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
384 /// The node_id of the node which should receive this message
385 node_id: crate::c_types::PublicKey,
386 /// The message which should be sent.
387 msg: crate::lightning::ln::msgs::FundingSigned,
389 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
391 /// The node_id of the node which should receive these message(s)
392 node_id: crate::c_types::PublicKey,
393 /// The funding_locked message which should be sent.
394 msg: crate::lightning::ln::msgs::FundingLocked,
396 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
397 SendAnnouncementSignatures {
398 /// The node_id of the node which should receive these message(s)
399 node_id: crate::c_types::PublicKey,
400 /// The announcement_signatures message which should be sent.
401 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
403 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
404 /// message should be sent to the peer with the given node_id.
406 /// The node_id of the node which should receive these message(s)
407 node_id: crate::c_types::PublicKey,
408 /// The update messages which should be sent. ALL messages in the struct should be sent!
409 updates: crate::lightning::ln::msgs::CommitmentUpdate,
411 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
413 /// The node_id of the node which should receive this message
414 node_id: crate::c_types::PublicKey,
415 /// The message which should be sent.
416 msg: crate::lightning::ln::msgs::RevokeAndACK,
418 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
420 /// The node_id of the node which should receive this message
421 node_id: crate::c_types::PublicKey,
422 /// The message which should be sent.
423 msg: crate::lightning::ln::msgs::ClosingSigned,
425 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
427 /// The node_id of the node which should receive this message
428 node_id: crate::c_types::PublicKey,
429 /// The message which should be sent.
430 msg: crate::lightning::ln::msgs::Shutdown,
432 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
433 SendChannelReestablish {
434 /// The node_id of the node which should receive this message
435 node_id: crate::c_types::PublicKey,
436 /// The message which should be sent.
437 msg: crate::lightning::ln::msgs::ChannelReestablish,
439 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
440 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
442 /// Note that after doing so, you very likely (unless you did so very recently) want to call
443 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
444 /// This ensures that any nodes which see our channel_announcement also have a relevant
445 /// node_announcement, including relevant feature flags which may be important for routing
446 /// through or to us.
447 BroadcastChannelAnnouncement {
448 /// The channel_announcement which should be sent.
449 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
450 /// The followup channel_update which should be sent.
451 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
453 /// Used to indicate that a node_announcement should be broadcast to all peers.
454 BroadcastNodeAnnouncement {
455 /// The node_announcement which should be sent.
456 msg: crate::lightning::ln::msgs::NodeAnnouncement,
458 /// Used to indicate that a channel_update should be broadcast to all peers.
459 BroadcastChannelUpdate {
460 /// The channel_update which should be sent.
461 msg: crate::lightning::ln::msgs::ChannelUpdate,
463 /// Used to indicate that a channel_update should be sent to a single peer.
464 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
465 /// private channel and we shouldn't be informing all of our peers of channel parameters.
467 /// The node_id of the node which should receive this message
468 node_id: crate::c_types::PublicKey,
469 /// The channel_update which should be sent.
470 msg: crate::lightning::ln::msgs::ChannelUpdate,
472 /// Broadcast an error downstream to be handled
474 /// The node_id of the node which should receive this message
475 node_id: crate::c_types::PublicKey,
476 /// The action which should be taken.
477 action: crate::lightning::ln::msgs::ErrorAction,
479 /// When a payment fails we may receive updates back from the hop where it failed. In such
480 /// cases this event is generated so that we can inform the network graph of this information.
481 PaymentFailureNetworkUpdate {
482 /// The channel/node update which should be sent to NetGraphMsgHandler
483 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate,
485 /// Query a peer for channels with funding transaction UTXOs in a block range.
486 SendChannelRangeQuery {
487 /// The node_id of this message recipient
488 node_id: crate::c_types::PublicKey,
489 /// The query_channel_range which should be sent.
490 msg: crate::lightning::ln::msgs::QueryChannelRange,
492 /// Request routing gossip messages from a peer for a list of channels identified by
493 /// their short_channel_ids.
495 /// The node_id of this message recipient
496 node_id: crate::c_types::PublicKey,
497 /// The query_short_channel_ids which should be sent.
498 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
500 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
501 /// emitted during processing of the query.
502 SendReplyChannelRange {
503 /// The node_id of this message recipient
504 node_id: crate::c_types::PublicKey,
505 /// The reply_channel_range which should be sent.
506 msg: crate::lightning::ln::msgs::ReplyChannelRange,
509 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
510 impl MessageSendEvent {
512 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
514 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
515 let mut node_id_nonref = (*node_id).clone();
516 let mut msg_nonref = (*msg).clone();
517 nativeMessageSendEvent::SendAcceptChannel {
518 node_id: node_id_nonref.into_rust(),
519 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
522 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
523 let mut node_id_nonref = (*node_id).clone();
524 let mut msg_nonref = (*msg).clone();
525 nativeMessageSendEvent::SendOpenChannel {
526 node_id: node_id_nonref.into_rust(),
527 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
530 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
531 let mut node_id_nonref = (*node_id).clone();
532 let mut msg_nonref = (*msg).clone();
533 nativeMessageSendEvent::SendFundingCreated {
534 node_id: node_id_nonref.into_rust(),
535 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
538 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
539 let mut node_id_nonref = (*node_id).clone();
540 let mut msg_nonref = (*msg).clone();
541 nativeMessageSendEvent::SendFundingSigned {
542 node_id: node_id_nonref.into_rust(),
543 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
546 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
547 let mut node_id_nonref = (*node_id).clone();
548 let mut msg_nonref = (*msg).clone();
549 nativeMessageSendEvent::SendFundingLocked {
550 node_id: node_id_nonref.into_rust(),
551 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
554 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
555 let mut node_id_nonref = (*node_id).clone();
556 let mut msg_nonref = (*msg).clone();
557 nativeMessageSendEvent::SendAnnouncementSignatures {
558 node_id: node_id_nonref.into_rust(),
559 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
562 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
563 let mut node_id_nonref = (*node_id).clone();
564 let mut updates_nonref = (*updates).clone();
565 nativeMessageSendEvent::UpdateHTLCs {
566 node_id: node_id_nonref.into_rust(),
567 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
570 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
571 let mut node_id_nonref = (*node_id).clone();
572 let mut msg_nonref = (*msg).clone();
573 nativeMessageSendEvent::SendRevokeAndACK {
574 node_id: node_id_nonref.into_rust(),
575 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
578 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
579 let mut node_id_nonref = (*node_id).clone();
580 let mut msg_nonref = (*msg).clone();
581 nativeMessageSendEvent::SendClosingSigned {
582 node_id: node_id_nonref.into_rust(),
583 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
586 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
587 let mut node_id_nonref = (*node_id).clone();
588 let mut msg_nonref = (*msg).clone();
589 nativeMessageSendEvent::SendShutdown {
590 node_id: node_id_nonref.into_rust(),
591 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
594 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
595 let mut node_id_nonref = (*node_id).clone();
596 let mut msg_nonref = (*msg).clone();
597 nativeMessageSendEvent::SendChannelReestablish {
598 node_id: node_id_nonref.into_rust(),
599 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
602 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
603 let mut msg_nonref = (*msg).clone();
604 let mut update_msg_nonref = (*update_msg).clone();
605 nativeMessageSendEvent::BroadcastChannelAnnouncement {
606 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
607 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
610 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
611 let mut msg_nonref = (*msg).clone();
612 nativeMessageSendEvent::BroadcastNodeAnnouncement {
613 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
616 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
617 let mut msg_nonref = (*msg).clone();
618 nativeMessageSendEvent::BroadcastChannelUpdate {
619 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
622 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
623 let mut node_id_nonref = (*node_id).clone();
624 let mut msg_nonref = (*msg).clone();
625 nativeMessageSendEvent::SendChannelUpdate {
626 node_id: node_id_nonref.into_rust(),
627 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
630 MessageSendEvent::HandleError {ref node_id, ref action, } => {
631 let mut node_id_nonref = (*node_id).clone();
632 let mut action_nonref = (*action).clone();
633 nativeMessageSendEvent::HandleError {
634 node_id: node_id_nonref.into_rust(),
635 action: action_nonref.into_native(),
638 MessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
639 let mut update_nonref = (*update).clone();
640 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
641 update: update_nonref.into_native(),
644 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
645 let mut node_id_nonref = (*node_id).clone();
646 let mut msg_nonref = (*msg).clone();
647 nativeMessageSendEvent::SendChannelRangeQuery {
648 node_id: node_id_nonref.into_rust(),
649 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
652 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
653 let mut node_id_nonref = (*node_id).clone();
654 let mut msg_nonref = (*msg).clone();
655 nativeMessageSendEvent::SendShortIdsQuery {
656 node_id: node_id_nonref.into_rust(),
657 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
660 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
661 let mut node_id_nonref = (*node_id).clone();
662 let mut msg_nonref = (*msg).clone();
663 nativeMessageSendEvent::SendReplyChannelRange {
664 node_id: node_id_nonref.into_rust(),
665 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
671 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
673 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
674 nativeMessageSendEvent::SendAcceptChannel {
675 node_id: node_id.into_rust(),
676 msg: *unsafe { Box::from_raw(msg.take_inner()) },
679 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
680 nativeMessageSendEvent::SendOpenChannel {
681 node_id: node_id.into_rust(),
682 msg: *unsafe { Box::from_raw(msg.take_inner()) },
685 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
686 nativeMessageSendEvent::SendFundingCreated {
687 node_id: node_id.into_rust(),
688 msg: *unsafe { Box::from_raw(msg.take_inner()) },
691 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
692 nativeMessageSendEvent::SendFundingSigned {
693 node_id: node_id.into_rust(),
694 msg: *unsafe { Box::from_raw(msg.take_inner()) },
697 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
698 nativeMessageSendEvent::SendFundingLocked {
699 node_id: node_id.into_rust(),
700 msg: *unsafe { Box::from_raw(msg.take_inner()) },
703 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
704 nativeMessageSendEvent::SendAnnouncementSignatures {
705 node_id: node_id.into_rust(),
706 msg: *unsafe { Box::from_raw(msg.take_inner()) },
709 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
710 nativeMessageSendEvent::UpdateHTLCs {
711 node_id: node_id.into_rust(),
712 updates: *unsafe { Box::from_raw(updates.take_inner()) },
715 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
716 nativeMessageSendEvent::SendRevokeAndACK {
717 node_id: node_id.into_rust(),
718 msg: *unsafe { Box::from_raw(msg.take_inner()) },
721 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
722 nativeMessageSendEvent::SendClosingSigned {
723 node_id: node_id.into_rust(),
724 msg: *unsafe { Box::from_raw(msg.take_inner()) },
727 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
728 nativeMessageSendEvent::SendShutdown {
729 node_id: node_id.into_rust(),
730 msg: *unsafe { Box::from_raw(msg.take_inner()) },
733 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
734 nativeMessageSendEvent::SendChannelReestablish {
735 node_id: node_id.into_rust(),
736 msg: *unsafe { Box::from_raw(msg.take_inner()) },
739 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
740 nativeMessageSendEvent::BroadcastChannelAnnouncement {
741 msg: *unsafe { Box::from_raw(msg.take_inner()) },
742 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
745 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
746 nativeMessageSendEvent::BroadcastNodeAnnouncement {
747 msg: *unsafe { Box::from_raw(msg.take_inner()) },
750 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
751 nativeMessageSendEvent::BroadcastChannelUpdate {
752 msg: *unsafe { Box::from_raw(msg.take_inner()) },
755 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
756 nativeMessageSendEvent::SendChannelUpdate {
757 node_id: node_id.into_rust(),
758 msg: *unsafe { Box::from_raw(msg.take_inner()) },
761 MessageSendEvent::HandleError {mut node_id, mut action, } => {
762 nativeMessageSendEvent::HandleError {
763 node_id: node_id.into_rust(),
764 action: action.into_native(),
767 MessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
768 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
769 update: update.into_native(),
772 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
773 nativeMessageSendEvent::SendChannelRangeQuery {
774 node_id: node_id.into_rust(),
775 msg: *unsafe { Box::from_raw(msg.take_inner()) },
778 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
779 nativeMessageSendEvent::SendShortIdsQuery {
780 node_id: node_id.into_rust(),
781 msg: *unsafe { Box::from_raw(msg.take_inner()) },
784 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
785 nativeMessageSendEvent::SendReplyChannelRange {
786 node_id: node_id.into_rust(),
787 msg: *unsafe { Box::from_raw(msg.take_inner()) },
793 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
795 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
796 let mut node_id_nonref = (*node_id).clone();
797 let mut msg_nonref = (*msg).clone();
798 MessageSendEvent::SendAcceptChannel {
799 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
800 msg: crate::lightning::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
803 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
804 let mut node_id_nonref = (*node_id).clone();
805 let mut msg_nonref = (*msg).clone();
806 MessageSendEvent::SendOpenChannel {
807 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
808 msg: crate::lightning::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
811 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
812 let mut node_id_nonref = (*node_id).clone();
813 let mut msg_nonref = (*msg).clone();
814 MessageSendEvent::SendFundingCreated {
815 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
816 msg: crate::lightning::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
819 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
820 let mut node_id_nonref = (*node_id).clone();
821 let mut msg_nonref = (*msg).clone();
822 MessageSendEvent::SendFundingSigned {
823 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
824 msg: crate::lightning::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
827 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
828 let mut node_id_nonref = (*node_id).clone();
829 let mut msg_nonref = (*msg).clone();
830 MessageSendEvent::SendFundingLocked {
831 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
832 msg: crate::lightning::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
835 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
836 let mut node_id_nonref = (*node_id).clone();
837 let mut msg_nonref = (*msg).clone();
838 MessageSendEvent::SendAnnouncementSignatures {
839 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
840 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
843 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
844 let mut node_id_nonref = (*node_id).clone();
845 let mut updates_nonref = (*updates).clone();
846 MessageSendEvent::UpdateHTLCs {
847 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
848 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates_nonref)), is_owned: true },
851 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
852 let mut node_id_nonref = (*node_id).clone();
853 let mut msg_nonref = (*msg).clone();
854 MessageSendEvent::SendRevokeAndACK {
855 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
856 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
859 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
860 let mut node_id_nonref = (*node_id).clone();
861 let mut msg_nonref = (*msg).clone();
862 MessageSendEvent::SendClosingSigned {
863 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
864 msg: crate::lightning::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
867 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
868 let mut node_id_nonref = (*node_id).clone();
869 let mut msg_nonref = (*msg).clone();
870 MessageSendEvent::SendShutdown {
871 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
872 msg: crate::lightning::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
875 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
876 let mut node_id_nonref = (*node_id).clone();
877 let mut msg_nonref = (*msg).clone();
878 MessageSendEvent::SendChannelReestablish {
879 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
880 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
883 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
884 let mut msg_nonref = (*msg).clone();
885 let mut update_msg_nonref = (*update_msg).clone();
886 MessageSendEvent::BroadcastChannelAnnouncement {
887 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
888 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg_nonref)), is_owned: true },
891 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
892 let mut msg_nonref = (*msg).clone();
893 MessageSendEvent::BroadcastNodeAnnouncement {
894 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
897 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
898 let mut msg_nonref = (*msg).clone();
899 MessageSendEvent::BroadcastChannelUpdate {
900 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
903 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
904 let mut node_id_nonref = (*node_id).clone();
905 let mut msg_nonref = (*msg).clone();
906 MessageSendEvent::SendChannelUpdate {
907 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
908 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
911 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
912 let mut node_id_nonref = (*node_id).clone();
913 let mut action_nonref = (*action).clone();
914 MessageSendEvent::HandleError {
915 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
916 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
919 nativeMessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
920 let mut update_nonref = (*update).clone();
921 MessageSendEvent::PaymentFailureNetworkUpdate {
922 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update_nonref),
925 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
926 let mut node_id_nonref = (*node_id).clone();
927 let mut msg_nonref = (*msg).clone();
928 MessageSendEvent::SendChannelRangeQuery {
929 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
930 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
933 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
934 let mut node_id_nonref = (*node_id).clone();
935 let mut msg_nonref = (*msg).clone();
936 MessageSendEvent::SendShortIdsQuery {
937 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
938 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
941 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
942 let mut node_id_nonref = (*node_id).clone();
943 let mut msg_nonref = (*msg).clone();
944 MessageSendEvent::SendReplyChannelRange {
945 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
946 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
952 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
954 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
955 MessageSendEvent::SendAcceptChannel {
956 node_id: crate::c_types::PublicKey::from_rust(&node_id),
957 msg: crate::lightning::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
960 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
961 MessageSendEvent::SendOpenChannel {
962 node_id: crate::c_types::PublicKey::from_rust(&node_id),
963 msg: crate::lightning::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
966 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
967 MessageSendEvent::SendFundingCreated {
968 node_id: crate::c_types::PublicKey::from_rust(&node_id),
969 msg: crate::lightning::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg)), is_owned: true },
972 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
973 MessageSendEvent::SendFundingSigned {
974 node_id: crate::c_types::PublicKey::from_rust(&node_id),
975 msg: crate::lightning::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
978 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
979 MessageSendEvent::SendFundingLocked {
980 node_id: crate::c_types::PublicKey::from_rust(&node_id),
981 msg: crate::lightning::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg)), is_owned: true },
984 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
985 MessageSendEvent::SendAnnouncementSignatures {
986 node_id: crate::c_types::PublicKey::from_rust(&node_id),
987 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg)), is_owned: true },
990 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
991 MessageSendEvent::UpdateHTLCs {
992 node_id: crate::c_types::PublicKey::from_rust(&node_id),
993 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates)), is_owned: true },
996 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
997 MessageSendEvent::SendRevokeAndACK {
998 node_id: crate::c_types::PublicKey::from_rust(&node_id),
999 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1002 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1003 MessageSendEvent::SendClosingSigned {
1004 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1005 msg: crate::lightning::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1008 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1009 MessageSendEvent::SendShutdown {
1010 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1011 msg: crate::lightning::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1014 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1015 MessageSendEvent::SendChannelReestablish {
1016 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1017 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1020 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1021 MessageSendEvent::BroadcastChannelAnnouncement {
1022 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1023 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg)), is_owned: true },
1026 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1027 MessageSendEvent::BroadcastNodeAnnouncement {
1028 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1031 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1032 MessageSendEvent::BroadcastChannelUpdate {
1033 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1036 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1037 MessageSendEvent::SendChannelUpdate {
1038 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1039 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1042 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1043 MessageSendEvent::HandleError {
1044 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1045 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1048 nativeMessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
1049 MessageSendEvent::PaymentFailureNetworkUpdate {
1050 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update),
1053 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1054 MessageSendEvent::SendChannelRangeQuery {
1055 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1056 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1059 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1060 MessageSendEvent::SendShortIdsQuery {
1061 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1062 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1065 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1066 MessageSendEvent::SendReplyChannelRange {
1067 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1068 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1074 /// Frees any resources used by the MessageSendEvent
1076 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1077 /// Creates a copy of the MessageSendEvent
1079 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1082 /// A trait indicating an object may generate message send events
1084 pub struct MessageSendEventsProvider {
1085 /// An opaque pointer which is passed to your function implementations as an argument.
1086 /// This has no meaning in the LDK, and can be NULL or any other value.
1087 pub this_arg: *mut c_void,
1088 /// Gets the list of pending events which were generated by previous actions, clearing the list
1091 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1092 /// Frees any resources associated with this object given its this_arg pointer.
1093 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1094 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1096 unsafe impl Send for MessageSendEventsProvider {}
1097 unsafe impl Sync for MessageSendEventsProvider {}
1099 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1100 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1101 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1102 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1103 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1108 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1109 // directly as a Deref trait in higher-level structs:
1110 impl std::ops::Deref for MessageSendEventsProvider {
1112 fn deref(&self) -> &Self {
1116 /// Calls the free function if one is set
1118 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1119 impl Drop for MessageSendEventsProvider {
1120 fn drop(&mut self) {
1121 if let Some(f) = self.free {
1126 /// A trait indicating an object may generate events.
1128 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1132 /// See [`process_pending_events`] for requirements around event processing.
1134 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1135 /// event since the last invocation. The handler must either act upon the event immediately
1136 /// or preserve it for later handling.
1138 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1139 /// consult the provider's documentation on the implication of processing events and how a handler
1140 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1141 /// [`ChainMonitor::process_pending_events`]).
1143 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1146 /// [`process_pending_events`]: Self::process_pending_events
1147 /// [`handle_event`]: EventHandler::handle_event
1148 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1149 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1151 pub struct EventsProvider {
1152 /// An opaque pointer which is passed to your function implementations as an argument.
1153 /// This has no meaning in the LDK, and can be NULL or any other value.
1154 pub this_arg: *mut c_void,
1155 /// Processes any events generated since the last call using the given event handler.
1157 /// Subsequent calls must only process new events. However, handlers must be capable of handling
1158 /// duplicate events across process restarts. This may occur if the provider was recovered from
1159 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1160 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1161 /// Frees any resources associated with this object given its this_arg pointer.
1162 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1163 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1165 unsafe impl Send for EventsProvider {}
1166 unsafe impl Sync for EventsProvider {}
1168 use lightning::util::events::EventsProvider as rustEventsProvider;
1169 /// Calls the free function if one is set
1171 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1172 impl Drop for EventsProvider {
1173 fn drop(&mut self) {
1174 if let Some(f) = self.free {
1179 /// A trait implemented for objects handling events from [`EventsProvider`].
1181 pub struct EventHandler {
1182 /// An opaque pointer which is passed to your function implementations as an argument.
1183 /// This has no meaning in the LDK, and can be NULL or any other value.
1184 pub this_arg: *mut c_void,
1185 /// Handles the given [`Event`].
1187 /// See [`EventsProvider`] for details that must be considered when implementing this method.
1188 pub handle_event: extern "C" fn (this_arg: *const c_void, event: crate::lightning::util::events::Event),
1189 /// Frees any resources associated with this object given its this_arg pointer.
1190 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1191 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1193 unsafe impl Send for EventHandler {}
1194 unsafe impl Sync for EventHandler {}
1196 use lightning::util::events::EventHandler as rustEventHandler;
1197 impl rustEventHandler for EventHandler {
1198 fn handle_event(&self, mut event: lightning::util::events::Event) {
1199 (self.handle_event)(self.this_arg, crate::lightning::util::events::Event::native_into(event))
1203 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1204 // directly as a Deref trait in higher-level structs:
1205 impl std::ops::Deref for EventHandler {
1207 fn deref(&self) -> &Self {
1211 /// Calls the free function if one is set
1213 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
1214 impl Drop for EventHandler {
1215 fn drop(&mut self) {
1216 if let Some(f) = self.free {