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::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, )
158 /// Checks if two PaymentPurposes contain equal inner contents.
159 /// This ignores pointers and is_owned flags and looks at the values in fields.
161 pub extern "C" fn PaymentPurpose_eq(a: &PaymentPurpose, b: &PaymentPurpose) -> bool {
162 if &a.to_native() == &b.to_native() { true } else { false }
165 /// Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
166 pub extern "C" fn PaymentPurpose_write(obj: &crate::lightning::events::PaymentPurpose) -> crate::c_types::derived::CVec_u8Z {
167 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
170 /// Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
171 pub extern "C" fn PaymentPurpose_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentPurposeDecodeErrorZ {
172 let res: Result<lightning::events::PaymentPurpose, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
173 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::events::PaymentPurpose::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
176 /// When the payment path failure took place and extra details about it. [`PathFailure::OnPath`] may
177 /// contain a [`NetworkUpdate`] that needs to be applied to the [`NetworkGraph`].
179 /// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
180 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
184 pub enum PathFailure {
185 /// We failed to initially send the payment and no HTLC was committed to. Contains the relevant
188 /// The error surfaced from initial send.
189 err: crate::lightning::util::errors::APIError,
191 /// A hop on the path failed to forward our payment.
193 /// If present, this [`NetworkUpdate`] should be applied to the [`NetworkGraph`] so that routing
194 /// decisions can take into account the update.
196 /// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
197 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
198 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
201 use lightning::events::PathFailure as PathFailureImport;
202 pub(crate) type nativePathFailure = PathFailureImport;
206 pub(crate) fn to_native(&self) -> nativePathFailure {
208 PathFailure::InitialSend {ref err, } => {
209 let mut err_nonref = Clone::clone(err);
210 nativePathFailure::InitialSend {
211 err: err_nonref.into_native(),
214 PathFailure::OnPath {ref network_update, } => {
215 let mut network_update_nonref = Clone::clone(network_update);
216 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() }})} };
217 nativePathFailure::OnPath {
218 network_update: local_network_update_nonref,
224 pub(crate) fn into_native(self) -> nativePathFailure {
226 PathFailure::InitialSend {mut err, } => {
227 nativePathFailure::InitialSend {
228 err: err.into_native(),
231 PathFailure::OnPath {mut network_update, } => {
232 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() }})} };
233 nativePathFailure::OnPath {
234 network_update: local_network_update,
240 pub(crate) fn from_native(native: &nativePathFailure) -> Self {
242 nativePathFailure::InitialSend {ref err, } => {
243 let mut err_nonref = Clone::clone(err);
244 PathFailure::InitialSend {
245 err: crate::lightning::util::errors::APIError::native_into(err_nonref),
248 nativePathFailure::OnPath {ref network_update, } => {
249 let mut network_update_nonref = Clone::clone(network_update);
250 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()) }) };
251 PathFailure::OnPath {
252 network_update: local_network_update_nonref,
258 pub(crate) fn native_into(native: nativePathFailure) -> Self {
260 nativePathFailure::InitialSend {mut err, } => {
261 PathFailure::InitialSend {
262 err: crate::lightning::util::errors::APIError::native_into(err),
265 nativePathFailure::OnPath {mut network_update, } => {
266 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()) }) };
267 PathFailure::OnPath {
268 network_update: local_network_update,
274 /// Frees any resources used by the PathFailure
276 pub extern "C" fn PathFailure_free(this_ptr: PathFailure) { }
277 /// Creates a copy of the PathFailure
279 pub extern "C" fn PathFailure_clone(orig: &PathFailure) -> PathFailure {
283 /// Utility method to constructs a new InitialSend-variant PathFailure
284 pub extern "C" fn PathFailure_initial_send(err: crate::lightning::util::errors::APIError) -> PathFailure {
285 PathFailure::InitialSend {
290 /// Utility method to constructs a new OnPath-variant PathFailure
291 pub extern "C" fn PathFailure_on_path(network_update: crate::c_types::derived::COption_NetworkUpdateZ) -> PathFailure {
292 PathFailure::OnPath {
296 /// Checks if two PathFailures contain equal inner contents.
297 /// This ignores pointers and is_owned flags and looks at the values in fields.
299 pub extern "C" fn PathFailure_eq(a: &PathFailure, b: &PathFailure) -> bool {
300 if &a.to_native() == &b.to_native() { true } else { false }
303 /// Serialize the PathFailure object into a byte array which can be read by PathFailure_read
304 pub extern "C" fn PathFailure_write(obj: &crate::lightning::events::PathFailure) -> crate::c_types::derived::CVec_u8Z {
305 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
308 /// Read a PathFailure from a byte array, created by PathFailure_write
309 pub extern "C" fn PathFailure_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_PathFailureZDecodeErrorZ {
310 let res: Result<Option<lightning::events::PathFailure>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
311 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_PathFailureZ::None } else { crate::c_types::derived::COption_PathFailureZ::Some( { crate::lightning::events::PathFailure::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() };
314 /// The reason the channel was closed. See individual variants more details.
318 pub enum ClosureReason {
319 /// Closure generated from receiving a peer error message.
321 /// Our counterparty may have broadcasted their latest commitment state, and we have
323 CounterpartyForceClosed {
324 /// The error which the peer sent us.
326 /// Be careful about printing the peer_msg, a well-crafted message could exploit
327 /// a security vulnerability in the terminal emulator or the logging subsystem.
328 /// To be safe, use `Display` on `UntrustedString`
330 /// [`UntrustedString`]: crate::util::string::UntrustedString
331 peer_msg: crate::lightning::util::string::UntrustedString,
333 /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
335 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
337 /// The channel was closed after negotiating a cooperative close and we've now broadcasted
338 /// the cooperative close transaction. Note the shutdown may have been initiated by us.
340 /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
341 /// commitment transaction came from our counterparty, but it may also have come from
342 /// a copy of our own `ChannelMonitor`.
343 CommitmentTxConfirmed,
344 /// The funding transaction failed to confirm in a timely manner on an inbound channel.
346 /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
348 /// A developer-readable error message which we generated.
349 err: crate::c_types::Str,
351 /// The peer disconnected prior to funding completing. In this case the spec mandates that we
352 /// forget the channel entirely - we can attempt again if the peer reconnects.
354 /// This includes cases where we restarted prior to funding completion, including prior to the
355 /// initial [`ChannelMonitor`] persistence completing.
357 /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
358 /// peer because of mutual incompatibility between us and our channel counterparty.
360 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
362 /// Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
363 /// the [`ChannelManager`] deserialized.
365 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
366 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
367 OutdatedChannelManager,
369 use lightning::events::ClosureReason as ClosureReasonImport;
370 pub(crate) type nativeClosureReason = ClosureReasonImport;
374 pub(crate) fn to_native(&self) -> nativeClosureReason {
376 ClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
377 let mut peer_msg_nonref = Clone::clone(peer_msg);
378 nativeClosureReason::CounterpartyForceClosed {
379 peer_msg: *unsafe { Box::from_raw(peer_msg_nonref.take_inner()) },
382 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
383 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
384 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
385 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
386 ClosureReason::ProcessingError {ref err, } => {
387 let mut err_nonref = Clone::clone(err);
388 nativeClosureReason::ProcessingError {
389 err: err_nonref.into_string(),
392 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
393 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
397 pub(crate) fn into_native(self) -> nativeClosureReason {
399 ClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
400 nativeClosureReason::CounterpartyForceClosed {
401 peer_msg: *unsafe { Box::from_raw(peer_msg.take_inner()) },
404 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
405 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
406 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
407 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
408 ClosureReason::ProcessingError {mut err, } => {
409 nativeClosureReason::ProcessingError {
410 err: err.into_string(),
413 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
414 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
418 pub(crate) fn from_native(native: &nativeClosureReason) -> Self {
420 nativeClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
421 let mut peer_msg_nonref = Clone::clone(peer_msg);
422 ClosureReason::CounterpartyForceClosed {
423 peer_msg: crate::lightning::util::string::UntrustedString { inner: ObjOps::heap_alloc(peer_msg_nonref), is_owned: true },
426 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
427 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
428 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
429 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
430 nativeClosureReason::ProcessingError {ref err, } => {
431 let mut err_nonref = Clone::clone(err);
432 ClosureReason::ProcessingError {
433 err: err_nonref.into(),
436 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
437 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
441 pub(crate) fn native_into(native: nativeClosureReason) -> Self {
443 nativeClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
444 ClosureReason::CounterpartyForceClosed {
445 peer_msg: crate::lightning::util::string::UntrustedString { inner: ObjOps::heap_alloc(peer_msg), is_owned: true },
448 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
449 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
450 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
451 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
452 nativeClosureReason::ProcessingError {mut err, } => {
453 ClosureReason::ProcessingError {
457 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
458 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
462 /// Frees any resources used by the ClosureReason
464 pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { }
465 /// Creates a copy of the ClosureReason
467 pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason {
471 /// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
472 pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::lightning::util::string::UntrustedString) -> ClosureReason {
473 ClosureReason::CounterpartyForceClosed {
478 /// Utility method to constructs a new HolderForceClosed-variant ClosureReason
479 pub extern "C" fn ClosureReason_holder_force_closed() -> ClosureReason {
480 ClosureReason::HolderForceClosed}
482 /// Utility method to constructs a new CooperativeClosure-variant ClosureReason
483 pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason {
484 ClosureReason::CooperativeClosure}
486 /// Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
487 pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason {
488 ClosureReason::CommitmentTxConfirmed}
490 /// Utility method to constructs a new FundingTimedOut-variant ClosureReason
491 pub extern "C" fn ClosureReason_funding_timed_out() -> ClosureReason {
492 ClosureReason::FundingTimedOut}
494 /// Utility method to constructs a new ProcessingError-variant ClosureReason
495 pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason {
496 ClosureReason::ProcessingError {
501 /// Utility method to constructs a new DisconnectedPeer-variant ClosureReason
502 pub extern "C" fn ClosureReason_disconnected_peer() -> ClosureReason {
503 ClosureReason::DisconnectedPeer}
505 /// Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
506 pub extern "C" fn ClosureReason_outdated_channel_manager() -> ClosureReason {
507 ClosureReason::OutdatedChannelManager}
508 /// Checks if two ClosureReasons contain equal inner contents.
509 /// This ignores pointers and is_owned flags and looks at the values in fields.
511 pub extern "C" fn ClosureReason_eq(a: &ClosureReason, b: &ClosureReason) -> bool {
512 if &a.to_native() == &b.to_native() { true } else { false }
515 /// Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
516 pub extern "C" fn ClosureReason_write(obj: &crate::lightning::events::ClosureReason) -> crate::c_types::derived::CVec_u8Z {
517 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
520 /// Read a ClosureReason from a byte array, created by ClosureReason_write
521 pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_ClosureReasonZDecodeErrorZ {
522 let res: Result<Option<lightning::events::ClosureReason>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
523 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::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() };
526 /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
530 pub enum HTLCDestination {
531 /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
532 /// there is insufficient capacity in our outbound channel.
534 /// The `node_id` of the next node. For backwards compatibility, this field is
535 /// marked as optional, versions prior to 0.0.110 may not always be able to provide
536 /// counterparty node information.
538 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
539 node_id: crate::c_types::PublicKey,
540 /// The outgoing `channel_id` between us and the next node.
541 channel_id: crate::c_types::ThirtyTwoBytes,
543 /// Scenario where we are unsure of the next node to forward the HTLC to.
545 /// Short channel id we are requesting to forward an HTLC to.
546 requested_forward_scid: u64,
548 /// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
551 /// Short channel id we are requesting to forward an HTLC to.
552 requested_forward_scid: u64,
554 /// Failure scenario where an HTLC may have been forwarded to be intended for us,
555 /// but is invalid for some reason, so we reject it.
557 /// Some of the reasons may include:
559 /// * Excess HTLCs for a payment that we have already fully received, over-paying for the
561 /// * The counterparty node modified the HTLC in transit,
562 /// * A probing attack where an intermediary node is trying to detect if we are the ultimate
563 /// recipient for a payment.
565 /// The payment hash of the payment we attempted to process.
566 payment_hash: crate::c_types::ThirtyTwoBytes,
569 use lightning::events::HTLCDestination as HTLCDestinationImport;
570 pub(crate) type nativeHTLCDestination = HTLCDestinationImport;
572 impl HTLCDestination {
574 pub(crate) fn to_native(&self) -> nativeHTLCDestination {
576 HTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
577 let mut node_id_nonref = Clone::clone(node_id);
578 let mut local_node_id_nonref = if node_id_nonref.is_null() { None } else { Some( { node_id_nonref.into_rust() }) };
579 let mut channel_id_nonref = Clone::clone(channel_id);
580 nativeHTLCDestination::NextHopChannel {
581 node_id: local_node_id_nonref,
582 channel_id: channel_id_nonref.data,
585 HTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
586 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
587 nativeHTLCDestination::UnknownNextHop {
588 requested_forward_scid: requested_forward_scid_nonref,
591 HTLCDestination::InvalidForward {ref requested_forward_scid, } => {
592 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
593 nativeHTLCDestination::InvalidForward {
594 requested_forward_scid: requested_forward_scid_nonref,
597 HTLCDestination::FailedPayment {ref payment_hash, } => {
598 let mut payment_hash_nonref = Clone::clone(payment_hash);
599 nativeHTLCDestination::FailedPayment {
600 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
606 pub(crate) fn into_native(self) -> nativeHTLCDestination {
608 HTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
609 let mut local_node_id = if node_id.is_null() { None } else { Some( { node_id.into_rust() }) };
610 nativeHTLCDestination::NextHopChannel {
611 node_id: local_node_id,
612 channel_id: channel_id.data,
615 HTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
616 nativeHTLCDestination::UnknownNextHop {
617 requested_forward_scid: requested_forward_scid,
620 HTLCDestination::InvalidForward {mut requested_forward_scid, } => {
621 nativeHTLCDestination::InvalidForward {
622 requested_forward_scid: requested_forward_scid,
625 HTLCDestination::FailedPayment {mut payment_hash, } => {
626 nativeHTLCDestination::FailedPayment {
627 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
633 pub(crate) fn from_native(native: &nativeHTLCDestination) -> Self {
635 nativeHTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
636 let mut node_id_nonref = Clone::clone(node_id);
637 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())) } };
638 let mut channel_id_nonref = Clone::clone(channel_id);
639 HTLCDestination::NextHopChannel {
640 node_id: local_node_id_nonref,
641 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
644 nativeHTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
645 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
646 HTLCDestination::UnknownNextHop {
647 requested_forward_scid: requested_forward_scid_nonref,
650 nativeHTLCDestination::InvalidForward {ref requested_forward_scid, } => {
651 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
652 HTLCDestination::InvalidForward {
653 requested_forward_scid: requested_forward_scid_nonref,
656 nativeHTLCDestination::FailedPayment {ref payment_hash, } => {
657 let mut payment_hash_nonref = Clone::clone(payment_hash);
658 HTLCDestination::FailedPayment {
659 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
665 pub(crate) fn native_into(native: nativeHTLCDestination) -> Self {
667 nativeHTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
668 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())) } };
669 HTLCDestination::NextHopChannel {
670 node_id: local_node_id,
671 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
674 nativeHTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
675 HTLCDestination::UnknownNextHop {
676 requested_forward_scid: requested_forward_scid,
679 nativeHTLCDestination::InvalidForward {mut requested_forward_scid, } => {
680 HTLCDestination::InvalidForward {
681 requested_forward_scid: requested_forward_scid,
684 nativeHTLCDestination::FailedPayment {mut payment_hash, } => {
685 HTLCDestination::FailedPayment {
686 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
692 /// Frees any resources used by the HTLCDestination
694 pub extern "C" fn HTLCDestination_free(this_ptr: HTLCDestination) { }
695 /// Creates a copy of the HTLCDestination
697 pub extern "C" fn HTLCDestination_clone(orig: &HTLCDestination) -> HTLCDestination {
701 /// Utility method to constructs a new NextHopChannel-variant HTLCDestination
702 pub extern "C" fn HTLCDestination_next_hop_channel(node_id: crate::c_types::PublicKey, channel_id: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
703 HTLCDestination::NextHopChannel {
709 /// Utility method to constructs a new UnknownNextHop-variant HTLCDestination
710 pub extern "C" fn HTLCDestination_unknown_next_hop(requested_forward_scid: u64) -> HTLCDestination {
711 HTLCDestination::UnknownNextHop {
712 requested_forward_scid,
716 /// Utility method to constructs a new InvalidForward-variant HTLCDestination
717 pub extern "C" fn HTLCDestination_invalid_forward(requested_forward_scid: u64) -> HTLCDestination {
718 HTLCDestination::InvalidForward {
719 requested_forward_scid,
723 /// Utility method to constructs a new FailedPayment-variant HTLCDestination
724 pub extern "C" fn HTLCDestination_failed_payment(payment_hash: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
725 HTLCDestination::FailedPayment {
729 /// Checks if two HTLCDestinations contain equal inner contents.
730 /// This ignores pointers and is_owned flags and looks at the values in fields.
732 pub extern "C" fn HTLCDestination_eq(a: &HTLCDestination, b: &HTLCDestination) -> bool {
733 if &a.to_native() == &b.to_native() { true } else { false }
736 /// Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
737 pub extern "C" fn HTLCDestination_write(obj: &crate::lightning::events::HTLCDestination) -> crate::c_types::derived::CVec_u8Z {
738 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
741 /// Read a HTLCDestination from a byte array, created by HTLCDestination_write
742 pub extern "C" fn HTLCDestination_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_HTLCDestinationZDecodeErrorZ {
743 let res: Result<Option<lightning::events::HTLCDestination>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
744 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::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() };
747 /// The reason the payment failed. Used in [`Event::PaymentFailed`].
751 pub enum PaymentFailureReason {
752 /// The intended recipient rejected our payment.
754 /// The user chose to abandon this payment by calling [`ChannelManager::abandon_payment`].
756 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
758 /// We exhausted all of our retry attempts while trying to send the payment, or we
759 /// exhausted the [`Retry::Timeout`] if the user set one. If at any point a retry
760 /// attempt failed while being forwarded along the path, an [`Event::PaymentPathFailed`] will
761 /// have come before this.
763 /// [`Retry::Timeout`]: crate::ln::channelmanager::Retry::Timeout
765 /// The payment expired while retrying, based on the provided
766 /// [`PaymentParameters::expiry_time`].
768 /// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
770 /// We failed to find a route while retrying the payment.
772 /// This error should generally never happen. This likely means that there is a problem with
776 use lightning::events::PaymentFailureReason as PaymentFailureReasonImport;
777 pub(crate) type nativePaymentFailureReason = PaymentFailureReasonImport;
779 impl PaymentFailureReason {
781 pub(crate) fn to_native(&self) -> nativePaymentFailureReason {
783 PaymentFailureReason::RecipientRejected => nativePaymentFailureReason::RecipientRejected,
784 PaymentFailureReason::UserAbandoned => nativePaymentFailureReason::UserAbandoned,
785 PaymentFailureReason::RetriesExhausted => nativePaymentFailureReason::RetriesExhausted,
786 PaymentFailureReason::PaymentExpired => nativePaymentFailureReason::PaymentExpired,
787 PaymentFailureReason::RouteNotFound => nativePaymentFailureReason::RouteNotFound,
788 PaymentFailureReason::UnexpectedError => nativePaymentFailureReason::UnexpectedError,
792 pub(crate) fn into_native(self) -> nativePaymentFailureReason {
794 PaymentFailureReason::RecipientRejected => nativePaymentFailureReason::RecipientRejected,
795 PaymentFailureReason::UserAbandoned => nativePaymentFailureReason::UserAbandoned,
796 PaymentFailureReason::RetriesExhausted => nativePaymentFailureReason::RetriesExhausted,
797 PaymentFailureReason::PaymentExpired => nativePaymentFailureReason::PaymentExpired,
798 PaymentFailureReason::RouteNotFound => nativePaymentFailureReason::RouteNotFound,
799 PaymentFailureReason::UnexpectedError => nativePaymentFailureReason::UnexpectedError,
803 pub(crate) fn from_native(native: &nativePaymentFailureReason) -> Self {
805 nativePaymentFailureReason::RecipientRejected => PaymentFailureReason::RecipientRejected,
806 nativePaymentFailureReason::UserAbandoned => PaymentFailureReason::UserAbandoned,
807 nativePaymentFailureReason::RetriesExhausted => PaymentFailureReason::RetriesExhausted,
808 nativePaymentFailureReason::PaymentExpired => PaymentFailureReason::PaymentExpired,
809 nativePaymentFailureReason::RouteNotFound => PaymentFailureReason::RouteNotFound,
810 nativePaymentFailureReason::UnexpectedError => PaymentFailureReason::UnexpectedError,
814 pub(crate) fn native_into(native: nativePaymentFailureReason) -> Self {
816 nativePaymentFailureReason::RecipientRejected => PaymentFailureReason::RecipientRejected,
817 nativePaymentFailureReason::UserAbandoned => PaymentFailureReason::UserAbandoned,
818 nativePaymentFailureReason::RetriesExhausted => PaymentFailureReason::RetriesExhausted,
819 nativePaymentFailureReason::PaymentExpired => PaymentFailureReason::PaymentExpired,
820 nativePaymentFailureReason::RouteNotFound => PaymentFailureReason::RouteNotFound,
821 nativePaymentFailureReason::UnexpectedError => PaymentFailureReason::UnexpectedError,
825 /// Creates a copy of the PaymentFailureReason
827 pub extern "C" fn PaymentFailureReason_clone(orig: &PaymentFailureReason) -> PaymentFailureReason {
831 /// Utility method to constructs a new RecipientRejected-variant PaymentFailureReason
832 pub extern "C" fn PaymentFailureReason_recipient_rejected() -> PaymentFailureReason {
833 PaymentFailureReason::RecipientRejected}
835 /// Utility method to constructs a new UserAbandoned-variant PaymentFailureReason
836 pub extern "C" fn PaymentFailureReason_user_abandoned() -> PaymentFailureReason {
837 PaymentFailureReason::UserAbandoned}
839 /// Utility method to constructs a new RetriesExhausted-variant PaymentFailureReason
840 pub extern "C" fn PaymentFailureReason_retries_exhausted() -> PaymentFailureReason {
841 PaymentFailureReason::RetriesExhausted}
843 /// Utility method to constructs a new PaymentExpired-variant PaymentFailureReason
844 pub extern "C" fn PaymentFailureReason_payment_expired() -> PaymentFailureReason {
845 PaymentFailureReason::PaymentExpired}
847 /// Utility method to constructs a new RouteNotFound-variant PaymentFailureReason
848 pub extern "C" fn PaymentFailureReason_route_not_found() -> PaymentFailureReason {
849 PaymentFailureReason::RouteNotFound}
851 /// Utility method to constructs a new UnexpectedError-variant PaymentFailureReason
852 pub extern "C" fn PaymentFailureReason_unexpected_error() -> PaymentFailureReason {
853 PaymentFailureReason::UnexpectedError}
854 /// Checks if two PaymentFailureReasons contain equal inner contents.
855 /// This ignores pointers and is_owned flags and looks at the values in fields.
857 pub extern "C" fn PaymentFailureReason_eq(a: &PaymentFailureReason, b: &PaymentFailureReason) -> bool {
858 if &a.to_native() == &b.to_native() { true } else { false }
861 /// Serialize the PaymentFailureReason object into a byte array which can be read by PaymentFailureReason_read
862 pub extern "C" fn PaymentFailureReason_write(obj: &crate::lightning::events::PaymentFailureReason) -> crate::c_types::derived::CVec_u8Z {
863 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
866 /// Read a PaymentFailureReason from a byte array, created by PaymentFailureReason_write
867 pub extern "C" fn PaymentFailureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentFailureReasonDecodeErrorZ {
868 let res: Result<lightning::events::PaymentFailureReason, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
869 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::events::PaymentFailureReason::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
872 /// An Event which you should probably take some action in response to.
874 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
875 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
876 /// written as it makes no sense to respond to it after reconnecting to peers).
881 /// Used to indicate that the client should generate a funding transaction with the given
882 /// parameters and then call [`ChannelManager::funding_transaction_generated`].
883 /// Generated in [`ChannelManager`] message handling.
884 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
885 /// counterparty can steal your funds!
887 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
888 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
889 FundingGenerationReady {
890 /// The random channel_id we picked which you'll need to pass into
891 /// [`ChannelManager::funding_transaction_generated`].
893 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
894 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
895 /// The counterparty's node_id, which you'll need to pass back into
896 /// [`ChannelManager::funding_transaction_generated`].
898 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
899 counterparty_node_id: crate::c_types::PublicKey,
900 /// The value, in satoshis, that the output should have.
901 channel_value_satoshis: u64,
902 /// The script which should be used in the transaction output.
903 output_script: crate::c_types::derived::CVec_u8Z,
904 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or a
905 /// random value for an inbound channel. This may be zero for objects serialized with LDK
906 /// versions prior to 0.0.113.
908 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
909 user_channel_id: crate::c_types::U128,
911 /// Indicates that we've been offered a payment and it needs to be claimed via calling
912 /// [`ChannelManager::claim_funds`] with the preimage given in [`PaymentPurpose`].
914 /// Note that if the preimage is not known, you should call
915 /// [`ChannelManager::fail_htlc_backwards`] or [`ChannelManager::fail_htlc_backwards_with_reason`]
916 /// to free up resources for this HTLC and avoid network congestion.
917 /// If you fail to call either [`ChannelManager::claim_funds`], [`ChannelManager::fail_htlc_backwards`],
918 /// or [`ChannelManager::fail_htlc_backwards_with_reason`] within the HTLC's timeout, the HTLC will be
919 /// automatically failed.
922 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
923 /// `PaymentClaimable` events may be generated for the same payment. In such a case it is
924 /// polite (and required in the lightning specification) to fail the payment the second time
925 /// and give the sender their money back rather than accepting double payment.
928 /// This event used to be called `PaymentReceived` in LDK versions 0.0.112 and earlier.
930 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
931 /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
932 /// [`ChannelManager::fail_htlc_backwards_with_reason`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards_with_reason
934 /// The node that will receive the payment after it has been claimed.
935 /// This is useful to identify payments received via [phantom nodes].
936 /// This field will always be filled in when the event was generated by LDK versions
937 /// 0.0.113 and above.
939 /// [phantom nodes]: crate::chain::keysinterface::PhantomKeysManager
941 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
942 receiver_node_id: crate::c_types::PublicKey,
943 /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
944 /// not stop you from registering duplicate payment hashes for inbound payments.
945 payment_hash: crate::c_types::ThirtyTwoBytes,
946 /// The fields in the onion which were received with each HTLC. Only fields which were
947 /// identical in each HTLC involved in the payment will be included here.
949 /// Payments received on LDK versions prior to 0.0.115 will have this field unset.
951 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
952 onion_fields: crate::lightning::ln::outbound_payment::RecipientOnionFields,
953 /// The value, in thousandths of a satoshi, that this payment is for.
955 /// Information for claiming this received payment, based on whether the purpose of the
956 /// payment is to pay an invoice or to send a spontaneous payment.
957 purpose: crate::lightning::events::PaymentPurpose,
958 /// The `channel_id` indicating over which channel we received the payment.
960 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
961 via_channel_id: crate::c_types::ThirtyTwoBytes,
962 /// The `user_channel_id` indicating over which channel we received the payment.
963 via_user_channel_id: crate::c_types::derived::COption_u128Z,
964 /// The block height at which this payment will be failed back and will no longer be
965 /// eligible for claiming.
967 /// Prior to this height, a call to [`ChannelManager::claim_funds`] is guaranteed to
968 /// succeed, however you should wait for [`Event::PaymentClaimed`] to be sure.
970 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
971 claim_deadline: crate::c_types::derived::COption_u32Z,
973 /// Indicates a payment has been claimed and we've received money!
975 /// This most likely occurs when [`ChannelManager::claim_funds`] has been called in response
976 /// to an [`Event::PaymentClaimable`]. However, if we previously crashed during a
977 /// [`ChannelManager::claim_funds`] call you may see this event without a corresponding
978 /// [`Event::PaymentClaimable`] event.
981 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
982 /// `PaymentClaimable` events may be generated for the same payment. If you then call
983 /// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentClaimable`] you may get
984 /// multiple `PaymentClaimed` events.
986 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
988 /// The node that received the payment.
989 /// This is useful to identify payments which were received via [phantom nodes].
990 /// This field will always be filled in when the event was generated by LDK versions
991 /// 0.0.113 and above.
993 /// [phantom nodes]: crate::chain::keysinterface::PhantomKeysManager
995 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
996 receiver_node_id: crate::c_types::PublicKey,
997 /// The payment hash of the claimed payment. Note that LDK will not stop you from
998 /// registering duplicate payment hashes for inbound payments.
999 payment_hash: crate::c_types::ThirtyTwoBytes,
1000 /// The value, in thousandths of a satoshi, that this payment is for.
1002 /// The purpose of the claimed payment, i.e. whether the payment was for an invoice or a
1003 /// spontaneous payment.
1004 purpose: crate::lightning::events::PaymentPurpose,
1006 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
1007 /// and we got back the payment preimage for it).
1009 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
1010 /// event. In this situation, you SHOULD treat this payment as having succeeded.
1012 /// The `payment_id` passed to [`ChannelManager::send_payment`].
1014 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1016 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1017 payment_id: crate::c_types::ThirtyTwoBytes,
1018 /// The preimage to the hash given to ChannelManager::send_payment.
1019 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
1020 /// store it somehow!
1021 payment_preimage: crate::c_types::ThirtyTwoBytes,
1022 /// The hash that was given to [`ChannelManager::send_payment`].
1024 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1025 payment_hash: crate::c_types::ThirtyTwoBytes,
1026 /// The total fee which was spent at intermediate hops in this payment, across all paths.
1028 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
1029 /// overpayment to the recipient node.
1031 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
1032 /// overstate the amount paid, though this is unlikely.
1034 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
1035 fee_paid_msat: crate::c_types::derived::COption_u64Z,
1037 /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
1038 /// provide failure information for each path attempt in the payment, including retries.
1040 /// This event is provided once there are no further pending HTLCs for the payment and the
1041 /// payment is no longer retryable, due either to the [`Retry`] provided or
1042 /// [`ChannelManager::abandon_payment`] having been called for the corresponding payment.
1044 /// [`Retry`]: crate::ln::channelmanager::Retry
1045 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
1047 /// The `payment_id` passed to [`ChannelManager::send_payment`].
1049 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1050 payment_id: crate::c_types::ThirtyTwoBytes,
1051 /// The hash that was given to [`ChannelManager::send_payment`].
1053 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1054 payment_hash: crate::c_types::ThirtyTwoBytes,
1055 /// The reason the payment failed. This is only `None` for events generated or serialized
1056 /// by versions prior to 0.0.115.
1057 reason: crate::c_types::derived::COption_PaymentFailureReasonZ,
1059 /// Indicates that a path for an outbound payment was successful.
1061 /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
1062 /// [`Event::PaymentSent`] for obtaining the payment preimage.
1063 PaymentPathSuccessful {
1064 /// The `payment_id` passed to [`ChannelManager::send_payment`].
1066 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1067 payment_id: crate::c_types::ThirtyTwoBytes,
1068 /// The hash that was given to [`ChannelManager::send_payment`].
1070 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1072 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1073 payment_hash: crate::c_types::ThirtyTwoBytes,
1074 /// The payment path that was successful.
1076 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
1077 path: crate::lightning::routing::router::Path,
1079 /// Indicates an outbound HTLC we sent failed, likely due to an intermediary node being unable to
1080 /// handle the HTLC.
1082 /// Note that this does *not* indicate that all paths for an MPP payment have failed, see
1083 /// [`Event::PaymentFailed`].
1085 /// See [`ChannelManager::abandon_payment`] for giving up on this payment before its retries have
1088 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
1090 /// The `payment_id` passed to [`ChannelManager::send_payment`].
1092 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1093 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
1095 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1096 payment_id: crate::c_types::ThirtyTwoBytes,
1097 /// The hash that was given to [`ChannelManager::send_payment`].
1099 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
1100 payment_hash: crate::c_types::ThirtyTwoBytes,
1101 /// Indicates the payment was rejected for some reason by the recipient. This implies that
1102 /// the payment has failed, not just the route in question. If this is not set, the payment may
1103 /// be retried via a different route.
1104 payment_failed_permanently: bool,
1105 /// Extra error details based on the failure type. May contain an update that needs to be
1106 /// applied to the [`NetworkGraph`].
1108 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
1109 failure: crate::lightning::events::PathFailure,
1110 /// The payment path that failed.
1111 path: crate::lightning::routing::router::Path,
1112 /// The channel responsible for the failed payment path.
1114 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
1115 /// may not refer to a channel in the public network graph. These aliases may also collide
1116 /// with channels in the public network graph.
1118 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
1119 /// retried. May be `None` for older [`Event`] serializations.
1120 short_channel_id: crate::c_types::derived::COption_u64Z,
1122 /// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
1124 /// The id returned by [`ChannelManager::send_probe`].
1126 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
1127 payment_id: crate::c_types::ThirtyTwoBytes,
1128 /// The hash generated by [`ChannelManager::send_probe`].
1130 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
1131 payment_hash: crate::c_types::ThirtyTwoBytes,
1132 /// The payment path that was successful.
1133 path: crate::lightning::routing::router::Path,
1135 /// Indicates that a probe payment we sent failed at an intermediary node on the path.
1137 /// The id returned by [`ChannelManager::send_probe`].
1139 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
1140 payment_id: crate::c_types::ThirtyTwoBytes,
1141 /// The hash generated by [`ChannelManager::send_probe`].
1143 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
1144 payment_hash: crate::c_types::ThirtyTwoBytes,
1145 /// The payment path that failed.
1146 path: crate::lightning::routing::router::Path,
1147 /// The channel responsible for the failed probe.
1149 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
1150 /// may not refer to a channel in the public network graph. These aliases may also collide
1151 /// with channels in the public network graph.
1152 short_channel_id: crate::c_types::derived::COption_u64Z,
1154 /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
1155 /// a time in the future.
1157 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1158 PendingHTLCsForwardable {
1159 /// The minimum amount of time that should be waited prior to calling
1160 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
1161 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
1162 /// now + 5*time_forwardable).
1163 time_forwardable: u64,
1165 /// Used to indicate that we've intercepted an HTLC forward. This event will only be generated if
1166 /// you've encoded an intercept scid in the receiver's invoice route hints using
1167 /// [`ChannelManager::get_intercept_scid`] and have set [`UserConfig::accept_intercept_htlcs`].
1169 /// [`ChannelManager::forward_intercepted_htlc`] or
1170 /// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to this event. See
1171 /// their docs for more information.
1173 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1174 /// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
1175 /// [`ChannelManager::forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
1176 /// [`ChannelManager::fail_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::fail_intercepted_htlc
1178 /// An id to help LDK identify which HTLC is being forwarded or failed.
1179 intercept_id: crate::c_types::ThirtyTwoBytes,
1180 /// The fake scid that was programmed as the next hop's scid, generated using
1181 /// [`ChannelManager::get_intercept_scid`].
1183 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1184 requested_next_hop_scid: u64,
1185 /// The payment hash used for this HTLC.
1186 payment_hash: crate::c_types::ThirtyTwoBytes,
1187 /// How many msats were received on the inbound edge of this HTLC.
1188 inbound_amount_msat: u64,
1189 /// How many msats the payer intended to route to the next node. Depending on the reason you are
1190 /// intercepting this payment, you might take a fee by forwarding less than this amount.
1192 /// Note that LDK will NOT check that expected fees were factored into this value. You MUST
1193 /// check that whatever fee you want has been included here or subtract it as required. Further,
1194 /// LDK will not stop you from forwarding more than you received.
1195 expected_outbound_amount_msat: u64,
1197 /// Used to indicate that an output which you should know how to spend was confirmed on chain
1198 /// and is now spendable.
1199 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
1200 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
1201 /// somewhere and spend them when you create on-chain transactions.
1203 /// The outputs which you should store as spendable by you.
1204 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
1206 /// This event is generated when a payment has been successfully forwarded through us and a
1207 /// forwarding fee earned.
1209 /// The incoming channel between the previous node and us. This is only `None` for events
1210 /// generated or serialized by versions prior to 0.0.107.
1212 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1213 prev_channel_id: crate::c_types::ThirtyTwoBytes,
1214 /// The outgoing channel between the next node and us. This is only `None` for events
1215 /// generated or serialized by versions prior to 0.0.107.
1217 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1218 next_channel_id: crate::c_types::ThirtyTwoBytes,
1219 /// The fee, in milli-satoshis, which was earned as a result of the payment.
1221 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
1222 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
1223 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
1224 /// claimed the full value in millisatoshis from the source. In this case,
1225 /// `claim_from_onchain_tx` will be set.
1227 /// If the channel which sent us the payment has been force-closed, we will claim the funds
1228 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
1229 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
1230 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
1232 fee_earned_msat: crate::c_types::derived::COption_u64Z,
1233 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
1235 claim_from_onchain_tx: bool,
1236 /// The final amount forwarded, in milli-satoshis, after the fee is deducted.
1238 /// The caveat described above the `fee_earned_msat` field applies here as well.
1239 outbound_amount_forwarded_msat: crate::c_types::derived::COption_u64Z,
1241 /// Used to indicate that a channel with the given `channel_id` is being opened and pending
1242 /// confirmation on-chain.
1244 /// This event is emitted when the funding transaction has been signed and is broadcast to the
1245 /// network. For 0conf channels it will be immediately followed by the corresponding
1246 /// [`Event::ChannelReady`] event.
1248 /// The `channel_id` of the channel that is pending confirmation.
1249 channel_id: crate::c_types::ThirtyTwoBytes,
1250 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1251 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1252 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1253 /// `user_channel_id` will be randomized for an inbound channel.
1255 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1256 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1257 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1258 user_channel_id: crate::c_types::U128,
1259 /// The `temporary_channel_id` this channel used to be known by during channel establishment.
1261 /// Will be `None` for channels created prior to LDK version 0.0.115.
1263 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1264 former_temporary_channel_id: crate::c_types::ThirtyTwoBytes,
1265 /// The `node_id` of the channel counterparty.
1266 counterparty_node_id: crate::c_types::PublicKey,
1267 /// The outpoint of the channel's funding transaction.
1268 funding_txo: crate::lightning::chain::transaction::OutPoint,
1270 /// Used to indicate that a channel with the given `channel_id` is ready to
1271 /// be used. This event is emitted either when the funding transaction has been confirmed
1272 /// on-chain, or, in case of a 0conf channel, when both parties have confirmed the channel
1275 /// The `channel_id` of the channel that is ready.
1276 channel_id: crate::c_types::ThirtyTwoBytes,
1277 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1278 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1279 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1280 /// `user_channel_id` will be randomized for an inbound channel.
1282 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1283 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1284 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1285 user_channel_id: crate::c_types::U128,
1286 /// The `node_id` of the channel counterparty.
1287 counterparty_node_id: crate::c_types::PublicKey,
1288 /// The features that this channel will operate with.
1289 channel_type: crate::lightning::ln::features::ChannelTypeFeatures,
1291 /// Used to indicate that a previously opened channel with the given `channel_id` is in the
1292 /// process of closure.
1294 /// The `channel_id` of the channel which has been closed. Note that on-chain transactions
1295 /// resolving the channel are likely still awaiting confirmation.
1296 channel_id: crate::c_types::ThirtyTwoBytes,
1297 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1298 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1299 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1300 /// `user_channel_id` will be randomized for inbound channels.
1301 /// This may be zero for inbound channels serialized prior to 0.0.113 and will always be
1302 /// zero for objects serialized with LDK versions prior to 0.0.102.
1304 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1305 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1306 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1307 user_channel_id: crate::c_types::U128,
1308 /// The reason the channel was closed.
1309 reason: crate::lightning::events::ClosureReason,
1311 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
1312 /// inputs for another purpose.
1314 /// The channel_id of the channel which has been closed.
1315 channel_id: crate::c_types::ThirtyTwoBytes,
1316 /// The full transaction received from the user
1317 transaction: crate::c_types::Transaction,
1319 /// Indicates a request to open a new channel by a peer.
1321 /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the
1322 /// request, call [`ChannelManager::force_close_without_broadcasting_txn`].
1324 /// The event is only triggered when a new open channel request is received and the
1325 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
1327 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1328 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
1329 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1330 OpenChannelRequest {
1331 /// The temporary channel ID of the channel requested to be opened.
1333 /// When responding to the request, the `temporary_channel_id` should be passed
1334 /// back to the ChannelManager through [`ChannelManager::accept_inbound_channel`] to accept,
1335 /// or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject.
1337 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1338 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
1339 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
1340 /// The node_id of the counterparty requesting to open the channel.
1342 /// When responding to the request, the `counterparty_node_id` should be passed
1343 /// back to the `ChannelManager` through [`ChannelManager::accept_inbound_channel`] to
1344 /// accept the request, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject the
1347 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1348 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
1349 counterparty_node_id: crate::c_types::PublicKey,
1350 /// The channel value of the requested channel.
1351 funding_satoshis: u64,
1352 /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
1354 /// The features that this channel will operate with. If you reject the channel, a
1355 /// well-behaved counterparty may automatically re-attempt the channel with a new set of
1358 /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
1359 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
1362 /// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
1363 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
1364 /// 0.0.107. Channels setting this type also need to get manually accepted via
1365 /// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
1366 /// or will be rejected otherwise.
1368 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1369 channel_type: crate::lightning::ln::features::ChannelTypeFeatures,
1371 /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
1374 /// Some scenarios where this event may be sent include:
1375 /// * Insufficient capacity in the outbound channel
1376 /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
1377 /// * When an unknown SCID is requested for forwarding a payment.
1378 /// * Expected MPP amount has already been reached
1379 /// * The HTLC has timed out
1381 /// This event, however, does not get generated if an HTLC fails to meet the forwarding
1382 /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
1383 HTLCHandlingFailed {
1384 /// The channel over which the HTLC was received.
1385 prev_channel_id: crate::c_types::ThirtyTwoBytes,
1386 /// Destination of the HTLC that failed to be processed.
1387 failed_next_destination: crate::lightning::events::HTLCDestination,
1390 use lightning::events::Event as EventImport;
1391 pub(crate) type nativeEvent = EventImport;
1395 pub(crate) fn to_native(&self) -> nativeEvent {
1397 Event::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
1398 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1399 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1400 let mut channel_value_satoshis_nonref = Clone::clone(channel_value_satoshis);
1401 let mut output_script_nonref = Clone::clone(output_script);
1402 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1403 nativeEvent::FundingGenerationReady {
1404 temporary_channel_id: temporary_channel_id_nonref.data,
1405 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1406 channel_value_satoshis: channel_value_satoshis_nonref,
1407 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
1408 user_channel_id: user_channel_id_nonref.into(),
1411 Event::PaymentClaimable {ref receiver_node_id, ref payment_hash, ref onion_fields, ref amount_msat, ref purpose, ref via_channel_id, ref via_user_channel_id, ref claim_deadline, } => {
1412 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1413 let mut local_receiver_node_id_nonref = if receiver_node_id_nonref.is_null() { None } else { Some( { receiver_node_id_nonref.into_rust() }) };
1414 let mut payment_hash_nonref = Clone::clone(payment_hash);
1415 let mut onion_fields_nonref = Clone::clone(onion_fields);
1416 let mut local_onion_fields_nonref = if onion_fields_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(onion_fields_nonref.take_inner()) } }) };
1417 let mut amount_msat_nonref = Clone::clone(amount_msat);
1418 let mut purpose_nonref = Clone::clone(purpose);
1419 let mut via_channel_id_nonref = Clone::clone(via_channel_id);
1420 let mut local_via_channel_id_nonref = if via_channel_id_nonref.data == [0; 32] { None } else { Some( { via_channel_id_nonref.data }) };
1421 let mut via_user_channel_id_nonref = Clone::clone(via_user_channel_id);
1422 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() }})} };
1423 let mut claim_deadline_nonref = Clone::clone(claim_deadline);
1424 let mut local_claim_deadline_nonref = if claim_deadline_nonref.is_some() { Some( { claim_deadline_nonref.take() }) } else { None };
1425 nativeEvent::PaymentClaimable {
1426 receiver_node_id: local_receiver_node_id_nonref,
1427 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1428 onion_fields: local_onion_fields_nonref,
1429 amount_msat: amount_msat_nonref,
1430 purpose: purpose_nonref.into_native(),
1431 via_channel_id: local_via_channel_id_nonref,
1432 via_user_channel_id: local_via_user_channel_id_nonref,
1433 claim_deadline: local_claim_deadline_nonref,
1436 Event::PaymentClaimed {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, } => {
1437 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1438 let mut local_receiver_node_id_nonref = if receiver_node_id_nonref.is_null() { None } else { Some( { receiver_node_id_nonref.into_rust() }) };
1439 let mut payment_hash_nonref = Clone::clone(payment_hash);
1440 let mut amount_msat_nonref = Clone::clone(amount_msat);
1441 let mut purpose_nonref = Clone::clone(purpose);
1442 nativeEvent::PaymentClaimed {
1443 receiver_node_id: local_receiver_node_id_nonref,
1444 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1445 amount_msat: amount_msat_nonref,
1446 purpose: purpose_nonref.into_native(),
1449 Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1450 let mut payment_id_nonref = Clone::clone(payment_id);
1451 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1452 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
1453 let mut payment_hash_nonref = Clone::clone(payment_hash);
1454 let mut fee_paid_msat_nonref = Clone::clone(fee_paid_msat);
1455 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
1456 nativeEvent::PaymentSent {
1457 payment_id: local_payment_id_nonref,
1458 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
1459 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1460 fee_paid_msat: local_fee_paid_msat_nonref,
1463 Event::PaymentFailed {ref payment_id, ref payment_hash, ref reason, } => {
1464 let mut payment_id_nonref = Clone::clone(payment_id);
1465 let mut payment_hash_nonref = Clone::clone(payment_hash);
1466 let mut reason_nonref = Clone::clone(reason);
1467 let mut local_reason_nonref = { /*reason_nonref*/ let reason_nonref_opt = reason_nonref; if reason_nonref_opt.is_none() { None } else { Some({ { { reason_nonref_opt.take() }.into_native() }})} };
1468 nativeEvent::PaymentFailed {
1469 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1470 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1471 reason: local_reason_nonref,
1474 Event::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1475 let mut payment_id_nonref = Clone::clone(payment_id);
1476 let mut payment_hash_nonref = Clone::clone(payment_hash);
1477 let mut local_payment_hash_nonref = if payment_hash_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash_nonref.data) }) };
1478 let mut path_nonref = Clone::clone(path);
1479 nativeEvent::PaymentPathSuccessful {
1480 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1481 payment_hash: local_payment_hash_nonref,
1482 path: *unsafe { Box::from_raw(path_nonref.take_inner()) },
1485 Event::PaymentPathFailed {ref payment_id, ref payment_hash, ref payment_failed_permanently, ref failure, ref path, ref short_channel_id, } => {
1486 let mut payment_id_nonref = Clone::clone(payment_id);
1487 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1488 let mut payment_hash_nonref = Clone::clone(payment_hash);
1489 let mut payment_failed_permanently_nonref = Clone::clone(payment_failed_permanently);
1490 let mut failure_nonref = Clone::clone(failure);
1491 let mut path_nonref = Clone::clone(path);
1492 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1493 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1494 nativeEvent::PaymentPathFailed {
1495 payment_id: local_payment_id_nonref,
1496 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1497 payment_failed_permanently: payment_failed_permanently_nonref,
1498 failure: failure_nonref.into_native(),
1499 path: *unsafe { Box::from_raw(path_nonref.take_inner()) },
1500 short_channel_id: local_short_channel_id_nonref,
1503 Event::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1504 let mut payment_id_nonref = Clone::clone(payment_id);
1505 let mut payment_hash_nonref = Clone::clone(payment_hash);
1506 let mut path_nonref = Clone::clone(path);
1507 nativeEvent::ProbeSuccessful {
1508 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1509 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1510 path: *unsafe { Box::from_raw(path_nonref.take_inner()) },
1513 Event::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1514 let mut payment_id_nonref = Clone::clone(payment_id);
1515 let mut payment_hash_nonref = Clone::clone(payment_hash);
1516 let mut path_nonref = Clone::clone(path);
1517 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1518 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1519 nativeEvent::ProbeFailed {
1520 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1521 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1522 path: *unsafe { Box::from_raw(path_nonref.take_inner()) },
1523 short_channel_id: local_short_channel_id_nonref,
1526 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
1527 let mut time_forwardable_nonref = Clone::clone(time_forwardable);
1528 nativeEvent::PendingHTLCsForwardable {
1529 time_forwardable: core::time::Duration::from_secs(time_forwardable_nonref),
1532 Event::HTLCIntercepted {ref intercept_id, ref requested_next_hop_scid, ref payment_hash, ref inbound_amount_msat, ref expected_outbound_amount_msat, } => {
1533 let mut intercept_id_nonref = Clone::clone(intercept_id);
1534 let mut requested_next_hop_scid_nonref = Clone::clone(requested_next_hop_scid);
1535 let mut payment_hash_nonref = Clone::clone(payment_hash);
1536 let mut inbound_amount_msat_nonref = Clone::clone(inbound_amount_msat);
1537 let mut expected_outbound_amount_msat_nonref = Clone::clone(expected_outbound_amount_msat);
1538 nativeEvent::HTLCIntercepted {
1539 intercept_id: ::lightning::ln::channelmanager::InterceptId(intercept_id_nonref.data),
1540 requested_next_hop_scid: requested_next_hop_scid_nonref,
1541 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1542 inbound_amount_msat: inbound_amount_msat_nonref,
1543 expected_outbound_amount_msat: expected_outbound_amount_msat_nonref,
1546 Event::SpendableOutputs {ref outputs, } => {
1547 let mut outputs_nonref = Clone::clone(outputs);
1548 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
1549 nativeEvent::SpendableOutputs {
1550 outputs: local_outputs_nonref,
1553 Event::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, ref outbound_amount_forwarded_msat, } => {
1554 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1555 let mut local_prev_channel_id_nonref = if prev_channel_id_nonref.data == [0; 32] { None } else { Some( { prev_channel_id_nonref.data }) };
1556 let mut next_channel_id_nonref = Clone::clone(next_channel_id);
1557 let mut local_next_channel_id_nonref = if next_channel_id_nonref.data == [0; 32] { None } else { Some( { next_channel_id_nonref.data }) };
1558 let mut fee_earned_msat_nonref = Clone::clone(fee_earned_msat);
1559 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
1560 let mut claim_from_onchain_tx_nonref = Clone::clone(claim_from_onchain_tx);
1561 let mut outbound_amount_forwarded_msat_nonref = Clone::clone(outbound_amount_forwarded_msat);
1562 let mut local_outbound_amount_forwarded_msat_nonref = if outbound_amount_forwarded_msat_nonref.is_some() { Some( { outbound_amount_forwarded_msat_nonref.take() }) } else { None };
1563 nativeEvent::PaymentForwarded {
1564 prev_channel_id: local_prev_channel_id_nonref,
1565 next_channel_id: local_next_channel_id_nonref,
1566 fee_earned_msat: local_fee_earned_msat_nonref,
1567 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1568 outbound_amount_forwarded_msat: local_outbound_amount_forwarded_msat_nonref,
1571 Event::ChannelPending {ref channel_id, ref user_channel_id, ref former_temporary_channel_id, ref counterparty_node_id, ref funding_txo, } => {
1572 let mut channel_id_nonref = Clone::clone(channel_id);
1573 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1574 let mut former_temporary_channel_id_nonref = Clone::clone(former_temporary_channel_id);
1575 let mut local_former_temporary_channel_id_nonref = if former_temporary_channel_id_nonref.data == [0; 32] { None } else { Some( { former_temporary_channel_id_nonref.data }) };
1576 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1577 let mut funding_txo_nonref = Clone::clone(funding_txo);
1578 nativeEvent::ChannelPending {
1579 channel_id: channel_id_nonref.data,
1580 user_channel_id: user_channel_id_nonref.into(),
1581 former_temporary_channel_id: local_former_temporary_channel_id_nonref,
1582 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1583 funding_txo: crate::c_types::C_to_bitcoin_outpoint(funding_txo_nonref),
1586 Event::ChannelReady {ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type, } => {
1587 let mut channel_id_nonref = Clone::clone(channel_id);
1588 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1589 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1590 let mut channel_type_nonref = Clone::clone(channel_type);
1591 nativeEvent::ChannelReady {
1592 channel_id: channel_id_nonref.data,
1593 user_channel_id: user_channel_id_nonref.into(),
1594 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1595 channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) },
1598 Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
1599 let mut channel_id_nonref = Clone::clone(channel_id);
1600 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1601 let mut reason_nonref = Clone::clone(reason);
1602 nativeEvent::ChannelClosed {
1603 channel_id: channel_id_nonref.data,
1604 user_channel_id: user_channel_id_nonref.into(),
1605 reason: reason_nonref.into_native(),
1608 Event::DiscardFunding {ref channel_id, ref transaction, } => {
1609 let mut channel_id_nonref = Clone::clone(channel_id);
1610 let mut transaction_nonref = Clone::clone(transaction);
1611 nativeEvent::DiscardFunding {
1612 channel_id: channel_id_nonref.data,
1613 transaction: transaction_nonref.into_bitcoin(),
1616 Event::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1617 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1618 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1619 let mut funding_satoshis_nonref = Clone::clone(funding_satoshis);
1620 let mut push_msat_nonref = Clone::clone(push_msat);
1621 let mut channel_type_nonref = Clone::clone(channel_type);
1622 nativeEvent::OpenChannelRequest {
1623 temporary_channel_id: temporary_channel_id_nonref.data,
1624 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1625 funding_satoshis: funding_satoshis_nonref,
1626 push_msat: push_msat_nonref,
1627 channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) },
1630 Event::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
1631 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1632 let mut failed_next_destination_nonref = Clone::clone(failed_next_destination);
1633 nativeEvent::HTLCHandlingFailed {
1634 prev_channel_id: prev_channel_id_nonref.data,
1635 failed_next_destination: failed_next_destination_nonref.into_native(),
1641 pub(crate) fn into_native(self) -> nativeEvent {
1643 Event::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1644 nativeEvent::FundingGenerationReady {
1645 temporary_channel_id: temporary_channel_id.data,
1646 counterparty_node_id: counterparty_node_id.into_rust(),
1647 channel_value_satoshis: channel_value_satoshis,
1648 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
1649 user_channel_id: user_channel_id.into(),
1652 Event::PaymentClaimable {mut receiver_node_id, mut payment_hash, mut onion_fields, mut amount_msat, mut purpose, mut via_channel_id, mut via_user_channel_id, mut claim_deadline, } => {
1653 let mut local_receiver_node_id = if receiver_node_id.is_null() { None } else { Some( { receiver_node_id.into_rust() }) };
1654 let mut local_onion_fields = if onion_fields.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(onion_fields.take_inner()) } }) };
1655 let mut local_via_channel_id = if via_channel_id.data == [0; 32] { None } else { Some( { via_channel_id.data }) };
1656 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() }})} };
1657 let mut local_claim_deadline = if claim_deadline.is_some() { Some( { claim_deadline.take() }) } else { None };
1658 nativeEvent::PaymentClaimable {
1659 receiver_node_id: local_receiver_node_id,
1660 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1661 onion_fields: local_onion_fields,
1662 amount_msat: amount_msat,
1663 purpose: purpose.into_native(),
1664 via_channel_id: local_via_channel_id,
1665 via_user_channel_id: local_via_user_channel_id,
1666 claim_deadline: local_claim_deadline,
1669 Event::PaymentClaimed {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, } => {
1670 let mut local_receiver_node_id = if receiver_node_id.is_null() { None } else { Some( { receiver_node_id.into_rust() }) };
1671 nativeEvent::PaymentClaimed {
1672 receiver_node_id: local_receiver_node_id,
1673 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1674 amount_msat: amount_msat,
1675 purpose: purpose.into_native(),
1678 Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1679 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1680 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
1681 nativeEvent::PaymentSent {
1682 payment_id: local_payment_id,
1683 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
1684 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1685 fee_paid_msat: local_fee_paid_msat,
1688 Event::PaymentFailed {mut payment_id, mut payment_hash, mut reason, } => {
1689 let mut local_reason = { /*reason*/ let reason_opt = reason; if reason_opt.is_none() { None } else { Some({ { { reason_opt.take() }.into_native() }})} };
1690 nativeEvent::PaymentFailed {
1691 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1692 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1693 reason: local_reason,
1696 Event::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1697 let mut local_payment_hash = if payment_hash.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash.data) }) };
1698 nativeEvent::PaymentPathSuccessful {
1699 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1700 payment_hash: local_payment_hash,
1701 path: *unsafe { Box::from_raw(path.take_inner()) },
1704 Event::PaymentPathFailed {mut payment_id, mut payment_hash, mut payment_failed_permanently, mut failure, mut path, mut short_channel_id, } => {
1705 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1706 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1707 nativeEvent::PaymentPathFailed {
1708 payment_id: local_payment_id,
1709 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1710 payment_failed_permanently: payment_failed_permanently,
1711 failure: failure.into_native(),
1712 path: *unsafe { Box::from_raw(path.take_inner()) },
1713 short_channel_id: local_short_channel_id,
1716 Event::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1717 nativeEvent::ProbeSuccessful {
1718 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1719 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1720 path: *unsafe { Box::from_raw(path.take_inner()) },
1723 Event::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
1724 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1725 nativeEvent::ProbeFailed {
1726 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1727 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1728 path: *unsafe { Box::from_raw(path.take_inner()) },
1729 short_channel_id: local_short_channel_id,
1732 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
1733 nativeEvent::PendingHTLCsForwardable {
1734 time_forwardable: core::time::Duration::from_secs(time_forwardable),
1737 Event::HTLCIntercepted {mut intercept_id, mut requested_next_hop_scid, mut payment_hash, mut inbound_amount_msat, mut expected_outbound_amount_msat, } => {
1738 nativeEvent::HTLCIntercepted {
1739 intercept_id: ::lightning::ln::channelmanager::InterceptId(intercept_id.data),
1740 requested_next_hop_scid: requested_next_hop_scid,
1741 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1742 inbound_amount_msat: inbound_amount_msat,
1743 expected_outbound_amount_msat: expected_outbound_amount_msat,
1746 Event::SpendableOutputs {mut outputs, } => {
1747 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
1748 nativeEvent::SpendableOutputs {
1749 outputs: local_outputs,
1752 Event::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, mut outbound_amount_forwarded_msat, } => {
1753 let mut local_prev_channel_id = if prev_channel_id.data == [0; 32] { None } else { Some( { prev_channel_id.data }) };
1754 let mut local_next_channel_id = if next_channel_id.data == [0; 32] { None } else { Some( { next_channel_id.data }) };
1755 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
1756 let mut local_outbound_amount_forwarded_msat = if outbound_amount_forwarded_msat.is_some() { Some( { outbound_amount_forwarded_msat.take() }) } else { None };
1757 nativeEvent::PaymentForwarded {
1758 prev_channel_id: local_prev_channel_id,
1759 next_channel_id: local_next_channel_id,
1760 fee_earned_msat: local_fee_earned_msat,
1761 claim_from_onchain_tx: claim_from_onchain_tx,
1762 outbound_amount_forwarded_msat: local_outbound_amount_forwarded_msat,
1765 Event::ChannelPending {mut channel_id, mut user_channel_id, mut former_temporary_channel_id, mut counterparty_node_id, mut funding_txo, } => {
1766 let mut local_former_temporary_channel_id = if former_temporary_channel_id.data == [0; 32] { None } else { Some( { former_temporary_channel_id.data }) };
1767 nativeEvent::ChannelPending {
1768 channel_id: channel_id.data,
1769 user_channel_id: user_channel_id.into(),
1770 former_temporary_channel_id: local_former_temporary_channel_id,
1771 counterparty_node_id: counterparty_node_id.into_rust(),
1772 funding_txo: crate::c_types::C_to_bitcoin_outpoint(funding_txo),
1775 Event::ChannelReady {mut channel_id, mut user_channel_id, mut counterparty_node_id, mut channel_type, } => {
1776 nativeEvent::ChannelReady {
1777 channel_id: channel_id.data,
1778 user_channel_id: user_channel_id.into(),
1779 counterparty_node_id: counterparty_node_id.into_rust(),
1780 channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) },
1783 Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1784 nativeEvent::ChannelClosed {
1785 channel_id: channel_id.data,
1786 user_channel_id: user_channel_id.into(),
1787 reason: reason.into_native(),
1790 Event::DiscardFunding {mut channel_id, mut transaction, } => {
1791 nativeEvent::DiscardFunding {
1792 channel_id: channel_id.data,
1793 transaction: transaction.into_bitcoin(),
1796 Event::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1797 nativeEvent::OpenChannelRequest {
1798 temporary_channel_id: temporary_channel_id.data,
1799 counterparty_node_id: counterparty_node_id.into_rust(),
1800 funding_satoshis: funding_satoshis,
1801 push_msat: push_msat,
1802 channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) },
1805 Event::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
1806 nativeEvent::HTLCHandlingFailed {
1807 prev_channel_id: prev_channel_id.data,
1808 failed_next_destination: failed_next_destination.into_native(),
1814 pub(crate) fn from_native(native: &nativeEvent) -> Self {
1816 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
1817 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1818 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1819 let mut channel_value_satoshis_nonref = Clone::clone(channel_value_satoshis);
1820 let mut output_script_nonref = Clone::clone(output_script);
1821 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1822 Event::FundingGenerationReady {
1823 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1824 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1825 channel_value_satoshis: channel_value_satoshis_nonref,
1826 output_script: output_script_nonref.into_bytes().into(),
1827 user_channel_id: user_channel_id_nonref.into(),
1830 nativeEvent::PaymentClaimable {ref receiver_node_id, ref payment_hash, ref onion_fields, ref amount_msat, ref purpose, ref via_channel_id, ref via_user_channel_id, ref claim_deadline, } => {
1831 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1832 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())) } };
1833 let mut payment_hash_nonref = Clone::clone(payment_hash);
1834 let mut onion_fields_nonref = Clone::clone(onion_fields);
1835 let mut local_onion_fields_nonref = crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: if onion_fields_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((onion_fields_nonref.unwrap())) } }, is_owned: true };
1836 let mut amount_msat_nonref = Clone::clone(amount_msat);
1837 let mut purpose_nonref = Clone::clone(purpose);
1838 let mut via_channel_id_nonref = Clone::clone(via_channel_id);
1839 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()) } } };
1840 let mut via_user_channel_id_nonref = Clone::clone(via_user_channel_id);
1841 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() }) };
1842 let mut claim_deadline_nonref = Clone::clone(claim_deadline);
1843 let mut local_claim_deadline_nonref = if claim_deadline_nonref.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { claim_deadline_nonref.unwrap() }) };
1844 Event::PaymentClaimable {
1845 receiver_node_id: local_receiver_node_id_nonref,
1846 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1847 onion_fields: local_onion_fields_nonref,
1848 amount_msat: amount_msat_nonref,
1849 purpose: crate::lightning::events::PaymentPurpose::native_into(purpose_nonref),
1850 via_channel_id: local_via_channel_id_nonref,
1851 via_user_channel_id: local_via_user_channel_id_nonref,
1852 claim_deadline: local_claim_deadline_nonref,
1855 nativeEvent::PaymentClaimed {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, } => {
1856 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1857 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())) } };
1858 let mut payment_hash_nonref = Clone::clone(payment_hash);
1859 let mut amount_msat_nonref = Clone::clone(amount_msat);
1860 let mut purpose_nonref = Clone::clone(purpose);
1861 Event::PaymentClaimed {
1862 receiver_node_id: local_receiver_node_id_nonref,
1863 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1864 amount_msat: amount_msat_nonref,
1865 purpose: crate::lightning::events::PaymentPurpose::native_into(purpose_nonref),
1868 nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1869 let mut payment_id_nonref = Clone::clone(payment_id);
1870 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 } } };
1871 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
1872 let mut payment_hash_nonref = Clone::clone(payment_hash);
1873 let mut fee_paid_msat_nonref = Clone::clone(fee_paid_msat);
1874 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() }) };
1875 Event::PaymentSent {
1876 payment_id: local_payment_id_nonref,
1877 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
1878 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1879 fee_paid_msat: local_fee_paid_msat_nonref,
1882 nativeEvent::PaymentFailed {ref payment_id, ref payment_hash, ref reason, } => {
1883 let mut payment_id_nonref = Clone::clone(payment_id);
1884 let mut payment_hash_nonref = Clone::clone(payment_hash);
1885 let mut reason_nonref = Clone::clone(reason);
1886 let mut local_reason_nonref = if reason_nonref.is_none() { crate::c_types::derived::COption_PaymentFailureReasonZ::None } else { crate::c_types::derived::COption_PaymentFailureReasonZ::Some( { crate::lightning::events::PaymentFailureReason::native_into(reason_nonref.unwrap()) }) };
1887 Event::PaymentFailed {
1888 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1889 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1890 reason: local_reason_nonref,
1893 nativeEvent::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1894 let mut payment_id_nonref = Clone::clone(payment_id);
1895 let mut payment_hash_nonref = Clone::clone(payment_hash);
1896 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 } } };
1897 let mut path_nonref = Clone::clone(path);
1898 Event::PaymentPathSuccessful {
1899 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1900 payment_hash: local_payment_hash_nonref,
1901 path: crate::lightning::routing::router::Path { inner: ObjOps::heap_alloc(path_nonref), is_owned: true },
1904 nativeEvent::PaymentPathFailed {ref payment_id, ref payment_hash, ref payment_failed_permanently, ref failure, ref path, ref short_channel_id, } => {
1905 let mut payment_id_nonref = Clone::clone(payment_id);
1906 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 } } };
1907 let mut payment_hash_nonref = Clone::clone(payment_hash);
1908 let mut payment_failed_permanently_nonref = Clone::clone(payment_failed_permanently);
1909 let mut failure_nonref = Clone::clone(failure);
1910 let mut path_nonref = Clone::clone(path);
1911 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1912 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() }) };
1913 Event::PaymentPathFailed {
1914 payment_id: local_payment_id_nonref,
1915 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1916 payment_failed_permanently: payment_failed_permanently_nonref,
1917 failure: crate::lightning::events::PathFailure::native_into(failure_nonref),
1918 path: crate::lightning::routing::router::Path { inner: ObjOps::heap_alloc(path_nonref), is_owned: true },
1919 short_channel_id: local_short_channel_id_nonref,
1922 nativeEvent::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1923 let mut payment_id_nonref = Clone::clone(payment_id);
1924 let mut payment_hash_nonref = Clone::clone(payment_hash);
1925 let mut path_nonref = Clone::clone(path);
1926 Event::ProbeSuccessful {
1927 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1928 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1929 path: crate::lightning::routing::router::Path { inner: ObjOps::heap_alloc(path_nonref), is_owned: true },
1932 nativeEvent::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1933 let mut payment_id_nonref = Clone::clone(payment_id);
1934 let mut payment_hash_nonref = Clone::clone(payment_hash);
1935 let mut path_nonref = Clone::clone(path);
1936 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1937 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() }) };
1938 Event::ProbeFailed {
1939 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1940 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1941 path: crate::lightning::routing::router::Path { inner: ObjOps::heap_alloc(path_nonref), is_owned: true },
1942 short_channel_id: local_short_channel_id_nonref,
1945 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
1946 let mut time_forwardable_nonref = Clone::clone(time_forwardable);
1947 Event::PendingHTLCsForwardable {
1948 time_forwardable: time_forwardable_nonref.as_secs(),
1951 nativeEvent::HTLCIntercepted {ref intercept_id, ref requested_next_hop_scid, ref payment_hash, ref inbound_amount_msat, ref expected_outbound_amount_msat, } => {
1952 let mut intercept_id_nonref = Clone::clone(intercept_id);
1953 let mut requested_next_hop_scid_nonref = Clone::clone(requested_next_hop_scid);
1954 let mut payment_hash_nonref = Clone::clone(payment_hash);
1955 let mut inbound_amount_msat_nonref = Clone::clone(inbound_amount_msat);
1956 let mut expected_outbound_amount_msat_nonref = Clone::clone(expected_outbound_amount_msat);
1957 Event::HTLCIntercepted {
1958 intercept_id: crate::c_types::ThirtyTwoBytes { data: intercept_id_nonref.0 },
1959 requested_next_hop_scid: requested_next_hop_scid_nonref,
1960 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1961 inbound_amount_msat: inbound_amount_msat_nonref,
1962 expected_outbound_amount_msat: expected_outbound_amount_msat_nonref,
1965 nativeEvent::SpendableOutputs {ref outputs, } => {
1966 let mut outputs_nonref = Clone::clone(outputs);
1967 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) }); };
1968 Event::SpendableOutputs {
1969 outputs: local_outputs_nonref.into(),
1972 nativeEvent::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, ref outbound_amount_forwarded_msat, } => {
1973 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1974 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()) } } };
1975 let mut next_channel_id_nonref = Clone::clone(next_channel_id);
1976 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()) } } };
1977 let mut fee_earned_msat_nonref = Clone::clone(fee_earned_msat);
1978 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() }) };
1979 let mut claim_from_onchain_tx_nonref = Clone::clone(claim_from_onchain_tx);
1980 let mut outbound_amount_forwarded_msat_nonref = Clone::clone(outbound_amount_forwarded_msat);
1981 let mut local_outbound_amount_forwarded_msat_nonref = if outbound_amount_forwarded_msat_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { outbound_amount_forwarded_msat_nonref.unwrap() }) };
1982 Event::PaymentForwarded {
1983 prev_channel_id: local_prev_channel_id_nonref,
1984 next_channel_id: local_next_channel_id_nonref,
1985 fee_earned_msat: local_fee_earned_msat_nonref,
1986 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1987 outbound_amount_forwarded_msat: local_outbound_amount_forwarded_msat_nonref,
1990 nativeEvent::ChannelPending {ref channel_id, ref user_channel_id, ref former_temporary_channel_id, ref counterparty_node_id, ref funding_txo, } => {
1991 let mut channel_id_nonref = Clone::clone(channel_id);
1992 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1993 let mut former_temporary_channel_id_nonref = Clone::clone(former_temporary_channel_id);
1994 let mut local_former_temporary_channel_id_nonref = if former_temporary_channel_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (former_temporary_channel_id_nonref.unwrap()) } } };
1995 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1996 let mut funding_txo_nonref = Clone::clone(funding_txo);
1997 Event::ChannelPending {
1998 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1999 user_channel_id: user_channel_id_nonref.into(),
2000 former_temporary_channel_id: local_former_temporary_channel_id_nonref,
2001 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
2002 funding_txo: crate::c_types::bitcoin_to_C_outpoint(funding_txo_nonref),
2005 nativeEvent::ChannelReady {ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type, } => {
2006 let mut channel_id_nonref = Clone::clone(channel_id);
2007 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
2008 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
2009 let mut channel_type_nonref = Clone::clone(channel_type);
2010 Event::ChannelReady {
2011 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
2012 user_channel_id: user_channel_id_nonref.into(),
2013 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
2014 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true },
2017 nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
2018 let mut channel_id_nonref = Clone::clone(channel_id);
2019 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
2020 let mut reason_nonref = Clone::clone(reason);
2021 Event::ChannelClosed {
2022 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
2023 user_channel_id: user_channel_id_nonref.into(),
2024 reason: crate::lightning::events::ClosureReason::native_into(reason_nonref),
2027 nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
2028 let mut channel_id_nonref = Clone::clone(channel_id);
2029 let mut transaction_nonref = Clone::clone(transaction);
2030 Event::DiscardFunding {
2031 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
2032 transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
2035 nativeEvent::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
2036 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
2037 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
2038 let mut funding_satoshis_nonref = Clone::clone(funding_satoshis);
2039 let mut push_msat_nonref = Clone::clone(push_msat);
2040 let mut channel_type_nonref = Clone::clone(channel_type);
2041 Event::OpenChannelRequest {
2042 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
2043 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
2044 funding_satoshis: funding_satoshis_nonref,
2045 push_msat: push_msat_nonref,
2046 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true },
2049 nativeEvent::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
2050 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
2051 let mut failed_next_destination_nonref = Clone::clone(failed_next_destination);
2052 Event::HTLCHandlingFailed {
2053 prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id_nonref },
2054 failed_next_destination: crate::lightning::events::HTLCDestination::native_into(failed_next_destination_nonref),
2060 pub(crate) fn native_into(native: nativeEvent) -> Self {
2062 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
2063 Event::FundingGenerationReady {
2064 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
2065 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
2066 channel_value_satoshis: channel_value_satoshis,
2067 output_script: output_script.into_bytes().into(),
2068 user_channel_id: user_channel_id.into(),
2071 nativeEvent::PaymentClaimable {mut receiver_node_id, mut payment_hash, mut onion_fields, mut amount_msat, mut purpose, mut via_channel_id, mut via_user_channel_id, mut claim_deadline, } => {
2072 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())) } };
2073 let mut local_onion_fields = crate::lightning::ln::outbound_payment::RecipientOnionFields { inner: if onion_fields.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((onion_fields.unwrap())) } }, is_owned: true };
2074 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()) } } };
2075 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() }) };
2076 let mut local_claim_deadline = if claim_deadline.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { claim_deadline.unwrap() }) };
2077 Event::PaymentClaimable {
2078 receiver_node_id: local_receiver_node_id,
2079 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2080 onion_fields: local_onion_fields,
2081 amount_msat: amount_msat,
2082 purpose: crate::lightning::events::PaymentPurpose::native_into(purpose),
2083 via_channel_id: local_via_channel_id,
2084 via_user_channel_id: local_via_user_channel_id,
2085 claim_deadline: local_claim_deadline,
2088 nativeEvent::PaymentClaimed {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, } => {
2089 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())) } };
2090 Event::PaymentClaimed {
2091 receiver_node_id: local_receiver_node_id,
2092 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2093 amount_msat: amount_msat,
2094 purpose: crate::lightning::events::PaymentPurpose::native_into(purpose),
2097 nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
2098 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 } } };
2099 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() }) };
2100 Event::PaymentSent {
2101 payment_id: local_payment_id,
2102 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
2103 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2104 fee_paid_msat: local_fee_paid_msat,
2107 nativeEvent::PaymentFailed {mut payment_id, mut payment_hash, mut reason, } => {
2108 let mut local_reason = if reason.is_none() { crate::c_types::derived::COption_PaymentFailureReasonZ::None } else { crate::c_types::derived::COption_PaymentFailureReasonZ::Some( { crate::lightning::events::PaymentFailureReason::native_into(reason.unwrap()) }) };
2109 Event::PaymentFailed {
2110 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
2111 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2112 reason: local_reason,
2115 nativeEvent::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
2116 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 } } };
2117 Event::PaymentPathSuccessful {
2118 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
2119 payment_hash: local_payment_hash,
2120 path: crate::lightning::routing::router::Path { inner: ObjOps::heap_alloc(path), is_owned: true },
2123 nativeEvent::PaymentPathFailed {mut payment_id, mut payment_hash, mut payment_failed_permanently, mut failure, mut path, mut short_channel_id, } => {
2124 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 } } };
2125 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() }) };
2126 Event::PaymentPathFailed {
2127 payment_id: local_payment_id,
2128 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2129 payment_failed_permanently: payment_failed_permanently,
2130 failure: crate::lightning::events::PathFailure::native_into(failure),
2131 path: crate::lightning::routing::router::Path { inner: ObjOps::heap_alloc(path), is_owned: true },
2132 short_channel_id: local_short_channel_id,
2135 nativeEvent::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
2136 Event::ProbeSuccessful {
2137 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
2138 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2139 path: crate::lightning::routing::router::Path { inner: ObjOps::heap_alloc(path), is_owned: true },
2142 nativeEvent::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
2143 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() }) };
2144 Event::ProbeFailed {
2145 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
2146 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2147 path: crate::lightning::routing::router::Path { inner: ObjOps::heap_alloc(path), is_owned: true },
2148 short_channel_id: local_short_channel_id,
2151 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
2152 Event::PendingHTLCsForwardable {
2153 time_forwardable: time_forwardable.as_secs(),
2156 nativeEvent::HTLCIntercepted {mut intercept_id, mut requested_next_hop_scid, mut payment_hash, mut inbound_amount_msat, mut expected_outbound_amount_msat, } => {
2157 Event::HTLCIntercepted {
2158 intercept_id: crate::c_types::ThirtyTwoBytes { data: intercept_id.0 },
2159 requested_next_hop_scid: requested_next_hop_scid,
2160 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
2161 inbound_amount_msat: inbound_amount_msat,
2162 expected_outbound_amount_msat: expected_outbound_amount_msat,
2165 nativeEvent::SpendableOutputs {mut outputs, } => {
2166 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
2167 Event::SpendableOutputs {
2168 outputs: local_outputs.into(),
2171 nativeEvent::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, mut outbound_amount_forwarded_msat, } => {
2172 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()) } } };
2173 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()) } } };
2174 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() }) };
2175 let mut local_outbound_amount_forwarded_msat = if outbound_amount_forwarded_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { outbound_amount_forwarded_msat.unwrap() }) };
2176 Event::PaymentForwarded {
2177 prev_channel_id: local_prev_channel_id,
2178 next_channel_id: local_next_channel_id,
2179 fee_earned_msat: local_fee_earned_msat,
2180 claim_from_onchain_tx: claim_from_onchain_tx,
2181 outbound_amount_forwarded_msat: local_outbound_amount_forwarded_msat,
2184 nativeEvent::ChannelPending {mut channel_id, mut user_channel_id, mut former_temporary_channel_id, mut counterparty_node_id, mut funding_txo, } => {
2185 let mut local_former_temporary_channel_id = if former_temporary_channel_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (former_temporary_channel_id.unwrap()) } } };
2186 Event::ChannelPending {
2187 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
2188 user_channel_id: user_channel_id.into(),
2189 former_temporary_channel_id: local_former_temporary_channel_id,
2190 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
2191 funding_txo: crate::c_types::bitcoin_to_C_outpoint(funding_txo),
2194 nativeEvent::ChannelReady {mut channel_id, mut user_channel_id, mut counterparty_node_id, mut channel_type, } => {
2195 Event::ChannelReady {
2196 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
2197 user_channel_id: user_channel_id.into(),
2198 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
2199 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true },
2202 nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
2203 Event::ChannelClosed {
2204 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
2205 user_channel_id: user_channel_id.into(),
2206 reason: crate::lightning::events::ClosureReason::native_into(reason),
2209 nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
2210 Event::DiscardFunding {
2211 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
2212 transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
2215 nativeEvent::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
2216 Event::OpenChannelRequest {
2217 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
2218 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
2219 funding_satoshis: funding_satoshis,
2220 push_msat: push_msat,
2221 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true },
2224 nativeEvent::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
2225 Event::HTLCHandlingFailed {
2226 prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id },
2227 failed_next_destination: crate::lightning::events::HTLCDestination::native_into(failed_next_destination),
2233 /// Frees any resources used by the Event
2235 pub extern "C" fn Event_free(this_ptr: Event) { }
2236 /// Creates a copy of the Event
2238 pub extern "C" fn Event_clone(orig: &Event) -> Event {
2242 /// Utility method to constructs a new FundingGenerationReady-variant Event
2243 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 {
2244 Event::FundingGenerationReady {
2245 temporary_channel_id,
2246 counterparty_node_id,
2247 channel_value_satoshis,
2253 /// Utility method to constructs a new PaymentClaimable-variant Event
2254 pub extern "C" fn Event_payment_claimable(receiver_node_id: crate::c_types::PublicKey, payment_hash: crate::c_types::ThirtyTwoBytes, onion_fields: crate::lightning::ln::outbound_payment::RecipientOnionFields, amount_msat: u64, purpose: crate::lightning::events::PaymentPurpose, via_channel_id: crate::c_types::ThirtyTwoBytes, via_user_channel_id: crate::c_types::derived::COption_u128Z, claim_deadline: crate::c_types::derived::COption_u32Z) -> Event {
2255 Event::PaymentClaimable {
2262 via_user_channel_id,
2267 /// Utility method to constructs a new PaymentClaimed-variant Event
2268 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::events::PaymentPurpose) -> Event {
2269 Event::PaymentClaimed {
2277 /// Utility method to constructs a new PaymentSent-variant Event
2278 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 {
2279 Event::PaymentSent {
2287 /// Utility method to constructs a new PaymentFailed-variant Event
2288 pub extern "C" fn Event_payment_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, reason: crate::c_types::derived::COption_PaymentFailureReasonZ) -> Event {
2289 Event::PaymentFailed {
2296 /// Utility method to constructs a new PaymentPathSuccessful-variant Event
2297 pub extern "C" fn Event_payment_path_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::lightning::routing::router::Path) -> Event {
2298 Event::PaymentPathSuccessful {
2305 /// Utility method to constructs a new PaymentPathFailed-variant Event
2306 pub extern "C" fn Event_payment_path_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, payment_failed_permanently: bool, failure: crate::lightning::events::PathFailure, path: crate::lightning::routing::router::Path, short_channel_id: crate::c_types::derived::COption_u64Z) -> Event {
2307 Event::PaymentPathFailed {
2310 payment_failed_permanently,
2317 /// Utility method to constructs a new ProbeSuccessful-variant Event
2318 pub extern "C" fn Event_probe_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::lightning::routing::router::Path) -> Event {
2319 Event::ProbeSuccessful {
2326 /// Utility method to constructs a new ProbeFailed-variant Event
2327 pub extern "C" fn Event_probe_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::lightning::routing::router::Path, short_channel_id: crate::c_types::derived::COption_u64Z) -> Event {
2328 Event::ProbeFailed {
2336 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
2337 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
2338 Event::PendingHTLCsForwardable {
2343 /// Utility method to constructs a new HTLCIntercepted-variant Event
2344 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 {
2345 Event::HTLCIntercepted {
2347 requested_next_hop_scid,
2349 inbound_amount_msat,
2350 expected_outbound_amount_msat,
2354 /// Utility method to constructs a new SpendableOutputs-variant Event
2355 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
2356 Event::SpendableOutputs {
2361 /// Utility method to constructs a new PaymentForwarded-variant Event
2362 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, outbound_amount_forwarded_msat: crate::c_types::derived::COption_u64Z) -> Event {
2363 Event::PaymentForwarded {
2367 claim_from_onchain_tx,
2368 outbound_amount_forwarded_msat,
2372 /// Utility method to constructs a new ChannelPending-variant Event
2373 pub extern "C" fn Event_channel_pending(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: crate::c_types::U128, former_temporary_channel_id: crate::c_types::ThirtyTwoBytes, counterparty_node_id: crate::c_types::PublicKey, funding_txo: crate::lightning::chain::transaction::OutPoint) -> Event {
2374 Event::ChannelPending {
2377 former_temporary_channel_id,
2378 counterparty_node_id,
2383 /// Utility method to constructs a new ChannelReady-variant Event
2384 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 {
2385 Event::ChannelReady {
2388 counterparty_node_id,
2393 /// Utility method to constructs a new ChannelClosed-variant Event
2394 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: crate::c_types::U128, reason: crate::lightning::events::ClosureReason) -> Event {
2395 Event::ChannelClosed {
2402 /// Utility method to constructs a new DiscardFunding-variant Event
2403 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
2404 Event::DiscardFunding {
2410 /// Utility method to constructs a new OpenChannelRequest-variant Event
2411 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 {
2412 Event::OpenChannelRequest {
2413 temporary_channel_id,
2414 counterparty_node_id,
2421 /// Utility method to constructs a new HTLCHandlingFailed-variant Event
2422 pub extern "C" fn Event_htlchandling_failed(prev_channel_id: crate::c_types::ThirtyTwoBytes, failed_next_destination: crate::lightning::events::HTLCDestination) -> Event {
2423 Event::HTLCHandlingFailed {
2425 failed_next_destination,
2428 /// Checks if two Events contain equal inner contents.
2429 /// This ignores pointers and is_owned flags and looks at the values in fields.
2431 pub extern "C" fn Event_eq(a: &Event, b: &Event) -> bool {
2432 if &a.to_native() == &b.to_native() { true } else { false }
2435 /// Serialize the Event object into a byte array which can be read by Event_read
2436 pub extern "C" fn Event_write(obj: &crate::lightning::events::Event) -> crate::c_types::derived::CVec_u8Z {
2437 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
2440 /// Read a Event from a byte array, created by Event_write
2441 pub extern "C" fn Event_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_EventZDecodeErrorZ {
2442 let res: Result<Option<lightning::events::Event>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
2443 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::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() };
2446 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
2447 /// broadcast to most peers).
2448 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
2452 pub enum MessageSendEvent {
2453 /// Used to indicate that we've accepted a channel open and should send the accept_channel
2454 /// message provided to the given peer.
2456 /// The node_id of the node which should receive this message
2457 node_id: crate::c_types::PublicKey,
2458 /// The message which should be sent.
2459 msg: crate::lightning::ln::msgs::AcceptChannel,
2461 /// Used to indicate that we've initiated a channel open and should send the open_channel
2462 /// message provided to the given peer.
2464 /// The node_id of the node which should receive this message
2465 node_id: crate::c_types::PublicKey,
2466 /// The message which should be sent.
2467 msg: crate::lightning::ln::msgs::OpenChannel,
2469 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
2470 SendFundingCreated {
2471 /// The node_id of the node which should receive this message
2472 node_id: crate::c_types::PublicKey,
2473 /// The message which should be sent.
2474 msg: crate::lightning::ln::msgs::FundingCreated,
2476 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
2478 /// The node_id of the node which should receive this message
2479 node_id: crate::c_types::PublicKey,
2480 /// The message which should be sent.
2481 msg: crate::lightning::ln::msgs::FundingSigned,
2483 /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
2485 /// The node_id of the node which should receive these message(s)
2486 node_id: crate::c_types::PublicKey,
2487 /// The channel_ready message which should be sent.
2488 msg: crate::lightning::ln::msgs::ChannelReady,
2490 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
2491 SendAnnouncementSignatures {
2492 /// The node_id of the node which should receive these message(s)
2493 node_id: crate::c_types::PublicKey,
2494 /// The announcement_signatures message which should be sent.
2495 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
2497 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
2498 /// message should be sent to the peer with the given node_id.
2500 /// The node_id of the node which should receive these message(s)
2501 node_id: crate::c_types::PublicKey,
2502 /// The update messages which should be sent. ALL messages in the struct should be sent!
2503 updates: crate::lightning::ln::msgs::CommitmentUpdate,
2505 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
2507 /// The node_id of the node which should receive this message
2508 node_id: crate::c_types::PublicKey,
2509 /// The message which should be sent.
2510 msg: crate::lightning::ln::msgs::RevokeAndACK,
2512 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
2514 /// The node_id of the node which should receive this message
2515 node_id: crate::c_types::PublicKey,
2516 /// The message which should be sent.
2517 msg: crate::lightning::ln::msgs::ClosingSigned,
2519 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
2521 /// The node_id of the node which should receive this message
2522 node_id: crate::c_types::PublicKey,
2523 /// The message which should be sent.
2524 msg: crate::lightning::ln::msgs::Shutdown,
2526 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
2527 SendChannelReestablish {
2528 /// The node_id of the node which should receive this message
2529 node_id: crate::c_types::PublicKey,
2530 /// The message which should be sent.
2531 msg: crate::lightning::ln::msgs::ChannelReestablish,
2533 /// Used to send a channel_announcement and channel_update to a specific peer, likely on
2534 /// initial connection to ensure our peers know about our channels.
2535 SendChannelAnnouncement {
2536 /// The node_id of the node which should receive this message
2537 node_id: crate::c_types::PublicKey,
2538 /// The channel_announcement which should be sent.
2539 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
2540 /// The followup channel_update which should be sent.
2541 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
2543 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
2544 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
2546 /// Note that after doing so, you very likely (unless you did so very recently) want to
2547 /// broadcast a node_announcement (e.g. via [`PeerManager::broadcast_node_announcement`]). This
2548 /// ensures that any nodes which see our channel_announcement also have a relevant
2549 /// node_announcement, including relevant feature flags which may be important for routing
2550 /// through or to us.
2552 /// [`PeerManager::broadcast_node_announcement`]: crate::ln::peer_handler::PeerManager::broadcast_node_announcement
2553 BroadcastChannelAnnouncement {
2554 /// The channel_announcement which should be sent.
2555 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
2556 /// The followup channel_update which should be sent.
2558 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
2559 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
2561 /// Used to indicate that a channel_update should be broadcast to all peers.
2562 BroadcastChannelUpdate {
2563 /// The channel_update which should be sent.
2564 msg: crate::lightning::ln::msgs::ChannelUpdate,
2566 /// Used to indicate that a node_announcement should be broadcast to all peers.
2567 BroadcastNodeAnnouncement {
2568 /// The node_announcement which should be sent.
2569 msg: crate::lightning::ln::msgs::NodeAnnouncement,
2571 /// Used to indicate that a channel_update should be sent to a single peer.
2572 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
2573 /// private channel and we shouldn't be informing all of our peers of channel parameters.
2575 /// The node_id of the node which should receive this message
2576 node_id: crate::c_types::PublicKey,
2577 /// The channel_update which should be sent.
2578 msg: crate::lightning::ln::msgs::ChannelUpdate,
2580 /// Broadcast an error downstream to be handled
2582 /// The node_id of the node which should receive this message
2583 node_id: crate::c_types::PublicKey,
2584 /// The action which should be taken.
2585 action: crate::lightning::ln::msgs::ErrorAction,
2587 /// Query a peer for channels with funding transaction UTXOs in a block range.
2588 SendChannelRangeQuery {
2589 /// The node_id of this message recipient
2590 node_id: crate::c_types::PublicKey,
2591 /// The query_channel_range which should be sent.
2592 msg: crate::lightning::ln::msgs::QueryChannelRange,
2594 /// Request routing gossip messages from a peer for a list of channels identified by
2595 /// their short_channel_ids.
2597 /// The node_id of this message recipient
2598 node_id: crate::c_types::PublicKey,
2599 /// The query_short_channel_ids which should be sent.
2600 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
2602 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
2603 /// emitted during processing of the query.
2604 SendReplyChannelRange {
2605 /// The node_id of this message recipient
2606 node_id: crate::c_types::PublicKey,
2607 /// The reply_channel_range which should be sent.
2608 msg: crate::lightning::ln::msgs::ReplyChannelRange,
2610 /// Sends a timestamp filter for inbound gossip. This should be sent on each new connection to
2611 /// enable receiving gossip messages from the peer.
2612 SendGossipTimestampFilter {
2613 /// The node_id of this message recipient
2614 node_id: crate::c_types::PublicKey,
2615 /// The gossip_timestamp_filter which should be sent.
2616 msg: crate::lightning::ln::msgs::GossipTimestampFilter,
2619 use lightning::events::MessageSendEvent as MessageSendEventImport;
2620 pub(crate) type nativeMessageSendEvent = MessageSendEventImport;
2622 impl MessageSendEvent {
2624 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
2626 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
2627 let mut node_id_nonref = Clone::clone(node_id);
2628 let mut msg_nonref = Clone::clone(msg);
2629 nativeMessageSendEvent::SendAcceptChannel {
2630 node_id: node_id_nonref.into_rust(),
2631 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2634 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
2635 let mut node_id_nonref = Clone::clone(node_id);
2636 let mut msg_nonref = Clone::clone(msg);
2637 nativeMessageSendEvent::SendOpenChannel {
2638 node_id: node_id_nonref.into_rust(),
2639 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2642 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
2643 let mut node_id_nonref = Clone::clone(node_id);
2644 let mut msg_nonref = Clone::clone(msg);
2645 nativeMessageSendEvent::SendFundingCreated {
2646 node_id: node_id_nonref.into_rust(),
2647 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2650 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
2651 let mut node_id_nonref = Clone::clone(node_id);
2652 let mut msg_nonref = Clone::clone(msg);
2653 nativeMessageSendEvent::SendFundingSigned {
2654 node_id: node_id_nonref.into_rust(),
2655 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2658 MessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
2659 let mut node_id_nonref = Clone::clone(node_id);
2660 let mut msg_nonref = Clone::clone(msg);
2661 nativeMessageSendEvent::SendChannelReady {
2662 node_id: node_id_nonref.into_rust(),
2663 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2666 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
2667 let mut node_id_nonref = Clone::clone(node_id);
2668 let mut msg_nonref = Clone::clone(msg);
2669 nativeMessageSendEvent::SendAnnouncementSignatures {
2670 node_id: node_id_nonref.into_rust(),
2671 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2674 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2675 let mut node_id_nonref = Clone::clone(node_id);
2676 let mut updates_nonref = Clone::clone(updates);
2677 nativeMessageSendEvent::UpdateHTLCs {
2678 node_id: node_id_nonref.into_rust(),
2679 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
2682 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2683 let mut node_id_nonref = Clone::clone(node_id);
2684 let mut msg_nonref = Clone::clone(msg);
2685 nativeMessageSendEvent::SendRevokeAndACK {
2686 node_id: node_id_nonref.into_rust(),
2687 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2690 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2691 let mut node_id_nonref = Clone::clone(node_id);
2692 let mut msg_nonref = Clone::clone(msg);
2693 nativeMessageSendEvent::SendClosingSigned {
2694 node_id: node_id_nonref.into_rust(),
2695 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2698 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
2699 let mut node_id_nonref = Clone::clone(node_id);
2700 let mut msg_nonref = Clone::clone(msg);
2701 nativeMessageSendEvent::SendShutdown {
2702 node_id: node_id_nonref.into_rust(),
2703 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2706 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
2707 let mut node_id_nonref = Clone::clone(node_id);
2708 let mut msg_nonref = Clone::clone(msg);
2709 nativeMessageSendEvent::SendChannelReestablish {
2710 node_id: node_id_nonref.into_rust(),
2711 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2714 MessageSendEvent::SendChannelAnnouncement {ref node_id, ref msg, ref update_msg, } => {
2715 let mut node_id_nonref = Clone::clone(node_id);
2716 let mut msg_nonref = Clone::clone(msg);
2717 let mut update_msg_nonref = Clone::clone(update_msg);
2718 nativeMessageSendEvent::SendChannelAnnouncement {
2719 node_id: node_id_nonref.into_rust(),
2720 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2721 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
2724 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
2725 let mut msg_nonref = Clone::clone(msg);
2726 let mut update_msg_nonref = Clone::clone(update_msg);
2727 let mut local_update_msg_nonref = if update_msg_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(update_msg_nonref.take_inner()) } }) };
2728 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2729 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2730 update_msg: local_update_msg_nonref,
2733 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
2734 let mut msg_nonref = Clone::clone(msg);
2735 nativeMessageSendEvent::BroadcastChannelUpdate {
2736 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2739 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
2740 let mut msg_nonref = Clone::clone(msg);
2741 nativeMessageSendEvent::BroadcastNodeAnnouncement {
2742 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2745 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
2746 let mut node_id_nonref = Clone::clone(node_id);
2747 let mut msg_nonref = Clone::clone(msg);
2748 nativeMessageSendEvent::SendChannelUpdate {
2749 node_id: node_id_nonref.into_rust(),
2750 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2753 MessageSendEvent::HandleError {ref node_id, ref action, } => {
2754 let mut node_id_nonref = Clone::clone(node_id);
2755 let mut action_nonref = Clone::clone(action);
2756 nativeMessageSendEvent::HandleError {
2757 node_id: node_id_nonref.into_rust(),
2758 action: action_nonref.into_native(),
2761 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
2762 let mut node_id_nonref = Clone::clone(node_id);
2763 let mut msg_nonref = Clone::clone(msg);
2764 nativeMessageSendEvent::SendChannelRangeQuery {
2765 node_id: node_id_nonref.into_rust(),
2766 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2769 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
2770 let mut node_id_nonref = Clone::clone(node_id);
2771 let mut msg_nonref = Clone::clone(msg);
2772 nativeMessageSendEvent::SendShortIdsQuery {
2773 node_id: node_id_nonref.into_rust(),
2774 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2777 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
2778 let mut node_id_nonref = Clone::clone(node_id);
2779 let mut msg_nonref = Clone::clone(msg);
2780 nativeMessageSendEvent::SendReplyChannelRange {
2781 node_id: node_id_nonref.into_rust(),
2782 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2785 MessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
2786 let mut node_id_nonref = Clone::clone(node_id);
2787 let mut msg_nonref = Clone::clone(msg);
2788 nativeMessageSendEvent::SendGossipTimestampFilter {
2789 node_id: node_id_nonref.into_rust(),
2790 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2796 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
2798 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
2799 nativeMessageSendEvent::SendAcceptChannel {
2800 node_id: node_id.into_rust(),
2801 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2804 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
2805 nativeMessageSendEvent::SendOpenChannel {
2806 node_id: node_id.into_rust(),
2807 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2810 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
2811 nativeMessageSendEvent::SendFundingCreated {
2812 node_id: node_id.into_rust(),
2813 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2816 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
2817 nativeMessageSendEvent::SendFundingSigned {
2818 node_id: node_id.into_rust(),
2819 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2822 MessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
2823 nativeMessageSendEvent::SendChannelReady {
2824 node_id: node_id.into_rust(),
2825 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2828 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
2829 nativeMessageSendEvent::SendAnnouncementSignatures {
2830 node_id: node_id.into_rust(),
2831 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2834 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
2835 nativeMessageSendEvent::UpdateHTLCs {
2836 node_id: node_id.into_rust(),
2837 updates: *unsafe { Box::from_raw(updates.take_inner()) },
2840 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
2841 nativeMessageSendEvent::SendRevokeAndACK {
2842 node_id: node_id.into_rust(),
2843 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2846 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
2847 nativeMessageSendEvent::SendClosingSigned {
2848 node_id: node_id.into_rust(),
2849 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2852 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
2853 nativeMessageSendEvent::SendShutdown {
2854 node_id: node_id.into_rust(),
2855 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2858 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
2859 nativeMessageSendEvent::SendChannelReestablish {
2860 node_id: node_id.into_rust(),
2861 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2864 MessageSendEvent::SendChannelAnnouncement {mut node_id, mut msg, mut update_msg, } => {
2865 nativeMessageSendEvent::SendChannelAnnouncement {
2866 node_id: node_id.into_rust(),
2867 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2868 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
2871 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
2872 let mut local_update_msg = if update_msg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(update_msg.take_inner()) } }) };
2873 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2874 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2875 update_msg: local_update_msg,
2878 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
2879 nativeMessageSendEvent::BroadcastChannelUpdate {
2880 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2883 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
2884 nativeMessageSendEvent::BroadcastNodeAnnouncement {
2885 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2888 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
2889 nativeMessageSendEvent::SendChannelUpdate {
2890 node_id: node_id.into_rust(),
2891 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2894 MessageSendEvent::HandleError {mut node_id, mut action, } => {
2895 nativeMessageSendEvent::HandleError {
2896 node_id: node_id.into_rust(),
2897 action: action.into_native(),
2900 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
2901 nativeMessageSendEvent::SendChannelRangeQuery {
2902 node_id: node_id.into_rust(),
2903 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2906 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
2907 nativeMessageSendEvent::SendShortIdsQuery {
2908 node_id: node_id.into_rust(),
2909 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2912 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
2913 nativeMessageSendEvent::SendReplyChannelRange {
2914 node_id: node_id.into_rust(),
2915 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2918 MessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
2919 nativeMessageSendEvent::SendGossipTimestampFilter {
2920 node_id: node_id.into_rust(),
2921 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2927 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
2929 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
2930 let mut node_id_nonref = Clone::clone(node_id);
2931 let mut msg_nonref = Clone::clone(msg);
2932 MessageSendEvent::SendAcceptChannel {
2933 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2934 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2937 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
2938 let mut node_id_nonref = Clone::clone(node_id);
2939 let mut msg_nonref = Clone::clone(msg);
2940 MessageSendEvent::SendOpenChannel {
2941 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2942 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2945 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
2946 let mut node_id_nonref = Clone::clone(node_id);
2947 let mut msg_nonref = Clone::clone(msg);
2948 MessageSendEvent::SendFundingCreated {
2949 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2950 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2953 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
2954 let mut node_id_nonref = Clone::clone(node_id);
2955 let mut msg_nonref = Clone::clone(msg);
2956 MessageSendEvent::SendFundingSigned {
2957 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2958 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2961 nativeMessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
2962 let mut node_id_nonref = Clone::clone(node_id);
2963 let mut msg_nonref = Clone::clone(msg);
2964 MessageSendEvent::SendChannelReady {
2965 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2966 msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2969 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
2970 let mut node_id_nonref = Clone::clone(node_id);
2971 let mut msg_nonref = Clone::clone(msg);
2972 MessageSendEvent::SendAnnouncementSignatures {
2973 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2974 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2977 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2978 let mut node_id_nonref = Clone::clone(node_id);
2979 let mut updates_nonref = Clone::clone(updates);
2980 MessageSendEvent::UpdateHTLCs {
2981 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2982 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
2985 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2986 let mut node_id_nonref = Clone::clone(node_id);
2987 let mut msg_nonref = Clone::clone(msg);
2988 MessageSendEvent::SendRevokeAndACK {
2989 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2990 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2993 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2994 let mut node_id_nonref = Clone::clone(node_id);
2995 let mut msg_nonref = Clone::clone(msg);
2996 MessageSendEvent::SendClosingSigned {
2997 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2998 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3001 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
3002 let mut node_id_nonref = Clone::clone(node_id);
3003 let mut msg_nonref = Clone::clone(msg);
3004 MessageSendEvent::SendShutdown {
3005 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
3006 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3009 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
3010 let mut node_id_nonref = Clone::clone(node_id);
3011 let mut msg_nonref = Clone::clone(msg);
3012 MessageSendEvent::SendChannelReestablish {
3013 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
3014 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3017 nativeMessageSendEvent::SendChannelAnnouncement {ref node_id, ref msg, ref update_msg, } => {
3018 let mut node_id_nonref = Clone::clone(node_id);
3019 let mut msg_nonref = Clone::clone(msg);
3020 let mut update_msg_nonref = Clone::clone(update_msg);
3021 MessageSendEvent::SendChannelAnnouncement {
3022 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
3023 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3024 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
3027 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
3028 let mut msg_nonref = Clone::clone(msg);
3029 let mut update_msg_nonref = Clone::clone(update_msg);
3030 let mut local_update_msg_nonref = crate::lightning::ln::msgs::ChannelUpdate { inner: if update_msg_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((update_msg_nonref.unwrap())) } }, is_owned: true };
3031 MessageSendEvent::BroadcastChannelAnnouncement {
3032 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3033 update_msg: local_update_msg_nonref,
3036 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
3037 let mut msg_nonref = Clone::clone(msg);
3038 MessageSendEvent::BroadcastChannelUpdate {
3039 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3042 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
3043 let mut msg_nonref = Clone::clone(msg);
3044 MessageSendEvent::BroadcastNodeAnnouncement {
3045 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3048 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
3049 let mut node_id_nonref = Clone::clone(node_id);
3050 let mut msg_nonref = Clone::clone(msg);
3051 MessageSendEvent::SendChannelUpdate {
3052 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
3053 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3056 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
3057 let mut node_id_nonref = Clone::clone(node_id);
3058 let mut action_nonref = Clone::clone(action);
3059 MessageSendEvent::HandleError {
3060 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
3061 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
3064 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
3065 let mut node_id_nonref = Clone::clone(node_id);
3066 let mut msg_nonref = Clone::clone(msg);
3067 MessageSendEvent::SendChannelRangeQuery {
3068 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
3069 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3072 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
3073 let mut node_id_nonref = Clone::clone(node_id);
3074 let mut msg_nonref = Clone::clone(msg);
3075 MessageSendEvent::SendShortIdsQuery {
3076 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
3077 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3080 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
3081 let mut node_id_nonref = Clone::clone(node_id);
3082 let mut msg_nonref = Clone::clone(msg);
3083 MessageSendEvent::SendReplyChannelRange {
3084 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
3085 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3088 nativeMessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
3089 let mut node_id_nonref = Clone::clone(node_id);
3090 let mut msg_nonref = Clone::clone(msg);
3091 MessageSendEvent::SendGossipTimestampFilter {
3092 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
3093 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
3099 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
3101 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
3102 MessageSendEvent::SendAcceptChannel {
3103 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3104 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
3107 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
3108 MessageSendEvent::SendOpenChannel {
3109 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3110 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
3113 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
3114 MessageSendEvent::SendFundingCreated {
3115 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3116 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
3119 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
3120 MessageSendEvent::SendFundingSigned {
3121 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3122 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
3125 nativeMessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
3126 MessageSendEvent::SendChannelReady {
3127 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3128 msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg), is_owned: true },
3131 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
3132 MessageSendEvent::SendAnnouncementSignatures {
3133 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3134 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
3137 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
3138 MessageSendEvent::UpdateHTLCs {
3139 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3140 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
3143 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
3144 MessageSendEvent::SendRevokeAndACK {
3145 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3146 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
3149 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
3150 MessageSendEvent::SendClosingSigned {
3151 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3152 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
3155 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
3156 MessageSendEvent::SendShutdown {
3157 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3158 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
3161 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
3162 MessageSendEvent::SendChannelReestablish {
3163 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3164 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
3167 nativeMessageSendEvent::SendChannelAnnouncement {mut node_id, mut msg, mut update_msg, } => {
3168 MessageSendEvent::SendChannelAnnouncement {
3169 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3170 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
3171 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
3174 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
3175 let mut local_update_msg = crate::lightning::ln::msgs::ChannelUpdate { inner: if update_msg.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((update_msg.unwrap())) } }, is_owned: true };
3176 MessageSendEvent::BroadcastChannelAnnouncement {
3177 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
3178 update_msg: local_update_msg,
3181 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
3182 MessageSendEvent::BroadcastChannelUpdate {
3183 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
3186 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
3187 MessageSendEvent::BroadcastNodeAnnouncement {
3188 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
3191 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
3192 MessageSendEvent::SendChannelUpdate {
3193 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3194 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
3197 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
3198 MessageSendEvent::HandleError {
3199 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3200 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
3203 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
3204 MessageSendEvent::SendChannelRangeQuery {
3205 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3206 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
3209 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
3210 MessageSendEvent::SendShortIdsQuery {
3211 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3212 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
3215 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
3216 MessageSendEvent::SendReplyChannelRange {
3217 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3218 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
3221 nativeMessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
3222 MessageSendEvent::SendGossipTimestampFilter {
3223 node_id: crate::c_types::PublicKey::from_rust(&node_id),
3224 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg), is_owned: true },
3230 /// Frees any resources used by the MessageSendEvent
3232 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
3233 /// Creates a copy of the MessageSendEvent
3235 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
3239 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
3240 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
3241 MessageSendEvent::SendAcceptChannel {
3247 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
3248 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
3249 MessageSendEvent::SendOpenChannel {
3255 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
3256 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
3257 MessageSendEvent::SendFundingCreated {
3263 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
3264 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
3265 MessageSendEvent::SendFundingSigned {
3271 /// Utility method to constructs a new SendChannelReady-variant MessageSendEvent
3272 pub extern "C" fn MessageSendEvent_send_channel_ready(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReady) -> MessageSendEvent {
3273 MessageSendEvent::SendChannelReady {
3279 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
3280 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
3281 MessageSendEvent::SendAnnouncementSignatures {
3287 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
3288 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
3289 MessageSendEvent::UpdateHTLCs {
3295 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
3296 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
3297 MessageSendEvent::SendRevokeAndACK {
3303 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
3304 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
3305 MessageSendEvent::SendClosingSigned {
3311 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
3312 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
3313 MessageSendEvent::SendShutdown {
3319 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
3320 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
3321 MessageSendEvent::SendChannelReestablish {
3327 /// Utility method to constructs a new SendChannelAnnouncement-variant MessageSendEvent
3328 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 {
3329 MessageSendEvent::SendChannelAnnouncement {
3336 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
3337 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
3338 MessageSendEvent::BroadcastChannelAnnouncement {
3344 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
3345 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
3346 MessageSendEvent::BroadcastChannelUpdate {
3351 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
3352 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
3353 MessageSendEvent::BroadcastNodeAnnouncement {
3358 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
3359 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
3360 MessageSendEvent::SendChannelUpdate {
3366 /// Utility method to constructs a new HandleError-variant MessageSendEvent
3367 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
3368 MessageSendEvent::HandleError {
3374 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
3375 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
3376 MessageSendEvent::SendChannelRangeQuery {
3382 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
3383 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
3384 MessageSendEvent::SendShortIdsQuery {
3390 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
3391 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
3392 MessageSendEvent::SendReplyChannelRange {
3398 /// Utility method to constructs a new SendGossipTimestampFilter-variant MessageSendEvent
3399 pub extern "C" fn MessageSendEvent_send_gossip_timestamp_filter(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::GossipTimestampFilter) -> MessageSendEvent {
3400 MessageSendEvent::SendGossipTimestampFilter {
3405 /// A trait indicating an object may generate message send events
3407 pub struct MessageSendEventsProvider {
3408 /// An opaque pointer which is passed to your function implementations as an argument.
3409 /// This has no meaning in the LDK, and can be NULL or any other value.
3410 pub this_arg: *mut c_void,
3411 /// Gets the list of pending events which were generated by previous actions, clearing the list
3414 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
3415 /// Frees any resources associated with this object given its this_arg pointer.
3416 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3417 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3419 unsafe impl Send for MessageSendEventsProvider {}
3420 unsafe impl Sync for MessageSendEventsProvider {}
3422 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
3423 MessageSendEventsProvider {
3424 this_arg: orig.this_arg,
3425 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
3426 free: Clone::clone(&orig.free),
3430 use lightning::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
3431 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
3432 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::events::MessageSendEvent> {
3433 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
3434 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
3439 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
3440 // directly as a Deref trait in higher-level structs:
3441 impl core::ops::Deref for MessageSendEventsProvider {
3443 fn deref(&self) -> &Self {
3447 /// Calls the free function if one is set
3449 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
3450 impl Drop for MessageSendEventsProvider {
3451 fn drop(&mut self) {
3452 if let Some(f) = self.free {
3457 /// A trait indicating an object may generate onion messages to send
3459 pub struct OnionMessageProvider {
3460 /// An opaque pointer which is passed to your function implementations as an argument.
3461 /// This has no meaning in the LDK, and can be NULL or any other value.
3462 pub this_arg: *mut c_void,
3463 /// Gets the next pending onion message for the peer with the given node id.
3465 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
3467 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,
3468 /// Frees any resources associated with this object given its this_arg pointer.
3469 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3470 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3472 unsafe impl Send for OnionMessageProvider {}
3473 unsafe impl Sync for OnionMessageProvider {}
3475 pub(crate) extern "C" fn OnionMessageProvider_clone_fields(orig: &OnionMessageProvider) -> OnionMessageProvider {
3476 OnionMessageProvider {
3477 this_arg: orig.this_arg,
3478 next_onion_message_for_peer: Clone::clone(&orig.next_onion_message_for_peer),
3479 free: Clone::clone(&orig.free),
3483 use lightning::events::OnionMessageProvider as rustOnionMessageProvider;
3484 impl rustOnionMessageProvider for OnionMessageProvider {
3485 fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option<lightning::ln::msgs::OnionMessage> {
3486 let mut ret = (self.next_onion_message_for_peer)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id));
3487 let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) };
3492 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
3493 // directly as a Deref trait in higher-level structs:
3494 impl core::ops::Deref for OnionMessageProvider {
3496 fn deref(&self) -> &Self {
3500 /// Calls the free function if one is set
3502 pub extern "C" fn OnionMessageProvider_free(this_ptr: OnionMessageProvider) { }
3503 impl Drop for OnionMessageProvider {
3504 fn drop(&mut self) {
3505 if let Some(f) = self.free {
3510 /// A trait indicating an object may generate events.
3512 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
3514 /// Implementations of this trait may also feature an async version of event handling, as shown with
3515 /// [`ChannelManager::process_pending_events_async`] and
3516 /// [`ChainMonitor::process_pending_events_async`].
3520 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
3521 /// event since the last invocation.
3523 /// In order to ensure no [`Event`]s are lost, implementors of this trait will persist [`Event`]s
3524 /// and replay any unhandled events on startup. An [`Event`] is considered handled when
3525 /// [`process_pending_events`] returns, thus handlers MUST fully handle [`Event`]s and persist any
3526 /// relevant changes to disk *before* returning.
3528 /// Further, because an application may crash between an [`Event`] being handled and the
3529 /// implementor of this trait being re-serialized, [`Event`] handling must be idempotent - in
3530 /// effect, [`Event`]s may be replayed.
3532 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
3533 /// consult the provider's documentation on the implication of processing events and how a handler
3534 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
3535 /// [`ChainMonitor::process_pending_events`]).
3537 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
3540 /// [`process_pending_events`]: Self::process_pending_events
3541 /// [`handle_event`]: EventHandler::handle_event
3542 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
3543 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
3544 /// [`ChannelManager::process_pending_events_async`]: crate::ln::channelmanager::ChannelManager::process_pending_events_async
3545 /// [`ChainMonitor::process_pending_events_async`]: crate::chain::chainmonitor::ChainMonitor::process_pending_events_async
3547 pub struct EventsProvider {
3548 /// An opaque pointer which is passed to your function implementations as an argument.
3549 /// This has no meaning in the LDK, and can be NULL or any other value.
3550 pub this_arg: *mut c_void,
3551 /// Processes any events generated since the last call using the given event handler.
3553 /// See the trait-level documentation for requirements.
3554 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::events::EventHandler),
3555 /// Frees any resources associated with this object given its this_arg pointer.
3556 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3557 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3559 unsafe impl Send for EventsProvider {}
3560 unsafe impl Sync for EventsProvider {}
3562 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
3564 this_arg: orig.this_arg,
3565 process_pending_events: Clone::clone(&orig.process_pending_events),
3566 free: Clone::clone(&orig.free),
3570 use lightning::events::EventsProvider as rustEventsProvider;
3571 /// Calls the free function if one is set
3573 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
3574 impl Drop for EventsProvider {
3575 fn drop(&mut self) {
3576 if let Some(f) = self.free {
3581 /// A trait implemented for objects handling events from [`EventsProvider`].
3583 /// An async variation also exists for implementations of [`EventsProvider`] that support async
3584 /// event handling. The async event handler should satisfy the generic bounds: `F:
3585 /// core::future::Future, H: Fn(Event) -> F`.
3587 pub struct EventHandler {
3588 /// An opaque pointer which is passed to your function implementations as an argument.
3589 /// This has no meaning in the LDK, and can be NULL or any other value.
3590 pub this_arg: *mut c_void,
3591 /// Handles the given [`Event`].
3593 /// See [`EventsProvider`] for details that must be considered when implementing this method.
3594 pub handle_event: extern "C" fn (this_arg: *const c_void, event: crate::lightning::events::Event),
3595 /// Frees any resources associated with this object given its this_arg pointer.
3596 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3597 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3599 unsafe impl Send for EventHandler {}
3600 unsafe impl Sync for EventHandler {}
3602 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
3604 this_arg: orig.this_arg,
3605 handle_event: Clone::clone(&orig.handle_event),
3606 free: Clone::clone(&orig.free),
3610 use lightning::events::EventHandler as rustEventHandler;
3611 impl rustEventHandler for EventHandler {
3612 fn handle_event(&self, mut event: lightning::events::Event) {
3613 (self.handle_event)(self.this_arg, crate::lightning::events::Event::native_into(event))
3617 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
3618 // directly as a Deref trait in higher-level structs:
3619 impl core::ops::Deref for EventHandler {
3621 fn deref(&self) -> &Self {
3625 /// Calls the free function if one is set
3627 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
3628 impl Drop for EventHandler {
3629 fn drop(&mut self) {
3630 if let Some(f) = self.free {