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 was generated on-chain which you should know how to spend.
119 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
120 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
121 /// somewhere and spend them when you create on-chain transactions.
123 /// The outputs which you should store as spendable by you.
124 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
127 use lightning::util::events::Event as nativeEvent;
130 pub(crate) fn to_native(&self) -> nativeEvent {
132 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
133 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
134 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
135 let mut output_script_nonref = (*output_script).clone();
136 let mut user_channel_id_nonref = (*user_channel_id).clone();
137 nativeEvent::FundingGenerationReady {
138 temporary_channel_id: temporary_channel_id_nonref.data,
139 channel_value_satoshis: channel_value_satoshis_nonref,
140 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
141 user_channel_id: user_channel_id_nonref,
144 Event::PaymentReceived {ref payment_hash, ref payment_preimage, ref payment_secret, ref amt, ref user_payment_id, } => {
145 let mut payment_hash_nonref = (*payment_hash).clone();
146 let mut payment_preimage_nonref = (*payment_preimage).clone();
147 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
148 let mut payment_secret_nonref = (*payment_secret).clone();
149 let mut amt_nonref = (*amt).clone();
150 let mut user_payment_id_nonref = (*user_payment_id).clone();
151 nativeEvent::PaymentReceived {
152 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
153 payment_preimage: local_payment_preimage_nonref,
154 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
156 user_payment_id: user_payment_id_nonref,
159 Event::PaymentSent {ref payment_preimage, } => {
160 let mut payment_preimage_nonref = (*payment_preimage).clone();
161 nativeEvent::PaymentSent {
162 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
165 Event::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
166 let mut payment_hash_nonref = (*payment_hash).clone();
167 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
168 nativeEvent::PaymentFailed {
169 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
170 rejected_by_dest: rejected_by_dest_nonref,
173 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
174 let mut time_forwardable_nonref = (*time_forwardable).clone();
175 nativeEvent::PendingHTLCsForwardable {
176 time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
179 Event::SpendableOutputs {ref outputs, } => {
180 let mut outputs_nonref = (*outputs).clone();
181 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
182 nativeEvent::SpendableOutputs {
183 outputs: local_outputs_nonref,
189 pub(crate) fn into_native(self) -> nativeEvent {
191 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
192 nativeEvent::FundingGenerationReady {
193 temporary_channel_id: temporary_channel_id.data,
194 channel_value_satoshis: channel_value_satoshis,
195 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
196 user_channel_id: user_channel_id,
199 Event::PaymentReceived {mut payment_hash, mut payment_preimage, mut payment_secret, mut amt, mut user_payment_id, } => {
200 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
201 nativeEvent::PaymentReceived {
202 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
203 payment_preimage: local_payment_preimage,
204 payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
206 user_payment_id: user_payment_id,
209 Event::PaymentSent {mut payment_preimage, } => {
210 nativeEvent::PaymentSent {
211 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
214 Event::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
215 nativeEvent::PaymentFailed {
216 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
217 rejected_by_dest: rejected_by_dest,
220 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
221 nativeEvent::PendingHTLCsForwardable {
222 time_forwardable: std::time::Duration::from_secs(time_forwardable),
225 Event::SpendableOutputs {mut outputs, } => {
226 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
227 nativeEvent::SpendableOutputs {
228 outputs: local_outputs,
234 pub(crate) fn from_native(native: &nativeEvent) -> Self {
236 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
237 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
238 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
239 let mut output_script_nonref = (*output_script).clone();
240 let mut user_channel_id_nonref = (*user_channel_id).clone();
241 Event::FundingGenerationReady {
242 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
243 channel_value_satoshis: channel_value_satoshis_nonref,
244 output_script: output_script_nonref.into_bytes().into(),
245 user_channel_id: user_channel_id_nonref,
248 nativeEvent::PaymentReceived {ref payment_hash, ref payment_preimage, ref payment_secret, ref amt, ref user_payment_id, } => {
249 let mut payment_hash_nonref = (*payment_hash).clone();
250 let mut payment_preimage_nonref = (*payment_preimage).clone();
251 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 } } };
252 let mut payment_secret_nonref = (*payment_secret).clone();
253 let mut amt_nonref = (*amt).clone();
254 let mut user_payment_id_nonref = (*user_payment_id).clone();
255 Event::PaymentReceived {
256 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
257 payment_preimage: local_payment_preimage_nonref,
258 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
260 user_payment_id: user_payment_id_nonref,
263 nativeEvent::PaymentSent {ref payment_preimage, } => {
264 let mut payment_preimage_nonref = (*payment_preimage).clone();
266 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
269 nativeEvent::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
270 let mut payment_hash_nonref = (*payment_hash).clone();
271 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
272 Event::PaymentFailed {
273 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
274 rejected_by_dest: rejected_by_dest_nonref,
277 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
278 let mut time_forwardable_nonref = (*time_forwardable).clone();
279 Event::PendingHTLCsForwardable {
280 time_forwardable: time_forwardable_nonref.as_secs(),
283 nativeEvent::SpendableOutputs {ref outputs, } => {
284 let mut outputs_nonref = (*outputs).clone();
285 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.drain(..) { local_outputs_nonref.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
286 Event::SpendableOutputs {
287 outputs: local_outputs_nonref.into(),
293 pub(crate) fn native_into(native: nativeEvent) -> Self {
295 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
296 Event::FundingGenerationReady {
297 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
298 channel_value_satoshis: channel_value_satoshis,
299 output_script: output_script.into_bytes().into(),
300 user_channel_id: user_channel_id,
303 nativeEvent::PaymentReceived {mut payment_hash, mut payment_preimage, mut payment_secret, mut amt, mut user_payment_id, } => {
304 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 } } };
305 Event::PaymentReceived {
306 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
307 payment_preimage: local_payment_preimage,
308 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
310 user_payment_id: user_payment_id,
313 nativeEvent::PaymentSent {mut payment_preimage, } => {
315 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
318 nativeEvent::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
319 Event::PaymentFailed {
320 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
321 rejected_by_dest: rejected_by_dest,
324 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
325 Event::PendingHTLCsForwardable {
326 time_forwardable: time_forwardable.as_secs(),
329 nativeEvent::SpendableOutputs {mut outputs, } => {
330 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
331 Event::SpendableOutputs {
332 outputs: local_outputs.into(),
338 /// Frees any resources used by the Event
340 pub extern "C" fn Event_free(this_ptr: Event) { }
341 /// Creates a copy of the Event
343 pub extern "C" fn Event_clone(orig: &Event) -> Event {
347 /// Serialize the Event object into a byte array which can be read by Event_read
348 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
349 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
351 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
352 /// broadcast to most peers).
353 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
357 pub enum MessageSendEvent {
358 /// Used to indicate that we've accepted a channel open and should send the accept_channel
359 /// message provided to the given peer.
361 /// The node_id of the node which should receive this message
362 node_id: crate::c_types::PublicKey,
363 /// The message which should be sent.
364 msg: crate::lightning::ln::msgs::AcceptChannel,
366 /// Used to indicate that we've initiated a channel open and should send the open_channel
367 /// message provided to the given peer.
369 /// The node_id of the node which should receive this message
370 node_id: crate::c_types::PublicKey,
371 /// The message which should be sent.
372 msg: crate::lightning::ln::msgs::OpenChannel,
374 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
376 /// The node_id of the node which should receive this message
377 node_id: crate::c_types::PublicKey,
378 /// The message which should be sent.
379 msg: crate::lightning::ln::msgs::FundingCreated,
381 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
383 /// The node_id of the node which should receive this message
384 node_id: crate::c_types::PublicKey,
385 /// The message which should be sent.
386 msg: crate::lightning::ln::msgs::FundingSigned,
388 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
390 /// The node_id of the node which should receive these message(s)
391 node_id: crate::c_types::PublicKey,
392 /// The funding_locked message which should be sent.
393 msg: crate::lightning::ln::msgs::FundingLocked,
395 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
396 SendAnnouncementSignatures {
397 /// The node_id of the node which should receive these message(s)
398 node_id: crate::c_types::PublicKey,
399 /// The announcement_signatures message which should be sent.
400 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
402 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
403 /// message should be sent to the peer with the given node_id.
405 /// The node_id of the node which should receive these message(s)
406 node_id: crate::c_types::PublicKey,
407 /// The update messages which should be sent. ALL messages in the struct should be sent!
408 updates: crate::lightning::ln::msgs::CommitmentUpdate,
410 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
412 /// The node_id of the node which should receive this message
413 node_id: crate::c_types::PublicKey,
414 /// The message which should be sent.
415 msg: crate::lightning::ln::msgs::RevokeAndACK,
417 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
419 /// The node_id of the node which should receive this message
420 node_id: crate::c_types::PublicKey,
421 /// The message which should be sent.
422 msg: crate::lightning::ln::msgs::ClosingSigned,
424 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
426 /// The node_id of the node which should receive this message
427 node_id: crate::c_types::PublicKey,
428 /// The message which should be sent.
429 msg: crate::lightning::ln::msgs::Shutdown,
431 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
432 SendChannelReestablish {
433 /// The node_id of the node which should receive this message
434 node_id: crate::c_types::PublicKey,
435 /// The message which should be sent.
436 msg: crate::lightning::ln::msgs::ChannelReestablish,
438 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
439 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
441 /// Note that after doing so, you very likely (unless you did so very recently) want to call
442 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
443 /// This ensures that any nodes which see our channel_announcement also have a relevant
444 /// node_announcement, including relevant feature flags which may be important for routing
445 /// through or to us.
446 BroadcastChannelAnnouncement {
447 /// The channel_announcement which should be sent.
448 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
449 /// The followup channel_update which should be sent.
450 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
452 /// Used to indicate that a node_announcement should be broadcast to all peers.
453 BroadcastNodeAnnouncement {
454 /// The node_announcement which should be sent.
455 msg: crate::lightning::ln::msgs::NodeAnnouncement,
457 /// Used to indicate that a channel_update should be broadcast to all peers.
458 BroadcastChannelUpdate {
459 /// The channel_update which should be sent.
460 msg: crate::lightning::ln::msgs::ChannelUpdate,
462 /// Broadcast an error downstream to be handled
464 /// The node_id of the node which should receive this message
465 node_id: crate::c_types::PublicKey,
466 /// The action which should be taken.
467 action: crate::lightning::ln::msgs::ErrorAction,
469 /// When a payment fails we may receive updates back from the hop where it failed. In such
470 /// cases this event is generated so that we can inform the network graph of this information.
471 PaymentFailureNetworkUpdate {
472 /// The channel/node update which should be sent to NetGraphMsgHandler
473 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate,
475 /// Query a peer for channels with funding transaction UTXOs in a block range.
476 SendChannelRangeQuery {
477 /// The node_id of this message recipient
478 node_id: crate::c_types::PublicKey,
479 /// The query_channel_range which should be sent.
480 msg: crate::lightning::ln::msgs::QueryChannelRange,
482 /// Request routing gossip messages from a peer for a list of channels identified by
483 /// their short_channel_ids.
485 /// The node_id of this message recipient
486 node_id: crate::c_types::PublicKey,
487 /// The query_short_channel_ids which should be sent.
488 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
490 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
491 /// emitted during processing of the query.
492 SendReplyChannelRange {
493 /// The node_id of this message recipient
494 node_id: crate::c_types::PublicKey,
495 /// The reply_channel_range which should be sent.
496 msg: crate::lightning::ln::msgs::ReplyChannelRange,
499 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
500 impl MessageSendEvent {
502 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
504 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
505 let mut node_id_nonref = (*node_id).clone();
506 let mut msg_nonref = (*msg).clone();
507 nativeMessageSendEvent::SendAcceptChannel {
508 node_id: node_id_nonref.into_rust(),
509 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
512 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
513 let mut node_id_nonref = (*node_id).clone();
514 let mut msg_nonref = (*msg).clone();
515 nativeMessageSendEvent::SendOpenChannel {
516 node_id: node_id_nonref.into_rust(),
517 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
520 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
521 let mut node_id_nonref = (*node_id).clone();
522 let mut msg_nonref = (*msg).clone();
523 nativeMessageSendEvent::SendFundingCreated {
524 node_id: node_id_nonref.into_rust(),
525 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
528 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
529 let mut node_id_nonref = (*node_id).clone();
530 let mut msg_nonref = (*msg).clone();
531 nativeMessageSendEvent::SendFundingSigned {
532 node_id: node_id_nonref.into_rust(),
533 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
536 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
537 let mut node_id_nonref = (*node_id).clone();
538 let mut msg_nonref = (*msg).clone();
539 nativeMessageSendEvent::SendFundingLocked {
540 node_id: node_id_nonref.into_rust(),
541 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
544 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
545 let mut node_id_nonref = (*node_id).clone();
546 let mut msg_nonref = (*msg).clone();
547 nativeMessageSendEvent::SendAnnouncementSignatures {
548 node_id: node_id_nonref.into_rust(),
549 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
552 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
553 let mut node_id_nonref = (*node_id).clone();
554 let mut updates_nonref = (*updates).clone();
555 nativeMessageSendEvent::UpdateHTLCs {
556 node_id: node_id_nonref.into_rust(),
557 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
560 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
561 let mut node_id_nonref = (*node_id).clone();
562 let mut msg_nonref = (*msg).clone();
563 nativeMessageSendEvent::SendRevokeAndACK {
564 node_id: node_id_nonref.into_rust(),
565 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
568 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
569 let mut node_id_nonref = (*node_id).clone();
570 let mut msg_nonref = (*msg).clone();
571 nativeMessageSendEvent::SendClosingSigned {
572 node_id: node_id_nonref.into_rust(),
573 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
576 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
577 let mut node_id_nonref = (*node_id).clone();
578 let mut msg_nonref = (*msg).clone();
579 nativeMessageSendEvent::SendShutdown {
580 node_id: node_id_nonref.into_rust(),
581 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
584 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
585 let mut node_id_nonref = (*node_id).clone();
586 let mut msg_nonref = (*msg).clone();
587 nativeMessageSendEvent::SendChannelReestablish {
588 node_id: node_id_nonref.into_rust(),
589 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
592 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
593 let mut msg_nonref = (*msg).clone();
594 let mut update_msg_nonref = (*update_msg).clone();
595 nativeMessageSendEvent::BroadcastChannelAnnouncement {
596 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
597 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
600 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
601 let mut msg_nonref = (*msg).clone();
602 nativeMessageSendEvent::BroadcastNodeAnnouncement {
603 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
606 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
607 let mut msg_nonref = (*msg).clone();
608 nativeMessageSendEvent::BroadcastChannelUpdate {
609 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
612 MessageSendEvent::HandleError {ref node_id, ref action, } => {
613 let mut node_id_nonref = (*node_id).clone();
614 let mut action_nonref = (*action).clone();
615 nativeMessageSendEvent::HandleError {
616 node_id: node_id_nonref.into_rust(),
617 action: action_nonref.into_native(),
620 MessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
621 let mut update_nonref = (*update).clone();
622 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
623 update: update_nonref.into_native(),
626 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
627 let mut node_id_nonref = (*node_id).clone();
628 let mut msg_nonref = (*msg).clone();
629 nativeMessageSendEvent::SendChannelRangeQuery {
630 node_id: node_id_nonref.into_rust(),
631 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
634 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
635 let mut node_id_nonref = (*node_id).clone();
636 let mut msg_nonref = (*msg).clone();
637 nativeMessageSendEvent::SendShortIdsQuery {
638 node_id: node_id_nonref.into_rust(),
639 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
642 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
643 let mut node_id_nonref = (*node_id).clone();
644 let mut msg_nonref = (*msg).clone();
645 nativeMessageSendEvent::SendReplyChannelRange {
646 node_id: node_id_nonref.into_rust(),
647 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
653 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
655 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
656 nativeMessageSendEvent::SendAcceptChannel {
657 node_id: node_id.into_rust(),
658 msg: *unsafe { Box::from_raw(msg.take_inner()) },
661 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
662 nativeMessageSendEvent::SendOpenChannel {
663 node_id: node_id.into_rust(),
664 msg: *unsafe { Box::from_raw(msg.take_inner()) },
667 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
668 nativeMessageSendEvent::SendFundingCreated {
669 node_id: node_id.into_rust(),
670 msg: *unsafe { Box::from_raw(msg.take_inner()) },
673 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
674 nativeMessageSendEvent::SendFundingSigned {
675 node_id: node_id.into_rust(),
676 msg: *unsafe { Box::from_raw(msg.take_inner()) },
679 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
680 nativeMessageSendEvent::SendFundingLocked {
681 node_id: node_id.into_rust(),
682 msg: *unsafe { Box::from_raw(msg.take_inner()) },
685 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
686 nativeMessageSendEvent::SendAnnouncementSignatures {
687 node_id: node_id.into_rust(),
688 msg: *unsafe { Box::from_raw(msg.take_inner()) },
691 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
692 nativeMessageSendEvent::UpdateHTLCs {
693 node_id: node_id.into_rust(),
694 updates: *unsafe { Box::from_raw(updates.take_inner()) },
697 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
698 nativeMessageSendEvent::SendRevokeAndACK {
699 node_id: node_id.into_rust(),
700 msg: *unsafe { Box::from_raw(msg.take_inner()) },
703 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
704 nativeMessageSendEvent::SendClosingSigned {
705 node_id: node_id.into_rust(),
706 msg: *unsafe { Box::from_raw(msg.take_inner()) },
709 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
710 nativeMessageSendEvent::SendShutdown {
711 node_id: node_id.into_rust(),
712 msg: *unsafe { Box::from_raw(msg.take_inner()) },
715 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
716 nativeMessageSendEvent::SendChannelReestablish {
717 node_id: node_id.into_rust(),
718 msg: *unsafe { Box::from_raw(msg.take_inner()) },
721 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
722 nativeMessageSendEvent::BroadcastChannelAnnouncement {
723 msg: *unsafe { Box::from_raw(msg.take_inner()) },
724 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
727 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
728 nativeMessageSendEvent::BroadcastNodeAnnouncement {
729 msg: *unsafe { Box::from_raw(msg.take_inner()) },
732 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
733 nativeMessageSendEvent::BroadcastChannelUpdate {
734 msg: *unsafe { Box::from_raw(msg.take_inner()) },
737 MessageSendEvent::HandleError {mut node_id, mut action, } => {
738 nativeMessageSendEvent::HandleError {
739 node_id: node_id.into_rust(),
740 action: action.into_native(),
743 MessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
744 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
745 update: update.into_native(),
748 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
749 nativeMessageSendEvent::SendChannelRangeQuery {
750 node_id: node_id.into_rust(),
751 msg: *unsafe { Box::from_raw(msg.take_inner()) },
754 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
755 nativeMessageSendEvent::SendShortIdsQuery {
756 node_id: node_id.into_rust(),
757 msg: *unsafe { Box::from_raw(msg.take_inner()) },
760 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
761 nativeMessageSendEvent::SendReplyChannelRange {
762 node_id: node_id.into_rust(),
763 msg: *unsafe { Box::from_raw(msg.take_inner()) },
769 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
771 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
772 let mut node_id_nonref = (*node_id).clone();
773 let mut msg_nonref = (*msg).clone();
774 MessageSendEvent::SendAcceptChannel {
775 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
776 msg: crate::lightning::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
779 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
780 let mut node_id_nonref = (*node_id).clone();
781 let mut msg_nonref = (*msg).clone();
782 MessageSendEvent::SendOpenChannel {
783 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
784 msg: crate::lightning::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
787 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
788 let mut node_id_nonref = (*node_id).clone();
789 let mut msg_nonref = (*msg).clone();
790 MessageSendEvent::SendFundingCreated {
791 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
792 msg: crate::lightning::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
795 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
796 let mut node_id_nonref = (*node_id).clone();
797 let mut msg_nonref = (*msg).clone();
798 MessageSendEvent::SendFundingSigned {
799 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
800 msg: crate::lightning::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
803 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
804 let mut node_id_nonref = (*node_id).clone();
805 let mut msg_nonref = (*msg).clone();
806 MessageSendEvent::SendFundingLocked {
807 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
808 msg: crate::lightning::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
811 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
812 let mut node_id_nonref = (*node_id).clone();
813 let mut msg_nonref = (*msg).clone();
814 MessageSendEvent::SendAnnouncementSignatures {
815 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
816 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
819 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
820 let mut node_id_nonref = (*node_id).clone();
821 let mut updates_nonref = (*updates).clone();
822 MessageSendEvent::UpdateHTLCs {
823 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
824 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates_nonref)), is_owned: true },
827 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
828 let mut node_id_nonref = (*node_id).clone();
829 let mut msg_nonref = (*msg).clone();
830 MessageSendEvent::SendRevokeAndACK {
831 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
832 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
835 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
836 let mut node_id_nonref = (*node_id).clone();
837 let mut msg_nonref = (*msg).clone();
838 MessageSendEvent::SendClosingSigned {
839 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
840 msg: crate::lightning::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
843 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
844 let mut node_id_nonref = (*node_id).clone();
845 let mut msg_nonref = (*msg).clone();
846 MessageSendEvent::SendShutdown {
847 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
848 msg: crate::lightning::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
851 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
852 let mut node_id_nonref = (*node_id).clone();
853 let mut msg_nonref = (*msg).clone();
854 MessageSendEvent::SendChannelReestablish {
855 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
856 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
859 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
860 let mut msg_nonref = (*msg).clone();
861 let mut update_msg_nonref = (*update_msg).clone();
862 MessageSendEvent::BroadcastChannelAnnouncement {
863 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
864 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg_nonref)), is_owned: true },
867 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
868 let mut msg_nonref = (*msg).clone();
869 MessageSendEvent::BroadcastNodeAnnouncement {
870 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
873 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
874 let mut msg_nonref = (*msg).clone();
875 MessageSendEvent::BroadcastChannelUpdate {
876 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
879 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
880 let mut node_id_nonref = (*node_id).clone();
881 let mut action_nonref = (*action).clone();
882 MessageSendEvent::HandleError {
883 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
884 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
887 nativeMessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
888 let mut update_nonref = (*update).clone();
889 MessageSendEvent::PaymentFailureNetworkUpdate {
890 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update_nonref),
893 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
894 let mut node_id_nonref = (*node_id).clone();
895 let mut msg_nonref = (*msg).clone();
896 MessageSendEvent::SendChannelRangeQuery {
897 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
898 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
901 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
902 let mut node_id_nonref = (*node_id).clone();
903 let mut msg_nonref = (*msg).clone();
904 MessageSendEvent::SendShortIdsQuery {
905 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
906 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
909 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
910 let mut node_id_nonref = (*node_id).clone();
911 let mut msg_nonref = (*msg).clone();
912 MessageSendEvent::SendReplyChannelRange {
913 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
914 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
920 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
922 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
923 MessageSendEvent::SendAcceptChannel {
924 node_id: crate::c_types::PublicKey::from_rust(&node_id),
925 msg: crate::lightning::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
928 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
929 MessageSendEvent::SendOpenChannel {
930 node_id: crate::c_types::PublicKey::from_rust(&node_id),
931 msg: crate::lightning::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
934 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
935 MessageSendEvent::SendFundingCreated {
936 node_id: crate::c_types::PublicKey::from_rust(&node_id),
937 msg: crate::lightning::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg)), is_owned: true },
940 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
941 MessageSendEvent::SendFundingSigned {
942 node_id: crate::c_types::PublicKey::from_rust(&node_id),
943 msg: crate::lightning::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
946 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
947 MessageSendEvent::SendFundingLocked {
948 node_id: crate::c_types::PublicKey::from_rust(&node_id),
949 msg: crate::lightning::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg)), is_owned: true },
952 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
953 MessageSendEvent::SendAnnouncementSignatures {
954 node_id: crate::c_types::PublicKey::from_rust(&node_id),
955 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg)), is_owned: true },
958 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
959 MessageSendEvent::UpdateHTLCs {
960 node_id: crate::c_types::PublicKey::from_rust(&node_id),
961 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates)), is_owned: true },
964 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
965 MessageSendEvent::SendRevokeAndACK {
966 node_id: crate::c_types::PublicKey::from_rust(&node_id),
967 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg)), is_owned: true },
970 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
971 MessageSendEvent::SendClosingSigned {
972 node_id: crate::c_types::PublicKey::from_rust(&node_id),
973 msg: crate::lightning::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
976 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
977 MessageSendEvent::SendShutdown {
978 node_id: crate::c_types::PublicKey::from_rust(&node_id),
979 msg: crate::lightning::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg)), is_owned: true },
982 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
983 MessageSendEvent::SendChannelReestablish {
984 node_id: crate::c_types::PublicKey::from_rust(&node_id),
985 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg)), is_owned: true },
988 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
989 MessageSendEvent::BroadcastChannelAnnouncement {
990 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
991 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg)), is_owned: true },
994 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
995 MessageSendEvent::BroadcastNodeAnnouncement {
996 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
999 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1000 MessageSendEvent::BroadcastChannelUpdate {
1001 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1004 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1005 MessageSendEvent::HandleError {
1006 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1007 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1010 nativeMessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
1011 MessageSendEvent::PaymentFailureNetworkUpdate {
1012 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update),
1015 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1016 MessageSendEvent::SendChannelRangeQuery {
1017 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1018 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1021 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1022 MessageSendEvent::SendShortIdsQuery {
1023 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1024 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1027 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1028 MessageSendEvent::SendReplyChannelRange {
1029 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1030 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true },
1036 /// Frees any resources used by the MessageSendEvent
1038 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1039 /// Creates a copy of the MessageSendEvent
1041 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1044 /// A trait indicating an object may generate message send events
1046 pub struct MessageSendEventsProvider {
1047 /// An opaque pointer which is passed to your function implementations as an argument.
1048 /// This has no meaning in the LDK, and can be NULL or any other value.
1049 pub this_arg: *mut c_void,
1050 /// Gets the list of pending events which were generated by previous actions, clearing the list
1053 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1054 /// Frees any resources associated with this object given its this_arg pointer.
1055 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1056 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1059 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1060 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1061 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1062 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1063 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1068 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1069 // directly as a Deref trait in higher-level structs:
1070 impl std::ops::Deref for MessageSendEventsProvider {
1072 fn deref(&self) -> &Self {
1076 /// Calls the free function if one is set
1078 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1079 impl Drop for MessageSendEventsProvider {
1080 fn drop(&mut self) {
1081 if let Some(f) = self.free {
1086 /// A trait indicating an object may generate events.
1088 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1092 /// See [`process_pending_events`] for requirements around event processing.
1094 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1095 /// event since the last invocation. The handler must either act upon the event immediately
1096 /// or preserve it for later handling.
1098 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1099 /// consult the provider's documentation on the implication of processing events and how a handler
1100 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1101 /// [`ChainMonitor::process_pending_events`]).
1103 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1106 /// [`process_pending_events`]: Self::process_pending_events
1107 /// [`handle_event`]: EventHandler::handle_event
1108 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1109 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1111 pub struct EventsProvider {
1112 /// An opaque pointer which is passed to your function implementations as an argument.
1113 /// This has no meaning in the LDK, and can be NULL or any other value.
1114 pub this_arg: *mut c_void,
1115 /// Processes any events generated since the last call using the given event handler.
1117 /// Subsequent calls must only process new events. However, handlers must be capable of handling
1118 /// duplicate events across process restarts. This may occur if the provider was recovered from
1119 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1120 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1121 /// Frees any resources associated with this object given its this_arg pointer.
1122 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1123 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1126 use lightning::util::events::EventsProvider as rustEventsProvider;
1127 /// Calls the free function if one is set
1129 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1130 impl Drop for EventsProvider {
1131 fn drop(&mut self) {
1132 if let Some(f) = self.free {
1137 /// A trait implemented for objects handling events from [`EventsProvider`].
1139 pub struct EventHandler {
1140 /// An opaque pointer which is passed to your function implementations as an argument.
1141 /// This has no meaning in the LDK, and can be NULL or any other value.
1142 pub this_arg: *mut c_void,
1143 /// Handles the given [`Event`].
1145 /// See [`EventsProvider`] for details that must be considered when implementing this method.
1146 pub handle_event: extern "C" fn (this_arg: *const c_void, event: crate::lightning::util::events::Event),
1147 /// Frees any resources associated with this object given its this_arg pointer.
1148 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1149 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1152 use lightning::util::events::EventHandler as rustEventHandler;
1153 impl rustEventHandler for EventHandler {
1154 fn handle_event(&self, mut event: lightning::util::events::Event) {
1155 (self.handle_event)(self.this_arg, crate::lightning::util::events::Event::native_into(event))
1159 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1160 // directly as a Deref trait in higher-level structs:
1161 impl std::ops::Deref for EventHandler {
1163 fn deref(&self) -> &Self {
1167 /// Calls the free function if one is set
1169 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
1170 impl Drop for EventHandler {
1171 fn drop(&mut self) {
1172 if let Some(f) = self.free {