1 //! Events are returned from various bits in the library which indicate some action must be taken
4 //! Because we don't have a built-in runtime, it's up to the client to call events at a time in the
5 //! future, as well as generate and broadcast funding transactions handle payment preimages and a
9 use bitcoin::hashes::Hash;
10 use crate::c_types::*;
12 /// An Event which you should probably take some action in response to.
14 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
15 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
16 /// written as it makes no sense to respond to it after reconnecting to peers).
21 /// Used to indicate that the client should generate a funding transaction with the given
22 /// parameters and then call ChannelManager::funding_transaction_generated.
23 /// Generated in ChannelManager message handling.
24 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
25 /// counterparty can steal your funds!
26 FundingGenerationReady {
27 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
28 channel_value_satoshis: u64,
29 output_script: crate::c_types::derived::CVec_u8Z,
32 /// Used to indicate that the client may now broadcast the funding transaction it created for a
33 /// channel. Broadcasting such a transaction prior to this event may lead to our counterparty
34 /// trivially stealing all funds in the funding transaction!
35 FundingBroadcastSafe {
36 funding_txo: crate::chain::transaction::OutPoint,
39 /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
40 /// ChannelManager::claim_funds to get it....
41 /// Note that if the preimage is not known or the amount paid is incorrect, you should call
42 /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid
43 /// network congestion.
44 /// The amount paid should be considered 'incorrect' when it is less than or more than twice
45 /// the amount expected.
46 /// If you fail to call either ChannelManager::claim_funds or
47 /// ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be
48 /// automatically failed.
50 payment_hash: crate::c_types::ThirtyTwoBytes,
51 payment_secret: crate::c_types::ThirtyTwoBytes,
54 /// Indicates an outbound payment we made succeeded (ie it made it all the way to its target
55 /// and we got back the payment preimage for it).
56 /// Note that duplicative PaymentSent Events may be generated - it is your responsibility to
57 /// deduplicate them by payment_preimage (which MUST be unique)!
59 payment_preimage: crate::c_types::ThirtyTwoBytes,
61 /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
62 /// something. You may wish to retry with a different route.
63 /// Note that duplicative PaymentFailed Events may be generated - it is your responsibility to
64 /// deduplicate them by payment_hash (which MUST be unique)!
66 payment_hash: crate::c_types::ThirtyTwoBytes,
67 rejected_by_dest: bool,
69 /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
70 /// time in the future.
71 PendingHTLCsForwardable {
72 time_forwardable: u64,
74 /// Used to indicate that an output was generated on-chain which you should know how to spend.
75 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
76 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
77 /// somewhere and spend them when you create on-chain transactions.
79 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
82 use lightning::util::events::Event as nativeEvent;
85 pub(crate) fn to_native(&self) -> nativeEvent {
87 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
88 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
89 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
90 let mut output_script_nonref = (*output_script).clone();
91 let mut user_channel_id_nonref = (*user_channel_id).clone();
92 nativeEvent::FundingGenerationReady {
93 temporary_channel_id: temporary_channel_id_nonref.data,
94 channel_value_satoshis: channel_value_satoshis_nonref,
95 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
96 user_channel_id: user_channel_id_nonref,
99 Event::FundingBroadcastSafe {ref funding_txo, ref user_channel_id, } => {
100 let mut funding_txo_nonref = (*funding_txo).clone();
101 let mut user_channel_id_nonref = (*user_channel_id).clone();
102 nativeEvent::FundingBroadcastSafe {
103 funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
104 user_channel_id: user_channel_id_nonref,
107 Event::PaymentReceived {ref payment_hash, ref payment_secret, ref amt, } => {
108 let mut payment_hash_nonref = (*payment_hash).clone();
109 let mut payment_secret_nonref = (*payment_secret).clone();
110 let mut local_payment_secret_nonref = if payment_secret_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret_nonref.data) }) };
111 let mut amt_nonref = (*amt).clone();
112 nativeEvent::PaymentReceived {
113 payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash_nonref.data),
114 payment_secret: local_payment_secret_nonref,
118 Event::PaymentSent {ref payment_preimage, } => {
119 let mut payment_preimage_nonref = (*payment_preimage).clone();
120 nativeEvent::PaymentSent {
121 payment_preimage: ::lightning::ln::channelmanager::PaymentPreimage(payment_preimage_nonref.data),
124 Event::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
125 let mut payment_hash_nonref = (*payment_hash).clone();
126 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
127 nativeEvent::PaymentFailed {
128 payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash_nonref.data),
129 rejected_by_dest: rejected_by_dest_nonref,
132 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
133 let mut time_forwardable_nonref = (*time_forwardable).clone();
134 nativeEvent::PendingHTLCsForwardable {
135 time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
138 Event::SpendableOutputs {ref outputs, } => {
139 let mut outputs_nonref = (*outputs).clone();
140 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
141 nativeEvent::SpendableOutputs {
142 outputs: local_outputs_nonref,
148 pub(crate) fn into_native(self) -> nativeEvent {
150 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
151 nativeEvent::FundingGenerationReady {
152 temporary_channel_id: temporary_channel_id.data,
153 channel_value_satoshis: channel_value_satoshis,
154 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
155 user_channel_id: user_channel_id,
158 Event::FundingBroadcastSafe {mut funding_txo, mut user_channel_id, } => {
159 nativeEvent::FundingBroadcastSafe {
160 funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
161 user_channel_id: user_channel_id,
164 Event::PaymentReceived {mut payment_hash, mut payment_secret, mut amt, } => {
165 let mut local_payment_secret = if payment_secret.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentSecret(payment_secret.data) }) };
166 nativeEvent::PaymentReceived {
167 payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash.data),
168 payment_secret: local_payment_secret,
172 Event::PaymentSent {mut payment_preimage, } => {
173 nativeEvent::PaymentSent {
174 payment_preimage: ::lightning::ln::channelmanager::PaymentPreimage(payment_preimage.data),
177 Event::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
178 nativeEvent::PaymentFailed {
179 payment_hash: ::lightning::ln::channelmanager::PaymentHash(payment_hash.data),
180 rejected_by_dest: rejected_by_dest,
183 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
184 nativeEvent::PendingHTLCsForwardable {
185 time_forwardable: std::time::Duration::from_secs(time_forwardable),
188 Event::SpendableOutputs {mut outputs, } => {
189 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
190 nativeEvent::SpendableOutputs {
191 outputs: local_outputs,
197 pub(crate) fn from_native(native: &nativeEvent) -> Self {
199 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
200 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
201 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
202 let mut output_script_nonref = (*output_script).clone();
203 let mut user_channel_id_nonref = (*user_channel_id).clone();
204 Event::FundingGenerationReady {
205 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
206 channel_value_satoshis: channel_value_satoshis_nonref,
207 output_script: output_script_nonref.into_bytes().into(),
208 user_channel_id: user_channel_id_nonref,
211 nativeEvent::FundingBroadcastSafe {ref funding_txo, ref user_channel_id, } => {
212 let mut funding_txo_nonref = (*funding_txo).clone();
213 let mut user_channel_id_nonref = (*user_channel_id).clone();
214 Event::FundingBroadcastSafe {
215 funding_txo: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo_nonref)), is_owned: true },
216 user_channel_id: user_channel_id_nonref,
219 nativeEvent::PaymentReceived {ref payment_hash, ref payment_secret, ref amt, } => {
220 let mut payment_hash_nonref = (*payment_hash).clone();
221 let mut payment_secret_nonref = (*payment_secret).clone();
222 let mut local_payment_secret_nonref = if payment_secret_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_secret_nonref.unwrap()).0 } } };
223 let mut amt_nonref = (*amt).clone();
224 Event::PaymentReceived {
225 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
226 payment_secret: local_payment_secret_nonref,
230 nativeEvent::PaymentSent {ref payment_preimage, } => {
231 let mut payment_preimage_nonref = (*payment_preimage).clone();
233 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
236 nativeEvent::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
237 let mut payment_hash_nonref = (*payment_hash).clone();
238 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
239 Event::PaymentFailed {
240 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
241 rejected_by_dest: rejected_by_dest_nonref,
244 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
245 let mut time_forwardable_nonref = (*time_forwardable).clone();
246 Event::PendingHTLCsForwardable {
247 time_forwardable: time_forwardable_nonref.as_secs(),
250 nativeEvent::SpendableOutputs {ref outputs, } => {
251 let mut outputs_nonref = (*outputs).clone();
252 let mut local_outputs_nonref = Vec::new(); for item in outputs_nonref.drain(..) { local_outputs_nonref.push( { crate::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
253 Event::SpendableOutputs {
254 outputs: local_outputs_nonref.into(),
260 pub(crate) fn native_into(native: nativeEvent) -> Self {
262 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
263 Event::FundingGenerationReady {
264 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
265 channel_value_satoshis: channel_value_satoshis,
266 output_script: output_script.into_bytes().into(),
267 user_channel_id: user_channel_id,
270 nativeEvent::FundingBroadcastSafe {mut funding_txo, mut user_channel_id, } => {
271 Event::FundingBroadcastSafe {
272 funding_txo: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true },
273 user_channel_id: user_channel_id,
276 nativeEvent::PaymentReceived {mut payment_hash, mut payment_secret, mut amt, } => {
277 let mut local_payment_secret = if payment_secret.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_secret.unwrap()).0 } } };
278 Event::PaymentReceived {
279 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
280 payment_secret: local_payment_secret,
284 nativeEvent::PaymentSent {mut payment_preimage, } => {
286 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
289 nativeEvent::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
290 Event::PaymentFailed {
291 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
292 rejected_by_dest: rejected_by_dest,
295 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
296 Event::PendingHTLCsForwardable {
297 time_forwardable: time_forwardable.as_secs(),
300 nativeEvent::SpendableOutputs {mut outputs, } => {
301 let mut local_outputs = Vec::new(); for item in outputs.drain(..) { local_outputs.push( { crate::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
302 Event::SpendableOutputs {
303 outputs: local_outputs.into(),
310 pub extern "C" fn Event_free(this_ptr: Event) { }
312 pub extern "C" fn Event_clone(orig: &Event) -> Event {
315 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
316 /// broadcast to most peers).
317 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
321 pub enum MessageSendEvent {
322 /// Used to indicate that we've accepted a channel open and should send the accept_channel
323 /// message provided to the given peer.
325 node_id: crate::c_types::PublicKey,
326 msg: crate::ln::msgs::AcceptChannel,
328 /// Used to indicate that we've initiated a channel open and should send the open_channel
329 /// message provided to the given peer.
331 node_id: crate::c_types::PublicKey,
332 msg: crate::ln::msgs::OpenChannel,
334 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
336 node_id: crate::c_types::PublicKey,
337 msg: crate::ln::msgs::FundingCreated,
339 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
341 node_id: crate::c_types::PublicKey,
342 msg: crate::ln::msgs::FundingSigned,
344 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
346 node_id: crate::c_types::PublicKey,
347 msg: crate::ln::msgs::FundingLocked,
349 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
350 SendAnnouncementSignatures {
351 node_id: crate::c_types::PublicKey,
352 msg: crate::ln::msgs::AnnouncementSignatures,
354 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
355 /// message should be sent to the peer with the given node_id.
357 node_id: crate::c_types::PublicKey,
358 updates: crate::ln::msgs::CommitmentUpdate,
360 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
362 node_id: crate::c_types::PublicKey,
363 msg: crate::ln::msgs::RevokeAndACK,
365 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
367 node_id: crate::c_types::PublicKey,
368 msg: crate::ln::msgs::ClosingSigned,
370 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
372 node_id: crate::c_types::PublicKey,
373 msg: crate::ln::msgs::Shutdown,
375 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
376 SendChannelReestablish {
377 node_id: crate::c_types::PublicKey,
378 msg: crate::ln::msgs::ChannelReestablish,
380 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
381 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
383 /// Note that after doing so, you very likely (unless you did so very recently) want to call
384 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
385 /// This ensures that any nodes which see our channel_announcement also have a relevant
386 /// node_announcement, including relevant feature flags which may be important for routing
387 /// through or to us.
388 BroadcastChannelAnnouncement {
389 msg: crate::ln::msgs::ChannelAnnouncement,
390 update_msg: crate::ln::msgs::ChannelUpdate,
392 /// Used to indicate that a node_announcement should be broadcast to all peers.
393 BroadcastNodeAnnouncement {
394 msg: crate::ln::msgs::NodeAnnouncement,
396 /// Used to indicate that a channel_update should be broadcast to all peers.
397 BroadcastChannelUpdate {
398 msg: crate::ln::msgs::ChannelUpdate,
400 /// Broadcast an error downstream to be handled
402 node_id: crate::c_types::PublicKey,
403 action: crate::ln::msgs::ErrorAction,
405 /// When a payment fails we may receive updates back from the hop where it failed. In such
406 /// cases this event is generated so that we can inform the network graph of this information.
407 PaymentFailureNetworkUpdate {
408 update: crate::ln::msgs::HTLCFailChannelUpdate,
410 /// Query a peer for channels with funding transaction UTXOs in a block range.
411 SendChannelRangeQuery {
412 node_id: crate::c_types::PublicKey,
413 msg: crate::ln::msgs::QueryChannelRange,
415 /// Request routing gossip messages from a peer for a list of channels identified by
416 /// their short_channel_ids.
418 node_id: crate::c_types::PublicKey,
419 msg: crate::ln::msgs::QueryShortChannelIds,
422 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
423 impl MessageSendEvent {
425 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
427 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
428 let mut node_id_nonref = (*node_id).clone();
429 let mut msg_nonref = (*msg).clone();
430 nativeMessageSendEvent::SendAcceptChannel {
431 node_id: node_id_nonref.into_rust(),
432 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
435 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
436 let mut node_id_nonref = (*node_id).clone();
437 let mut msg_nonref = (*msg).clone();
438 nativeMessageSendEvent::SendOpenChannel {
439 node_id: node_id_nonref.into_rust(),
440 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
443 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
444 let mut node_id_nonref = (*node_id).clone();
445 let mut msg_nonref = (*msg).clone();
446 nativeMessageSendEvent::SendFundingCreated {
447 node_id: node_id_nonref.into_rust(),
448 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
451 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
452 let mut node_id_nonref = (*node_id).clone();
453 let mut msg_nonref = (*msg).clone();
454 nativeMessageSendEvent::SendFundingSigned {
455 node_id: node_id_nonref.into_rust(),
456 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
459 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
460 let mut node_id_nonref = (*node_id).clone();
461 let mut msg_nonref = (*msg).clone();
462 nativeMessageSendEvent::SendFundingLocked {
463 node_id: node_id_nonref.into_rust(),
464 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
467 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
468 let mut node_id_nonref = (*node_id).clone();
469 let mut msg_nonref = (*msg).clone();
470 nativeMessageSendEvent::SendAnnouncementSignatures {
471 node_id: node_id_nonref.into_rust(),
472 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
475 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
476 let mut node_id_nonref = (*node_id).clone();
477 let mut updates_nonref = (*updates).clone();
478 nativeMessageSendEvent::UpdateHTLCs {
479 node_id: node_id_nonref.into_rust(),
480 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
483 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
484 let mut node_id_nonref = (*node_id).clone();
485 let mut msg_nonref = (*msg).clone();
486 nativeMessageSendEvent::SendRevokeAndACK {
487 node_id: node_id_nonref.into_rust(),
488 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
491 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
492 let mut node_id_nonref = (*node_id).clone();
493 let mut msg_nonref = (*msg).clone();
494 nativeMessageSendEvent::SendClosingSigned {
495 node_id: node_id_nonref.into_rust(),
496 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
499 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
500 let mut node_id_nonref = (*node_id).clone();
501 let mut msg_nonref = (*msg).clone();
502 nativeMessageSendEvent::SendShutdown {
503 node_id: node_id_nonref.into_rust(),
504 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
507 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
508 let mut node_id_nonref = (*node_id).clone();
509 let mut msg_nonref = (*msg).clone();
510 nativeMessageSendEvent::SendChannelReestablish {
511 node_id: node_id_nonref.into_rust(),
512 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
515 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
516 let mut msg_nonref = (*msg).clone();
517 let mut update_msg_nonref = (*update_msg).clone();
518 nativeMessageSendEvent::BroadcastChannelAnnouncement {
519 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
520 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
523 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
524 let mut msg_nonref = (*msg).clone();
525 nativeMessageSendEvent::BroadcastNodeAnnouncement {
526 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
529 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
530 let mut msg_nonref = (*msg).clone();
531 nativeMessageSendEvent::BroadcastChannelUpdate {
532 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
535 MessageSendEvent::HandleError {ref node_id, ref action, } => {
536 let mut node_id_nonref = (*node_id).clone();
537 let mut action_nonref = (*action).clone();
538 nativeMessageSendEvent::HandleError {
539 node_id: node_id_nonref.into_rust(),
540 action: action_nonref.into_native(),
543 MessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
544 let mut update_nonref = (*update).clone();
545 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
546 update: update_nonref.into_native(),
549 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
550 let mut node_id_nonref = (*node_id).clone();
551 let mut msg_nonref = (*msg).clone();
552 nativeMessageSendEvent::SendChannelRangeQuery {
553 node_id: node_id_nonref.into_rust(),
554 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
557 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
558 let mut node_id_nonref = (*node_id).clone();
559 let mut msg_nonref = (*msg).clone();
560 nativeMessageSendEvent::SendShortIdsQuery {
561 node_id: node_id_nonref.into_rust(),
562 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
568 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
570 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
571 nativeMessageSendEvent::SendAcceptChannel {
572 node_id: node_id.into_rust(),
573 msg: *unsafe { Box::from_raw(msg.take_inner()) },
576 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
577 nativeMessageSendEvent::SendOpenChannel {
578 node_id: node_id.into_rust(),
579 msg: *unsafe { Box::from_raw(msg.take_inner()) },
582 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
583 nativeMessageSendEvent::SendFundingCreated {
584 node_id: node_id.into_rust(),
585 msg: *unsafe { Box::from_raw(msg.take_inner()) },
588 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
589 nativeMessageSendEvent::SendFundingSigned {
590 node_id: node_id.into_rust(),
591 msg: *unsafe { Box::from_raw(msg.take_inner()) },
594 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
595 nativeMessageSendEvent::SendFundingLocked {
596 node_id: node_id.into_rust(),
597 msg: *unsafe { Box::from_raw(msg.take_inner()) },
600 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
601 nativeMessageSendEvent::SendAnnouncementSignatures {
602 node_id: node_id.into_rust(),
603 msg: *unsafe { Box::from_raw(msg.take_inner()) },
606 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
607 nativeMessageSendEvent::UpdateHTLCs {
608 node_id: node_id.into_rust(),
609 updates: *unsafe { Box::from_raw(updates.take_inner()) },
612 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
613 nativeMessageSendEvent::SendRevokeAndACK {
614 node_id: node_id.into_rust(),
615 msg: *unsafe { Box::from_raw(msg.take_inner()) },
618 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
619 nativeMessageSendEvent::SendClosingSigned {
620 node_id: node_id.into_rust(),
621 msg: *unsafe { Box::from_raw(msg.take_inner()) },
624 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
625 nativeMessageSendEvent::SendShutdown {
626 node_id: node_id.into_rust(),
627 msg: *unsafe { Box::from_raw(msg.take_inner()) },
630 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
631 nativeMessageSendEvent::SendChannelReestablish {
632 node_id: node_id.into_rust(),
633 msg: *unsafe { Box::from_raw(msg.take_inner()) },
636 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
637 nativeMessageSendEvent::BroadcastChannelAnnouncement {
638 msg: *unsafe { Box::from_raw(msg.take_inner()) },
639 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
642 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
643 nativeMessageSendEvent::BroadcastNodeAnnouncement {
644 msg: *unsafe { Box::from_raw(msg.take_inner()) },
647 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
648 nativeMessageSendEvent::BroadcastChannelUpdate {
649 msg: *unsafe { Box::from_raw(msg.take_inner()) },
652 MessageSendEvent::HandleError {mut node_id, mut action, } => {
653 nativeMessageSendEvent::HandleError {
654 node_id: node_id.into_rust(),
655 action: action.into_native(),
658 MessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
659 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
660 update: update.into_native(),
663 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
664 nativeMessageSendEvent::SendChannelRangeQuery {
665 node_id: node_id.into_rust(),
666 msg: *unsafe { Box::from_raw(msg.take_inner()) },
669 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
670 nativeMessageSendEvent::SendShortIdsQuery {
671 node_id: node_id.into_rust(),
672 msg: *unsafe { Box::from_raw(msg.take_inner()) },
678 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
680 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
681 let mut node_id_nonref = (*node_id).clone();
682 let mut msg_nonref = (*msg).clone();
683 MessageSendEvent::SendAcceptChannel {
684 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
685 msg: crate::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
688 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
689 let mut node_id_nonref = (*node_id).clone();
690 let mut msg_nonref = (*msg).clone();
691 MessageSendEvent::SendOpenChannel {
692 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
693 msg: crate::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
696 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
697 let mut node_id_nonref = (*node_id).clone();
698 let mut msg_nonref = (*msg).clone();
699 MessageSendEvent::SendFundingCreated {
700 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
701 msg: crate::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
704 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
705 let mut node_id_nonref = (*node_id).clone();
706 let mut msg_nonref = (*msg).clone();
707 MessageSendEvent::SendFundingSigned {
708 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
709 msg: crate::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
712 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
713 let mut node_id_nonref = (*node_id).clone();
714 let mut msg_nonref = (*msg).clone();
715 MessageSendEvent::SendFundingLocked {
716 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
717 msg: crate::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
720 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
721 let mut node_id_nonref = (*node_id).clone();
722 let mut msg_nonref = (*msg).clone();
723 MessageSendEvent::SendAnnouncementSignatures {
724 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
725 msg: crate::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
728 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
729 let mut node_id_nonref = (*node_id).clone();
730 let mut updates_nonref = (*updates).clone();
731 MessageSendEvent::UpdateHTLCs {
732 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
733 updates: crate::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates_nonref)), is_owned: true },
736 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
737 let mut node_id_nonref = (*node_id).clone();
738 let mut msg_nonref = (*msg).clone();
739 MessageSendEvent::SendRevokeAndACK {
740 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
741 msg: crate::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
744 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
745 let mut node_id_nonref = (*node_id).clone();
746 let mut msg_nonref = (*msg).clone();
747 MessageSendEvent::SendClosingSigned {
748 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
749 msg: crate::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
752 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
753 let mut node_id_nonref = (*node_id).clone();
754 let mut msg_nonref = (*msg).clone();
755 MessageSendEvent::SendShutdown {
756 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
757 msg: crate::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
760 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
761 let mut node_id_nonref = (*node_id).clone();
762 let mut msg_nonref = (*msg).clone();
763 MessageSendEvent::SendChannelReestablish {
764 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
765 msg: crate::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
768 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
769 let mut msg_nonref = (*msg).clone();
770 let mut update_msg_nonref = (*update_msg).clone();
771 MessageSendEvent::BroadcastChannelAnnouncement {
772 msg: crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
773 update_msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg_nonref)), is_owned: true },
776 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
777 let mut msg_nonref = (*msg).clone();
778 MessageSendEvent::BroadcastNodeAnnouncement {
779 msg: crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
782 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
783 let mut msg_nonref = (*msg).clone();
784 MessageSendEvent::BroadcastChannelUpdate {
785 msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
788 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
789 let mut node_id_nonref = (*node_id).clone();
790 let mut action_nonref = (*action).clone();
791 MessageSendEvent::HandleError {
792 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
793 action: crate::ln::msgs::ErrorAction::native_into(action_nonref),
796 nativeMessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
797 let mut update_nonref = (*update).clone();
798 MessageSendEvent::PaymentFailureNetworkUpdate {
799 update: crate::ln::msgs::HTLCFailChannelUpdate::native_into(update_nonref),
802 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
803 let mut node_id_nonref = (*node_id).clone();
804 let mut msg_nonref = (*msg).clone();
805 MessageSendEvent::SendChannelRangeQuery {
806 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
807 msg: crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
810 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
811 let mut node_id_nonref = (*node_id).clone();
812 let mut msg_nonref = (*msg).clone();
813 MessageSendEvent::SendShortIdsQuery {
814 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
815 msg: crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
821 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
823 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
824 MessageSendEvent::SendAcceptChannel {
825 node_id: crate::c_types::PublicKey::from_rust(&node_id),
826 msg: crate::ln::msgs::AcceptChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
829 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
830 MessageSendEvent::SendOpenChannel {
831 node_id: crate::c_types::PublicKey::from_rust(&node_id),
832 msg: crate::ln::msgs::OpenChannel { inner: Box::into_raw(Box::new(msg)), is_owned: true },
835 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
836 MessageSendEvent::SendFundingCreated {
837 node_id: crate::c_types::PublicKey::from_rust(&node_id),
838 msg: crate::ln::msgs::FundingCreated { inner: Box::into_raw(Box::new(msg)), is_owned: true },
841 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
842 MessageSendEvent::SendFundingSigned {
843 node_id: crate::c_types::PublicKey::from_rust(&node_id),
844 msg: crate::ln::msgs::FundingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
847 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
848 MessageSendEvent::SendFundingLocked {
849 node_id: crate::c_types::PublicKey::from_rust(&node_id),
850 msg: crate::ln::msgs::FundingLocked { inner: Box::into_raw(Box::new(msg)), is_owned: true },
853 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
854 MessageSendEvent::SendAnnouncementSignatures {
855 node_id: crate::c_types::PublicKey::from_rust(&node_id),
856 msg: crate::ln::msgs::AnnouncementSignatures { inner: Box::into_raw(Box::new(msg)), is_owned: true },
859 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
860 MessageSendEvent::UpdateHTLCs {
861 node_id: crate::c_types::PublicKey::from_rust(&node_id),
862 updates: crate::ln::msgs::CommitmentUpdate { inner: Box::into_raw(Box::new(updates)), is_owned: true },
865 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
866 MessageSendEvent::SendRevokeAndACK {
867 node_id: crate::c_types::PublicKey::from_rust(&node_id),
868 msg: crate::ln::msgs::RevokeAndACK { inner: Box::into_raw(Box::new(msg)), is_owned: true },
871 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
872 MessageSendEvent::SendClosingSigned {
873 node_id: crate::c_types::PublicKey::from_rust(&node_id),
874 msg: crate::ln::msgs::ClosingSigned { inner: Box::into_raw(Box::new(msg)), is_owned: true },
877 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
878 MessageSendEvent::SendShutdown {
879 node_id: crate::c_types::PublicKey::from_rust(&node_id),
880 msg: crate::ln::msgs::Shutdown { inner: Box::into_raw(Box::new(msg)), is_owned: true },
883 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
884 MessageSendEvent::SendChannelReestablish {
885 node_id: crate::c_types::PublicKey::from_rust(&node_id),
886 msg: crate::ln::msgs::ChannelReestablish { inner: Box::into_raw(Box::new(msg)), is_owned: true },
889 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
890 MessageSendEvent::BroadcastChannelAnnouncement {
891 msg: crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
892 update_msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(update_msg)), is_owned: true },
895 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
896 MessageSendEvent::BroadcastNodeAnnouncement {
897 msg: crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(msg)), is_owned: true },
900 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
901 MessageSendEvent::BroadcastChannelUpdate {
902 msg: crate::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg)), is_owned: true },
905 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
906 MessageSendEvent::HandleError {
907 node_id: crate::c_types::PublicKey::from_rust(&node_id),
908 action: crate::ln::msgs::ErrorAction::native_into(action),
911 nativeMessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
912 MessageSendEvent::PaymentFailureNetworkUpdate {
913 update: crate::ln::msgs::HTLCFailChannelUpdate::native_into(update),
916 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
917 MessageSendEvent::SendChannelRangeQuery {
918 node_id: crate::c_types::PublicKey::from_rust(&node_id),
919 msg: crate::ln::msgs::QueryChannelRange { inner: Box::into_raw(Box::new(msg)), is_owned: true },
922 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
923 MessageSendEvent::SendShortIdsQuery {
924 node_id: crate::c_types::PublicKey::from_rust(&node_id),
925 msg: crate::ln::msgs::QueryShortChannelIds { inner: Box::into_raw(Box::new(msg)), is_owned: true },
932 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
934 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
937 /// A trait indicating an object may generate message send events
939 pub struct MessageSendEventsProvider {
940 pub this_arg: *mut c_void,
941 /// Gets the list of pending events which were generated by previous actions, clearing the list
944 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
945 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
948 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
949 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
950 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
951 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
952 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
957 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
958 // directly as a Deref trait in higher-level structs:
959 impl std::ops::Deref for MessageSendEventsProvider {
961 fn deref(&self) -> &Self {
965 /// Calls the free function if one is set
967 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
968 impl Drop for MessageSendEventsProvider {
970 if let Some(f) = self.free {
975 /// A trait indicating an object may generate events
977 pub struct EventsProvider {
978 pub this_arg: *mut c_void,
979 /// Gets the list of pending events which were generated by previous actions, clearing the list
982 pub get_and_clear_pending_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_EventZ,
983 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
986 use lightning::util::events::EventsProvider as rustEventsProvider;
987 impl rustEventsProvider for EventsProvider {
988 fn get_and_clear_pending_events(&self) -> Vec<lightning::util::events::Event> {
989 let mut ret = (self.get_and_clear_pending_events)(self.this_arg);
990 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
995 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
996 // directly as a Deref trait in higher-level structs:
997 impl std::ops::Deref for EventsProvider {
999 fn deref(&self) -> &Self {
1003 /// Calls the free function if one is set
1005 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1006 impl Drop for EventsProvider {
1007 fn drop(&mut self) {
1008 if let Some(f) = self.free {