1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Events are returned from various bits in the library which indicate some action must be taken
12 //! Because we don't have a built-in runtime, it's up to the client to call events at a time in the
13 //! future, as well as generate and broadcast funding transactions handle payment preimages and a
16 use alloc::str::FromStr;
17 use core::ffi::c_void;
18 use core::convert::Infallible;
19 use bitcoin::hashes::Hash;
20 use crate::c_types::*;
21 #[cfg(feature="no-std")]
22 use alloc::{vec::Vec, boxed::Box};
24 /// Some information provided on receipt of payment depends on whether the payment received is a
25 /// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
29 pub enum PaymentPurpose {
30 /// Information for receiving a payment that we generated an invoice for.
32 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
33 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
34 /// [`ChannelManager::claim_funds`].
36 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
37 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
39 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
40 payment_preimage: crate::c_types::ThirtyTwoBytes,
41 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
42 /// number of deanonymization attacks during the routing process.
43 /// It is provided here for your reference, however its accuracy is enforced directly by
44 /// [`ChannelManager`] using the values you previously provided to
45 /// [`ChannelManager::create_inbound_payment`] or
46 /// [`ChannelManager::create_inbound_payment_for_hash`].
48 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
49 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
50 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
51 payment_secret: crate::c_types::ThirtyTwoBytes,
53 /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
54 /// (the payee) providing a preimage.
56 crate::c_types::ThirtyTwoBytes),
58 use lightning::util::events::PaymentPurpose as PaymentPurposeImport;
59 pub(crate) type nativePaymentPurpose = PaymentPurposeImport;
63 pub(crate) fn to_native(&self) -> nativePaymentPurpose {
65 PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
66 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
67 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
68 let mut payment_secret_nonref = Clone::clone(payment_secret);
69 nativePaymentPurpose::InvoicePayment {
70 payment_preimage: local_payment_preimage_nonref,
71 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
74 PaymentPurpose::SpontaneousPayment (ref a, ) => {
75 let mut a_nonref = Clone::clone(a);
76 nativePaymentPurpose::SpontaneousPayment (
77 ::lightning::ln::PaymentPreimage(a_nonref.data),
83 pub(crate) fn into_native(self) -> nativePaymentPurpose {
85 PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
86 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
87 nativePaymentPurpose::InvoicePayment {
88 payment_preimage: local_payment_preimage,
89 payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
92 PaymentPurpose::SpontaneousPayment (mut a, ) => {
93 nativePaymentPurpose::SpontaneousPayment (
94 ::lightning::ln::PaymentPreimage(a.data),
100 pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
102 nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
103 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
104 let mut local_payment_preimage_nonref = if payment_preimage_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_preimage_nonref.unwrap()).0 } } };
105 let mut payment_secret_nonref = Clone::clone(payment_secret);
106 PaymentPurpose::InvoicePayment {
107 payment_preimage: local_payment_preimage_nonref,
108 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
111 nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
112 let mut a_nonref = Clone::clone(a);
113 PaymentPurpose::SpontaneousPayment (
114 crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
120 pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
122 nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
123 let mut local_payment_preimage = if payment_preimage.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_preimage.unwrap()).0 } } };
124 PaymentPurpose::InvoicePayment {
125 payment_preimage: local_payment_preimage,
126 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
129 nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
130 PaymentPurpose::SpontaneousPayment (
131 crate::c_types::ThirtyTwoBytes { data: a.0 },
137 /// Frees any resources used by the PaymentPurpose
139 pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
140 /// Creates a copy of the PaymentPurpose
142 pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
146 /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
147 pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
148 PaymentPurpose::InvoicePayment {
154 /// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
155 pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
156 PaymentPurpose::SpontaneousPayment(a, )
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::util::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::util::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::util::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::util::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::util::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::util::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::util::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 /// The string should be sanitized before it is used (e.g emitted to logs
327 /// or printed to stdout). Otherwise, a well crafted error message may exploit
328 /// a security vulnerability in the terminal emulator or the logging subsystem.
329 peer_msg: crate::c_types::Str,
331 /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
333 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
335 /// The channel was closed after negotiating a cooperative close and we've now broadcasted
336 /// the cooperative close transaction. Note the shutdown may have been initiated by us.
338 /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
339 /// commitment transaction came from our counterparty, but it may also have come from
340 /// a copy of our own `ChannelMonitor`.
341 CommitmentTxConfirmed,
342 /// The funding transaction failed to confirm in a timely manner on an inbound channel.
344 /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
346 /// A developer-readable error message which we generated.
347 err: crate::c_types::Str,
349 /// The peer disconnected prior to funding completing. In this case the spec mandates that we
350 /// forget the channel entirely - we can attempt again if the peer reconnects.
352 /// This includes cases where we restarted prior to funding completion, including prior to the
353 /// initial [`ChannelMonitor`] persistence completing.
355 /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
356 /// peer because of mutual incompatibility between us and our channel counterparty.
358 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
360 /// Closure generated from `ChannelManager::read` if the [`ChannelMonitor`] is newer than
361 /// the [`ChannelManager`] deserialized.
363 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
364 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
365 OutdatedChannelManager,
367 use lightning::util::events::ClosureReason as ClosureReasonImport;
368 pub(crate) type nativeClosureReason = ClosureReasonImport;
372 pub(crate) fn to_native(&self) -> nativeClosureReason {
374 ClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
375 let mut peer_msg_nonref = Clone::clone(peer_msg);
376 nativeClosureReason::CounterpartyForceClosed {
377 peer_msg: peer_msg_nonref.into_string(),
380 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
381 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
382 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
383 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
384 ClosureReason::ProcessingError {ref err, } => {
385 let mut err_nonref = Clone::clone(err);
386 nativeClosureReason::ProcessingError {
387 err: err_nonref.into_string(),
390 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
391 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
395 pub(crate) fn into_native(self) -> nativeClosureReason {
397 ClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
398 nativeClosureReason::CounterpartyForceClosed {
399 peer_msg: peer_msg.into_string(),
402 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
403 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
404 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
405 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
406 ClosureReason::ProcessingError {mut err, } => {
407 nativeClosureReason::ProcessingError {
408 err: err.into_string(),
411 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
412 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
416 pub(crate) fn from_native(native: &nativeClosureReason) -> Self {
418 nativeClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
419 let mut peer_msg_nonref = Clone::clone(peer_msg);
420 ClosureReason::CounterpartyForceClosed {
421 peer_msg: peer_msg_nonref.into(),
424 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
425 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
426 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
427 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
428 nativeClosureReason::ProcessingError {ref err, } => {
429 let mut err_nonref = Clone::clone(err);
430 ClosureReason::ProcessingError {
431 err: err_nonref.into(),
434 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
435 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
439 pub(crate) fn native_into(native: nativeClosureReason) -> Self {
441 nativeClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
442 ClosureReason::CounterpartyForceClosed {
443 peer_msg: peer_msg.into(),
446 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
447 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
448 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
449 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
450 nativeClosureReason::ProcessingError {mut err, } => {
451 ClosureReason::ProcessingError {
455 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
456 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
460 /// Frees any resources used by the ClosureReason
462 pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { }
463 /// Creates a copy of the ClosureReason
465 pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason {
469 /// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
470 pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::c_types::Str) -> ClosureReason {
471 ClosureReason::CounterpartyForceClosed {
476 /// Utility method to constructs a new HolderForceClosed-variant ClosureReason
477 pub extern "C" fn ClosureReason_holder_force_closed() -> ClosureReason {
478 ClosureReason::HolderForceClosed}
480 /// Utility method to constructs a new CooperativeClosure-variant ClosureReason
481 pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason {
482 ClosureReason::CooperativeClosure}
484 /// Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
485 pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason {
486 ClosureReason::CommitmentTxConfirmed}
488 /// Utility method to constructs a new FundingTimedOut-variant ClosureReason
489 pub extern "C" fn ClosureReason_funding_timed_out() -> ClosureReason {
490 ClosureReason::FundingTimedOut}
492 /// Utility method to constructs a new ProcessingError-variant ClosureReason
493 pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason {
494 ClosureReason::ProcessingError {
499 /// Utility method to constructs a new DisconnectedPeer-variant ClosureReason
500 pub extern "C" fn ClosureReason_disconnected_peer() -> ClosureReason {
501 ClosureReason::DisconnectedPeer}
503 /// Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
504 pub extern "C" fn ClosureReason_outdated_channel_manager() -> ClosureReason {
505 ClosureReason::OutdatedChannelManager}
506 /// Checks if two ClosureReasons contain equal inner contents.
507 /// This ignores pointers and is_owned flags and looks at the values in fields.
509 pub extern "C" fn ClosureReason_eq(a: &ClosureReason, b: &ClosureReason) -> bool {
510 if &a.to_native() == &b.to_native() { true } else { false }
513 /// Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
514 pub extern "C" fn ClosureReason_write(obj: &crate::lightning::util::events::ClosureReason) -> crate::c_types::derived::CVec_u8Z {
515 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
518 /// Read a ClosureReason from a byte array, created by ClosureReason_write
519 pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_ClosureReasonZDecodeErrorZ {
520 let res: Result<Option<lightning::util::events::ClosureReason>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
521 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_ClosureReasonZ::None } else { crate::c_types::derived::COption_ClosureReasonZ::Some( { crate::lightning::util::events::ClosureReason::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
524 /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
528 pub enum HTLCDestination {
529 /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
530 /// there is insufficient capacity in our outbound channel.
532 /// The `node_id` of the next node. For backwards compatibility, this field is
533 /// marked as optional, versions prior to 0.0.110 may not always be able to provide
534 /// counterparty node information.
536 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
537 node_id: crate::c_types::PublicKey,
538 /// The outgoing `channel_id` between us and the next node.
539 channel_id: crate::c_types::ThirtyTwoBytes,
541 /// Scenario where we are unsure of the next node to forward the HTLC to.
543 /// Short channel id we are requesting to forward an HTLC to.
544 requested_forward_scid: u64,
546 /// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
549 /// Short channel id we are requesting to forward an HTLC to.
550 requested_forward_scid: u64,
552 /// Failure scenario where an HTLC may have been forwarded to be intended for us,
553 /// but is invalid for some reason, so we reject it.
555 /// Some of the reasons may include:
557 /// * Expected MPP amount to claim does not equal HTLC total
558 /// * Claimable amount does not match expected amount
560 /// The payment hash of the payment we attempted to process.
561 payment_hash: crate::c_types::ThirtyTwoBytes,
564 use lightning::util::events::HTLCDestination as HTLCDestinationImport;
565 pub(crate) type nativeHTLCDestination = HTLCDestinationImport;
567 impl HTLCDestination {
569 pub(crate) fn to_native(&self) -> nativeHTLCDestination {
571 HTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
572 let mut node_id_nonref = Clone::clone(node_id);
573 let mut local_node_id_nonref = if node_id_nonref.is_null() { None } else { Some( { node_id_nonref.into_rust() }) };
574 let mut channel_id_nonref = Clone::clone(channel_id);
575 nativeHTLCDestination::NextHopChannel {
576 node_id: local_node_id_nonref,
577 channel_id: channel_id_nonref.data,
580 HTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
581 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
582 nativeHTLCDestination::UnknownNextHop {
583 requested_forward_scid: requested_forward_scid_nonref,
586 HTLCDestination::InvalidForward {ref requested_forward_scid, } => {
587 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
588 nativeHTLCDestination::InvalidForward {
589 requested_forward_scid: requested_forward_scid_nonref,
592 HTLCDestination::FailedPayment {ref payment_hash, } => {
593 let mut payment_hash_nonref = Clone::clone(payment_hash);
594 nativeHTLCDestination::FailedPayment {
595 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
601 pub(crate) fn into_native(self) -> nativeHTLCDestination {
603 HTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
604 let mut local_node_id = if node_id.is_null() { None } else { Some( { node_id.into_rust() }) };
605 nativeHTLCDestination::NextHopChannel {
606 node_id: local_node_id,
607 channel_id: channel_id.data,
610 HTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
611 nativeHTLCDestination::UnknownNextHop {
612 requested_forward_scid: requested_forward_scid,
615 HTLCDestination::InvalidForward {mut requested_forward_scid, } => {
616 nativeHTLCDestination::InvalidForward {
617 requested_forward_scid: requested_forward_scid,
620 HTLCDestination::FailedPayment {mut payment_hash, } => {
621 nativeHTLCDestination::FailedPayment {
622 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
628 pub(crate) fn from_native(native: &nativeHTLCDestination) -> Self {
630 nativeHTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
631 let mut node_id_nonref = Clone::clone(node_id);
632 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())) } };
633 let mut channel_id_nonref = Clone::clone(channel_id);
634 HTLCDestination::NextHopChannel {
635 node_id: local_node_id_nonref,
636 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
639 nativeHTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
640 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
641 HTLCDestination::UnknownNextHop {
642 requested_forward_scid: requested_forward_scid_nonref,
645 nativeHTLCDestination::InvalidForward {ref requested_forward_scid, } => {
646 let mut requested_forward_scid_nonref = Clone::clone(requested_forward_scid);
647 HTLCDestination::InvalidForward {
648 requested_forward_scid: requested_forward_scid_nonref,
651 nativeHTLCDestination::FailedPayment {ref payment_hash, } => {
652 let mut payment_hash_nonref = Clone::clone(payment_hash);
653 HTLCDestination::FailedPayment {
654 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
660 pub(crate) fn native_into(native: nativeHTLCDestination) -> Self {
662 nativeHTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
663 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())) } };
664 HTLCDestination::NextHopChannel {
665 node_id: local_node_id,
666 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
669 nativeHTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
670 HTLCDestination::UnknownNextHop {
671 requested_forward_scid: requested_forward_scid,
674 nativeHTLCDestination::InvalidForward {mut requested_forward_scid, } => {
675 HTLCDestination::InvalidForward {
676 requested_forward_scid: requested_forward_scid,
679 nativeHTLCDestination::FailedPayment {mut payment_hash, } => {
680 HTLCDestination::FailedPayment {
681 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
687 /// Frees any resources used by the HTLCDestination
689 pub extern "C" fn HTLCDestination_free(this_ptr: HTLCDestination) { }
690 /// Creates a copy of the HTLCDestination
692 pub extern "C" fn HTLCDestination_clone(orig: &HTLCDestination) -> HTLCDestination {
696 /// Utility method to constructs a new NextHopChannel-variant HTLCDestination
697 pub extern "C" fn HTLCDestination_next_hop_channel(node_id: crate::c_types::PublicKey, channel_id: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
698 HTLCDestination::NextHopChannel {
704 /// Utility method to constructs a new UnknownNextHop-variant HTLCDestination
705 pub extern "C" fn HTLCDestination_unknown_next_hop(requested_forward_scid: u64) -> HTLCDestination {
706 HTLCDestination::UnknownNextHop {
707 requested_forward_scid,
711 /// Utility method to constructs a new InvalidForward-variant HTLCDestination
712 pub extern "C" fn HTLCDestination_invalid_forward(requested_forward_scid: u64) -> HTLCDestination {
713 HTLCDestination::InvalidForward {
714 requested_forward_scid,
718 /// Utility method to constructs a new FailedPayment-variant HTLCDestination
719 pub extern "C" fn HTLCDestination_failed_payment(payment_hash: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
720 HTLCDestination::FailedPayment {
724 /// Checks if two HTLCDestinations contain equal inner contents.
725 /// This ignores pointers and is_owned flags and looks at the values in fields.
727 pub extern "C" fn HTLCDestination_eq(a: &HTLCDestination, b: &HTLCDestination) -> bool {
728 if &a.to_native() == &b.to_native() { true } else { false }
731 /// Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
732 pub extern "C" fn HTLCDestination_write(obj: &crate::lightning::util::events::HTLCDestination) -> crate::c_types::derived::CVec_u8Z {
733 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
736 /// Read a HTLCDestination from a byte array, created by HTLCDestination_write
737 pub extern "C" fn HTLCDestination_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_HTLCDestinationZDecodeErrorZ {
738 let res: Result<Option<lightning::util::events::HTLCDestination>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
739 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_HTLCDestinationZ::None } else { crate::c_types::derived::COption_HTLCDestinationZ::Some( { crate::lightning::util::events::HTLCDestination::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
742 /// An Event which you should probably take some action in response to.
744 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
745 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
746 /// written as it makes no sense to respond to it after reconnecting to peers).
751 /// Used to indicate that the client should generate a funding transaction with the given
752 /// parameters and then call [`ChannelManager::funding_transaction_generated`].
753 /// Generated in [`ChannelManager`] message handling.
754 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
755 /// counterparty can steal your funds!
757 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
758 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
759 FundingGenerationReady {
760 /// The random channel_id we picked which you'll need to pass into
761 /// [`ChannelManager::funding_transaction_generated`].
763 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
764 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
765 /// The counterparty's node_id, which you'll need to pass back into
766 /// [`ChannelManager::funding_transaction_generated`].
768 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
769 counterparty_node_id: crate::c_types::PublicKey,
770 /// The value, in satoshis, that the output should have.
771 channel_value_satoshis: u64,
772 /// The script which should be used in the transaction output.
773 output_script: crate::c_types::derived::CVec_u8Z,
774 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or a
775 /// random value for an inbound channel. This may be zero for objects serialized with LDK
776 /// versions prior to 0.0.113.
778 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
779 user_channel_id: crate::c_types::U128,
781 /// Indicates that we've been offered a payment and it needs to be claimed via calling
782 /// [`ChannelManager::claim_funds`] with the preimage given in [`PaymentPurpose`].
784 /// Note that if the preimage is not known, you should call
785 /// [`ChannelManager::fail_htlc_backwards`] or [`ChannelManager::fail_htlc_backwards_with_reason`]
786 /// to free up resources for this HTLC and avoid network congestion.
787 /// If you fail to call either [`ChannelManager::claim_funds`], [`ChannelManager::fail_htlc_backwards`],
788 /// or [`ChannelManager::fail_htlc_backwards_with_reason`] within the HTLC's timeout, the HTLC will be
789 /// automatically failed.
792 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
793 /// `PaymentClaimable` events may be generated for the same payment.
796 /// This event used to be called `PaymentReceived` in LDK versions 0.0.112 and earlier.
798 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
799 /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
800 /// [`ChannelManager::fail_htlc_backwards_with_reason`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards_with_reason
802 /// The node that will receive the payment after it has been claimed.
803 /// This is useful to identify payments received via [phantom nodes].
804 /// This field will always be filled in when the event was generated by LDK versions
805 /// 0.0.113 and above.
807 /// [phantom nodes]: crate::chain::keysinterface::PhantomKeysManager
809 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
810 receiver_node_id: crate::c_types::PublicKey,
811 /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
812 /// not stop you from registering duplicate payment hashes for inbound payments.
813 payment_hash: crate::c_types::ThirtyTwoBytes,
814 /// The value, in thousandths of a satoshi, that this payment is for.
816 /// Information for claiming this received payment, based on whether the purpose of the
817 /// payment is to pay an invoice or to send a spontaneous payment.
818 purpose: crate::lightning::util::events::PaymentPurpose,
819 /// The `channel_id` indicating over which channel we received the payment.
821 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
822 via_channel_id: crate::c_types::ThirtyTwoBytes,
823 /// The `user_channel_id` indicating over which channel we received the payment.
824 via_user_channel_id: crate::c_types::derived::COption_u128Z,
826 /// Indicates a payment has been claimed and we've received money!
828 /// This most likely occurs when [`ChannelManager::claim_funds`] has been called in response
829 /// to an [`Event::PaymentClaimable`]. However, if we previously crashed during a
830 /// [`ChannelManager::claim_funds`] call you may see this event without a corresponding
831 /// [`Event::PaymentClaimable`] event.
834 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
835 /// `PaymentClaimable` events may be generated for the same payment. If you then call
836 /// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentClaimable`] you may get
837 /// multiple `PaymentClaimed` events.
839 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
841 /// The node that received the payment.
842 /// This is useful to identify payments which were received via [phantom nodes].
843 /// This field will always be filled in when the event was generated by LDK versions
844 /// 0.0.113 and above.
846 /// [phantom nodes]: crate::chain::keysinterface::PhantomKeysManager
848 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
849 receiver_node_id: crate::c_types::PublicKey,
850 /// The payment hash of the claimed payment. Note that LDK will not stop you from
851 /// registering duplicate payment hashes for inbound payments.
852 payment_hash: crate::c_types::ThirtyTwoBytes,
853 /// The value, in thousandths of a satoshi, that this payment is for.
855 /// The purpose of the claimed payment, i.e. whether the payment was for an invoice or a
856 /// spontaneous payment.
857 purpose: crate::lightning::util::events::PaymentPurpose,
859 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
860 /// and we got back the payment preimage for it).
862 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
863 /// event. In this situation, you SHOULD treat this payment as having succeeded.
865 /// The id returned by [`ChannelManager::send_payment`].
867 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
869 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
870 payment_id: crate::c_types::ThirtyTwoBytes,
871 /// The preimage to the hash given to ChannelManager::send_payment.
872 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
873 /// store it somehow!
874 payment_preimage: crate::c_types::ThirtyTwoBytes,
875 /// The hash that was given to [`ChannelManager::send_payment`].
877 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
878 payment_hash: crate::c_types::ThirtyTwoBytes,
879 /// The total fee which was spent at intermediate hops in this payment, across all paths.
881 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
882 /// overpayment to the recipient node.
884 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
885 /// overstate the amount paid, though this is unlikely.
887 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
888 fee_paid_msat: crate::c_types::derived::COption_u64Z,
890 /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
891 /// provide failure information for each path attempt in the payment, including retries.
893 /// This event is provided once there are no further pending HTLCs for the payment and the
894 /// payment is no longer retryable, due either to the [`Retry`] provided or
895 /// [`ChannelManager::abandon_payment`] having been called for the corresponding payment.
897 /// [`Retry`]: crate::ln::channelmanager::Retry
898 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
900 /// The id returned by [`ChannelManager::send_payment`] and used with
901 /// [`ChannelManager::abandon_payment`].
903 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
904 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
905 payment_id: crate::c_types::ThirtyTwoBytes,
906 /// The hash that was given to [`ChannelManager::send_payment`].
908 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
909 payment_hash: crate::c_types::ThirtyTwoBytes,
911 /// Indicates that a path for an outbound payment was successful.
913 /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
914 /// [`Event::PaymentSent`] for obtaining the payment preimage.
915 PaymentPathSuccessful {
916 /// The id returned by [`ChannelManager::send_payment`].
918 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
919 payment_id: crate::c_types::ThirtyTwoBytes,
920 /// The hash that was given to [`ChannelManager::send_payment`].
922 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
924 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
925 payment_hash: crate::c_types::ThirtyTwoBytes,
926 /// The payment path that was successful.
928 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
929 path: crate::c_types::derived::CVec_RouteHopZ,
931 /// Indicates an outbound HTLC we sent failed, likely due to an intermediary node being unable to
934 /// Note that this does *not* indicate that all paths for an MPP payment have failed, see
935 /// [`Event::PaymentFailed`].
937 /// See [`ChannelManager::abandon_payment`] for giving up on this payment before its retries have
940 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
942 /// The id returned by [`ChannelManager::send_payment`] and used with
943 /// [`ChannelManager::abandon_payment`].
945 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
946 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
948 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
949 payment_id: crate::c_types::ThirtyTwoBytes,
950 /// The hash that was given to [`ChannelManager::send_payment`].
952 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
953 payment_hash: crate::c_types::ThirtyTwoBytes,
954 /// Indicates the payment was rejected for some reason by the recipient. This implies that
955 /// the payment has failed, not just the route in question. If this is not set, the payment may
956 /// be retried via a different route.
957 payment_failed_permanently: bool,
958 /// Extra error details based on the failure type. May contain an update that needs to be
959 /// applied to the [`NetworkGraph`].
961 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
962 failure: crate::lightning::util::events::PathFailure,
963 /// The payment path that failed.
964 path: crate::c_types::derived::CVec_RouteHopZ,
965 /// The channel responsible for the failed payment path.
967 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
968 /// may not refer to a channel in the public network graph. These aliases may also collide
969 /// with channels in the public network graph.
971 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
972 /// retried. May be `None` for older [`Event`] serializations.
973 short_channel_id: crate::c_types::derived::COption_u64Z,
974 /// Parameters used by LDK to compute a new [`Route`] when retrying the failed payment path.
976 /// [`Route`]: crate::routing::router::Route
978 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
979 retry: crate::lightning::routing::router::RouteParameters,
981 /// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
983 /// The id returned by [`ChannelManager::send_probe`].
985 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
986 payment_id: crate::c_types::ThirtyTwoBytes,
987 /// The hash generated by [`ChannelManager::send_probe`].
989 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
990 payment_hash: crate::c_types::ThirtyTwoBytes,
991 /// The payment path that was successful.
992 path: crate::c_types::derived::CVec_RouteHopZ,
994 /// Indicates that a probe payment we sent failed at an intermediary node on the path.
996 /// The id returned by [`ChannelManager::send_probe`].
998 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
999 payment_id: crate::c_types::ThirtyTwoBytes,
1000 /// The hash generated by [`ChannelManager::send_probe`].
1002 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
1003 payment_hash: crate::c_types::ThirtyTwoBytes,
1004 /// The payment path that failed.
1005 path: crate::c_types::derived::CVec_RouteHopZ,
1006 /// The channel responsible for the failed probe.
1008 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
1009 /// may not refer to a channel in the public network graph. These aliases may also collide
1010 /// with channels in the public network graph.
1011 short_channel_id: crate::c_types::derived::COption_u64Z,
1013 /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
1014 /// a time in the future.
1016 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
1017 PendingHTLCsForwardable {
1018 /// The minimum amount of time that should be waited prior to calling
1019 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
1020 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
1021 /// now + 5*time_forwardable).
1022 time_forwardable: u64,
1024 /// Used to indicate that we've intercepted an HTLC forward. This event will only be generated if
1025 /// you've encoded an intercept scid in the receiver's invoice route hints using
1026 /// [`ChannelManager::get_intercept_scid`] and have set [`UserConfig::accept_intercept_htlcs`].
1028 /// [`ChannelManager::forward_intercepted_htlc`] or
1029 /// [`ChannelManager::fail_intercepted_htlc`] MUST be called in response to this event. See
1030 /// their docs for more information.
1032 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1033 /// [`UserConfig::accept_intercept_htlcs`]: crate::util::config::UserConfig::accept_intercept_htlcs
1034 /// [`ChannelManager::forward_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::forward_intercepted_htlc
1035 /// [`ChannelManager::fail_intercepted_htlc`]: crate::ln::channelmanager::ChannelManager::fail_intercepted_htlc
1037 /// An id to help LDK identify which HTLC is being forwarded or failed.
1038 intercept_id: crate::c_types::ThirtyTwoBytes,
1039 /// The fake scid that was programmed as the next hop's scid, generated using
1040 /// [`ChannelManager::get_intercept_scid`].
1042 /// [`ChannelManager::get_intercept_scid`]: crate::ln::channelmanager::ChannelManager::get_intercept_scid
1043 requested_next_hop_scid: u64,
1044 /// The payment hash used for this HTLC.
1045 payment_hash: crate::c_types::ThirtyTwoBytes,
1046 /// How many msats were received on the inbound edge of this HTLC.
1047 inbound_amount_msat: u64,
1048 /// How many msats the payer intended to route to the next node. Depending on the reason you are
1049 /// intercepting this payment, you might take a fee by forwarding less than this amount.
1051 /// Note that LDK will NOT check that expected fees were factored into this value. You MUST
1052 /// check that whatever fee you want has been included here or subtract it as required. Further,
1053 /// LDK will not stop you from forwarding more than you received.
1054 expected_outbound_amount_msat: u64,
1056 /// Used to indicate that an output which you should know how to spend was confirmed on chain
1057 /// and is now spendable.
1058 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
1059 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
1060 /// somewhere and spend them when you create on-chain transactions.
1062 /// The outputs which you should store as spendable by you.
1063 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
1065 /// This event is generated when a payment has been successfully forwarded through us and a
1066 /// forwarding fee earned.
1068 /// The incoming channel between the previous node and us. This is only `None` for events
1069 /// generated or serialized by versions prior to 0.0.107.
1071 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1072 prev_channel_id: crate::c_types::ThirtyTwoBytes,
1073 /// The outgoing channel between the next node and us. This is only `None` for events
1074 /// generated or serialized by versions prior to 0.0.107.
1076 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1077 next_channel_id: crate::c_types::ThirtyTwoBytes,
1078 /// The fee, in milli-satoshis, which was earned as a result of the payment.
1080 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
1081 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
1082 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
1083 /// claimed the full value in millisatoshis from the source. In this case,
1084 /// `claim_from_onchain_tx` will be set.
1086 /// If the channel which sent us the payment has been force-closed, we will claim the funds
1087 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
1088 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
1089 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
1091 fee_earned_msat: crate::c_types::derived::COption_u64Z,
1092 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
1094 claim_from_onchain_tx: bool,
1096 /// Used to indicate that a channel with the given `channel_id` is ready to
1097 /// be used. This event is emitted either when the funding transaction has been confirmed
1098 /// on-chain, or, in case of a 0conf channel, when both parties have confirmed the channel
1101 /// The channel_id of the channel that is ready.
1102 channel_id: crate::c_types::ThirtyTwoBytes,
1103 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1104 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1105 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1106 /// `user_channel_id` will be randomized for an inbound channel.
1108 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1109 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1110 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1111 user_channel_id: crate::c_types::U128,
1112 /// The node_id of the channel counterparty.
1113 counterparty_node_id: crate::c_types::PublicKey,
1114 /// The features that this channel will operate with.
1115 channel_type: crate::lightning::ln::features::ChannelTypeFeatures,
1117 /// Used to indicate that a previously opened channel with the given `channel_id` is in the
1118 /// process of closure.
1120 /// The channel_id of the channel which has been closed. Note that on-chain transactions
1121 /// resolving the channel are likely still awaiting confirmation.
1122 channel_id: crate::c_types::ThirtyTwoBytes,
1123 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1124 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1125 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1126 /// `user_channel_id` will be randomized for inbound channels.
1127 /// This may be zero for inbound channels serialized prior to 0.0.113 and will always be
1128 /// zero for objects serialized with LDK versions prior to 0.0.102.
1130 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1131 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1132 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1133 user_channel_id: crate::c_types::U128,
1134 /// The reason the channel was closed.
1135 reason: crate::lightning::util::events::ClosureReason,
1137 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
1138 /// inputs for another purpose.
1140 /// The channel_id of the channel which has been closed.
1141 channel_id: crate::c_types::ThirtyTwoBytes,
1142 /// The full transaction received from the user
1143 transaction: crate::c_types::Transaction,
1145 /// Indicates a request to open a new channel by a peer.
1147 /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the
1148 /// request, call [`ChannelManager::force_close_without_broadcasting_txn`].
1150 /// The event is only triggered when a new open channel request is received and the
1151 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
1153 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1154 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
1155 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1156 OpenChannelRequest {
1157 /// The temporary channel ID of the channel requested to be opened.
1159 /// When responding to the request, the `temporary_channel_id` should be passed
1160 /// back to the ChannelManager through [`ChannelManager::accept_inbound_channel`] to accept,
1161 /// or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject.
1163 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1164 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
1165 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
1166 /// The node_id of the counterparty requesting to open the channel.
1168 /// When responding to the request, the `counterparty_node_id` should be passed
1169 /// back to the `ChannelManager` through [`ChannelManager::accept_inbound_channel`] to
1170 /// accept the request, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject the
1173 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1174 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
1175 counterparty_node_id: crate::c_types::PublicKey,
1176 /// The channel value of the requested channel.
1177 funding_satoshis: u64,
1178 /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
1180 /// The features that this channel will operate with. If you reject the channel, a
1181 /// well-behaved counterparty may automatically re-attempt the channel with a new set of
1184 /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
1185 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
1188 /// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
1189 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
1190 /// 0.0.107. Channels setting this type also need to get manually accepted via
1191 /// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
1192 /// or will be rejected otherwise.
1194 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1195 channel_type: crate::lightning::ln::features::ChannelTypeFeatures,
1197 /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
1200 /// Some scenarios where this event may be sent include:
1201 /// * Insufficient capacity in the outbound channel
1202 /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
1203 /// * When an unknown SCID is requested for forwarding a payment.
1204 /// * Claiming an amount for an MPP payment that exceeds the HTLC total
1205 /// * The HTLC has timed out
1207 /// This event, however, does not get generated if an HTLC fails to meet the forwarding
1208 /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
1209 HTLCHandlingFailed {
1210 /// The channel over which the HTLC was received.
1211 prev_channel_id: crate::c_types::ThirtyTwoBytes,
1212 /// Destination of the HTLC that failed to be processed.
1213 failed_next_destination: crate::lightning::util::events::HTLCDestination,
1216 use lightning::util::events::Event as EventImport;
1217 pub(crate) type nativeEvent = EventImport;
1221 pub(crate) fn to_native(&self) -> nativeEvent {
1223 Event::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
1224 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1225 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1226 let mut channel_value_satoshis_nonref = Clone::clone(channel_value_satoshis);
1227 let mut output_script_nonref = Clone::clone(output_script);
1228 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1229 nativeEvent::FundingGenerationReady {
1230 temporary_channel_id: temporary_channel_id_nonref.data,
1231 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1232 channel_value_satoshis: channel_value_satoshis_nonref,
1233 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
1234 user_channel_id: user_channel_id_nonref.into(),
1237 Event::PaymentClaimable {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, ref via_channel_id, ref via_user_channel_id, } => {
1238 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1239 let mut local_receiver_node_id_nonref = if receiver_node_id_nonref.is_null() { None } else { Some( { receiver_node_id_nonref.into_rust() }) };
1240 let mut payment_hash_nonref = Clone::clone(payment_hash);
1241 let mut amount_msat_nonref = Clone::clone(amount_msat);
1242 let mut purpose_nonref = Clone::clone(purpose);
1243 let mut via_channel_id_nonref = Clone::clone(via_channel_id);
1244 let mut local_via_channel_id_nonref = if via_channel_id_nonref.data == [0; 32] { None } else { Some( { via_channel_id_nonref.data }) };
1245 let mut via_user_channel_id_nonref = Clone::clone(via_user_channel_id);
1246 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() }) } };
1247 nativeEvent::PaymentClaimable {
1248 receiver_node_id: local_receiver_node_id_nonref,
1249 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1250 amount_msat: amount_msat_nonref,
1251 purpose: purpose_nonref.into_native(),
1252 via_channel_id: local_via_channel_id_nonref,
1253 via_user_channel_id: local_via_user_channel_id_nonref,
1256 Event::PaymentClaimed {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, } => {
1257 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1258 let mut local_receiver_node_id_nonref = if receiver_node_id_nonref.is_null() { None } else { Some( { receiver_node_id_nonref.into_rust() }) };
1259 let mut payment_hash_nonref = Clone::clone(payment_hash);
1260 let mut amount_msat_nonref = Clone::clone(amount_msat);
1261 let mut purpose_nonref = Clone::clone(purpose);
1262 nativeEvent::PaymentClaimed {
1263 receiver_node_id: local_receiver_node_id_nonref,
1264 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1265 amount_msat: amount_msat_nonref,
1266 purpose: purpose_nonref.into_native(),
1269 Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1270 let mut payment_id_nonref = Clone::clone(payment_id);
1271 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1272 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
1273 let mut payment_hash_nonref = Clone::clone(payment_hash);
1274 let mut fee_paid_msat_nonref = Clone::clone(fee_paid_msat);
1275 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
1276 nativeEvent::PaymentSent {
1277 payment_id: local_payment_id_nonref,
1278 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
1279 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1280 fee_paid_msat: local_fee_paid_msat_nonref,
1283 Event::PaymentFailed {ref payment_id, ref payment_hash, } => {
1284 let mut payment_id_nonref = Clone::clone(payment_id);
1285 let mut payment_hash_nonref = Clone::clone(payment_hash);
1286 nativeEvent::PaymentFailed {
1287 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1288 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1291 Event::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1292 let mut payment_id_nonref = Clone::clone(payment_id);
1293 let mut payment_hash_nonref = Clone::clone(payment_hash);
1294 let mut local_payment_hash_nonref = if payment_hash_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash_nonref.data) }) };
1295 let mut path_nonref = Clone::clone(path);
1296 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1297 nativeEvent::PaymentPathSuccessful {
1298 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1299 payment_hash: local_payment_hash_nonref,
1300 path: local_path_nonref,
1303 Event::PaymentPathFailed {ref payment_id, ref payment_hash, ref payment_failed_permanently, ref failure, ref path, ref short_channel_id, ref retry, } => {
1304 let mut payment_id_nonref = Clone::clone(payment_id);
1305 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1306 let mut payment_hash_nonref = Clone::clone(payment_hash);
1307 let mut payment_failed_permanently_nonref = Clone::clone(payment_failed_permanently);
1308 let mut failure_nonref = Clone::clone(failure);
1309 let mut path_nonref = Clone::clone(path);
1310 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1311 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1312 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1313 let mut retry_nonref = Clone::clone(retry);
1314 let mut local_retry_nonref = if retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry_nonref.take_inner()) } }) };
1315 nativeEvent::PaymentPathFailed {
1316 payment_id: local_payment_id_nonref,
1317 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1318 payment_failed_permanently: payment_failed_permanently_nonref,
1319 failure: failure_nonref.into_native(),
1320 path: local_path_nonref,
1321 short_channel_id: local_short_channel_id_nonref,
1322 retry: local_retry_nonref,
1325 Event::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1326 let mut payment_id_nonref = Clone::clone(payment_id);
1327 let mut payment_hash_nonref = Clone::clone(payment_hash);
1328 let mut path_nonref = Clone::clone(path);
1329 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1330 nativeEvent::ProbeSuccessful {
1331 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1332 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1333 path: local_path_nonref,
1336 Event::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1337 let mut payment_id_nonref = Clone::clone(payment_id);
1338 let mut payment_hash_nonref = Clone::clone(payment_hash);
1339 let mut path_nonref = Clone::clone(path);
1340 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1341 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1342 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1343 nativeEvent::ProbeFailed {
1344 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1345 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1346 path: local_path_nonref,
1347 short_channel_id: local_short_channel_id_nonref,
1350 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
1351 let mut time_forwardable_nonref = Clone::clone(time_forwardable);
1352 nativeEvent::PendingHTLCsForwardable {
1353 time_forwardable: core::time::Duration::from_secs(time_forwardable_nonref),
1356 Event::HTLCIntercepted {ref intercept_id, ref requested_next_hop_scid, ref payment_hash, ref inbound_amount_msat, ref expected_outbound_amount_msat, } => {
1357 let mut intercept_id_nonref = Clone::clone(intercept_id);
1358 let mut requested_next_hop_scid_nonref = Clone::clone(requested_next_hop_scid);
1359 let mut payment_hash_nonref = Clone::clone(payment_hash);
1360 let mut inbound_amount_msat_nonref = Clone::clone(inbound_amount_msat);
1361 let mut expected_outbound_amount_msat_nonref = Clone::clone(expected_outbound_amount_msat);
1362 nativeEvent::HTLCIntercepted {
1363 intercept_id: ::lightning::ln::channelmanager::InterceptId(intercept_id_nonref.data),
1364 requested_next_hop_scid: requested_next_hop_scid_nonref,
1365 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1366 inbound_amount_msat: inbound_amount_msat_nonref,
1367 expected_outbound_amount_msat: expected_outbound_amount_msat_nonref,
1370 Event::SpendableOutputs {ref outputs, } => {
1371 let mut outputs_nonref = Clone::clone(outputs);
1372 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
1373 nativeEvent::SpendableOutputs {
1374 outputs: local_outputs_nonref,
1377 Event::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, } => {
1378 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1379 let mut local_prev_channel_id_nonref = if prev_channel_id_nonref.data == [0; 32] { None } else { Some( { prev_channel_id_nonref.data }) };
1380 let mut next_channel_id_nonref = Clone::clone(next_channel_id);
1381 let mut local_next_channel_id_nonref = if next_channel_id_nonref.data == [0; 32] { None } else { Some( { next_channel_id_nonref.data }) };
1382 let mut fee_earned_msat_nonref = Clone::clone(fee_earned_msat);
1383 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
1384 let mut claim_from_onchain_tx_nonref = Clone::clone(claim_from_onchain_tx);
1385 nativeEvent::PaymentForwarded {
1386 prev_channel_id: local_prev_channel_id_nonref,
1387 next_channel_id: local_next_channel_id_nonref,
1388 fee_earned_msat: local_fee_earned_msat_nonref,
1389 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1392 Event::ChannelReady {ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type, } => {
1393 let mut channel_id_nonref = Clone::clone(channel_id);
1394 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1395 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1396 let mut channel_type_nonref = Clone::clone(channel_type);
1397 nativeEvent::ChannelReady {
1398 channel_id: channel_id_nonref.data,
1399 user_channel_id: user_channel_id_nonref.into(),
1400 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1401 channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) },
1404 Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
1405 let mut channel_id_nonref = Clone::clone(channel_id);
1406 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1407 let mut reason_nonref = Clone::clone(reason);
1408 nativeEvent::ChannelClosed {
1409 channel_id: channel_id_nonref.data,
1410 user_channel_id: user_channel_id_nonref.into(),
1411 reason: reason_nonref.into_native(),
1414 Event::DiscardFunding {ref channel_id, ref transaction, } => {
1415 let mut channel_id_nonref = Clone::clone(channel_id);
1416 let mut transaction_nonref = Clone::clone(transaction);
1417 nativeEvent::DiscardFunding {
1418 channel_id: channel_id_nonref.data,
1419 transaction: transaction_nonref.into_bitcoin(),
1422 Event::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1423 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1424 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1425 let mut funding_satoshis_nonref = Clone::clone(funding_satoshis);
1426 let mut push_msat_nonref = Clone::clone(push_msat);
1427 let mut channel_type_nonref = Clone::clone(channel_type);
1428 nativeEvent::OpenChannelRequest {
1429 temporary_channel_id: temporary_channel_id_nonref.data,
1430 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1431 funding_satoshis: funding_satoshis_nonref,
1432 push_msat: push_msat_nonref,
1433 channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) },
1436 Event::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
1437 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1438 let mut failed_next_destination_nonref = Clone::clone(failed_next_destination);
1439 nativeEvent::HTLCHandlingFailed {
1440 prev_channel_id: prev_channel_id_nonref.data,
1441 failed_next_destination: failed_next_destination_nonref.into_native(),
1447 pub(crate) fn into_native(self) -> nativeEvent {
1449 Event::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1450 nativeEvent::FundingGenerationReady {
1451 temporary_channel_id: temporary_channel_id.data,
1452 counterparty_node_id: counterparty_node_id.into_rust(),
1453 channel_value_satoshis: channel_value_satoshis,
1454 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
1455 user_channel_id: user_channel_id.into(),
1458 Event::PaymentClaimable {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, mut via_channel_id, mut via_user_channel_id, } => {
1459 let mut local_receiver_node_id = if receiver_node_id.is_null() { None } else { Some( { receiver_node_id.into_rust() }) };
1460 let mut local_via_channel_id = if via_channel_id.data == [0; 32] { None } else { Some( { via_channel_id.data }) };
1461 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() }) } };
1462 nativeEvent::PaymentClaimable {
1463 receiver_node_id: local_receiver_node_id,
1464 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1465 amount_msat: amount_msat,
1466 purpose: purpose.into_native(),
1467 via_channel_id: local_via_channel_id,
1468 via_user_channel_id: local_via_user_channel_id,
1471 Event::PaymentClaimed {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, } => {
1472 let mut local_receiver_node_id = if receiver_node_id.is_null() { None } else { Some( { receiver_node_id.into_rust() }) };
1473 nativeEvent::PaymentClaimed {
1474 receiver_node_id: local_receiver_node_id,
1475 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1476 amount_msat: amount_msat,
1477 purpose: purpose.into_native(),
1480 Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1481 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1482 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
1483 nativeEvent::PaymentSent {
1484 payment_id: local_payment_id,
1485 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
1486 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1487 fee_paid_msat: local_fee_paid_msat,
1490 Event::PaymentFailed {mut payment_id, mut payment_hash, } => {
1491 nativeEvent::PaymentFailed {
1492 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1493 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1496 Event::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1497 let mut local_payment_hash = if payment_hash.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash.data) }) };
1498 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1499 nativeEvent::PaymentPathSuccessful {
1500 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1501 payment_hash: local_payment_hash,
1505 Event::PaymentPathFailed {mut payment_id, mut payment_hash, mut payment_failed_permanently, mut failure, mut path, mut short_channel_id, mut retry, } => {
1506 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1507 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1508 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1509 let mut local_retry = if retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry.take_inner()) } }) };
1510 nativeEvent::PaymentPathFailed {
1511 payment_id: local_payment_id,
1512 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1513 payment_failed_permanently: payment_failed_permanently,
1514 failure: failure.into_native(),
1516 short_channel_id: local_short_channel_id,
1520 Event::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1521 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1522 nativeEvent::ProbeSuccessful {
1523 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1524 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1528 Event::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
1529 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1530 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1531 nativeEvent::ProbeFailed {
1532 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1533 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1535 short_channel_id: local_short_channel_id,
1538 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
1539 nativeEvent::PendingHTLCsForwardable {
1540 time_forwardable: core::time::Duration::from_secs(time_forwardable),
1543 Event::HTLCIntercepted {mut intercept_id, mut requested_next_hop_scid, mut payment_hash, mut inbound_amount_msat, mut expected_outbound_amount_msat, } => {
1544 nativeEvent::HTLCIntercepted {
1545 intercept_id: ::lightning::ln::channelmanager::InterceptId(intercept_id.data),
1546 requested_next_hop_scid: requested_next_hop_scid,
1547 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1548 inbound_amount_msat: inbound_amount_msat,
1549 expected_outbound_amount_msat: expected_outbound_amount_msat,
1552 Event::SpendableOutputs {mut outputs, } => {
1553 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
1554 nativeEvent::SpendableOutputs {
1555 outputs: local_outputs,
1558 Event::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1559 let mut local_prev_channel_id = if prev_channel_id.data == [0; 32] { None } else { Some( { prev_channel_id.data }) };
1560 let mut local_next_channel_id = if next_channel_id.data == [0; 32] { None } else { Some( { next_channel_id.data }) };
1561 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
1562 nativeEvent::PaymentForwarded {
1563 prev_channel_id: local_prev_channel_id,
1564 next_channel_id: local_next_channel_id,
1565 fee_earned_msat: local_fee_earned_msat,
1566 claim_from_onchain_tx: claim_from_onchain_tx,
1569 Event::ChannelReady {mut channel_id, mut user_channel_id, mut counterparty_node_id, mut channel_type, } => {
1570 nativeEvent::ChannelReady {
1571 channel_id: channel_id.data,
1572 user_channel_id: user_channel_id.into(),
1573 counterparty_node_id: counterparty_node_id.into_rust(),
1574 channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) },
1577 Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1578 nativeEvent::ChannelClosed {
1579 channel_id: channel_id.data,
1580 user_channel_id: user_channel_id.into(),
1581 reason: reason.into_native(),
1584 Event::DiscardFunding {mut channel_id, mut transaction, } => {
1585 nativeEvent::DiscardFunding {
1586 channel_id: channel_id.data,
1587 transaction: transaction.into_bitcoin(),
1590 Event::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1591 nativeEvent::OpenChannelRequest {
1592 temporary_channel_id: temporary_channel_id.data,
1593 counterparty_node_id: counterparty_node_id.into_rust(),
1594 funding_satoshis: funding_satoshis,
1595 push_msat: push_msat,
1596 channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) },
1599 Event::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
1600 nativeEvent::HTLCHandlingFailed {
1601 prev_channel_id: prev_channel_id.data,
1602 failed_next_destination: failed_next_destination.into_native(),
1608 pub(crate) fn from_native(native: &nativeEvent) -> Self {
1610 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
1611 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1612 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1613 let mut channel_value_satoshis_nonref = Clone::clone(channel_value_satoshis);
1614 let mut output_script_nonref = Clone::clone(output_script);
1615 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1616 Event::FundingGenerationReady {
1617 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1618 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1619 channel_value_satoshis: channel_value_satoshis_nonref,
1620 output_script: output_script_nonref.into_bytes().into(),
1621 user_channel_id: user_channel_id_nonref.into(),
1624 nativeEvent::PaymentClaimable {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, ref via_channel_id, ref via_user_channel_id, } => {
1625 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1626 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())) } };
1627 let mut payment_hash_nonref = Clone::clone(payment_hash);
1628 let mut amount_msat_nonref = Clone::clone(amount_msat);
1629 let mut purpose_nonref = Clone::clone(purpose);
1630 let mut via_channel_id_nonref = Clone::clone(via_channel_id);
1631 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()) } } };
1632 let mut via_user_channel_id_nonref = Clone::clone(via_user_channel_id);
1633 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() }) };
1634 Event::PaymentClaimable {
1635 receiver_node_id: local_receiver_node_id_nonref,
1636 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1637 amount_msat: amount_msat_nonref,
1638 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
1639 via_channel_id: local_via_channel_id_nonref,
1640 via_user_channel_id: local_via_user_channel_id_nonref,
1643 nativeEvent::PaymentClaimed {ref receiver_node_id, ref payment_hash, ref amount_msat, ref purpose, } => {
1644 let mut receiver_node_id_nonref = Clone::clone(receiver_node_id);
1645 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())) } };
1646 let mut payment_hash_nonref = Clone::clone(payment_hash);
1647 let mut amount_msat_nonref = Clone::clone(amount_msat);
1648 let mut purpose_nonref = Clone::clone(purpose);
1649 Event::PaymentClaimed {
1650 receiver_node_id: local_receiver_node_id_nonref,
1651 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1652 amount_msat: amount_msat_nonref,
1653 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
1656 nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1657 let mut payment_id_nonref = Clone::clone(payment_id);
1658 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 } } };
1659 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
1660 let mut payment_hash_nonref = Clone::clone(payment_hash);
1661 let mut fee_paid_msat_nonref = Clone::clone(fee_paid_msat);
1662 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() }) };
1663 Event::PaymentSent {
1664 payment_id: local_payment_id_nonref,
1665 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
1666 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1667 fee_paid_msat: local_fee_paid_msat_nonref,
1670 nativeEvent::PaymentFailed {ref payment_id, ref payment_hash, } => {
1671 let mut payment_id_nonref = Clone::clone(payment_id);
1672 let mut payment_hash_nonref = Clone::clone(payment_hash);
1673 Event::PaymentFailed {
1674 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1675 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1678 nativeEvent::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1679 let mut payment_id_nonref = Clone::clone(payment_id);
1680 let mut payment_hash_nonref = Clone::clone(payment_hash);
1681 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 } } };
1682 let mut path_nonref = Clone::clone(path);
1683 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1684 Event::PaymentPathSuccessful {
1685 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1686 payment_hash: local_payment_hash_nonref,
1687 path: local_path_nonref.into(),
1690 nativeEvent::PaymentPathFailed {ref payment_id, ref payment_hash, ref payment_failed_permanently, ref failure, ref path, ref short_channel_id, ref retry, } => {
1691 let mut payment_id_nonref = Clone::clone(payment_id);
1692 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 } } };
1693 let mut payment_hash_nonref = Clone::clone(payment_hash);
1694 let mut payment_failed_permanently_nonref = Clone::clone(payment_failed_permanently);
1695 let mut failure_nonref = Clone::clone(failure);
1696 let mut path_nonref = Clone::clone(path);
1697 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1698 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1699 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() }) };
1700 let mut retry_nonref = Clone::clone(retry);
1701 let mut local_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if retry_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((retry_nonref.unwrap())) } }, is_owned: true };
1702 Event::PaymentPathFailed {
1703 payment_id: local_payment_id_nonref,
1704 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1705 payment_failed_permanently: payment_failed_permanently_nonref,
1706 failure: crate::lightning::util::events::PathFailure::native_into(failure_nonref),
1707 path: local_path_nonref.into(),
1708 short_channel_id: local_short_channel_id_nonref,
1709 retry: local_retry_nonref,
1712 nativeEvent::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1713 let mut payment_id_nonref = Clone::clone(payment_id);
1714 let mut payment_hash_nonref = Clone::clone(payment_hash);
1715 let mut path_nonref = Clone::clone(path);
1716 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1717 Event::ProbeSuccessful {
1718 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1719 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1720 path: local_path_nonref.into(),
1723 nativeEvent::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1724 let mut payment_id_nonref = Clone::clone(payment_id);
1725 let mut payment_hash_nonref = Clone::clone(payment_hash);
1726 let mut path_nonref = Clone::clone(path);
1727 let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1728 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
1729 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() }) };
1730 Event::ProbeFailed {
1731 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1732 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1733 path: local_path_nonref.into(),
1734 short_channel_id: local_short_channel_id_nonref,
1737 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
1738 let mut time_forwardable_nonref = Clone::clone(time_forwardable);
1739 Event::PendingHTLCsForwardable {
1740 time_forwardable: time_forwardable_nonref.as_secs(),
1743 nativeEvent::HTLCIntercepted {ref intercept_id, ref requested_next_hop_scid, ref payment_hash, ref inbound_amount_msat, ref expected_outbound_amount_msat, } => {
1744 let mut intercept_id_nonref = Clone::clone(intercept_id);
1745 let mut requested_next_hop_scid_nonref = Clone::clone(requested_next_hop_scid);
1746 let mut payment_hash_nonref = Clone::clone(payment_hash);
1747 let mut inbound_amount_msat_nonref = Clone::clone(inbound_amount_msat);
1748 let mut expected_outbound_amount_msat_nonref = Clone::clone(expected_outbound_amount_msat);
1749 Event::HTLCIntercepted {
1750 intercept_id: crate::c_types::ThirtyTwoBytes { data: intercept_id_nonref.0 },
1751 requested_next_hop_scid: requested_next_hop_scid_nonref,
1752 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1753 inbound_amount_msat: inbound_amount_msat_nonref,
1754 expected_outbound_amount_msat: expected_outbound_amount_msat_nonref,
1757 nativeEvent::SpendableOutputs {ref outputs, } => {
1758 let mut outputs_nonref = Clone::clone(outputs);
1759 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) }); };
1760 Event::SpendableOutputs {
1761 outputs: local_outputs_nonref.into(),
1764 nativeEvent::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, } => {
1765 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1766 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()) } } };
1767 let mut next_channel_id_nonref = Clone::clone(next_channel_id);
1768 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()) } } };
1769 let mut fee_earned_msat_nonref = Clone::clone(fee_earned_msat);
1770 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() }) };
1771 let mut claim_from_onchain_tx_nonref = Clone::clone(claim_from_onchain_tx);
1772 Event::PaymentForwarded {
1773 prev_channel_id: local_prev_channel_id_nonref,
1774 next_channel_id: local_next_channel_id_nonref,
1775 fee_earned_msat: local_fee_earned_msat_nonref,
1776 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1779 nativeEvent::ChannelReady {ref channel_id, ref user_channel_id, ref counterparty_node_id, ref channel_type, } => {
1780 let mut channel_id_nonref = Clone::clone(channel_id);
1781 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1782 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1783 let mut channel_type_nonref = Clone::clone(channel_type);
1784 Event::ChannelReady {
1785 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1786 user_channel_id: user_channel_id_nonref.into(),
1787 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1788 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true },
1791 nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
1792 let mut channel_id_nonref = Clone::clone(channel_id);
1793 let mut user_channel_id_nonref = Clone::clone(user_channel_id);
1794 let mut reason_nonref = Clone::clone(reason);
1795 Event::ChannelClosed {
1796 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1797 user_channel_id: user_channel_id_nonref.into(),
1798 reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
1801 nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
1802 let mut channel_id_nonref = Clone::clone(channel_id);
1803 let mut transaction_nonref = Clone::clone(transaction);
1804 Event::DiscardFunding {
1805 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1806 transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
1809 nativeEvent::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1810 let mut temporary_channel_id_nonref = Clone::clone(temporary_channel_id);
1811 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
1812 let mut funding_satoshis_nonref = Clone::clone(funding_satoshis);
1813 let mut push_msat_nonref = Clone::clone(push_msat);
1814 let mut channel_type_nonref = Clone::clone(channel_type);
1815 Event::OpenChannelRequest {
1816 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1817 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1818 funding_satoshis: funding_satoshis_nonref,
1819 push_msat: push_msat_nonref,
1820 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true },
1823 nativeEvent::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
1824 let mut prev_channel_id_nonref = Clone::clone(prev_channel_id);
1825 let mut failed_next_destination_nonref = Clone::clone(failed_next_destination);
1826 Event::HTLCHandlingFailed {
1827 prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id_nonref },
1828 failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination_nonref),
1834 pub(crate) fn native_into(native: nativeEvent) -> Self {
1836 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1837 Event::FundingGenerationReady {
1838 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1839 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1840 channel_value_satoshis: channel_value_satoshis,
1841 output_script: output_script.into_bytes().into(),
1842 user_channel_id: user_channel_id.into(),
1845 nativeEvent::PaymentClaimable {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, mut via_channel_id, mut via_user_channel_id, } => {
1846 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())) } };
1847 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()) } } };
1848 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() }) };
1849 Event::PaymentClaimable {
1850 receiver_node_id: local_receiver_node_id,
1851 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1852 amount_msat: amount_msat,
1853 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
1854 via_channel_id: local_via_channel_id,
1855 via_user_channel_id: local_via_user_channel_id,
1858 nativeEvent::PaymentClaimed {mut receiver_node_id, mut payment_hash, mut amount_msat, mut purpose, } => {
1859 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())) } };
1860 Event::PaymentClaimed {
1861 receiver_node_id: local_receiver_node_id,
1862 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1863 amount_msat: amount_msat,
1864 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
1867 nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1868 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 } } };
1869 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() }) };
1870 Event::PaymentSent {
1871 payment_id: local_payment_id,
1872 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
1873 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1874 fee_paid_msat: local_fee_paid_msat,
1877 nativeEvent::PaymentFailed {mut payment_id, mut payment_hash, } => {
1878 Event::PaymentFailed {
1879 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1880 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1883 nativeEvent::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1884 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 } } };
1885 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1886 Event::PaymentPathSuccessful {
1887 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1888 payment_hash: local_payment_hash,
1889 path: local_path.into(),
1892 nativeEvent::PaymentPathFailed {mut payment_id, mut payment_hash, mut payment_failed_permanently, mut failure, mut path, mut short_channel_id, mut retry, } => {
1893 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 } } };
1894 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1895 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() }) };
1896 let mut local_retry = crate::lightning::routing::router::RouteParameters { inner: if retry.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((retry.unwrap())) } }, is_owned: true };
1897 Event::PaymentPathFailed {
1898 payment_id: local_payment_id,
1899 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1900 payment_failed_permanently: payment_failed_permanently,
1901 failure: crate::lightning::util::events::PathFailure::native_into(failure),
1902 path: local_path.into(),
1903 short_channel_id: local_short_channel_id,
1907 nativeEvent::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1908 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1909 Event::ProbeSuccessful {
1910 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1911 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1912 path: local_path.into(),
1915 nativeEvent::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
1916 let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1917 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() }) };
1918 Event::ProbeFailed {
1919 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1920 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1921 path: local_path.into(),
1922 short_channel_id: local_short_channel_id,
1925 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
1926 Event::PendingHTLCsForwardable {
1927 time_forwardable: time_forwardable.as_secs(),
1930 nativeEvent::HTLCIntercepted {mut intercept_id, mut requested_next_hop_scid, mut payment_hash, mut inbound_amount_msat, mut expected_outbound_amount_msat, } => {
1931 Event::HTLCIntercepted {
1932 intercept_id: crate::c_types::ThirtyTwoBytes { data: intercept_id.0 },
1933 requested_next_hop_scid: requested_next_hop_scid,
1934 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1935 inbound_amount_msat: inbound_amount_msat,
1936 expected_outbound_amount_msat: expected_outbound_amount_msat,
1939 nativeEvent::SpendableOutputs {mut outputs, } => {
1940 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
1941 Event::SpendableOutputs {
1942 outputs: local_outputs.into(),
1945 nativeEvent::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1946 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()) } } };
1947 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()) } } };
1948 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() }) };
1949 Event::PaymentForwarded {
1950 prev_channel_id: local_prev_channel_id,
1951 next_channel_id: local_next_channel_id,
1952 fee_earned_msat: local_fee_earned_msat,
1953 claim_from_onchain_tx: claim_from_onchain_tx,
1956 nativeEvent::ChannelReady {mut channel_id, mut user_channel_id, mut counterparty_node_id, mut channel_type, } => {
1957 Event::ChannelReady {
1958 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1959 user_channel_id: user_channel_id.into(),
1960 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1961 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true },
1964 nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1965 Event::ChannelClosed {
1966 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1967 user_channel_id: user_channel_id.into(),
1968 reason: crate::lightning::util::events::ClosureReason::native_into(reason),
1971 nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
1972 Event::DiscardFunding {
1973 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1974 transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
1977 nativeEvent::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1978 Event::OpenChannelRequest {
1979 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1980 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1981 funding_satoshis: funding_satoshis,
1982 push_msat: push_msat,
1983 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true },
1986 nativeEvent::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
1987 Event::HTLCHandlingFailed {
1988 prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id },
1989 failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination),
1995 /// Frees any resources used by the Event
1997 pub extern "C" fn Event_free(this_ptr: Event) { }
1998 /// Creates a copy of the Event
2000 pub extern "C" fn Event_clone(orig: &Event) -> Event {
2004 /// Utility method to constructs a new FundingGenerationReady-variant Event
2005 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 {
2006 Event::FundingGenerationReady {
2007 temporary_channel_id,
2008 counterparty_node_id,
2009 channel_value_satoshis,
2015 /// Utility method to constructs a new PaymentClaimable-variant Event
2016 pub extern "C" fn Event_payment_claimable(receiver_node_id: crate::c_types::PublicKey, payment_hash: crate::c_types::ThirtyTwoBytes, amount_msat: u64, purpose: crate::lightning::util::events::PaymentPurpose, via_channel_id: crate::c_types::ThirtyTwoBytes, via_user_channel_id: crate::c_types::derived::COption_u128Z) -> Event {
2017 Event::PaymentClaimable {
2023 via_user_channel_id,
2027 /// Utility method to constructs a new PaymentClaimed-variant Event
2028 pub extern "C" fn Event_payment_claimed(receiver_node_id: crate::c_types::PublicKey, payment_hash: crate::c_types::ThirtyTwoBytes, amount_msat: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
2029 Event::PaymentClaimed {
2037 /// Utility method to constructs a new PaymentSent-variant Event
2038 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 {
2039 Event::PaymentSent {
2047 /// Utility method to constructs a new PaymentFailed-variant Event
2048 pub extern "C" fn Event_payment_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> Event {
2049 Event::PaymentFailed {
2055 /// Utility method to constructs a new PaymentPathSuccessful-variant Event
2056 pub extern "C" fn Event_payment_path_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event {
2057 Event::PaymentPathSuccessful {
2064 /// Utility method to constructs a new PaymentPathFailed-variant Event
2065 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::util::events::PathFailure, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z, retry: crate::lightning::routing::router::RouteParameters) -> Event {
2066 Event::PaymentPathFailed {
2069 payment_failed_permanently,
2077 /// Utility method to constructs a new ProbeSuccessful-variant Event
2078 pub extern "C" fn Event_probe_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event {
2079 Event::ProbeSuccessful {
2086 /// Utility method to constructs a new ProbeFailed-variant Event
2087 pub extern "C" fn Event_probe_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z) -> Event {
2088 Event::ProbeFailed {
2096 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
2097 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
2098 Event::PendingHTLCsForwardable {
2103 /// Utility method to constructs a new HTLCIntercepted-variant Event
2104 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 {
2105 Event::HTLCIntercepted {
2107 requested_next_hop_scid,
2109 inbound_amount_msat,
2110 expected_outbound_amount_msat,
2114 /// Utility method to constructs a new SpendableOutputs-variant Event
2115 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
2116 Event::SpendableOutputs {
2121 /// Utility method to constructs a new PaymentForwarded-variant Event
2122 pub extern "C" fn Event_payment_forwarded(prev_channel_id: crate::c_types::ThirtyTwoBytes, next_channel_id: crate::c_types::ThirtyTwoBytes, fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
2123 Event::PaymentForwarded {
2127 claim_from_onchain_tx,
2131 /// Utility method to constructs a new ChannelReady-variant Event
2132 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 {
2133 Event::ChannelReady {
2136 counterparty_node_id,
2141 /// Utility method to constructs a new ChannelClosed-variant Event
2142 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: crate::c_types::U128, reason: crate::lightning::util::events::ClosureReason) -> Event {
2143 Event::ChannelClosed {
2150 /// Utility method to constructs a new DiscardFunding-variant Event
2151 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
2152 Event::DiscardFunding {
2158 /// Utility method to constructs a new OpenChannelRequest-variant Event
2159 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 {
2160 Event::OpenChannelRequest {
2161 temporary_channel_id,
2162 counterparty_node_id,
2169 /// Utility method to constructs a new HTLCHandlingFailed-variant Event
2170 pub extern "C" fn Event_htlchandling_failed(prev_channel_id: crate::c_types::ThirtyTwoBytes, failed_next_destination: crate::lightning::util::events::HTLCDestination) -> Event {
2171 Event::HTLCHandlingFailed {
2173 failed_next_destination,
2176 /// Checks if two Events contain equal inner contents.
2177 /// This ignores pointers and is_owned flags and looks at the values in fields.
2179 pub extern "C" fn Event_eq(a: &Event, b: &Event) -> bool {
2180 if &a.to_native() == &b.to_native() { true } else { false }
2183 /// Serialize the Event object into a byte array which can be read by Event_read
2184 pub extern "C" fn Event_write(obj: &crate::lightning::util::events::Event) -> crate::c_types::derived::CVec_u8Z {
2185 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
2188 /// Read a Event from a byte array, created by Event_write
2189 pub extern "C" fn Event_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_EventZDecodeErrorZ {
2190 let res: Result<Option<lightning::util::events::Event>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
2191 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_EventZ::None } else { crate::c_types::derived::COption_EventZ::Some( { crate::lightning::util::events::Event::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2194 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
2195 /// broadcast to most peers).
2196 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
2200 pub enum MessageSendEvent {
2201 /// Used to indicate that we've accepted a channel open and should send the accept_channel
2202 /// message provided to the given peer.
2204 /// The node_id of the node which should receive this message
2205 node_id: crate::c_types::PublicKey,
2206 /// The message which should be sent.
2207 msg: crate::lightning::ln::msgs::AcceptChannel,
2209 /// Used to indicate that we've initiated a channel open and should send the open_channel
2210 /// message provided to the given peer.
2212 /// The node_id of the node which should receive this message
2213 node_id: crate::c_types::PublicKey,
2214 /// The message which should be sent.
2215 msg: crate::lightning::ln::msgs::OpenChannel,
2217 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
2218 SendFundingCreated {
2219 /// The node_id of the node which should receive this message
2220 node_id: crate::c_types::PublicKey,
2221 /// The message which should be sent.
2222 msg: crate::lightning::ln::msgs::FundingCreated,
2224 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
2226 /// The node_id of the node which should receive this message
2227 node_id: crate::c_types::PublicKey,
2228 /// The message which should be sent.
2229 msg: crate::lightning::ln::msgs::FundingSigned,
2231 /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
2233 /// The node_id of the node which should receive these message(s)
2234 node_id: crate::c_types::PublicKey,
2235 /// The channel_ready message which should be sent.
2236 msg: crate::lightning::ln::msgs::ChannelReady,
2238 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
2239 SendAnnouncementSignatures {
2240 /// The node_id of the node which should receive these message(s)
2241 node_id: crate::c_types::PublicKey,
2242 /// The announcement_signatures message which should be sent.
2243 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
2245 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
2246 /// message should be sent to the peer with the given node_id.
2248 /// The node_id of the node which should receive these message(s)
2249 node_id: crate::c_types::PublicKey,
2250 /// The update messages which should be sent. ALL messages in the struct should be sent!
2251 updates: crate::lightning::ln::msgs::CommitmentUpdate,
2253 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
2255 /// The node_id of the node which should receive this message
2256 node_id: crate::c_types::PublicKey,
2257 /// The message which should be sent.
2258 msg: crate::lightning::ln::msgs::RevokeAndACK,
2260 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
2262 /// The node_id of the node which should receive this message
2263 node_id: crate::c_types::PublicKey,
2264 /// The message which should be sent.
2265 msg: crate::lightning::ln::msgs::ClosingSigned,
2267 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
2269 /// The node_id of the node which should receive this message
2270 node_id: crate::c_types::PublicKey,
2271 /// The message which should be sent.
2272 msg: crate::lightning::ln::msgs::Shutdown,
2274 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
2275 SendChannelReestablish {
2276 /// The node_id of the node which should receive this message
2277 node_id: crate::c_types::PublicKey,
2278 /// The message which should be sent.
2279 msg: crate::lightning::ln::msgs::ChannelReestablish,
2281 /// Used to send a channel_announcement and channel_update to a specific peer, likely on
2282 /// initial connection to ensure our peers know about our channels.
2283 SendChannelAnnouncement {
2284 /// The node_id of the node which should receive this message
2285 node_id: crate::c_types::PublicKey,
2286 /// The channel_announcement which should be sent.
2287 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
2288 /// The followup channel_update which should be sent.
2289 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
2291 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
2292 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
2294 /// Note that after doing so, you very likely (unless you did so very recently) want to
2295 /// broadcast a node_announcement (e.g. via [`PeerManager::broadcast_node_announcement`]). This
2296 /// ensures that any nodes which see our channel_announcement also have a relevant
2297 /// node_announcement, including relevant feature flags which may be important for routing
2298 /// through or to us.
2300 /// [`PeerManager::broadcast_node_announcement`]: crate::ln::peer_handler::PeerManager::broadcast_node_announcement
2301 BroadcastChannelAnnouncement {
2302 /// The channel_announcement which should be sent.
2303 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
2304 /// The followup channel_update which should be sent.
2306 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
2307 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
2309 /// Used to indicate that a channel_update should be broadcast to all peers.
2310 BroadcastChannelUpdate {
2311 /// The channel_update which should be sent.
2312 msg: crate::lightning::ln::msgs::ChannelUpdate,
2314 /// Used to indicate that a node_announcement should be broadcast to all peers.
2315 BroadcastNodeAnnouncement {
2316 /// The node_announcement which should be sent.
2317 msg: crate::lightning::ln::msgs::NodeAnnouncement,
2319 /// Used to indicate that a channel_update should be sent to a single peer.
2320 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
2321 /// private channel and we shouldn't be informing all of our peers of channel parameters.
2323 /// The node_id of the node which should receive this message
2324 node_id: crate::c_types::PublicKey,
2325 /// The channel_update which should be sent.
2326 msg: crate::lightning::ln::msgs::ChannelUpdate,
2328 /// Broadcast an error downstream to be handled
2330 /// The node_id of the node which should receive this message
2331 node_id: crate::c_types::PublicKey,
2332 /// The action which should be taken.
2333 action: crate::lightning::ln::msgs::ErrorAction,
2335 /// Query a peer for channels with funding transaction UTXOs in a block range.
2336 SendChannelRangeQuery {
2337 /// The node_id of this message recipient
2338 node_id: crate::c_types::PublicKey,
2339 /// The query_channel_range which should be sent.
2340 msg: crate::lightning::ln::msgs::QueryChannelRange,
2342 /// Request routing gossip messages from a peer for a list of channels identified by
2343 /// their short_channel_ids.
2345 /// The node_id of this message recipient
2346 node_id: crate::c_types::PublicKey,
2347 /// The query_short_channel_ids which should be sent.
2348 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
2350 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
2351 /// emitted during processing of the query.
2352 SendReplyChannelRange {
2353 /// The node_id of this message recipient
2354 node_id: crate::c_types::PublicKey,
2355 /// The reply_channel_range which should be sent.
2356 msg: crate::lightning::ln::msgs::ReplyChannelRange,
2358 /// Sends a timestamp filter for inbound gossip. This should be sent on each new connection to
2359 /// enable receiving gossip messages from the peer.
2360 SendGossipTimestampFilter {
2361 /// The node_id of this message recipient
2362 node_id: crate::c_types::PublicKey,
2363 /// The gossip_timestamp_filter which should be sent.
2364 msg: crate::lightning::ln::msgs::GossipTimestampFilter,
2367 use lightning::util::events::MessageSendEvent as MessageSendEventImport;
2368 pub(crate) type nativeMessageSendEvent = MessageSendEventImport;
2370 impl MessageSendEvent {
2372 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
2374 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
2375 let mut node_id_nonref = Clone::clone(node_id);
2376 let mut msg_nonref = Clone::clone(msg);
2377 nativeMessageSendEvent::SendAcceptChannel {
2378 node_id: node_id_nonref.into_rust(),
2379 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2382 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
2383 let mut node_id_nonref = Clone::clone(node_id);
2384 let mut msg_nonref = Clone::clone(msg);
2385 nativeMessageSendEvent::SendOpenChannel {
2386 node_id: node_id_nonref.into_rust(),
2387 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2390 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
2391 let mut node_id_nonref = Clone::clone(node_id);
2392 let mut msg_nonref = Clone::clone(msg);
2393 nativeMessageSendEvent::SendFundingCreated {
2394 node_id: node_id_nonref.into_rust(),
2395 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2398 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
2399 let mut node_id_nonref = Clone::clone(node_id);
2400 let mut msg_nonref = Clone::clone(msg);
2401 nativeMessageSendEvent::SendFundingSigned {
2402 node_id: node_id_nonref.into_rust(),
2403 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2406 MessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
2407 let mut node_id_nonref = Clone::clone(node_id);
2408 let mut msg_nonref = Clone::clone(msg);
2409 nativeMessageSendEvent::SendChannelReady {
2410 node_id: node_id_nonref.into_rust(),
2411 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2414 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
2415 let mut node_id_nonref = Clone::clone(node_id);
2416 let mut msg_nonref = Clone::clone(msg);
2417 nativeMessageSendEvent::SendAnnouncementSignatures {
2418 node_id: node_id_nonref.into_rust(),
2419 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2422 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2423 let mut node_id_nonref = Clone::clone(node_id);
2424 let mut updates_nonref = Clone::clone(updates);
2425 nativeMessageSendEvent::UpdateHTLCs {
2426 node_id: node_id_nonref.into_rust(),
2427 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
2430 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2431 let mut node_id_nonref = Clone::clone(node_id);
2432 let mut msg_nonref = Clone::clone(msg);
2433 nativeMessageSendEvent::SendRevokeAndACK {
2434 node_id: node_id_nonref.into_rust(),
2435 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2438 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2439 let mut node_id_nonref = Clone::clone(node_id);
2440 let mut msg_nonref = Clone::clone(msg);
2441 nativeMessageSendEvent::SendClosingSigned {
2442 node_id: node_id_nonref.into_rust(),
2443 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2446 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
2447 let mut node_id_nonref = Clone::clone(node_id);
2448 let mut msg_nonref = Clone::clone(msg);
2449 nativeMessageSendEvent::SendShutdown {
2450 node_id: node_id_nonref.into_rust(),
2451 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2454 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
2455 let mut node_id_nonref = Clone::clone(node_id);
2456 let mut msg_nonref = Clone::clone(msg);
2457 nativeMessageSendEvent::SendChannelReestablish {
2458 node_id: node_id_nonref.into_rust(),
2459 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2462 MessageSendEvent::SendChannelAnnouncement {ref node_id, ref msg, ref update_msg, } => {
2463 let mut node_id_nonref = Clone::clone(node_id);
2464 let mut msg_nonref = Clone::clone(msg);
2465 let mut update_msg_nonref = Clone::clone(update_msg);
2466 nativeMessageSendEvent::SendChannelAnnouncement {
2467 node_id: node_id_nonref.into_rust(),
2468 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2469 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
2472 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
2473 let mut msg_nonref = Clone::clone(msg);
2474 let mut update_msg_nonref = Clone::clone(update_msg);
2475 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()) } }) };
2476 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2477 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2478 update_msg: local_update_msg_nonref,
2481 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
2482 let mut msg_nonref = Clone::clone(msg);
2483 nativeMessageSendEvent::BroadcastChannelUpdate {
2484 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2487 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
2488 let mut msg_nonref = Clone::clone(msg);
2489 nativeMessageSendEvent::BroadcastNodeAnnouncement {
2490 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2493 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
2494 let mut node_id_nonref = Clone::clone(node_id);
2495 let mut msg_nonref = Clone::clone(msg);
2496 nativeMessageSendEvent::SendChannelUpdate {
2497 node_id: node_id_nonref.into_rust(),
2498 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2501 MessageSendEvent::HandleError {ref node_id, ref action, } => {
2502 let mut node_id_nonref = Clone::clone(node_id);
2503 let mut action_nonref = Clone::clone(action);
2504 nativeMessageSendEvent::HandleError {
2505 node_id: node_id_nonref.into_rust(),
2506 action: action_nonref.into_native(),
2509 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
2510 let mut node_id_nonref = Clone::clone(node_id);
2511 let mut msg_nonref = Clone::clone(msg);
2512 nativeMessageSendEvent::SendChannelRangeQuery {
2513 node_id: node_id_nonref.into_rust(),
2514 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2517 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
2518 let mut node_id_nonref = Clone::clone(node_id);
2519 let mut msg_nonref = Clone::clone(msg);
2520 nativeMessageSendEvent::SendShortIdsQuery {
2521 node_id: node_id_nonref.into_rust(),
2522 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2525 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
2526 let mut node_id_nonref = Clone::clone(node_id);
2527 let mut msg_nonref = Clone::clone(msg);
2528 nativeMessageSendEvent::SendReplyChannelRange {
2529 node_id: node_id_nonref.into_rust(),
2530 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2533 MessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
2534 let mut node_id_nonref = Clone::clone(node_id);
2535 let mut msg_nonref = Clone::clone(msg);
2536 nativeMessageSendEvent::SendGossipTimestampFilter {
2537 node_id: node_id_nonref.into_rust(),
2538 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2544 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
2546 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
2547 nativeMessageSendEvent::SendAcceptChannel {
2548 node_id: node_id.into_rust(),
2549 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2552 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
2553 nativeMessageSendEvent::SendOpenChannel {
2554 node_id: node_id.into_rust(),
2555 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2558 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
2559 nativeMessageSendEvent::SendFundingCreated {
2560 node_id: node_id.into_rust(),
2561 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2564 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
2565 nativeMessageSendEvent::SendFundingSigned {
2566 node_id: node_id.into_rust(),
2567 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2570 MessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
2571 nativeMessageSendEvent::SendChannelReady {
2572 node_id: node_id.into_rust(),
2573 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2576 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
2577 nativeMessageSendEvent::SendAnnouncementSignatures {
2578 node_id: node_id.into_rust(),
2579 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2582 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
2583 nativeMessageSendEvent::UpdateHTLCs {
2584 node_id: node_id.into_rust(),
2585 updates: *unsafe { Box::from_raw(updates.take_inner()) },
2588 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
2589 nativeMessageSendEvent::SendRevokeAndACK {
2590 node_id: node_id.into_rust(),
2591 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2594 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
2595 nativeMessageSendEvent::SendClosingSigned {
2596 node_id: node_id.into_rust(),
2597 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2600 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
2601 nativeMessageSendEvent::SendShutdown {
2602 node_id: node_id.into_rust(),
2603 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2606 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
2607 nativeMessageSendEvent::SendChannelReestablish {
2608 node_id: node_id.into_rust(),
2609 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2612 MessageSendEvent::SendChannelAnnouncement {mut node_id, mut msg, mut update_msg, } => {
2613 nativeMessageSendEvent::SendChannelAnnouncement {
2614 node_id: node_id.into_rust(),
2615 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2616 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
2619 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
2620 let mut local_update_msg = if update_msg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(update_msg.take_inner()) } }) };
2621 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2622 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2623 update_msg: local_update_msg,
2626 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
2627 nativeMessageSendEvent::BroadcastChannelUpdate {
2628 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2631 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
2632 nativeMessageSendEvent::BroadcastNodeAnnouncement {
2633 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2636 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
2637 nativeMessageSendEvent::SendChannelUpdate {
2638 node_id: node_id.into_rust(),
2639 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2642 MessageSendEvent::HandleError {mut node_id, mut action, } => {
2643 nativeMessageSendEvent::HandleError {
2644 node_id: node_id.into_rust(),
2645 action: action.into_native(),
2648 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
2649 nativeMessageSendEvent::SendChannelRangeQuery {
2650 node_id: node_id.into_rust(),
2651 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2654 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
2655 nativeMessageSendEvent::SendShortIdsQuery {
2656 node_id: node_id.into_rust(),
2657 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2660 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
2661 nativeMessageSendEvent::SendReplyChannelRange {
2662 node_id: node_id.into_rust(),
2663 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2666 MessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
2667 nativeMessageSendEvent::SendGossipTimestampFilter {
2668 node_id: node_id.into_rust(),
2669 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2675 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
2677 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
2678 let mut node_id_nonref = Clone::clone(node_id);
2679 let mut msg_nonref = Clone::clone(msg);
2680 MessageSendEvent::SendAcceptChannel {
2681 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2682 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2685 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
2686 let mut node_id_nonref = Clone::clone(node_id);
2687 let mut msg_nonref = Clone::clone(msg);
2688 MessageSendEvent::SendOpenChannel {
2689 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2690 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2693 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
2694 let mut node_id_nonref = Clone::clone(node_id);
2695 let mut msg_nonref = Clone::clone(msg);
2696 MessageSendEvent::SendFundingCreated {
2697 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2698 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2701 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
2702 let mut node_id_nonref = Clone::clone(node_id);
2703 let mut msg_nonref = Clone::clone(msg);
2704 MessageSendEvent::SendFundingSigned {
2705 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2706 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2709 nativeMessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
2710 let mut node_id_nonref = Clone::clone(node_id);
2711 let mut msg_nonref = Clone::clone(msg);
2712 MessageSendEvent::SendChannelReady {
2713 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2714 msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2717 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
2718 let mut node_id_nonref = Clone::clone(node_id);
2719 let mut msg_nonref = Clone::clone(msg);
2720 MessageSendEvent::SendAnnouncementSignatures {
2721 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2722 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2725 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2726 let mut node_id_nonref = Clone::clone(node_id);
2727 let mut updates_nonref = Clone::clone(updates);
2728 MessageSendEvent::UpdateHTLCs {
2729 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2730 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
2733 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2734 let mut node_id_nonref = Clone::clone(node_id);
2735 let mut msg_nonref = Clone::clone(msg);
2736 MessageSendEvent::SendRevokeAndACK {
2737 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2738 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2741 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2742 let mut node_id_nonref = Clone::clone(node_id);
2743 let mut msg_nonref = Clone::clone(msg);
2744 MessageSendEvent::SendClosingSigned {
2745 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2746 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2749 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
2750 let mut node_id_nonref = Clone::clone(node_id);
2751 let mut msg_nonref = Clone::clone(msg);
2752 MessageSendEvent::SendShutdown {
2753 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2754 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2757 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
2758 let mut node_id_nonref = Clone::clone(node_id);
2759 let mut msg_nonref = Clone::clone(msg);
2760 MessageSendEvent::SendChannelReestablish {
2761 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2762 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2765 nativeMessageSendEvent::SendChannelAnnouncement {ref node_id, ref msg, ref update_msg, } => {
2766 let mut node_id_nonref = Clone::clone(node_id);
2767 let mut msg_nonref = Clone::clone(msg);
2768 let mut update_msg_nonref = Clone::clone(update_msg);
2769 MessageSendEvent::SendChannelAnnouncement {
2770 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2771 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2772 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
2775 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
2776 let mut msg_nonref = Clone::clone(msg);
2777 let mut update_msg_nonref = Clone::clone(update_msg);
2778 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 };
2779 MessageSendEvent::BroadcastChannelAnnouncement {
2780 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2781 update_msg: local_update_msg_nonref,
2784 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
2785 let mut msg_nonref = Clone::clone(msg);
2786 MessageSendEvent::BroadcastChannelUpdate {
2787 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2790 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
2791 let mut msg_nonref = Clone::clone(msg);
2792 MessageSendEvent::BroadcastNodeAnnouncement {
2793 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2796 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
2797 let mut node_id_nonref = Clone::clone(node_id);
2798 let mut msg_nonref = Clone::clone(msg);
2799 MessageSendEvent::SendChannelUpdate {
2800 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2801 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2804 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
2805 let mut node_id_nonref = Clone::clone(node_id);
2806 let mut action_nonref = Clone::clone(action);
2807 MessageSendEvent::HandleError {
2808 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2809 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
2812 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
2813 let mut node_id_nonref = Clone::clone(node_id);
2814 let mut msg_nonref = Clone::clone(msg);
2815 MessageSendEvent::SendChannelRangeQuery {
2816 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2817 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2820 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
2821 let mut node_id_nonref = Clone::clone(node_id);
2822 let mut msg_nonref = Clone::clone(msg);
2823 MessageSendEvent::SendShortIdsQuery {
2824 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2825 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2828 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
2829 let mut node_id_nonref = Clone::clone(node_id);
2830 let mut msg_nonref = Clone::clone(msg);
2831 MessageSendEvent::SendReplyChannelRange {
2832 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2833 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2836 nativeMessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
2837 let mut node_id_nonref = Clone::clone(node_id);
2838 let mut msg_nonref = Clone::clone(msg);
2839 MessageSendEvent::SendGossipTimestampFilter {
2840 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2841 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2847 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
2849 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
2850 MessageSendEvent::SendAcceptChannel {
2851 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2852 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
2855 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
2856 MessageSendEvent::SendOpenChannel {
2857 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2858 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
2861 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
2862 MessageSendEvent::SendFundingCreated {
2863 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2864 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
2867 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
2868 MessageSendEvent::SendFundingSigned {
2869 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2870 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
2873 nativeMessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
2874 MessageSendEvent::SendChannelReady {
2875 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2876 msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg), is_owned: true },
2879 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
2880 MessageSendEvent::SendAnnouncementSignatures {
2881 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2882 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
2885 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
2886 MessageSendEvent::UpdateHTLCs {
2887 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2888 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
2891 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
2892 MessageSendEvent::SendRevokeAndACK {
2893 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2894 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
2897 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
2898 MessageSendEvent::SendClosingSigned {
2899 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2900 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
2903 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
2904 MessageSendEvent::SendShutdown {
2905 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2906 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
2909 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
2910 MessageSendEvent::SendChannelReestablish {
2911 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2912 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
2915 nativeMessageSendEvent::SendChannelAnnouncement {mut node_id, mut msg, mut update_msg, } => {
2916 MessageSendEvent::SendChannelAnnouncement {
2917 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2918 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
2919 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
2922 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
2923 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 };
2924 MessageSendEvent::BroadcastChannelAnnouncement {
2925 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
2926 update_msg: local_update_msg,
2929 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
2930 MessageSendEvent::BroadcastChannelUpdate {
2931 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
2934 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
2935 MessageSendEvent::BroadcastNodeAnnouncement {
2936 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
2939 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
2940 MessageSendEvent::SendChannelUpdate {
2941 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2942 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
2945 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
2946 MessageSendEvent::HandleError {
2947 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2948 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
2951 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
2952 MessageSendEvent::SendChannelRangeQuery {
2953 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2954 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
2957 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
2958 MessageSendEvent::SendShortIdsQuery {
2959 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2960 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
2963 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
2964 MessageSendEvent::SendReplyChannelRange {
2965 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2966 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
2969 nativeMessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
2970 MessageSendEvent::SendGossipTimestampFilter {
2971 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2972 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg), is_owned: true },
2978 /// Frees any resources used by the MessageSendEvent
2980 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
2981 /// Creates a copy of the MessageSendEvent
2983 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
2987 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
2988 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
2989 MessageSendEvent::SendAcceptChannel {
2995 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
2996 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
2997 MessageSendEvent::SendOpenChannel {
3003 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
3004 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
3005 MessageSendEvent::SendFundingCreated {
3011 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
3012 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
3013 MessageSendEvent::SendFundingSigned {
3019 /// Utility method to constructs a new SendChannelReady-variant MessageSendEvent
3020 pub extern "C" fn MessageSendEvent_send_channel_ready(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReady) -> MessageSendEvent {
3021 MessageSendEvent::SendChannelReady {
3027 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
3028 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
3029 MessageSendEvent::SendAnnouncementSignatures {
3035 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
3036 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
3037 MessageSendEvent::UpdateHTLCs {
3043 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
3044 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
3045 MessageSendEvent::SendRevokeAndACK {
3051 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
3052 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
3053 MessageSendEvent::SendClosingSigned {
3059 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
3060 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
3061 MessageSendEvent::SendShutdown {
3067 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
3068 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
3069 MessageSendEvent::SendChannelReestablish {
3075 /// Utility method to constructs a new SendChannelAnnouncement-variant MessageSendEvent
3076 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 {
3077 MessageSendEvent::SendChannelAnnouncement {
3084 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
3085 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
3086 MessageSendEvent::BroadcastChannelAnnouncement {
3092 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
3093 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
3094 MessageSendEvent::BroadcastChannelUpdate {
3099 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
3100 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
3101 MessageSendEvent::BroadcastNodeAnnouncement {
3106 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
3107 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
3108 MessageSendEvent::SendChannelUpdate {
3114 /// Utility method to constructs a new HandleError-variant MessageSendEvent
3115 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
3116 MessageSendEvent::HandleError {
3122 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
3123 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
3124 MessageSendEvent::SendChannelRangeQuery {
3130 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
3131 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
3132 MessageSendEvent::SendShortIdsQuery {
3138 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
3139 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
3140 MessageSendEvent::SendReplyChannelRange {
3146 /// Utility method to constructs a new SendGossipTimestampFilter-variant MessageSendEvent
3147 pub extern "C" fn MessageSendEvent_send_gossip_timestamp_filter(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::GossipTimestampFilter) -> MessageSendEvent {
3148 MessageSendEvent::SendGossipTimestampFilter {
3153 /// A trait indicating an object may generate message send events
3155 pub struct MessageSendEventsProvider {
3156 /// An opaque pointer which is passed to your function implementations as an argument.
3157 /// This has no meaning in the LDK, and can be NULL or any other value.
3158 pub this_arg: *mut c_void,
3159 /// Gets the list of pending events which were generated by previous actions, clearing the list
3162 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
3163 /// Frees any resources associated with this object given its this_arg pointer.
3164 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3165 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3167 unsafe impl Send for MessageSendEventsProvider {}
3168 unsafe impl Sync for MessageSendEventsProvider {}
3170 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
3171 MessageSendEventsProvider {
3172 this_arg: orig.this_arg,
3173 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
3174 free: Clone::clone(&orig.free),
3178 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
3179 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
3180 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
3181 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
3182 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
3187 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
3188 // directly as a Deref trait in higher-level structs:
3189 impl core::ops::Deref for MessageSendEventsProvider {
3191 fn deref(&self) -> &Self {
3195 /// Calls the free function if one is set
3197 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
3198 impl Drop for MessageSendEventsProvider {
3199 fn drop(&mut self) {
3200 if let Some(f) = self.free {
3205 /// A trait indicating an object may generate onion messages to send
3207 pub struct OnionMessageProvider {
3208 /// An opaque pointer which is passed to your function implementations as an argument.
3209 /// This has no meaning in the LDK, and can be NULL or any other value.
3210 pub this_arg: *mut c_void,
3211 /// Gets the next pending onion message for the peer with the given node id.
3213 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
3215 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,
3216 /// Frees any resources associated with this object given its this_arg pointer.
3217 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3218 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3220 unsafe impl Send for OnionMessageProvider {}
3221 unsafe impl Sync for OnionMessageProvider {}
3223 pub(crate) extern "C" fn OnionMessageProvider_clone_fields(orig: &OnionMessageProvider) -> OnionMessageProvider {
3224 OnionMessageProvider {
3225 this_arg: orig.this_arg,
3226 next_onion_message_for_peer: Clone::clone(&orig.next_onion_message_for_peer),
3227 free: Clone::clone(&orig.free),
3231 use lightning::util::events::OnionMessageProvider as rustOnionMessageProvider;
3232 impl rustOnionMessageProvider for OnionMessageProvider {
3233 fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option<lightning::ln::msgs::OnionMessage> {
3234 let mut ret = (self.next_onion_message_for_peer)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id));
3235 let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) };
3240 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
3241 // directly as a Deref trait in higher-level structs:
3242 impl core::ops::Deref for OnionMessageProvider {
3244 fn deref(&self) -> &Self {
3248 /// Calls the free function if one is set
3250 pub extern "C" fn OnionMessageProvider_free(this_ptr: OnionMessageProvider) { }
3251 impl Drop for OnionMessageProvider {
3252 fn drop(&mut self) {
3253 if let Some(f) = self.free {
3258 /// A trait indicating an object may generate events.
3260 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
3262 /// Implementations of this trait may also feature an async version of event handling, as shown with
3263 /// [`ChannelManager::process_pending_events_async`] and
3264 /// [`ChainMonitor::process_pending_events_async`].
3268 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
3269 /// event since the last invocation.
3271 /// In order to ensure no [`Event`]s are lost, implementors of this trait will persist [`Event`]s
3272 /// and replay any unhandled events on startup. An [`Event`] is considered handled when
3273 /// [`process_pending_events`] returns, thus handlers MUST fully handle [`Event`]s and persist any
3274 /// relevant changes to disk *before* returning.
3276 /// Further, because an application may crash between an [`Event`] being handled and the
3277 /// implementor of this trait being re-serialized, [`Event`] handling must be idempotent - in
3278 /// effect, [`Event`]s may be replayed.
3280 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
3281 /// consult the provider's documentation on the implication of processing events and how a handler
3282 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
3283 /// [`ChainMonitor::process_pending_events`]).
3285 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
3288 /// [`process_pending_events`]: Self::process_pending_events
3289 /// [`handle_event`]: EventHandler::handle_event
3290 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
3291 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
3292 /// [`ChannelManager::process_pending_events_async`]: crate::ln::channelmanager::ChannelManager::process_pending_events_async
3293 /// [`ChainMonitor::process_pending_events_async`]: crate::chain::chainmonitor::ChainMonitor::process_pending_events_async
3295 pub struct EventsProvider {
3296 /// An opaque pointer which is passed to your function implementations as an argument.
3297 /// This has no meaning in the LDK, and can be NULL or any other value.
3298 pub this_arg: *mut c_void,
3299 /// Processes any events generated since the last call using the given event handler.
3301 /// See the trait-level documentation for requirements.
3302 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
3303 /// Frees any resources associated with this object given its this_arg pointer.
3304 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3305 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3307 unsafe impl Send for EventsProvider {}
3308 unsafe impl Sync for EventsProvider {}
3310 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
3312 this_arg: orig.this_arg,
3313 process_pending_events: Clone::clone(&orig.process_pending_events),
3314 free: Clone::clone(&orig.free),
3318 use lightning::util::events::EventsProvider as rustEventsProvider;
3319 /// Calls the free function if one is set
3321 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
3322 impl Drop for EventsProvider {
3323 fn drop(&mut self) {
3324 if let Some(f) = self.free {
3329 /// A trait implemented for objects handling events from [`EventsProvider`].
3331 /// An async variation also exists for implementations of [`EventsProvider`] that support async
3332 /// event handling. The async event handler should satisfy the generic bounds: `F:
3333 /// core::future::Future, H: Fn(Event) -> F`.
3335 pub struct EventHandler {
3336 /// An opaque pointer which is passed to your function implementations as an argument.
3337 /// This has no meaning in the LDK, and can be NULL or any other value.
3338 pub this_arg: *mut c_void,
3339 /// Handles the given [`Event`].
3341 /// See [`EventsProvider`] for details that must be considered when implementing this method.
3342 pub handle_event: extern "C" fn (this_arg: *const c_void, event: crate::lightning::util::events::Event),
3343 /// Frees any resources associated with this object given its this_arg pointer.
3344 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
3345 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
3347 unsafe impl Send for EventHandler {}
3348 unsafe impl Sync for EventHandler {}
3350 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
3352 this_arg: orig.this_arg,
3353 handle_event: Clone::clone(&orig.handle_event),
3354 free: Clone::clone(&orig.free),
3358 use lightning::util::events::EventHandler as rustEventHandler;
3359 impl rustEventHandler for EventHandler {
3360 fn handle_event(&self, mut event: lightning::util::events::Event) {
3361 (self.handle_event)(self.this_arg, crate::lightning::util::events::Event::native_into(event))
3365 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
3366 // directly as a Deref trait in higher-level structs:
3367 impl core::ops::Deref for EventHandler {
3369 fn deref(&self) -> &Self {
3373 /// Calls the free function if one is set
3375 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
3376 impl Drop for EventHandler {
3377 fn drop(&mut self) {
3378 if let Some(f) = self.free {