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 alloc::str::FromStr;
17 use core::ffi::c_void;
18 use core::convert::Infallible;
19 use bitcoin::hashes::Hash;
20 use crate::c_types::*;
21 #[cfg(feature="no-std")]
22 use alloc::{vec::Vec, boxed::Box};
24 /// Some information provided on receipt of payment depends on whether the payment received is a
25 /// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
29 pub enum PaymentPurpose {
30 /// Information for receiving a payment that we generated an invoice for.
32 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
33 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
34 /// [`ChannelManager::claim_funds`].
36 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
37 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
39 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
40 payment_preimage: crate::c_types::ThirtyTwoBytes,
41 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
42 /// number of deanonymization attacks during the routing process.
43 /// It is provided here for your reference, however its accuracy is enforced directly by
44 /// [`ChannelManager`] using the values you previously provided to
45 /// [`ChannelManager::create_inbound_payment`] or
46 /// [`ChannelManager::create_inbound_payment_for_hash`].
48 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
49 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
50 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
51 payment_secret: crate::c_types::ThirtyTwoBytes,
53 /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
54 /// (the payee) providing a preimage.
56 crate::c_types::ThirtyTwoBytes),
58 use lightning::util::events::PaymentPurpose as PaymentPurposeImport;
59 pub(crate) type nativePaymentPurpose = PaymentPurposeImport;
63 pub(crate) fn to_native(&self) -> nativePaymentPurpose {
65 PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
66 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
67 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
68 let mut payment_secret_nonref = Clone::clone(payment_secret);
69 nativePaymentPurpose::InvoicePayment {
70 payment_preimage: local_payment_preimage_nonref,
71 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
74 PaymentPurpose::SpontaneousPayment (ref a, ) => {
75 let mut a_nonref = Clone::clone(a);
76 nativePaymentPurpose::SpontaneousPayment (
77 ::lightning::ln::PaymentPreimage(a_nonref.data),
83 pub(crate) fn into_native(self) -> nativePaymentPurpose {
85 PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
86 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
87 nativePaymentPurpose::InvoicePayment {
88 payment_preimage: local_payment_preimage,
89 payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
92 PaymentPurpose::SpontaneousPayment (mut a, ) => {
93 nativePaymentPurpose::SpontaneousPayment (
94 ::lightning::ln::PaymentPreimage(a.data),
100 pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
102 nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
103 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
104 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 } } };
105 let mut payment_secret_nonref = Clone::clone(payment_secret);
106 PaymentPurpose::InvoicePayment {
107 payment_preimage: local_payment_preimage_nonref,
108 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
111 nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
112 let mut a_nonref = Clone::clone(a);
113 PaymentPurpose::SpontaneousPayment (
114 crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
120 pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
122 nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
123 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 } } };
124 PaymentPurpose::InvoicePayment {
125 payment_preimage: local_payment_preimage,
126 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
129 nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
130 PaymentPurpose::SpontaneousPayment (
131 crate::c_types::ThirtyTwoBytes { data: a.0 },
137 /// Frees any resources used by the PaymentPurpose
139 pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
140 /// Creates a copy of the PaymentPurpose
142 pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
146 /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
147 pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
148 PaymentPurpose::InvoicePayment {
154 /// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
155 pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
156 PaymentPurpose::SpontaneousPayment(a, )
159 /// Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
160 pub extern "C" fn PaymentPurpose_write(obj: &crate::lightning::util::events::PaymentPurpose) -> crate::c_types::derived::CVec_u8Z {
161 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
164 /// Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
165 pub extern "C" fn PaymentPurpose_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentPurposeDecodeErrorZ {
166 let res: Result<lightning::util::events::PaymentPurpose, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
167 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::events::PaymentPurpose::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
170 /// The reason the channel was closed. See individual variants more details.
174 pub enum ClosureReason {
175 /// Closure generated from receiving a peer error message.
177 /// Our counterparty may have broadcasted their latest commitment state, and we have
179 CounterpartyForceClosed {
180 /// The error which the peer sent us.
182 /// The string should be sanitized before it is used (e.g emitted to logs
183 /// or printed to stdout). Otherwise, a well crafted error message may exploit
184 /// a security vulnerability in the terminal emulator or the logging subsystem.
185 peer_msg: crate::c_types::Str,
187 /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
189 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
191 /// The channel was closed after negotiating a cooperative close and we've now broadcasted
192 /// the cooperative close transaction. Note the shutdown may have been initiated by us.
194 /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
195 /// commitment transaction came from our counterparty, but it may also have come from
196 /// a copy of our own `ChannelMonitor`.
197 CommitmentTxConfirmed,
198 /// The funding transaction failed to confirm in a timely manner on an inbound channel.
200 /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
202 /// A developer-readable error message which we generated.
203 err: crate::c_types::Str,
205 /// The peer disconnected prior to funding completing. In this case the spec mandates that we
206 /// forget the channel entirely - we can attempt again if the peer reconnects.
208 /// This includes cases where we restarted prior to funding completion, including prior to the
209 /// initial [`ChannelMonitor`] persistence completing.
211 /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
212 /// peer because of mutual incompatibility between us and our channel counterparty.
214 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
216 /// Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
217 /// the [`ChannelManager`] deserialized.
219 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
220 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
221 OutdatedChannelManager,
223 use lightning::util::events::ClosureReason as ClosureReasonImport;
224 pub(crate) type nativeClosureReason = ClosureReasonImport;
228 pub(crate) fn to_native(&self) -> nativeClosureReason {
230 ClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
231 let mut peer_msg_nonref = Clone::clone(peer_msg);
232 nativeClosureReason::CounterpartyForceClosed {
233 peer_msg: peer_msg_nonref.into_string(),
236 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
237 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
238 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
239 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
240 ClosureReason::ProcessingError {ref err, } => {
241 let mut err_nonref = Clone::clone(err);
242 nativeClosureReason::ProcessingError {
243 err: err_nonref.into_string(),
246 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
247 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
251 pub(crate) fn into_native(self) -> nativeClosureReason {
253 ClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
254 nativeClosureReason::CounterpartyForceClosed {
255 peer_msg: peer_msg.into_string(),
258 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
259 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
260 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
261 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
262 ClosureReason::ProcessingError {mut err, } => {
263 nativeClosureReason::ProcessingError {
264 err: err.into_string(),
267 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
268 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
272 pub(crate) fn from_native(native: &nativeClosureReason) -> Self {
274 nativeClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
275 let mut peer_msg_nonref = Clone::clone(peer_msg);
276 ClosureReason::CounterpartyForceClosed {
277 peer_msg: peer_msg_nonref.into(),
280 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
281 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
282 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
283 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
284 nativeClosureReason::ProcessingError {ref err, } => {
285 let mut err_nonref = Clone::clone(err);
286 ClosureReason::ProcessingError {
287 err: err_nonref.into(),
290 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
291 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
295 pub(crate) fn native_into(native: nativeClosureReason) -> Self {
297 nativeClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
298 ClosureReason::CounterpartyForceClosed {
299 peer_msg: peer_msg.into(),
302 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
303 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
304 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
305 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
306 nativeClosureReason::ProcessingError {mut err, } => {
307 ClosureReason::ProcessingError {
311 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
312 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
316 /// Frees any resources used by the ClosureReason
318 pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { }
319 /// Creates a copy of the ClosureReason
321 pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason {
325 /// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
326 pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::c_types::Str) -> ClosureReason {
327 ClosureReason::CounterpartyForceClosed {
332 /// Utility method to constructs a new HolderForceClosed-variant ClosureReason
333 pub extern "C" fn ClosureReason_holder_force_closed() -> ClosureReason {
334 ClosureReason::HolderForceClosed}
336 /// Utility method to constructs a new CooperativeClosure-variant ClosureReason
337 pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason {
338 ClosureReason::CooperativeClosure}
340 /// Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
341 pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason {
342 ClosureReason::CommitmentTxConfirmed}
344 /// Utility method to constructs a new FundingTimedOut-variant ClosureReason
345 pub extern "C" fn ClosureReason_funding_timed_out() -> ClosureReason {
346 ClosureReason::FundingTimedOut}
348 /// Utility method to constructs a new ProcessingError-variant ClosureReason
349 pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason {
350 ClosureReason::ProcessingError {
355 /// Utility method to constructs a new DisconnectedPeer-variant ClosureReason
356 pub extern "C" fn ClosureReason_disconnected_peer() -> ClosureReason {
357 ClosureReason::DisconnectedPeer}
359 /// Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
360 pub extern "C" fn ClosureReason_outdated_channel_manager() -> ClosureReason {
361 ClosureReason::OutdatedChannelManager}
362 /// Checks if two ClosureReasons contain equal inner contents.
363 /// This ignores pointers and is_owned flags and looks at the values in fields.
365 pub extern "C" fn ClosureReason_eq(a: &ClosureReason, b: &ClosureReason) -> bool {
366 if &a.to_native() == &b.to_native() { true } else { false }
369 /// Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
370 pub extern "C" fn ClosureReason_write(obj: &crate::lightning::util::events::ClosureReason) -> crate::c_types::derived::CVec_u8Z {
371 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
374 /// Read a ClosureReason from a byte array, created by ClosureReason_write
375 pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_ClosureReasonZDecodeErrorZ {
376 let res: Result<Option<lightning::util::events::ClosureReason>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
377 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_ClosureReasonZ::None } else { crate::c_types::derived::COption_ClosureReasonZ::Some( { crate::lightning::util::events::ClosureReason::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
380 /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
384 pub enum HTLCDestination {
385 /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
386 /// there is insufficient capacity in our outbound channel.
388 /// The `node_id` of the next node. For backwards compatibility, this field is
389 /// marked as optional, versions prior to 0.0.110 may not always be able to provide
390 /// counterparty node information.
392 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
393 node_id: crate::c_types::PublicKey,
394 /// The outgoing `channel_id` between us and the next node.
395 channel_id: crate::c_types::ThirtyTwoBytes,
397 /// Scenario where we are unsure of the next node to forward the HTLC to.
399 /// Short channel id we are requesting to forward an HTLC to.
400 requested_forward_scid: u64,
402 /// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
405 /// Short channel id we are requesting to forward an HTLC to.
406 requested_forward_scid: u64,
408 /// Failure scenario where an HTLC may have been forwarded to be intended for us,
409 /// but is invalid for some reason, so we reject it.
411 /// Some of the reasons may include:
413 /// * Expected MPP amount to claim does not equal HTLC total
414 /// * Claimable amount does not match expected amount
416 /// The payment hash of the payment we attempted to process.
417 payment_hash: crate::c_types::ThirtyTwoBytes,
420 use lightning::util::events::HTLCDestination as HTLCDestinationImport;
421 pub(crate) type nativeHTLCDestination = HTLCDestinationImport;
423 impl HTLCDestination {
425 pub(crate) fn to_native(&self) -> nativeHTLCDestination {
427 HTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
428 let mut node_id_nonref = Clone::clone(node_id);
429 let mut local_node_id_nonref = if node_id_nonref.is_null() { None } else { Some( { node_id_nonref.into_rust() }) };
430 let mut channel_id_nonref = Clone::clone(channel_id);
431 nativeHTLCDestination::NextHopChannel {
432 node_id: local_node_id_nonref,
433 channel_id: channel_id_nonref.data,
436 HTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
437 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
438 nativeHTLCDestination::UnknownNextHop {
439 requested_forward_scid: requested_forward_scid_nonref,
442 HTLCDestination::InvalidForward {ref requested_forward_scid, } => {
443 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
444 nativeHTLCDestination::InvalidForward {
445 requested_forward_scid: requested_forward_scid_nonref,
448 HTLCDestination::FailedPayment {ref payment_hash, } => {
449 let mut payment_hash_nonref = Clone::clone(payment_hash);
450 nativeHTLCDestination::FailedPayment {
451 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
457 pub(crate) fn into_native(self) -> nativeHTLCDestination {
459 HTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
460 let mut local_node_id = if node_id.is_null() { None } else { Some( { node_id.into_rust() }) };
461 nativeHTLCDestination::NextHopChannel {
462 node_id: local_node_id,
463 channel_id: channel_id.data,
466 HTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
467 nativeHTLCDestination::UnknownNextHop {
468 requested_forward_scid: requested_forward_scid,
471 HTLCDestination::InvalidForward {mut requested_forward_scid, } => {
472 nativeHTLCDestination::InvalidForward {
473 requested_forward_scid: requested_forward_scid,
476 HTLCDestination::FailedPayment {mut payment_hash, } => {
477 nativeHTLCDestination::FailedPayment {
478 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
484 pub(crate) fn from_native(native: &nativeHTLCDestination) -> Self {
486 nativeHTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
487 let mut node_id_nonref = Clone::clone(node_id);
488 let mut local_node_id_nonref = if node_id_nonref.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(node_id_nonref.unwrap())) } };
489 let mut channel_id_nonref = Clone::clone(channel_id);
490 HTLCDestination::NextHopChannel {
491 node_id: local_node_id_nonref,
492 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
495 nativeHTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
496 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
497 HTLCDestination::UnknownNextHop {
498 requested_forward_scid: requested_forward_scid_nonref,
501 nativeHTLCDestination::InvalidForward {ref requested_forward_scid, } => {
502 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
503 HTLCDestination::InvalidForward {
504 requested_forward_scid: requested_forward_scid_nonref,
507 nativeHTLCDestination::FailedPayment {ref payment_hash, } => {
508 let mut payment_hash_nonref = Clone::clone(payment_hash);
509 HTLCDestination::FailedPayment {
510 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
516 pub(crate) fn native_into(native: nativeHTLCDestination) -> Self {
518 nativeHTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
519 let mut local_node_id = if node_id.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(node_id.unwrap())) } };
520 HTLCDestination::NextHopChannel {
521 node_id: local_node_id,
522 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
525 nativeHTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
526 HTLCDestination::UnknownNextHop {
527 requested_forward_scid: requested_forward_scid,
530 nativeHTLCDestination::InvalidForward {mut requested_forward_scid, } => {
531 HTLCDestination::InvalidForward {
532 requested_forward_scid: requested_forward_scid,
535 nativeHTLCDestination::FailedPayment {mut payment_hash, } => {
536 HTLCDestination::FailedPayment {
537 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
543 /// Frees any resources used by the HTLCDestination
545 pub extern "C" fn HTLCDestination_free(this_ptr: HTLCDestination) { }
546 /// Creates a copy of the HTLCDestination
548 pub extern "C" fn HTLCDestination_clone(orig: &HTLCDestination) -> HTLCDestination {
552 /// Utility method to constructs a new NextHopChannel-variant HTLCDestination
553 pub extern "C" fn HTLCDestination_next_hop_channel(node_id: crate::c_types::PublicKey, channel_id: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
554 HTLCDestination::NextHopChannel {
560 /// Utility method to constructs a new UnknownNextHop-variant HTLCDestination
561 pub extern "C" fn HTLCDestination_unknown_next_hop(requested_forward_scid: u64) -> HTLCDestination {
562 HTLCDestination::UnknownNextHop {
563 requested_forward_scid,
567 /// Utility method to constructs a new InvalidForward-variant HTLCDestination
568 pub extern "C" fn HTLCDestination_invalid_forward(requested_forward_scid: u64) -> HTLCDestination {
569 HTLCDestination::InvalidForward {
570 requested_forward_scid,
574 /// Utility method to constructs a new FailedPayment-variant HTLCDestination
575 pub extern "C" fn HTLCDestination_failed_payment(payment_hash: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
576 HTLCDestination::FailedPayment {
580 /// Checks if two HTLCDestinations contain equal inner contents.
581 /// This ignores pointers and is_owned flags and looks at the values in fields.
583 pub extern "C" fn HTLCDestination_eq(a: &HTLCDestination, b: &HTLCDestination) -> bool {
584 if &a.to_native() == &b.to_native() { true } else { false }
587 /// Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
588 pub extern "C" fn HTLCDestination_write(obj: &crate::lightning::util::events::HTLCDestination) -> crate::c_types::derived::CVec_u8Z {
589 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
592 /// Read a HTLCDestination from a byte array, created by HTLCDestination_write
593 pub extern "C" fn HTLCDestination_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_HTLCDestinationZDecodeErrorZ {
594 let res: Result<Option<lightning::util::events::HTLCDestination>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
595 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_HTLCDestinationZ::None } else { crate::c_types::derived::COption_HTLCDestinationZ::Some( { crate::lightning::util::events::HTLCDestination::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
598 /// An Event which you should probably take some action in response to.
600 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
601 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
602 /// written as it makes no sense to respond to it after reconnecting to peers).
607 /// Used to indicate that the client should generate a funding transaction with the given
608 /// parameters and then call [`ChannelManager::funding_transaction_generated`].
609 /// Generated in [`ChannelManager`] message handling.
610 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
611 /// counterparty can steal your funds!
613 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
614 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
615 FundingGenerationReady {
616 /// The random channel_id we picked which you'll need to pass into
617 /// [`ChannelManager::funding_transaction_generated`].
619 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
620 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
621 /// The counterparty's node_id, which you'll need to pass back into
622 /// [`ChannelManager::funding_transaction_generated`].
624 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
625 counterparty_node_id: crate::c_types::PublicKey,
626 /// The value, in satoshis, that the output should have.
627 channel_value_satoshis: u64,
628 /// The script which should be used in the transaction output.
629 output_script: crate::c_types::derived::CVec_u8Z,
630 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or a
631 /// random value for an inbound channel. This may be zero for objects serialized with LDK
632 /// versions prior to 0.0.113.
634 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
635 user_channel_id: crate::c_types::U128,
637 /// Indicates that we've been offered a payment and it needs to be claimed via calling
638 /// [`ChannelManager::claim_funds`] with the preimage given in [`PaymentPurpose`].
640 /// Note that if the preimage is not known, you should call
641 /// [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid
642 /// network congestion.
643 /// If you fail to call either [`ChannelManager::claim_funds`] or
644 /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be
645 /// automatically failed.
648 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
649 /// `PaymentClaimable` events may be generated for the same payment.
652 /// This event used to be called `PaymentReceived` in LDK versions 0.0.112 and earlier.
654 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
655 /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
657 /// The node that will receive the payment after it has been claimed.
658 /// This is useful to identify payments received via [phantom nodes].
659 /// This field will always be filled in when the event was generated by LDK versions
660 /// 0.0.113 and above.
662 /// [phantom nodes]: crate::chain::keysinterface::PhantomKeysManager
664 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
665 receiver_node_id: crate::c_types::PublicKey,
666 /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
667 /// not stop you from registering duplicate payment hashes for inbound payments.
668 payment_hash: crate::c_types::ThirtyTwoBytes,
669 /// The value, in thousandths of a satoshi, that this payment is for.
671 /// Information for claiming this received payment, based on whether the purpose of the
672 /// payment is to pay an invoice or to send a spontaneous payment.
673 purpose: crate::lightning::util::events::PaymentPurpose,
674 /// The `channel_id` indicating over which channel we received the payment.
676 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
677 via_channel_id: crate::c_types::ThirtyTwoBytes,
678 /// The `user_channel_id` indicating over which channel we received the payment.
679 via_user_channel_id: crate::c_types::derived::COption_u128Z,
681 /// Indicates a payment has been claimed and we've received money!
683 /// This most likely occurs when [`ChannelManager::claim_funds`] has been called in response
684 /// to an [`Event::PaymentClaimable`]. However, if we previously crashed during a
685 /// [`ChannelManager::claim_funds`] call you may see this event without a corresponding
686 /// [`Event::PaymentClaimable`] event.
689 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
690 /// `PaymentClaimable` events may be generated for the same payment. If you then call
691 /// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentClaimable`] you may get
692 /// multiple `PaymentClaimed` events.
694 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
696 /// The node that received the payment.
697 /// This is useful to identify payments which were received via [phantom nodes].
698 /// This field will always be filled in when the event was generated by LDK versions
699 /// 0.0.113 and above.
701 /// [phantom nodes]: crate::chain::keysinterface::PhantomKeysManager
703 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
704 receiver_node_id: crate::c_types::PublicKey,
705 /// The payment hash of the claimed payment. Note that LDK will not stop you from
706 /// registering duplicate payment hashes for inbound payments.
707 payment_hash: crate::c_types::ThirtyTwoBytes,
708 /// The value, in thousandths of a satoshi, that this payment is for.
710 /// The purpose of the claimed payment, i.e. whether the payment was for an invoice or a
711 /// spontaneous payment.
712 purpose: crate::lightning::util::events::PaymentPurpose,
714 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
715 /// and we got back the payment preimage for it).
717 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
718 /// event. In this situation, you SHOULD treat this payment as having succeeded.
720 /// The id returned by [`ChannelManager::send_payment`] and used with
721 /// [`ChannelManager::retry_payment`].
723 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
724 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
726 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
727 payment_id: crate::c_types::ThirtyTwoBytes,
728 /// The preimage to the hash given to ChannelManager::send_payment.
729 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
730 /// store it somehow!
731 payment_preimage: crate::c_types::ThirtyTwoBytes,
732 /// The hash that was given to [`ChannelManager::send_payment`].
734 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
735 payment_hash: crate::c_types::ThirtyTwoBytes,
736 /// The total fee which was spent at intermediate hops in this payment, across all paths.
738 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
739 /// overpayment to the recipient node.
741 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
742 /// overstate the amount paid, though this is unlikely.
744 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
745 fee_paid_msat: crate::c_types::derived::COption_u64Z,
747 /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
748 /// provide failure information for each MPP part in the payment.
750 /// This event is provided once there are no further pending HTLCs for the payment and the
751 /// payment is no longer retryable due to [`ChannelManager::abandon_payment`] having been
752 /// called for the corresponding payment.
754 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
756 /// The id returned by [`ChannelManager::send_payment`] and used with
757 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
759 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
760 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
761 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
762 payment_id: crate::c_types::ThirtyTwoBytes,
763 /// The hash that was given to [`ChannelManager::send_payment`].
765 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
766 payment_hash: crate::c_types::ThirtyTwoBytes,
768 /// Indicates that a path for an outbound payment was successful.
770 /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
771 /// [`Event::PaymentSent`] for obtaining the payment preimage.
772 PaymentPathSuccessful {
773 /// The id returned by [`ChannelManager::send_payment`] and used with
774 /// [`ChannelManager::retry_payment`].
776 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
777 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
778 payment_id: crate::c_types::ThirtyTwoBytes,
779 /// The hash that was given to [`ChannelManager::send_payment`].
781 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
783 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
784 payment_hash: crate::c_types::ThirtyTwoBytes,
785 /// The payment path that was successful.
787 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
788 path: crate::c_types::derived::CVec_RouteHopZ,
790 /// Indicates an outbound HTLC we sent failed. Probably some intermediary node dropped
791 /// something. You may wish to retry with a different route.
793 /// If you have given up retrying this payment and wish to fail it, you MUST call
794 /// [`ChannelManager::abandon_payment`] at least once for a given [`PaymentId`] or memory
795 /// related to payment tracking will leak.
797 /// Note that this does *not* indicate that all paths for an MPP payment have failed, see
798 /// [`Event::PaymentFailed`] and [`all_paths_failed`].
800 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
801 /// [`all_paths_failed`]: Self::PaymentPathFailed::all_paths_failed
803 /// The id returned by [`ChannelManager::send_payment`] and used with
804 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
806 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
807 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
808 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
810 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
811 payment_id: crate::c_types::ThirtyTwoBytes,
812 /// The hash that was given to [`ChannelManager::send_payment`].
814 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
815 payment_hash: crate::c_types::ThirtyTwoBytes,
816 /// Indicates the payment was rejected for some reason by the recipient. This implies that
817 /// the payment has failed, not just the route in question. If this is not set, you may
818 /// retry the payment via a different route.
819 payment_failed_permanently: bool,
820 /// Any failure information conveyed via the Onion return packet by a node along the failed
823 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
824 /// account the update.
826 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
827 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
828 /// For both single-path and multi-path payments, this is set if all paths of the payment have
829 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
830 /// larger MPP payment were still in flight when this event was generated.
832 /// Note that if you are retrying individual MPP parts, using this value to determine if a
833 /// payment has fully failed is race-y. Because multiple failures can happen prior to events
834 /// being processed, you may retry in response to a first failure, with a second failure
835 /// (with `all_paths_failed` set) still pending. Then, when the second failure is processed
836 /// you will see `all_paths_failed` set even though the retry of the first failure still
837 /// has an associated in-flight HTLC. See (1) for an example of such a failure.
839 /// If you wish to retry individual MPP parts and learn when a payment has failed, you must
840 /// call [`ChannelManager::abandon_payment`] and wait for a [`Event::PaymentFailed`] event.
842 /// (1) <https://github.com/lightningdevkit/rust-lightning/issues/1164>
844 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
845 all_paths_failed: bool,
846 /// The payment path that failed.
847 path: crate::c_types::derived::CVec_RouteHopZ,
848 /// The channel responsible for the failed payment path.
850 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
851 /// may not refer to a channel in the public network graph. These aliases may also collide
852 /// with channels in the public network graph.
854 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
855 /// retried. May be `None` for older [`Event`] serializations.
856 short_channel_id: crate::c_types::derived::COption_u64Z,
857 /// Parameters needed to compute a new [`Route`] when retrying the failed payment path.
859 /// See [`find_route`] for details.
861 /// [`Route`]: crate::routing::router::Route
862 /// [`find_route`]: crate::routing::router::find_route
864 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
865 retry: crate::lightning::routing::router::RouteParameters,
867 /// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
869 /// The id returned by [`ChannelManager::send_probe`].
871 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
872 payment_id: crate::c_types::ThirtyTwoBytes,
873 /// The hash generated by [`ChannelManager::send_probe`].
875 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
876 payment_hash: crate::c_types::ThirtyTwoBytes,
877 /// The payment path that was successful.
878 path: crate::c_types::derived::CVec_RouteHopZ,
880 /// Indicates that a probe payment we sent failed at an intermediary node on the path.
882 /// The id returned by [`ChannelManager::send_probe`].
884 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
885 payment_id: crate::c_types::ThirtyTwoBytes,
886 /// The hash generated by [`ChannelManager::send_probe`].
888 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
889 payment_hash: crate::c_types::ThirtyTwoBytes,
890 /// The payment path that failed.
891 path: crate::c_types::derived::CVec_RouteHopZ,
892 /// The channel responsible for the failed probe.
894 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
895 /// may not refer to a channel in the public network graph. These aliases may also collide
896 /// with channels in the public network graph.
897 short_channel_id: crate::c_types::derived::COption_u64Z,
899 /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
900 /// a time in the future.
902 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
903 PendingHTLCsForwardable {
904 /// The minimum amount of time that should be waited prior to calling
905 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
906 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
907 /// now + 5*time_forwardable).
908 time_forwardable: u64,
910 /// Used to indicate that we've intercepted an HTLC forward. This event will only be generated if
911 /// you've encoded an intercept scid in the receiver's invoice route hints using
912 /// [`ChannelManager::get_intercept_scid`] and have set [`UserConfig::accept_intercept_htlcs`].
914 /// [`ChannelManager::forward_intercepted_htlc`] or
915 /// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to this event. See
916 /// their docs for more information.
918 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
919 /// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
920 /// [`ChannelManager::forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
921 /// [`ChannelManager::fail_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::fail_intercepted_htlc
923 /// An id to help LDK identify which HTLC is being forwarded or failed.
924 intercept_id: crate::c_types::ThirtyTwoBytes,
925 /// The fake scid that was programmed as the next hop's scid, generated using
926 /// [`ChannelManager::get_intercept_scid`].
928 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
929 requested_next_hop_scid: u64,
930 /// The payment hash used for this HTLC.
931 payment_hash: crate::c_types::ThirtyTwoBytes,
932 /// How many msats were received on the inbound edge of this HTLC.
933 inbound_amount_msat: u64,
934 /// How many msats the payer intended to route to the next node. Depending on the reason you are
935 /// intercepting this payment, you might take a fee by forwarding less than this amount.
937 /// Note that LDK will NOT check that expected fees were factored into this value. You MUST
938 /// check that whatever fee you want has been included here or subtract it as required. Further,
939 /// LDK will not stop you from forwarding more than you received.
940 expected_outbound_amount_msat: u64,
942 /// Used to indicate that an output which you should know how to spend was confirmed on chain
943 /// and is now spendable.
944 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
945 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
946 /// somewhere and spend them when you create on-chain transactions.
948 /// The outputs which you should store as spendable by you.
949 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
951 /// This event is generated when a payment has been successfully forwarded through us and a
952 /// forwarding fee earned.
954 /// The incoming channel between the previous node and us. This is only `None` for events
955 /// generated or serialized by versions prior to 0.0.107.
957 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
958 prev_channel_id: crate::c_types::ThirtyTwoBytes,
959 /// The outgoing channel between the next node and us. This is only `None` for events
960 /// generated or serialized by versions prior to 0.0.107.
962 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
963 next_channel_id: crate::c_types::ThirtyTwoBytes,
964 /// The fee, in milli-satoshis, which was earned as a result of the payment.
966 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
967 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
968 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
969 /// claimed the full value in millisatoshis from the source. In this case,
970 /// `claim_from_onchain_tx` will be set.
972 /// If the channel which sent us the payment has been force-closed, we will claim the funds
973 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
974 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
975 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
977 fee_earned_msat: crate::c_types::derived::COption_u64Z,
978 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
980 claim_from_onchain_tx: bool,
982 /// Used to indicate that a channel with the given `channel_id` is ready to
983 /// be used. This event is emitted either when the funding transaction has been confirmed
984 /// on-chain, or, in case of a 0conf channel, when both parties have confirmed the channel
987 /// The channel_id of the channel that is ready.
988 channel_id: crate::c_types::ThirtyTwoBytes,
989 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
990 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
991 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
992 /// `user_channel_id` will be randomized for an inbound channel.
994 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
995 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
996 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
997 user_channel_id: crate::c_types::U128,
998 /// The node_id of the channel counterparty.
999 counterparty_node_id: crate::c_types::PublicKey,
1000 /// The features that this channel will operate with.
1001 channel_type: crate::lightning::ln::features::ChannelTypeFeatures,
1003 /// Used to indicate that a previously opened channel with the given `channel_id` is in the
1004 /// process of closure.
1006 /// The channel_id of the channel which has been closed. Note that on-chain transactions
1007 /// resolving the channel are likely still awaiting confirmation.
1008 channel_id: crate::c_types::ThirtyTwoBytes,
1009 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1010 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1011 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1012 /// `user_channel_id` will be randomized for inbound channels.
1013 /// This may be zero for inbound channels serialized prior to 0.0.113 and will always be
1014 /// zero for objects serialized with LDK versions prior to 0.0.102.
1016 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1017 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1018 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1019 user_channel_id: crate::c_types::U128,
1020 /// The reason the channel was closed.
1021 reason: crate::lightning::util::events::ClosureReason,
1023 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
1024 /// inputs for another purpose.
1026 /// The channel_id of the channel which has been closed.
1027 channel_id: crate::c_types::ThirtyTwoBytes,
1028 /// The full transaction received from the user
1029 transaction: crate::c_types::Transaction,
1031 /// Indicates a request to open a new channel by a peer.
1033 /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the
1034 /// request, call [`ChannelManager::force_close_without_broadcasting_txn`].
1036 /// The event is only triggered when a new open channel request is received and the
1037 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
1039 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1040 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
1041 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1042 OpenChannelRequest {
1043 /// The temporary channel ID of the channel requested to be opened.
1045 /// When responding to the request, the `temporary_channel_id` should be passed
1046 /// back to the ChannelManager through [`ChannelManager::accept_inbound_channel`] to accept,
1047 /// or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject.
1049 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1050 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
1051 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
1052 /// The node_id of the counterparty requesting to open the channel.
1054 /// When responding to the request, the `counterparty_node_id` should be passed
1055 /// back to the `ChannelManager` through [`ChannelManager::accept_inbound_channel`] to
1056 /// accept the request, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject the
1059 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1060 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
1061 counterparty_node_id: crate::c_types::PublicKey,
1062 /// The channel value of the requested channel.
1063 funding_satoshis: u64,
1064 /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
1066 /// The features that this channel will operate with. If you reject the channel, a
1067 /// well-behaved counterparty may automatically re-attempt the channel with a new set of
1070 /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
1071 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
1074 /// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
1075 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
1076 /// 0.0.107. Channels setting this type also need to get manually accepted via
1077 /// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
1078 /// or will be rejected otherwise.
1080 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1081 channel_type: crate::lightning::ln::features::ChannelTypeFeatures,
1083 /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
1086 /// Some scenarios where this event may be sent include:
1087 /// * Insufficient capacity in the outbound channel
1088 /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
1089 /// * When an unknown SCID is requested for forwarding a payment.
1090 /// * Claiming an amount for an MPP payment that exceeds the HTLC total
1091 /// * The HTLC has timed out
1093 /// This event, however, does not get generated if an HTLC fails to meet the forwarding
1094 /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
1095 HTLCHandlingFailed {
1096 /// The channel over which the HTLC was received.
1097 prev_channel_id: crate::c_types::ThirtyTwoBytes,
1098 /// Destination of the HTLC that failed to be processed.
1099 failed_next_destination: crate::lightning::util::events::HTLCDestination,
1102 use lightning::util::events::Event as EventImport;
1103 pub(crate) type nativeEvent = EventImport;
1107 pub(crate) fn to_native(&self) -> nativeEvent {
1109 Event::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
1110 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1111 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1112 let mut channel_value_satoshis_nonref = Clone::clone(channel_value_satoshis);
1113 let mut output_script_nonref = Clone::clone(output_script);
1114 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1115 nativeEvent::FundingGenerationReady {
1116 temporary_channel_id: temporary_channel_id_nonref.data,
1117 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1118 channel_value_satoshis: channel_value_satoshis_nonref,
1119 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
1120 user_channel_id: user_channel_id_nonref.into(),
1123 Event::PaymentClaimable {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, ref via_channel_id, ref via_user_channel_id, } => {
1124 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1125 let mut local_receiver_node_id_nonref = if receiver_node_id_nonref.is_null() { None } else { Some( { receiver_node_id_nonref.into_rust() }) };
1126 let mut payment_hash_nonref = Clone::clone(payment_hash);
1127 let mut amount_msat_nonref = Clone::clone(amount_msat);
1128 let mut purpose_nonref = Clone::clone(purpose);
1129 let mut via_channel_id_nonref = Clone::clone(via_channel_id);
1130 let mut local_via_channel_id_nonref = if via_channel_id_nonref.data == [0; 32] { None } else { Some( { via_channel_id_nonref.data }) };
1131 let mut via_user_channel_id_nonref = Clone::clone(via_user_channel_id);
1132 let mut local_via_user_channel_id_nonref = { /* via_user_channel_id_nonref*/ let via_user_channel_id_nonref_opt = via_user_channel_id_nonref; { } if via_user_channel_id_nonref_opt.is_none() { None } else { Some({ via_user_channel_id_nonref_opt.take().into() }) } };
1133 nativeEvent::PaymentClaimable {
1134 receiver_node_id: local_receiver_node_id_nonref,
1135 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1136 amount_msat: amount_msat_nonref,
1137 purpose: purpose_nonref.into_native(),
1138 via_channel_id: local_via_channel_id_nonref,
1139 via_user_channel_id: local_via_user_channel_id_nonref,
1142 Event::PaymentClaimed {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, } => {
1143 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1144 let mut local_receiver_node_id_nonref = if receiver_node_id_nonref.is_null() { None } else { Some( { receiver_node_id_nonref.into_rust() }) };
1145 let mut payment_hash_nonref = Clone::clone(payment_hash);
1146 let mut amount_msat_nonref = Clone::clone(amount_msat);
1147 let mut purpose_nonref = Clone::clone(purpose);
1148 nativeEvent::PaymentClaimed {
1149 receiver_node_id: local_receiver_node_id_nonref,
1150 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1151 amount_msat: amount_msat_nonref,
1152 purpose: purpose_nonref.into_native(),
1155 Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1156 let mut payment_id_nonref = Clone::clone(payment_id);
1157 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1158 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
1159 let mut payment_hash_nonref = Clone::clone(payment_hash);
1160 let mut fee_paid_msat_nonref = Clone::clone(fee_paid_msat);
1161 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
1162 nativeEvent::PaymentSent {
1163 payment_id: local_payment_id_nonref,
1164 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
1165 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1166 fee_paid_msat: local_fee_paid_msat_nonref,
1169 Event::PaymentFailed {ref payment_id, ref payment_hash, } => {
1170 let mut payment_id_nonref = Clone::clone(payment_id);
1171 let mut payment_hash_nonref = Clone::clone(payment_hash);
1172 nativeEvent::PaymentFailed {
1173 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1174 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1177 Event::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1178 let mut payment_id_nonref = Clone::clone(payment_id);
1179 let mut payment_hash_nonref = Clone::clone(payment_hash);
1180 let mut local_payment_hash_nonref = if payment_hash_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash_nonref.data) }) };
1181 let mut path_nonref = Clone::clone(path);
1182 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1183 nativeEvent::PaymentPathSuccessful {
1184 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1185 payment_hash: local_payment_hash_nonref,
1186 path: local_path_nonref,
1189 Event::PaymentPathFailed {ref payment_id, ref payment_hash, ref payment_failed_permanently, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, ref retry, } => {
1190 let mut payment_id_nonref = Clone::clone(payment_id);
1191 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1192 let mut payment_hash_nonref = Clone::clone(payment_hash);
1193 let mut payment_failed_permanently_nonref = Clone::clone(payment_failed_permanently);
1194 let mut network_update_nonref = Clone::clone(network_update);
1195 let mut local_network_update_nonref = { /* network_update_nonref*/ let network_update_nonref_opt = network_update_nonref; { } if network_update_nonref_opt.is_none() { None } else { Some({ network_update_nonref_opt.take().into_native() }) } };
1196 let mut all_paths_failed_nonref = Clone::clone(all_paths_failed);
1197 let mut path_nonref = Clone::clone(path);
1198 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1199 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1200 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1201 let mut retry_nonref = Clone::clone(retry);
1202 let mut local_retry_nonref = if retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry_nonref.take_inner()) } }) };
1203 nativeEvent::PaymentPathFailed {
1204 payment_id: local_payment_id_nonref,
1205 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1206 payment_failed_permanently: payment_failed_permanently_nonref,
1207 network_update: local_network_update_nonref,
1208 all_paths_failed: all_paths_failed_nonref,
1209 path: local_path_nonref,
1210 short_channel_id: local_short_channel_id_nonref,
1211 retry: local_retry_nonref,
1214 Event::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1215 let mut payment_id_nonref = Clone::clone(payment_id);
1216 let mut payment_hash_nonref = Clone::clone(payment_hash);
1217 let mut path_nonref = Clone::clone(path);
1218 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1219 nativeEvent::ProbeSuccessful {
1220 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1221 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1222 path: local_path_nonref,
1225 Event::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1226 let mut payment_id_nonref = Clone::clone(payment_id);
1227 let mut payment_hash_nonref = Clone::clone(payment_hash);
1228 let mut path_nonref = Clone::clone(path);
1229 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1230 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1231 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1232 nativeEvent::ProbeFailed {
1233 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1234 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1235 path: local_path_nonref,
1236 short_channel_id: local_short_channel_id_nonref,
1239 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
1240 let mut time_forwardable_nonref = Clone::clone(time_forwardable);
1241 nativeEvent::PendingHTLCsForwardable {
1242 time_forwardable: core::time::Duration::from_secs(time_forwardable_nonref),
1245 Event::HTLCIntercepted {ref intercept_id, ref requested_next_hop_scid, ref payment_hash, ref inbound_amount_msat, ref expected_outbound_amount_msat, } => {
1246 let mut intercept_id_nonref = Clone::clone(intercept_id);
1247 let mut requested_next_hop_scid_nonref = Clone::clone(requested_next_hop_scid);
1248 let mut payment_hash_nonref = Clone::clone(payment_hash);
1249 let mut inbound_amount_msat_nonref = Clone::clone(inbound_amount_msat);
1250 let mut expected_outbound_amount_msat_nonref = Clone::clone(expected_outbound_amount_msat);
1251 nativeEvent::HTLCIntercepted {
1252 intercept_id: ::lightning::ln::channelmanager::InterceptId(intercept_id_nonref.data),
1253 requested_next_hop_scid: requested_next_hop_scid_nonref,
1254 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1255 inbound_amount_msat: inbound_amount_msat_nonref,
1256 expected_outbound_amount_msat: expected_outbound_amount_msat_nonref,
1259 Event::SpendableOutputs {ref outputs, } => {
1260 let mut outputs_nonref = Clone::clone(outputs);
1261 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
1262 nativeEvent::SpendableOutputs {
1263 outputs: local_outputs_nonref,
1266 Event::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, } => {
1267 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1268 let mut local_prev_channel_id_nonref = if prev_channel_id_nonref.data == [0; 32] { None } else { Some( { prev_channel_id_nonref.data }) };
1269 let mut next_channel_id_nonref = Clone::clone(next_channel_id);
1270 let mut local_next_channel_id_nonref = if next_channel_id_nonref.data == [0; 32] { None } else { Some( { next_channel_id_nonref.data }) };
1271 let mut fee_earned_msat_nonref = Clone::clone(fee_earned_msat);
1272 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
1273 let mut claim_from_onchain_tx_nonref = Clone::clone(claim_from_onchain_tx);
1274 nativeEvent::PaymentForwarded {
1275 prev_channel_id: local_prev_channel_id_nonref,
1276 next_channel_id: local_next_channel_id_nonref,
1277 fee_earned_msat: local_fee_earned_msat_nonref,
1278 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1281 Event::ChannelReady {ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type, } => {
1282 let mut channel_id_nonref = Clone::clone(channel_id);
1283 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1284 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1285 let mut channel_type_nonref = Clone::clone(channel_type);
1286 nativeEvent::ChannelReady {
1287 channel_id: channel_id_nonref.data,
1288 user_channel_id: user_channel_id_nonref.into(),
1289 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1290 channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) },
1293 Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
1294 let mut channel_id_nonref = Clone::clone(channel_id);
1295 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1296 let mut reason_nonref = Clone::clone(reason);
1297 nativeEvent::ChannelClosed {
1298 channel_id: channel_id_nonref.data,
1299 user_channel_id: user_channel_id_nonref.into(),
1300 reason: reason_nonref.into_native(),
1303 Event::DiscardFunding {ref channel_id, ref transaction, } => {
1304 let mut channel_id_nonref = Clone::clone(channel_id);
1305 let mut transaction_nonref = Clone::clone(transaction);
1306 nativeEvent::DiscardFunding {
1307 channel_id: channel_id_nonref.data,
1308 transaction: transaction_nonref.into_bitcoin(),
1311 Event::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1312 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1313 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1314 let mut funding_satoshis_nonref = Clone::clone(funding_satoshis);
1315 let mut push_msat_nonref = Clone::clone(push_msat);
1316 let mut channel_type_nonref = Clone::clone(channel_type);
1317 nativeEvent::OpenChannelRequest {
1318 temporary_channel_id: temporary_channel_id_nonref.data,
1319 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1320 funding_satoshis: funding_satoshis_nonref,
1321 push_msat: push_msat_nonref,
1322 channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) },
1325 Event::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
1326 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1327 let mut failed_next_destination_nonref = Clone::clone(failed_next_destination);
1328 nativeEvent::HTLCHandlingFailed {
1329 prev_channel_id: prev_channel_id_nonref.data,
1330 failed_next_destination: failed_next_destination_nonref.into_native(),
1336 pub(crate) fn into_native(self) -> nativeEvent {
1338 Event::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1339 nativeEvent::FundingGenerationReady {
1340 temporary_channel_id: temporary_channel_id.data,
1341 counterparty_node_id: counterparty_node_id.into_rust(),
1342 channel_value_satoshis: channel_value_satoshis,
1343 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
1344 user_channel_id: user_channel_id.into(),
1347 Event::PaymentClaimable {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, mut via_channel_id, mut via_user_channel_id, } => {
1348 let mut local_receiver_node_id = if receiver_node_id.is_null() { None } else { Some( { receiver_node_id.into_rust() }) };
1349 let mut local_via_channel_id = if via_channel_id.data == [0; 32] { None } else { Some( { via_channel_id.data }) };
1350 let mut local_via_user_channel_id = { /* via_user_channel_id*/ let via_user_channel_id_opt = via_user_channel_id; { } if via_user_channel_id_opt.is_none() { None } else { Some({ via_user_channel_id_opt.take().into() }) } };
1351 nativeEvent::PaymentClaimable {
1352 receiver_node_id: local_receiver_node_id,
1353 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1354 amount_msat: amount_msat,
1355 purpose: purpose.into_native(),
1356 via_channel_id: local_via_channel_id,
1357 via_user_channel_id: local_via_user_channel_id,
1360 Event::PaymentClaimed {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, } => {
1361 let mut local_receiver_node_id = if receiver_node_id.is_null() { None } else { Some( { receiver_node_id.into_rust() }) };
1362 nativeEvent::PaymentClaimed {
1363 receiver_node_id: local_receiver_node_id,
1364 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1365 amount_msat: amount_msat,
1366 purpose: purpose.into_native(),
1369 Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1370 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1371 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
1372 nativeEvent::PaymentSent {
1373 payment_id: local_payment_id,
1374 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
1375 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1376 fee_paid_msat: local_fee_paid_msat,
1379 Event::PaymentFailed {mut payment_id, mut payment_hash, } => {
1380 nativeEvent::PaymentFailed {
1381 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1382 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1385 Event::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1386 let mut local_payment_hash = if payment_hash.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash.data) }) };
1387 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1388 nativeEvent::PaymentPathSuccessful {
1389 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1390 payment_hash: local_payment_hash,
1394 Event::PaymentPathFailed {mut payment_id, mut payment_hash, mut payment_failed_permanently, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, mut retry, } => {
1395 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1396 let mut local_network_update = { /* network_update*/ let network_update_opt = network_update; { } if network_update_opt.is_none() { None } else { Some({ network_update_opt.take().into_native() }) } };
1397 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1398 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1399 let mut local_retry = if retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry.take_inner()) } }) };
1400 nativeEvent::PaymentPathFailed {
1401 payment_id: local_payment_id,
1402 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1403 payment_failed_permanently: payment_failed_permanently,
1404 network_update: local_network_update,
1405 all_paths_failed: all_paths_failed,
1407 short_channel_id: local_short_channel_id,
1411 Event::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1412 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1413 nativeEvent::ProbeSuccessful {
1414 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1415 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1419 Event::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
1420 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1421 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1422 nativeEvent::ProbeFailed {
1423 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1424 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1426 short_channel_id: local_short_channel_id,
1429 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
1430 nativeEvent::PendingHTLCsForwardable {
1431 time_forwardable: core::time::Duration::from_secs(time_forwardable),
1434 Event::HTLCIntercepted {mut intercept_id, mut requested_next_hop_scid, mut payment_hash, mut inbound_amount_msat, mut expected_outbound_amount_msat, } => {
1435 nativeEvent::HTLCIntercepted {
1436 intercept_id: ::lightning::ln::channelmanager::InterceptId(intercept_id.data),
1437 requested_next_hop_scid: requested_next_hop_scid,
1438 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1439 inbound_amount_msat: inbound_amount_msat,
1440 expected_outbound_amount_msat: expected_outbound_amount_msat,
1443 Event::SpendableOutputs {mut outputs, } => {
1444 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
1445 nativeEvent::SpendableOutputs {
1446 outputs: local_outputs,
1449 Event::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1450 let mut local_prev_channel_id = if prev_channel_id.data == [0; 32] { None } else { Some( { prev_channel_id.data }) };
1451 let mut local_next_channel_id = if next_channel_id.data == [0; 32] { None } else { Some( { next_channel_id.data }) };
1452 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
1453 nativeEvent::PaymentForwarded {
1454 prev_channel_id: local_prev_channel_id,
1455 next_channel_id: local_next_channel_id,
1456 fee_earned_msat: local_fee_earned_msat,
1457 claim_from_onchain_tx: claim_from_onchain_tx,
1460 Event::ChannelReady {mut channel_id, mut user_channel_id, mut counterparty_node_id, mut channel_type, } => {
1461 nativeEvent::ChannelReady {
1462 channel_id: channel_id.data,
1463 user_channel_id: user_channel_id.into(),
1464 counterparty_node_id: counterparty_node_id.into_rust(),
1465 channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) },
1468 Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1469 nativeEvent::ChannelClosed {
1470 channel_id: channel_id.data,
1471 user_channel_id: user_channel_id.into(),
1472 reason: reason.into_native(),
1475 Event::DiscardFunding {mut channel_id, mut transaction, } => {
1476 nativeEvent::DiscardFunding {
1477 channel_id: channel_id.data,
1478 transaction: transaction.into_bitcoin(),
1481 Event::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1482 nativeEvent::OpenChannelRequest {
1483 temporary_channel_id: temporary_channel_id.data,
1484 counterparty_node_id: counterparty_node_id.into_rust(),
1485 funding_satoshis: funding_satoshis,
1486 push_msat: push_msat,
1487 channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) },
1490 Event::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
1491 nativeEvent::HTLCHandlingFailed {
1492 prev_channel_id: prev_channel_id.data,
1493 failed_next_destination: failed_next_destination.into_native(),
1499 pub(crate) fn from_native(native: &nativeEvent) -> Self {
1501 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
1502 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1503 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1504 let mut channel_value_satoshis_nonref = Clone::clone(channel_value_satoshis);
1505 let mut output_script_nonref = Clone::clone(output_script);
1506 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1507 Event::FundingGenerationReady {
1508 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1509 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1510 channel_value_satoshis: channel_value_satoshis_nonref,
1511 output_script: output_script_nonref.into_bytes().into(),
1512 user_channel_id: user_channel_id_nonref.into(),
1515 nativeEvent::PaymentClaimable {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, ref via_channel_id, ref via_user_channel_id, } => {
1516 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1517 let mut local_receiver_node_id_nonref = if receiver_node_id_nonref.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(receiver_node_id_nonref.unwrap())) } };
1518 let mut payment_hash_nonref = Clone::clone(payment_hash);
1519 let mut amount_msat_nonref = Clone::clone(amount_msat);
1520 let mut purpose_nonref = Clone::clone(purpose);
1521 let mut via_channel_id_nonref = Clone::clone(via_channel_id);
1522 let mut local_via_channel_id_nonref = if via_channel_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (via_channel_id_nonref.unwrap()) } } };
1523 let mut via_user_channel_id_nonref = Clone::clone(via_user_channel_id);
1524 let mut local_via_user_channel_id_nonref = if via_user_channel_id_nonref.is_none() { crate::c_types::derived::COption_u128Z::None } else { crate::c_types::derived::COption_u128Z::Some( { via_user_channel_id_nonref.unwrap().into() }) };
1525 Event::PaymentClaimable {
1526 receiver_node_id: local_receiver_node_id_nonref,
1527 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1528 amount_msat: amount_msat_nonref,
1529 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
1530 via_channel_id: local_via_channel_id_nonref,
1531 via_user_channel_id: local_via_user_channel_id_nonref,
1534 nativeEvent::PaymentClaimed {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, } => {
1535 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1536 let mut local_receiver_node_id_nonref = if receiver_node_id_nonref.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(receiver_node_id_nonref.unwrap())) } };
1537 let mut payment_hash_nonref = Clone::clone(payment_hash);
1538 let mut amount_msat_nonref = Clone::clone(amount_msat);
1539 let mut purpose_nonref = Clone::clone(purpose);
1540 Event::PaymentClaimed {
1541 receiver_node_id: local_receiver_node_id_nonref,
1542 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1543 amount_msat: amount_msat_nonref,
1544 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
1547 nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1548 let mut payment_id_nonref = Clone::clone(payment_id);
1549 let mut local_payment_id_nonref = if payment_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_id_nonref.unwrap()).0 } } };
1550 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
1551 let mut payment_hash_nonref = Clone::clone(payment_hash);
1552 let mut fee_paid_msat_nonref = Clone::clone(fee_paid_msat);
1553 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_paid_msat_nonref.unwrap() }) };
1554 Event::PaymentSent {
1555 payment_id: local_payment_id_nonref,
1556 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
1557 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1558 fee_paid_msat: local_fee_paid_msat_nonref,
1561 nativeEvent::PaymentFailed {ref payment_id, ref payment_hash, } => {
1562 let mut payment_id_nonref = Clone::clone(payment_id);
1563 let mut payment_hash_nonref = Clone::clone(payment_hash);
1564 Event::PaymentFailed {
1565 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1566 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1569 nativeEvent::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1570 let mut payment_id_nonref = Clone::clone(payment_id);
1571 let mut payment_hash_nonref = Clone::clone(payment_hash);
1572 let mut local_payment_hash_nonref = if payment_hash_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_hash_nonref.unwrap()).0 } } };
1573 let mut path_nonref = Clone::clone(path);
1574 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1575 Event::PaymentPathSuccessful {
1576 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1577 payment_hash: local_payment_hash_nonref,
1578 path: local_path_nonref.into(),
1581 nativeEvent::PaymentPathFailed {ref payment_id, ref payment_hash, ref payment_failed_permanently, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, ref retry, } => {
1582 let mut payment_id_nonref = Clone::clone(payment_id);
1583 let mut local_payment_id_nonref = if payment_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_id_nonref.unwrap()).0 } } };
1584 let mut payment_hash_nonref = Clone::clone(payment_hash);
1585 let mut payment_failed_permanently_nonref = Clone::clone(payment_failed_permanently);
1586 let mut network_update_nonref = Clone::clone(network_update);
1587 let mut local_network_update_nonref = if network_update_nonref.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::gossip::NetworkUpdate::native_into(network_update_nonref.unwrap()) }) };
1588 let mut all_paths_failed_nonref = Clone::clone(all_paths_failed);
1589 let mut path_nonref = Clone::clone(path);
1590 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1591 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1592 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id_nonref.unwrap() }) };
1593 let mut retry_nonref = Clone::clone(retry);
1594 let mut local_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if retry_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((retry_nonref.unwrap())) } }, is_owned: true };
1595 Event::PaymentPathFailed {
1596 payment_id: local_payment_id_nonref,
1597 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1598 payment_failed_permanently: payment_failed_permanently_nonref,
1599 network_update: local_network_update_nonref,
1600 all_paths_failed: all_paths_failed_nonref,
1601 path: local_path_nonref.into(),
1602 short_channel_id: local_short_channel_id_nonref,
1603 retry: local_retry_nonref,
1606 nativeEvent::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1607 let mut payment_id_nonref = Clone::clone(payment_id);
1608 let mut payment_hash_nonref = Clone::clone(payment_hash);
1609 let mut path_nonref = Clone::clone(path);
1610 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1611 Event::ProbeSuccessful {
1612 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1613 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1614 path: local_path_nonref.into(),
1617 nativeEvent::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1618 let mut payment_id_nonref = Clone::clone(payment_id);
1619 let mut payment_hash_nonref = Clone::clone(payment_hash);
1620 let mut path_nonref = Clone::clone(path);
1621 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1622 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1623 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id_nonref.unwrap() }) };
1624 Event::ProbeFailed {
1625 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1626 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1627 path: local_path_nonref.into(),
1628 short_channel_id: local_short_channel_id_nonref,
1631 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
1632 let mut time_forwardable_nonref = Clone::clone(time_forwardable);
1633 Event::PendingHTLCsForwardable {
1634 time_forwardable: time_forwardable_nonref.as_secs(),
1637 nativeEvent::HTLCIntercepted {ref intercept_id, ref requested_next_hop_scid, ref payment_hash, ref inbound_amount_msat, ref expected_outbound_amount_msat, } => {
1638 let mut intercept_id_nonref = Clone::clone(intercept_id);
1639 let mut requested_next_hop_scid_nonref = Clone::clone(requested_next_hop_scid);
1640 let mut payment_hash_nonref = Clone::clone(payment_hash);
1641 let mut inbound_amount_msat_nonref = Clone::clone(inbound_amount_msat);
1642 let mut expected_outbound_amount_msat_nonref = Clone::clone(expected_outbound_amount_msat);
1643 Event::HTLCIntercepted {
1644 intercept_id: crate::c_types::ThirtyTwoBytes { data: intercept_id_nonref.0 },
1645 requested_next_hop_scid: requested_next_hop_scid_nonref,
1646 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1647 inbound_amount_msat: inbound_amount_msat_nonref,
1648 expected_outbound_amount_msat: expected_outbound_amount_msat_nonref,
1651 nativeEvent::SpendableOutputs {ref outputs, } => {
1652 let mut outputs_nonref = Clone::clone(outputs);
1653 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) }); };
1654 Event::SpendableOutputs {
1655 outputs: local_outputs_nonref.into(),
1658 nativeEvent::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, } => {
1659 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1660 let mut local_prev_channel_id_nonref = if prev_channel_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (prev_channel_id_nonref.unwrap()) } } };
1661 let mut next_channel_id_nonref = Clone::clone(next_channel_id);
1662 let mut local_next_channel_id_nonref = if next_channel_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (next_channel_id_nonref.unwrap()) } } };
1663 let mut fee_earned_msat_nonref = Clone::clone(fee_earned_msat);
1664 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_earned_msat_nonref.unwrap() }) };
1665 let mut claim_from_onchain_tx_nonref = Clone::clone(claim_from_onchain_tx);
1666 Event::PaymentForwarded {
1667 prev_channel_id: local_prev_channel_id_nonref,
1668 next_channel_id: local_next_channel_id_nonref,
1669 fee_earned_msat: local_fee_earned_msat_nonref,
1670 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1673 nativeEvent::ChannelReady {ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type, } => {
1674 let mut channel_id_nonref = Clone::clone(channel_id);
1675 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1676 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1677 let mut channel_type_nonref = Clone::clone(channel_type);
1678 Event::ChannelReady {
1679 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1680 user_channel_id: user_channel_id_nonref.into(),
1681 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1682 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true },
1685 nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
1686 let mut channel_id_nonref = Clone::clone(channel_id);
1687 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1688 let mut reason_nonref = Clone::clone(reason);
1689 Event::ChannelClosed {
1690 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1691 user_channel_id: user_channel_id_nonref.into(),
1692 reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
1695 nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
1696 let mut channel_id_nonref = Clone::clone(channel_id);
1697 let mut transaction_nonref = Clone::clone(transaction);
1698 Event::DiscardFunding {
1699 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1700 transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
1703 nativeEvent::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1704 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1705 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1706 let mut funding_satoshis_nonref = Clone::clone(funding_satoshis);
1707 let mut push_msat_nonref = Clone::clone(push_msat);
1708 let mut channel_type_nonref = Clone::clone(channel_type);
1709 Event::OpenChannelRequest {
1710 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1711 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1712 funding_satoshis: funding_satoshis_nonref,
1713 push_msat: push_msat_nonref,
1714 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true },
1717 nativeEvent::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
1718 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1719 let mut failed_next_destination_nonref = Clone::clone(failed_next_destination);
1720 Event::HTLCHandlingFailed {
1721 prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id_nonref },
1722 failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination_nonref),
1728 pub(crate) fn native_into(native: nativeEvent) -> Self {
1730 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1731 Event::FundingGenerationReady {
1732 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1733 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1734 channel_value_satoshis: channel_value_satoshis,
1735 output_script: output_script.into_bytes().into(),
1736 user_channel_id: user_channel_id.into(),
1739 nativeEvent::PaymentClaimable {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, mut via_channel_id, mut via_user_channel_id, } => {
1740 let mut local_receiver_node_id = if receiver_node_id.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(receiver_node_id.unwrap())) } };
1741 let mut local_via_channel_id = if via_channel_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (via_channel_id.unwrap()) } } };
1742 let mut local_via_user_channel_id = if via_user_channel_id.is_none() { crate::c_types::derived::COption_u128Z::None } else { crate::c_types::derived::COption_u128Z::Some( { via_user_channel_id.unwrap().into() }) };
1743 Event::PaymentClaimable {
1744 receiver_node_id: local_receiver_node_id,
1745 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1746 amount_msat: amount_msat,
1747 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
1748 via_channel_id: local_via_channel_id,
1749 via_user_channel_id: local_via_user_channel_id,
1752 nativeEvent::PaymentClaimed {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, } => {
1753 let mut local_receiver_node_id = if receiver_node_id.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(receiver_node_id.unwrap())) } };
1754 Event::PaymentClaimed {
1755 receiver_node_id: local_receiver_node_id,
1756 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1757 amount_msat: amount_msat,
1758 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
1761 nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1762 let mut local_payment_id = if payment_id.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_id.unwrap()).0 } } };
1763 let mut local_fee_paid_msat = if fee_paid_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_paid_msat.unwrap() }) };
1764 Event::PaymentSent {
1765 payment_id: local_payment_id,
1766 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
1767 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1768 fee_paid_msat: local_fee_paid_msat,
1771 nativeEvent::PaymentFailed {mut payment_id, mut payment_hash, } => {
1772 Event::PaymentFailed {
1773 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1774 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1777 nativeEvent::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1778 let mut local_payment_hash = if payment_hash.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_hash.unwrap()).0 } } };
1779 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1780 Event::PaymentPathSuccessful {
1781 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1782 payment_hash: local_payment_hash,
1783 path: local_path.into(),
1786 nativeEvent::PaymentPathFailed {mut payment_id, mut payment_hash, mut payment_failed_permanently, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, mut retry, } => {
1787 let mut local_payment_id = if payment_id.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_id.unwrap()).0 } } };
1788 let mut local_network_update = if network_update.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::gossip::NetworkUpdate::native_into(network_update.unwrap()) }) };
1789 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1790 let mut local_short_channel_id = if short_channel_id.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id.unwrap() }) };
1791 let mut local_retry = crate::lightning::routing::router::RouteParameters { inner: if retry.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((retry.unwrap())) } }, is_owned: true };
1792 Event::PaymentPathFailed {
1793 payment_id: local_payment_id,
1794 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1795 payment_failed_permanently: payment_failed_permanently,
1796 network_update: local_network_update,
1797 all_paths_failed: all_paths_failed,
1798 path: local_path.into(),
1799 short_channel_id: local_short_channel_id,
1803 nativeEvent::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1804 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1805 Event::ProbeSuccessful {
1806 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1807 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1808 path: local_path.into(),
1811 nativeEvent::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
1812 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1813 let mut local_short_channel_id = if short_channel_id.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id.unwrap() }) };
1814 Event::ProbeFailed {
1815 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1816 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1817 path: local_path.into(),
1818 short_channel_id: local_short_channel_id,
1821 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
1822 Event::PendingHTLCsForwardable {
1823 time_forwardable: time_forwardable.as_secs(),
1826 nativeEvent::HTLCIntercepted {mut intercept_id, mut requested_next_hop_scid, mut payment_hash, mut inbound_amount_msat, mut expected_outbound_amount_msat, } => {
1827 Event::HTLCIntercepted {
1828 intercept_id: crate::c_types::ThirtyTwoBytes { data: intercept_id.0 },
1829 requested_next_hop_scid: requested_next_hop_scid,
1830 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1831 inbound_amount_msat: inbound_amount_msat,
1832 expected_outbound_amount_msat: expected_outbound_amount_msat,
1835 nativeEvent::SpendableOutputs {mut outputs, } => {
1836 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
1837 Event::SpendableOutputs {
1838 outputs: local_outputs.into(),
1841 nativeEvent::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1842 let mut local_prev_channel_id = if prev_channel_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (prev_channel_id.unwrap()) } } };
1843 let mut local_next_channel_id = if next_channel_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (next_channel_id.unwrap()) } } };
1844 let mut local_fee_earned_msat = if fee_earned_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_earned_msat.unwrap() }) };
1845 Event::PaymentForwarded {
1846 prev_channel_id: local_prev_channel_id,
1847 next_channel_id: local_next_channel_id,
1848 fee_earned_msat: local_fee_earned_msat,
1849 claim_from_onchain_tx: claim_from_onchain_tx,
1852 nativeEvent::ChannelReady {mut channel_id, mut user_channel_id, mut counterparty_node_id, mut channel_type, } => {
1853 Event::ChannelReady {
1854 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1855 user_channel_id: user_channel_id.into(),
1856 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1857 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true },
1860 nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1861 Event::ChannelClosed {
1862 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1863 user_channel_id: user_channel_id.into(),
1864 reason: crate::lightning::util::events::ClosureReason::native_into(reason),
1867 nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
1868 Event::DiscardFunding {
1869 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1870 transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
1873 nativeEvent::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1874 Event::OpenChannelRequest {
1875 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1876 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1877 funding_satoshis: funding_satoshis,
1878 push_msat: push_msat,
1879 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true },
1882 nativeEvent::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
1883 Event::HTLCHandlingFailed {
1884 prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id },
1885 failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination),
1891 /// Frees any resources used by the Event
1893 pub extern "C" fn Event_free(this_ptr: Event) { }
1894 /// Creates a copy of the Event
1896 pub extern "C" fn Event_clone(orig: &Event) -> Event {
1900 /// Utility method to constructs a new FundingGenerationReady-variant Event
1901 pub extern "C" fn Event_funding_generation_ready(temporary_channel_id: crate::c_types::ThirtyTwoBytes, counterparty_node_id: crate::c_types::PublicKey, channel_value_satoshis: u64, output_script: crate::c_types::derived::CVec_u8Z, user_channel_id: crate::c_types::U128) -> Event {
1902 Event::FundingGenerationReady {
1903 temporary_channel_id,
1904 counterparty_node_id,
1905 channel_value_satoshis,
1911 /// Utility method to constructs a new PaymentClaimable-variant Event
1912 pub extern "C" fn Event_payment_claimable(receiver_node_id: crate::c_types::PublicKey, payment_hash: crate::c_types::ThirtyTwoBytes, amount_msat: u64, purpose: crate::lightning::util::events::PaymentPurpose, via_channel_id: crate::c_types::ThirtyTwoBytes, via_user_channel_id: crate::c_types::derived::COption_u128Z) -> Event {
1913 Event::PaymentClaimable {
1919 via_user_channel_id,
1923 /// Utility method to constructs a new PaymentClaimed-variant Event
1924 pub extern "C" fn Event_payment_claimed(receiver_node_id: crate::c_types::PublicKey, payment_hash: crate::c_types::ThirtyTwoBytes, amount_msat: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
1925 Event::PaymentClaimed {
1933 /// Utility method to constructs a new PaymentSent-variant Event
1934 pub extern "C" fn Event_payment_sent(payment_id: crate::c_types::ThirtyTwoBytes, payment_preimage: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, fee_paid_msat: crate::c_types::derived::COption_u64Z) -> Event {
1935 Event::PaymentSent {
1943 /// Utility method to constructs a new PaymentFailed-variant Event
1944 pub extern "C" fn Event_payment_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> Event {
1945 Event::PaymentFailed {
1951 /// Utility method to constructs a new PaymentPathSuccessful-variant Event
1952 pub extern "C" fn Event_payment_path_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event {
1953 Event::PaymentPathSuccessful {
1960 /// Utility method to constructs a new PaymentPathFailed-variant Event
1961 pub extern "C" fn Event_payment_path_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, payment_failed_permanently: bool, network_update: crate::c_types::derived::COption_NetworkUpdateZ, all_paths_failed: bool, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z, retry: crate::lightning::routing::router::RouteParameters) -> Event {
1962 Event::PaymentPathFailed {
1965 payment_failed_permanently,
1974 /// Utility method to constructs a new ProbeSuccessful-variant Event
1975 pub extern "C" fn Event_probe_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event {
1976 Event::ProbeSuccessful {
1983 /// Utility method to constructs a new ProbeFailed-variant Event
1984 pub extern "C" fn Event_probe_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z) -> Event {
1985 Event::ProbeFailed {
1993 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
1994 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
1995 Event::PendingHTLCsForwardable {
2000 /// Utility method to constructs a new HTLCIntercepted-variant Event
2001 pub extern "C" fn Event_htlcintercepted(intercept_id: crate::c_types::ThirtyTwoBytes, requested_next_hop_scid: u64, payment_hash: crate::c_types::ThirtyTwoBytes, inbound_amount_msat: u64, expected_outbound_amount_msat: u64) -> Event {
2002 Event::HTLCIntercepted {
2004 requested_next_hop_scid,
2006 inbound_amount_msat,
2007 expected_outbound_amount_msat,
2011 /// Utility method to constructs a new SpendableOutputs-variant Event
2012 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
2013 Event::SpendableOutputs {
2018 /// Utility method to constructs a new PaymentForwarded-variant Event
2019 pub extern "C" fn Event_payment_forwarded(prev_channel_id: crate::c_types::ThirtyTwoBytes, next_channel_id: crate::c_types::ThirtyTwoBytes, fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
2020 Event::PaymentForwarded {
2024 claim_from_onchain_tx,
2028 /// Utility method to constructs a new ChannelReady-variant Event
2029 pub extern "C" fn Event_channel_ready(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: crate::c_types::U128, counterparty_node_id: crate::c_types::PublicKey, channel_type: crate::lightning::ln::features::ChannelTypeFeatures) -> Event {
2030 Event::ChannelReady {
2033 counterparty_node_id,
2038 /// Utility method to constructs a new ChannelClosed-variant Event
2039 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: crate::c_types::U128, reason: crate::lightning::util::events::ClosureReason) -> Event {
2040 Event::ChannelClosed {
2047 /// Utility method to constructs a new DiscardFunding-variant Event
2048 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
2049 Event::DiscardFunding {
2055 /// Utility method to constructs a new OpenChannelRequest-variant Event
2056 pub extern "C" fn Event_open_channel_request(temporary_channel_id: crate::c_types::ThirtyTwoBytes, counterparty_node_id: crate::c_types::PublicKey, funding_satoshis: u64, push_msat: u64, channel_type: crate::lightning::ln::features::ChannelTypeFeatures) -> Event {
2057 Event::OpenChannelRequest {
2058 temporary_channel_id,
2059 counterparty_node_id,
2066 /// Utility method to constructs a new HTLCHandlingFailed-variant Event
2067 pub extern "C" fn Event_htlchandling_failed(prev_channel_id: crate::c_types::ThirtyTwoBytes, failed_next_destination: crate::lightning::util::events::HTLCDestination) -> Event {
2068 Event::HTLCHandlingFailed {
2070 failed_next_destination,
2074 /// Serialize the Event object into a byte array which can be read by Event_read
2075 pub extern "C" fn Event_write(obj: &crate::lightning::util::events::Event) -> crate::c_types::derived::CVec_u8Z {
2076 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
2079 /// Read a Event from a byte array, created by Event_write
2080 pub extern "C" fn Event_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_EventZDecodeErrorZ {
2081 let res: Result<Option<lightning::util::events::Event>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
2082 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_EventZ::None } else { crate::c_types::derived::COption_EventZ::Some( { crate::lightning::util::events::Event::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2085 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
2086 /// broadcast to most peers).
2087 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
2091 pub enum MessageSendEvent {
2092 /// Used to indicate that we've accepted a channel open and should send the accept_channel
2093 /// message provided to the given peer.
2095 /// The node_id of the node which should receive this message
2096 node_id: crate::c_types::PublicKey,
2097 /// The message which should be sent.
2098 msg: crate::lightning::ln::msgs::AcceptChannel,
2100 /// Used to indicate that we've initiated a channel open and should send the open_channel
2101 /// message provided to the given peer.
2103 /// The node_id of the node which should receive this message
2104 node_id: crate::c_types::PublicKey,
2105 /// The message which should be sent.
2106 msg: crate::lightning::ln::msgs::OpenChannel,
2108 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
2109 SendFundingCreated {
2110 /// The node_id of the node which should receive this message
2111 node_id: crate::c_types::PublicKey,
2112 /// The message which should be sent.
2113 msg: crate::lightning::ln::msgs::FundingCreated,
2115 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
2117 /// The node_id of the node which should receive this message
2118 node_id: crate::c_types::PublicKey,
2119 /// The message which should be sent.
2120 msg: crate::lightning::ln::msgs::FundingSigned,
2122 /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
2124 /// The node_id of the node which should receive these message(s)
2125 node_id: crate::c_types::PublicKey,
2126 /// The channel_ready message which should be sent.
2127 msg: crate::lightning::ln::msgs::ChannelReady,
2129 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
2130 SendAnnouncementSignatures {
2131 /// The node_id of the node which should receive these message(s)
2132 node_id: crate::c_types::PublicKey,
2133 /// The announcement_signatures message which should be sent.
2134 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
2136 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
2137 /// message should be sent to the peer with the given node_id.
2139 /// The node_id of the node which should receive these message(s)
2140 node_id: crate::c_types::PublicKey,
2141 /// The update messages which should be sent. ALL messages in the struct should be sent!
2142 updates: crate::lightning::ln::msgs::CommitmentUpdate,
2144 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
2146 /// The node_id of the node which should receive this message
2147 node_id: crate::c_types::PublicKey,
2148 /// The message which should be sent.
2149 msg: crate::lightning::ln::msgs::RevokeAndACK,
2151 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
2153 /// The node_id of the node which should receive this message
2154 node_id: crate::c_types::PublicKey,
2155 /// The message which should be sent.
2156 msg: crate::lightning::ln::msgs::ClosingSigned,
2158 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
2160 /// The node_id of the node which should receive this message
2161 node_id: crate::c_types::PublicKey,
2162 /// The message which should be sent.
2163 msg: crate::lightning::ln::msgs::Shutdown,
2165 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
2166 SendChannelReestablish {
2167 /// The node_id of the node which should receive this message
2168 node_id: crate::c_types::PublicKey,
2169 /// The message which should be sent.
2170 msg: crate::lightning::ln::msgs::ChannelReestablish,
2172 /// Used to send a channel_announcement and channel_update to a specific peer, likely on
2173 /// initial connection to ensure our peers know about our channels.
2174 SendChannelAnnouncement {
2175 /// The node_id of the node which should receive this message
2176 node_id: crate::c_types::PublicKey,
2177 /// The channel_announcement which should be sent.
2178 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
2179 /// The followup channel_update which should be sent.
2180 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
2182 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
2183 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
2185 /// Note that after doing so, you very likely (unless you did so very recently) want to
2186 /// broadcast a node_announcement (e.g. via [`PeerManager::broadcast_node_announcement`]). This
2187 /// ensures that any nodes which see our channel_announcement also have a relevant
2188 /// node_announcement, including relevant feature flags which may be important for routing
2189 /// through or to us.
2191 /// [`PeerManager::broadcast_node_announcement`]: crate::ln::peer_handler::PeerManager::broadcast_node_announcement
2192 BroadcastChannelAnnouncement {
2193 /// The channel_announcement which should be sent.
2194 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
2195 /// The followup channel_update which should be sent.
2196 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
2198 /// Used to indicate that a channel_update should be broadcast to all peers.
2199 BroadcastChannelUpdate {
2200 /// The channel_update which should be sent.
2201 msg: crate::lightning::ln::msgs::ChannelUpdate,
2203 /// Used to indicate that a channel_update should be sent to a single peer.
2204 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
2205 /// private channel and we shouldn't be informing all of our peers of channel parameters.
2207 /// The node_id of the node which should receive this message
2208 node_id: crate::c_types::PublicKey,
2209 /// The channel_update which should be sent.
2210 msg: crate::lightning::ln::msgs::ChannelUpdate,
2212 /// Broadcast an error downstream to be handled
2214 /// The node_id of the node which should receive this message
2215 node_id: crate::c_types::PublicKey,
2216 /// The action which should be taken.
2217 action: crate::lightning::ln::msgs::ErrorAction,
2219 /// Query a peer for channels with funding transaction UTXOs in a block range.
2220 SendChannelRangeQuery {
2221 /// The node_id of this message recipient
2222 node_id: crate::c_types::PublicKey,
2223 /// The query_channel_range which should be sent.
2224 msg: crate::lightning::ln::msgs::QueryChannelRange,
2226 /// Request routing gossip messages from a peer for a list of channels identified by
2227 /// their short_channel_ids.
2229 /// The node_id of this message recipient
2230 node_id: crate::c_types::PublicKey,
2231 /// The query_short_channel_ids which should be sent.
2232 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
2234 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
2235 /// emitted during processing of the query.
2236 SendReplyChannelRange {
2237 /// The node_id of this message recipient
2238 node_id: crate::c_types::PublicKey,
2239 /// The reply_channel_range which should be sent.
2240 msg: crate::lightning::ln::msgs::ReplyChannelRange,
2242 /// Sends a timestamp filter for inbound gossip. This should be sent on each new connection to
2243 /// enable receiving gossip messages from the peer.
2244 SendGossipTimestampFilter {
2245 /// The node_id of this message recipient
2246 node_id: crate::c_types::PublicKey,
2247 /// The gossip_timestamp_filter which should be sent.
2248 msg: crate::lightning::ln::msgs::GossipTimestampFilter,
2251 use lightning::util::events::MessageSendEvent as MessageSendEventImport;
2252 pub(crate) type nativeMessageSendEvent = MessageSendEventImport;
2254 impl MessageSendEvent {
2256 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
2258 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
2259 let mut node_id_nonref = Clone::clone(node_id);
2260 let mut msg_nonref = Clone::clone(msg);
2261 nativeMessageSendEvent::SendAcceptChannel {
2262 node_id: node_id_nonref.into_rust(),
2263 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2266 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
2267 let mut node_id_nonref = Clone::clone(node_id);
2268 let mut msg_nonref = Clone::clone(msg);
2269 nativeMessageSendEvent::SendOpenChannel {
2270 node_id: node_id_nonref.into_rust(),
2271 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2274 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
2275 let mut node_id_nonref = Clone::clone(node_id);
2276 let mut msg_nonref = Clone::clone(msg);
2277 nativeMessageSendEvent::SendFundingCreated {
2278 node_id: node_id_nonref.into_rust(),
2279 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2282 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
2283 let mut node_id_nonref = Clone::clone(node_id);
2284 let mut msg_nonref = Clone::clone(msg);
2285 nativeMessageSendEvent::SendFundingSigned {
2286 node_id: node_id_nonref.into_rust(),
2287 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2290 MessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
2291 let mut node_id_nonref = Clone::clone(node_id);
2292 let mut msg_nonref = Clone::clone(msg);
2293 nativeMessageSendEvent::SendChannelReady {
2294 node_id: node_id_nonref.into_rust(),
2295 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2298 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
2299 let mut node_id_nonref = Clone::clone(node_id);
2300 let mut msg_nonref = Clone::clone(msg);
2301 nativeMessageSendEvent::SendAnnouncementSignatures {
2302 node_id: node_id_nonref.into_rust(),
2303 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2306 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2307 let mut node_id_nonref = Clone::clone(node_id);
2308 let mut updates_nonref = Clone::clone(updates);
2309 nativeMessageSendEvent::UpdateHTLCs {
2310 node_id: node_id_nonref.into_rust(),
2311 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
2314 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2315 let mut node_id_nonref = Clone::clone(node_id);
2316 let mut msg_nonref = Clone::clone(msg);
2317 nativeMessageSendEvent::SendRevokeAndACK {
2318 node_id: node_id_nonref.into_rust(),
2319 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2322 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2323 let mut node_id_nonref = Clone::clone(node_id);
2324 let mut msg_nonref = Clone::clone(msg);
2325 nativeMessageSendEvent::SendClosingSigned {
2326 node_id: node_id_nonref.into_rust(),
2327 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2330 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
2331 let mut node_id_nonref = Clone::clone(node_id);
2332 let mut msg_nonref = Clone::clone(msg);
2333 nativeMessageSendEvent::SendShutdown {
2334 node_id: node_id_nonref.into_rust(),
2335 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2338 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
2339 let mut node_id_nonref = Clone::clone(node_id);
2340 let mut msg_nonref = Clone::clone(msg);
2341 nativeMessageSendEvent::SendChannelReestablish {
2342 node_id: node_id_nonref.into_rust(),
2343 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2346 MessageSendEvent::SendChannelAnnouncement {ref node_id, ref msg, ref update_msg, } => {
2347 let mut node_id_nonref = Clone::clone(node_id);
2348 let mut msg_nonref = Clone::clone(msg);
2349 let mut update_msg_nonref = Clone::clone(update_msg);
2350 nativeMessageSendEvent::SendChannelAnnouncement {
2351 node_id: node_id_nonref.into_rust(),
2352 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2353 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
2356 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
2357 let mut msg_nonref = Clone::clone(msg);
2358 let mut update_msg_nonref = Clone::clone(update_msg);
2359 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2360 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2361 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
2364 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
2365 let mut msg_nonref = Clone::clone(msg);
2366 nativeMessageSendEvent::BroadcastChannelUpdate {
2367 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2370 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
2371 let mut node_id_nonref = Clone::clone(node_id);
2372 let mut msg_nonref = Clone::clone(msg);
2373 nativeMessageSendEvent::SendChannelUpdate {
2374 node_id: node_id_nonref.into_rust(),
2375 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2378 MessageSendEvent::HandleError {ref node_id, ref action, } => {
2379 let mut node_id_nonref = Clone::clone(node_id);
2380 let mut action_nonref = Clone::clone(action);
2381 nativeMessageSendEvent::HandleError {
2382 node_id: node_id_nonref.into_rust(),
2383 action: action_nonref.into_native(),
2386 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
2387 let mut node_id_nonref = Clone::clone(node_id);
2388 let mut msg_nonref = Clone::clone(msg);
2389 nativeMessageSendEvent::SendChannelRangeQuery {
2390 node_id: node_id_nonref.into_rust(),
2391 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2394 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
2395 let mut node_id_nonref = Clone::clone(node_id);
2396 let mut msg_nonref = Clone::clone(msg);
2397 nativeMessageSendEvent::SendShortIdsQuery {
2398 node_id: node_id_nonref.into_rust(),
2399 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2402 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
2403 let mut node_id_nonref = Clone::clone(node_id);
2404 let mut msg_nonref = Clone::clone(msg);
2405 nativeMessageSendEvent::SendReplyChannelRange {
2406 node_id: node_id_nonref.into_rust(),
2407 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2410 MessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
2411 let mut node_id_nonref = Clone::clone(node_id);
2412 let mut msg_nonref = Clone::clone(msg);
2413 nativeMessageSendEvent::SendGossipTimestampFilter {
2414 node_id: node_id_nonref.into_rust(),
2415 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2421 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
2423 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
2424 nativeMessageSendEvent::SendAcceptChannel {
2425 node_id: node_id.into_rust(),
2426 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2429 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
2430 nativeMessageSendEvent::SendOpenChannel {
2431 node_id: node_id.into_rust(),
2432 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2435 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
2436 nativeMessageSendEvent::SendFundingCreated {
2437 node_id: node_id.into_rust(),
2438 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2441 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
2442 nativeMessageSendEvent::SendFundingSigned {
2443 node_id: node_id.into_rust(),
2444 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2447 MessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
2448 nativeMessageSendEvent::SendChannelReady {
2449 node_id: node_id.into_rust(),
2450 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2453 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
2454 nativeMessageSendEvent::SendAnnouncementSignatures {
2455 node_id: node_id.into_rust(),
2456 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2459 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
2460 nativeMessageSendEvent::UpdateHTLCs {
2461 node_id: node_id.into_rust(),
2462 updates: *unsafe { Box::from_raw(updates.take_inner()) },
2465 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
2466 nativeMessageSendEvent::SendRevokeAndACK {
2467 node_id: node_id.into_rust(),
2468 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2471 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
2472 nativeMessageSendEvent::SendClosingSigned {
2473 node_id: node_id.into_rust(),
2474 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2477 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
2478 nativeMessageSendEvent::SendShutdown {
2479 node_id: node_id.into_rust(),
2480 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2483 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
2484 nativeMessageSendEvent::SendChannelReestablish {
2485 node_id: node_id.into_rust(),
2486 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2489 MessageSendEvent::SendChannelAnnouncement {mut node_id, mut msg, mut update_msg, } => {
2490 nativeMessageSendEvent::SendChannelAnnouncement {
2491 node_id: node_id.into_rust(),
2492 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2493 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
2496 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
2497 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2498 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2499 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
2502 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
2503 nativeMessageSendEvent::BroadcastChannelUpdate {
2504 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2507 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
2508 nativeMessageSendEvent::SendChannelUpdate {
2509 node_id: node_id.into_rust(),
2510 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2513 MessageSendEvent::HandleError {mut node_id, mut action, } => {
2514 nativeMessageSendEvent::HandleError {
2515 node_id: node_id.into_rust(),
2516 action: action.into_native(),
2519 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
2520 nativeMessageSendEvent::SendChannelRangeQuery {
2521 node_id: node_id.into_rust(),
2522 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2525 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
2526 nativeMessageSendEvent::SendShortIdsQuery {
2527 node_id: node_id.into_rust(),
2528 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2531 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
2532 nativeMessageSendEvent::SendReplyChannelRange {
2533 node_id: node_id.into_rust(),
2534 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2537 MessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
2538 nativeMessageSendEvent::SendGossipTimestampFilter {
2539 node_id: node_id.into_rust(),
2540 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2546 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
2548 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
2549 let mut node_id_nonref = Clone::clone(node_id);
2550 let mut msg_nonref = Clone::clone(msg);
2551 MessageSendEvent::SendAcceptChannel {
2552 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2553 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2556 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
2557 let mut node_id_nonref = Clone::clone(node_id);
2558 let mut msg_nonref = Clone::clone(msg);
2559 MessageSendEvent::SendOpenChannel {
2560 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2561 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2564 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
2565 let mut node_id_nonref = Clone::clone(node_id);
2566 let mut msg_nonref = Clone::clone(msg);
2567 MessageSendEvent::SendFundingCreated {
2568 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2569 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2572 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
2573 let mut node_id_nonref = Clone::clone(node_id);
2574 let mut msg_nonref = Clone::clone(msg);
2575 MessageSendEvent::SendFundingSigned {
2576 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2577 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2580 nativeMessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
2581 let mut node_id_nonref = Clone::clone(node_id);
2582 let mut msg_nonref = Clone::clone(msg);
2583 MessageSendEvent::SendChannelReady {
2584 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2585 msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2588 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
2589 let mut node_id_nonref = Clone::clone(node_id);
2590 let mut msg_nonref = Clone::clone(msg);
2591 MessageSendEvent::SendAnnouncementSignatures {
2592 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2593 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2596 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2597 let mut node_id_nonref = Clone::clone(node_id);
2598 let mut updates_nonref = Clone::clone(updates);
2599 MessageSendEvent::UpdateHTLCs {
2600 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2601 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
2604 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2605 let mut node_id_nonref = Clone::clone(node_id);
2606 let mut msg_nonref = Clone::clone(msg);
2607 MessageSendEvent::SendRevokeAndACK {
2608 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2609 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2612 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2613 let mut node_id_nonref = Clone::clone(node_id);
2614 let mut msg_nonref = Clone::clone(msg);
2615 MessageSendEvent::SendClosingSigned {
2616 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2617 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2620 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
2621 let mut node_id_nonref = Clone::clone(node_id);
2622 let mut msg_nonref = Clone::clone(msg);
2623 MessageSendEvent::SendShutdown {
2624 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2625 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2628 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
2629 let mut node_id_nonref = Clone::clone(node_id);
2630 let mut msg_nonref = Clone::clone(msg);
2631 MessageSendEvent::SendChannelReestablish {
2632 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2633 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2636 nativeMessageSendEvent::SendChannelAnnouncement {ref node_id, ref msg, ref update_msg, } => {
2637 let mut node_id_nonref = Clone::clone(node_id);
2638 let mut msg_nonref = Clone::clone(msg);
2639 let mut update_msg_nonref = Clone::clone(update_msg);
2640 MessageSendEvent::SendChannelAnnouncement {
2641 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2642 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2643 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
2646 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
2647 let mut msg_nonref = Clone::clone(msg);
2648 let mut update_msg_nonref = Clone::clone(update_msg);
2649 MessageSendEvent::BroadcastChannelAnnouncement {
2650 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2651 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
2654 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
2655 let mut msg_nonref = Clone::clone(msg);
2656 MessageSendEvent::BroadcastChannelUpdate {
2657 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2660 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
2661 let mut node_id_nonref = Clone::clone(node_id);
2662 let mut msg_nonref = Clone::clone(msg);
2663 MessageSendEvent::SendChannelUpdate {
2664 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2665 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2668 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
2669 let mut node_id_nonref = Clone::clone(node_id);
2670 let mut action_nonref = Clone::clone(action);
2671 MessageSendEvent::HandleError {
2672 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2673 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
2676 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
2677 let mut node_id_nonref = Clone::clone(node_id);
2678 let mut msg_nonref = Clone::clone(msg);
2679 MessageSendEvent::SendChannelRangeQuery {
2680 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2681 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2684 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
2685 let mut node_id_nonref = Clone::clone(node_id);
2686 let mut msg_nonref = Clone::clone(msg);
2687 MessageSendEvent::SendShortIdsQuery {
2688 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2689 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2692 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
2693 let mut node_id_nonref = Clone::clone(node_id);
2694 let mut msg_nonref = Clone::clone(msg);
2695 MessageSendEvent::SendReplyChannelRange {
2696 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2697 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2700 nativeMessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
2701 let mut node_id_nonref = Clone::clone(node_id);
2702 let mut msg_nonref = Clone::clone(msg);
2703 MessageSendEvent::SendGossipTimestampFilter {
2704 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2705 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2711 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
2713 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
2714 MessageSendEvent::SendAcceptChannel {
2715 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2716 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
2719 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
2720 MessageSendEvent::SendOpenChannel {
2721 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2722 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
2725 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
2726 MessageSendEvent::SendFundingCreated {
2727 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2728 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
2731 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
2732 MessageSendEvent::SendFundingSigned {
2733 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2734 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
2737 nativeMessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
2738 MessageSendEvent::SendChannelReady {
2739 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2740 msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg), is_owned: true },
2743 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
2744 MessageSendEvent::SendAnnouncementSignatures {
2745 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2746 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
2749 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
2750 MessageSendEvent::UpdateHTLCs {
2751 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2752 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
2755 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
2756 MessageSendEvent::SendRevokeAndACK {
2757 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2758 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
2761 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
2762 MessageSendEvent::SendClosingSigned {
2763 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2764 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
2767 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
2768 MessageSendEvent::SendShutdown {
2769 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2770 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
2773 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
2774 MessageSendEvent::SendChannelReestablish {
2775 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2776 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
2779 nativeMessageSendEvent::SendChannelAnnouncement {mut node_id, mut msg, mut update_msg, } => {
2780 MessageSendEvent::SendChannelAnnouncement {
2781 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2782 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
2783 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
2786 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
2787 MessageSendEvent::BroadcastChannelAnnouncement {
2788 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
2789 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
2792 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
2793 MessageSendEvent::BroadcastChannelUpdate {
2794 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
2797 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
2798 MessageSendEvent::SendChannelUpdate {
2799 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2800 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
2803 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
2804 MessageSendEvent::HandleError {
2805 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2806 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
2809 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
2810 MessageSendEvent::SendChannelRangeQuery {
2811 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2812 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
2815 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
2816 MessageSendEvent::SendShortIdsQuery {
2817 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2818 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
2821 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
2822 MessageSendEvent::SendReplyChannelRange {
2823 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2824 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
2827 nativeMessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
2828 MessageSendEvent::SendGossipTimestampFilter {
2829 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2830 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg), is_owned: true },
2836 /// Frees any resources used by the MessageSendEvent
2838 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
2839 /// Creates a copy of the MessageSendEvent
2841 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
2845 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
2846 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
2847 MessageSendEvent::SendAcceptChannel {
2853 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
2854 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
2855 MessageSendEvent::SendOpenChannel {
2861 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
2862 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
2863 MessageSendEvent::SendFundingCreated {
2869 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
2870 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
2871 MessageSendEvent::SendFundingSigned {
2877 /// Utility method to constructs a new SendChannelReady-variant MessageSendEvent
2878 pub extern "C" fn MessageSendEvent_send_channel_ready(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReady) -> MessageSendEvent {
2879 MessageSendEvent::SendChannelReady {
2885 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
2886 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
2887 MessageSendEvent::SendAnnouncementSignatures {
2893 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
2894 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
2895 MessageSendEvent::UpdateHTLCs {
2901 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
2902 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
2903 MessageSendEvent::SendRevokeAndACK {
2909 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
2910 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
2911 MessageSendEvent::SendClosingSigned {
2917 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
2918 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
2919 MessageSendEvent::SendShutdown {
2925 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
2926 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
2927 MessageSendEvent::SendChannelReestablish {
2933 /// Utility method to constructs a new SendChannelAnnouncement-variant MessageSendEvent
2934 pub extern "C" fn MessageSendEvent_send_channel_announcement(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2935 MessageSendEvent::SendChannelAnnouncement {
2942 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
2943 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2944 MessageSendEvent::BroadcastChannelAnnouncement {
2950 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
2951 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2952 MessageSendEvent::BroadcastChannelUpdate {
2957 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
2958 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2959 MessageSendEvent::SendChannelUpdate {
2965 /// Utility method to constructs a new HandleError-variant MessageSendEvent
2966 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
2967 MessageSendEvent::HandleError {
2973 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
2974 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
2975 MessageSendEvent::SendChannelRangeQuery {
2981 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
2982 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
2983 MessageSendEvent::SendShortIdsQuery {
2989 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
2990 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
2991 MessageSendEvent::SendReplyChannelRange {
2997 /// Utility method to constructs a new SendGossipTimestampFilter-variant MessageSendEvent
2998 pub extern "C" fn MessageSendEvent_send_gossip_timestamp_filter(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::GossipTimestampFilter) -> MessageSendEvent {
2999 MessageSendEvent::SendGossipTimestampFilter {
3004 /// A trait indicating an object may generate message send events
3006 pub struct MessageSendEventsProvider {
3007 /// An opaque pointer which is passed to your function implementations as an argument.
3008 /// This has no meaning in the LDK, and can be NULL or any other value.
3009 pub this_arg: *mut c_void,
3010 /// Gets the list of pending events which were generated by previous actions, clearing the list
3013 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
3014 /// Frees any resources associated with this object given its this_arg pointer.
3015 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3016 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3018 unsafe impl Send for MessageSendEventsProvider {}
3019 unsafe impl Sync for MessageSendEventsProvider {}
3021 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
3022 MessageSendEventsProvider {
3023 this_arg: orig.this_arg,
3024 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
3025 free: Clone::clone(&orig.free),
3029 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
3030 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
3031 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
3032 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
3033 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
3038 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
3039 // directly as a Deref trait in higher-level structs:
3040 impl core::ops::Deref for MessageSendEventsProvider {
3042 fn deref(&self) -> &Self {
3046 /// Calls the free function if one is set
3048 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
3049 impl Drop for MessageSendEventsProvider {
3050 fn drop(&mut self) {
3051 if let Some(f) = self.free {
3056 /// A trait indicating an object may generate onion messages to send
3058 pub struct OnionMessageProvider {
3059 /// An opaque pointer which is passed to your function implementations as an argument.
3060 /// This has no meaning in the LDK, and can be NULL or any other value.
3061 pub this_arg: *mut c_void,
3062 /// Gets the next pending onion message for the peer with the given node id.
3064 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
3066 pub next_onion_message_for_peer: extern "C" fn (this_arg: *const c_void, peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage,
3067 /// Frees any resources associated with this object given its this_arg pointer.
3068 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3069 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3071 unsafe impl Send for OnionMessageProvider {}
3072 unsafe impl Sync for OnionMessageProvider {}
3074 pub(crate) extern "C" fn OnionMessageProvider_clone_fields(orig: &OnionMessageProvider) -> OnionMessageProvider {
3075 OnionMessageProvider {
3076 this_arg: orig.this_arg,
3077 next_onion_message_for_peer: Clone::clone(&orig.next_onion_message_for_peer),
3078 free: Clone::clone(&orig.free),
3082 use lightning::util::events::OnionMessageProvider as rustOnionMessageProvider;
3083 impl rustOnionMessageProvider for OnionMessageProvider {
3084 fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option<lightning::ln::msgs::OnionMessage> {
3085 let mut ret = (self.next_onion_message_for_peer)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id));
3086 let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) };
3091 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
3092 // directly as a Deref trait in higher-level structs:
3093 impl core::ops::Deref for OnionMessageProvider {
3095 fn deref(&self) -> &Self {
3099 /// Calls the free function if one is set
3101 pub extern "C" fn OnionMessageProvider_free(this_ptr: OnionMessageProvider) { }
3102 impl Drop for OnionMessageProvider {
3103 fn drop(&mut self) {
3104 if let Some(f) = self.free {
3109 /// A trait indicating an object may generate events.
3111 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
3113 /// Implementations of this trait may also feature an async version of event handling, as shown with
3114 /// [`ChannelManager::process_pending_events_async`] and
3115 /// [`ChainMonitor::process_pending_events_async`].
3119 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
3120 /// event since the last invocation.
3122 /// In order to ensure no [`Event`]s are lost, implementors of this trait will persist [`Event`]s
3123 /// and replay any unhandled events on startup. An [`Event`] is considered handled when
3124 /// [`process_pending_events`] returns, thus handlers MUST fully handle [`Event`]s and persist any
3125 /// relevant changes to disk *before* returning.
3127 /// Further, because an application may crash between an [`Event`] being handled and the
3128 /// implementor of this trait being re-serialized, [`Event`] handling must be idempotent - in
3129 /// effect, [`Event`]s may be replayed.
3131 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
3132 /// consult the provider's documentation on the implication of processing events and how a handler
3133 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
3134 /// [`ChainMonitor::process_pending_events`]).
3136 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
3139 /// [`process_pending_events`]: Self::process_pending_events
3140 /// [`handle_event`]: EventHandler::handle_event
3141 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
3142 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
3143 /// [`ChannelManager::process_pending_events_async`]: crate::ln::channelmanager::ChannelManager::process_pending_events_async
3144 /// [`ChainMonitor::process_pending_events_async`]: crate::chain::chainmonitor::ChainMonitor::process_pending_events_async
3146 pub struct EventsProvider {
3147 /// An opaque pointer which is passed to your function implementations as an argument.
3148 /// This has no meaning in the LDK, and can be NULL or any other value.
3149 pub this_arg: *mut c_void,
3150 /// Processes any events generated since the last call using the given event handler.
3152 /// See the trait-level documentation for requirements.
3153 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
3154 /// Frees any resources associated with this object given its this_arg pointer.
3155 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3156 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3158 unsafe impl Send for EventsProvider {}
3159 unsafe impl Sync for EventsProvider {}
3161 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
3163 this_arg: orig.this_arg,
3164 process_pending_events: Clone::clone(&orig.process_pending_events),
3165 free: Clone::clone(&orig.free),
3169 use lightning::util::events::EventsProvider as rustEventsProvider;
3170 /// Calls the free function if one is set
3172 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
3173 impl Drop for EventsProvider {
3174 fn drop(&mut self) {
3175 if let Some(f) = self.free {
3180 /// A trait implemented for objects handling events from [`EventsProvider`].
3182 /// An async variation also exists for implementations of [`EventsProvider`] that support async
3183 /// event handling. The async event handler should satisfy the generic bounds: `F:
3184 /// core::future::Future, H: Fn(Event) -> F`.
3186 pub struct EventHandler {
3187 /// An opaque pointer which is passed to your function implementations as an argument.
3188 /// This has no meaning in the LDK, and can be NULL or any other value.
3189 pub this_arg: *mut c_void,
3190 /// Handles the given [`Event`].
3192 /// See [`EventsProvider`] for details that must be considered when implementing this method.
3193 pub handle_event: extern "C" fn (this_arg: *const c_void, event: crate::lightning::util::events::Event),
3194 /// Frees any resources associated with this object given its this_arg pointer.
3195 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3196 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3198 unsafe impl Send for EventHandler {}
3199 unsafe impl Sync for EventHandler {}
3201 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
3203 this_arg: orig.this_arg,
3204 handle_event: Clone::clone(&orig.handle_event),
3205 free: Clone::clone(&orig.free),
3209 use lightning::util::events::EventHandler as rustEventHandler;
3210 impl rustEventHandler for EventHandler {
3211 fn handle_event(&self, mut event: lightning::util::events::Event) {
3212 (self.handle_event)(self.this_arg, crate::lightning::util::events::Event::native_into(event))
3216 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
3217 // directly as a Deref trait in higher-level structs:
3218 impl core::ops::Deref for EventHandler {
3220 fn deref(&self) -> &Self {
3224 /// Calls the free function if one is set
3226 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
3227 impl Drop for EventHandler {
3228 fn drop(&mut self) {
3229 if let Some(f) = self.free {