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.
55 SpontaneousPayment(crate::c_types::ThirtyTwoBytes),
57 use lightning::util::events::PaymentPurpose as nativePaymentPurpose;
60 pub(crate) fn to_native(&self) -> nativePaymentPurpose {
62 PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
63 let mut payment_preimage_nonref = (*payment_preimage).clone();
64 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
65 let mut payment_secret_nonref = (*payment_secret).clone();
66 nativePaymentPurpose::InvoicePayment {
67 payment_preimage: local_payment_preimage_nonref,
68 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
71 PaymentPurpose::SpontaneousPayment (ref a, ) => {
72 let mut a_nonref = (*a).clone();
73 nativePaymentPurpose::SpontaneousPayment (
74 ::lightning::ln::PaymentPreimage(a_nonref.data),
80 pub(crate) fn into_native(self) -> nativePaymentPurpose {
82 PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
83 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
84 nativePaymentPurpose::InvoicePayment {
85 payment_preimage: local_payment_preimage,
86 payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
89 PaymentPurpose::SpontaneousPayment (mut a, ) => {
90 nativePaymentPurpose::SpontaneousPayment (
91 ::lightning::ln::PaymentPreimage(a.data),
97 pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
99 nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
100 let mut payment_preimage_nonref = (*payment_preimage).clone();
101 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 } } };
102 let mut payment_secret_nonref = (*payment_secret).clone();
103 PaymentPurpose::InvoicePayment {
104 payment_preimage: local_payment_preimage_nonref,
105 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
108 nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
109 let mut a_nonref = (*a).clone();
110 PaymentPurpose::SpontaneousPayment (
111 crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
117 pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
119 nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
120 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 } } };
121 PaymentPurpose::InvoicePayment {
122 payment_preimage: local_payment_preimage,
123 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
126 nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
127 PaymentPurpose::SpontaneousPayment (
128 crate::c_types::ThirtyTwoBytes { data: a.0 },
134 /// Frees any resources used by the PaymentPurpose
136 pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
137 /// Creates a copy of the PaymentPurpose
139 pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
143 /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
144 pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
145 PaymentPurpose::InvoicePayment {
151 /// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
152 pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
153 PaymentPurpose::SpontaneousPayment(a, )
155 /// The reason the channel was closed. See individual variants more details.
159 pub enum ClosureReason {
160 /// Closure generated from receiving a peer error message.
162 /// Our counterparty may have broadcasted their latest commitment state, and we have
164 CounterpartyForceClosed {
165 /// The error which the peer sent us.
167 /// The string should be sanitized before it is used (e.g emitted to logs
168 /// or printed to stdout). Otherwise, a well crafted error message may exploit
169 /// a security vulnerability in the terminal emulator or the logging subsystem.
170 peer_msg: crate::c_types::Str,
172 /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
174 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
176 /// The channel was closed after negotiating a cooperative close and we've now broadcasted
177 /// the cooperative close transaction. Note the shutdown may have been initiated by us.
179 /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
180 /// commitment transaction came from our counterparty, but it may also have come from
181 /// a copy of our own `ChannelMonitor`.
182 CommitmentTxConfirmed,
183 /// The funding transaction failed to confirm in a timely manner on an inbound channel.
185 /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
187 /// A developer-readable error message which we generated.
188 err: crate::c_types::Str,
190 /// The `PeerManager` informed us that we've disconnected from the peer. We close channels
191 /// if the `PeerManager` informed us that it is unlikely we'll be able to connect to the
192 /// peer again in the future or if the peer disconnected before we finished negotiating
193 /// the channel open. The first case may be caused by incompatible features which our
194 /// counterparty, or we, require.
196 /// Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than
197 /// the ChannelManager deserialized.
198 OutdatedChannelManager,
200 use lightning::util::events::ClosureReason as nativeClosureReason;
203 pub(crate) fn to_native(&self) -> nativeClosureReason {
205 ClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
206 let mut peer_msg_nonref = (*peer_msg).clone();
207 nativeClosureReason::CounterpartyForceClosed {
208 peer_msg: peer_msg_nonref.into_string(),
211 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
212 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
213 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
214 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
215 ClosureReason::ProcessingError {ref err, } => {
216 let mut err_nonref = (*err).clone();
217 nativeClosureReason::ProcessingError {
218 err: err_nonref.into_string(),
221 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
222 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
226 pub(crate) fn into_native(self) -> nativeClosureReason {
228 ClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
229 nativeClosureReason::CounterpartyForceClosed {
230 peer_msg: peer_msg.into_string(),
233 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
234 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
235 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
236 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
237 ClosureReason::ProcessingError {mut err, } => {
238 nativeClosureReason::ProcessingError {
239 err: err.into_string(),
242 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
243 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
247 pub(crate) fn from_native(native: &nativeClosureReason) -> Self {
249 nativeClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
250 let mut peer_msg_nonref = (*peer_msg).clone();
251 ClosureReason::CounterpartyForceClosed {
252 peer_msg: peer_msg_nonref.into(),
255 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
256 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
257 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
258 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
259 nativeClosureReason::ProcessingError {ref err, } => {
260 let mut err_nonref = (*err).clone();
261 ClosureReason::ProcessingError {
262 err: err_nonref.into(),
265 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
266 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
270 pub(crate) fn native_into(native: nativeClosureReason) -> Self {
272 nativeClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
273 ClosureReason::CounterpartyForceClosed {
274 peer_msg: peer_msg.into(),
277 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
278 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
279 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
280 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
281 nativeClosureReason::ProcessingError {mut err, } => {
282 ClosureReason::ProcessingError {
286 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
287 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
291 /// Frees any resources used by the ClosureReason
293 pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { }
294 /// Creates a copy of the ClosureReason
296 pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason {
300 /// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
301 pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::c_types::Str) -> ClosureReason {
302 ClosureReason::CounterpartyForceClosed {
307 /// Utility method to constructs a new HolderForceClosed-variant ClosureReason
308 pub extern "C" fn ClosureReason_holder_force_closed() -> ClosureReason {
309 ClosureReason::HolderForceClosed}
311 /// Utility method to constructs a new CooperativeClosure-variant ClosureReason
312 pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason {
313 ClosureReason::CooperativeClosure}
315 /// Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
316 pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason {
317 ClosureReason::CommitmentTxConfirmed}
319 /// Utility method to constructs a new FundingTimedOut-variant ClosureReason
320 pub extern "C" fn ClosureReason_funding_timed_out() -> ClosureReason {
321 ClosureReason::FundingTimedOut}
323 /// Utility method to constructs a new ProcessingError-variant ClosureReason
324 pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason {
325 ClosureReason::ProcessingError {
330 /// Utility method to constructs a new DisconnectedPeer-variant ClosureReason
331 pub extern "C" fn ClosureReason_disconnected_peer() -> ClosureReason {
332 ClosureReason::DisconnectedPeer}
334 /// Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
335 pub extern "C" fn ClosureReason_outdated_channel_manager() -> ClosureReason {
336 ClosureReason::OutdatedChannelManager}
338 /// Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
339 pub extern "C" fn ClosureReason_write(obj: &crate::lightning::util::events::ClosureReason) -> crate::c_types::derived::CVec_u8Z {
340 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
343 /// Read a ClosureReason from a byte array, created by ClosureReason_write
344 pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_ClosureReasonZDecodeErrorZ {
345 let res: Result<Option<lightning::util::events::ClosureReason>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
346 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
349 /// An Event which you should probably take some action in response to.
351 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
352 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
353 /// written as it makes no sense to respond to it after reconnecting to peers).
358 /// Used to indicate that the client should generate a funding transaction with the given
359 /// parameters and then call [`ChannelManager::funding_transaction_generated`].
360 /// Generated in [`ChannelManager`] message handling.
361 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
362 /// counterparty can steal your funds!
364 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
365 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
366 FundingGenerationReady {
367 /// The random channel_id we picked which you'll need to pass into
368 /// ChannelManager::funding_transaction_generated.
369 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
370 /// The value, in satoshis, that the output should have.
371 channel_value_satoshis: u64,
372 /// The script which should be used in the transaction output.
373 output_script: crate::c_types::derived::CVec_u8Z,
374 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
375 /// an inbound channel.
377 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
378 user_channel_id: u64,
380 /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
381 /// [`ChannelManager::claim_funds`] to get it....
382 /// Note that if the preimage is not known, you should call
383 /// [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid
384 /// network congestion.
385 /// If you fail to call either [`ChannelManager::claim_funds`] or
386 /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be
387 /// automatically failed.
390 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
391 /// `PaymentReceived` events may be generated for the same payment.
393 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
394 /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
396 /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
397 /// not stop you from registering duplicate payment hashes for inbound payments.
398 payment_hash: crate::c_types::ThirtyTwoBytes,
399 /// The value, in thousandths of a satoshi, that this payment is for.
401 /// Information for claiming this received payment, based on whether the purpose of the
402 /// payment is to pay an invoice or to send a spontaneous payment.
403 purpose: crate::lightning::util::events::PaymentPurpose,
405 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
406 /// and we got back the payment preimage for it).
408 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
409 /// event. In this situation, you SHOULD treat this payment as having succeeded.
411 /// The id returned by [`ChannelManager::send_payment`] and used with
412 /// [`ChannelManager::retry_payment`].
414 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
415 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
417 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
418 payment_id: crate::c_types::ThirtyTwoBytes,
419 /// The preimage to the hash given to ChannelManager::send_payment.
420 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
421 /// store it somehow!
422 payment_preimage: crate::c_types::ThirtyTwoBytes,
423 /// The hash that was given to [`ChannelManager::send_payment`].
425 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
426 payment_hash: crate::c_types::ThirtyTwoBytes,
427 /// The total fee which was spent at intermediate hops in this payment, across all paths.
429 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
430 /// overpayment to the recipient node.
432 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
433 /// overstate the amount paid, though this is unlikely.
435 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
436 fee_paid_msat: crate::c_types::derived::COption_u64Z,
438 /// Indicates an outbound HTLC we sent failed. Probably some intermediary node dropped
439 /// something. You may wish to retry with a different route.
441 /// Note that this does *not* indicate that all paths for an MPP payment have failed, see
442 /// [`Event::PaymentFailed`] and [`all_paths_failed`].
444 /// [`all_paths_failed`]: Self::PaymentPathFailed::all_paths_failed
446 /// The id returned by [`ChannelManager::send_payment`] and used with
447 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
449 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
450 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
451 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
453 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
454 payment_id: crate::c_types::ThirtyTwoBytes,
455 /// The hash that was given to [`ChannelManager::send_payment`].
457 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
458 payment_hash: crate::c_types::ThirtyTwoBytes,
459 /// Indicates the payment was rejected for some reason by the recipient. This implies that
460 /// the payment has failed, not just the route in question. If this is not set, you may
461 /// retry the payment via a different route.
462 rejected_by_dest: bool,
463 /// Any failure information conveyed via the Onion return packet by a node along the failed
466 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
467 /// account the update. [`NetGraphMsgHandler`] is capable of doing this.
469 /// [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph
470 /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
471 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
472 /// For both single-path and multi-path payments, this is set if all paths of the payment have
473 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
474 /// larger MPP payment were still in flight when this event was generated.
476 /// Note that if you are retrying individual MPP parts, using this value to determine if a
477 /// payment has fully failed is race-y. Because multiple failures can happen prior to events
478 /// being processed, you may retry in response to a first failure, with a second failure
479 /// (with `all_paths_failed` set) still pending. Then, when the second failure is processed
480 /// you will see `all_paths_failed` set even though the retry of the first failure still
481 /// has an associated in-flight HTLC. See (1) for an example of such a failure.
483 /// If you wish to retry individual MPP parts and learn when a payment has failed, you must
484 /// call [`ChannelManager::abandon_payment`] and wait for a [`Event::PaymentFailed`] event.
486 /// (1) <https://github.com/lightningdevkit/rust-lightning/issues/1164>
488 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
489 all_paths_failed: bool,
490 /// The payment path that failed.
491 path: crate::c_types::derived::CVec_RouteHopZ,
492 /// The channel responsible for the failed payment path.
494 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
495 /// retried. May be `None` for older [`Event`] serializations.
496 short_channel_id: crate::c_types::derived::COption_u64Z,
497 /// Parameters needed to compute a new [`Route`] when retrying the failed payment path.
499 /// See [`find_route`] for details.
501 /// [`Route`]: crate::routing::router::Route
502 /// [`find_route`]: crate::routing::router::find_route
504 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
505 retry: crate::lightning::routing::router::RouteParameters,
507 /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
508 /// provide failure information for each MPP part in the payment.
510 /// This event is provided once there are no further pending HTLCs for the payment and the
511 /// payment is no longer retryable, either due to a several-block timeout or because
512 /// [`ChannelManager::abandon_payment`] was previously called for the corresponding payment.
514 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
516 /// The id returned by [`ChannelManager::send_payment`] and used with
517 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
519 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
520 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
521 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
522 payment_id: crate::c_types::ThirtyTwoBytes,
523 /// The hash that was given to [`ChannelManager::send_payment`].
525 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
526 payment_hash: crate::c_types::ThirtyTwoBytes,
528 /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
529 /// a time in the future.
531 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
532 PendingHTLCsForwardable {
533 /// The minimum amount of time that should be waited prior to calling
534 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
535 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
536 /// now + 5*time_forwardable).
537 time_forwardable: u64,
539 /// Used to indicate that an output which you should know how to spend was confirmed on chain
540 /// and is now spendable.
541 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
542 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
543 /// somewhere and spend them when you create on-chain transactions.
545 /// The outputs which you should store as spendable by you.
546 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
548 /// This event is generated when a payment has been successfully forwarded through us and a
549 /// forwarding fee earned.
551 /// The fee, in milli-satoshis, which was earned as a result of the payment.
553 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
554 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
555 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
556 /// claimed the full value in millisatoshis from the source. In this case,
557 /// `claim_from_onchain_tx` will be set.
559 /// If the channel which sent us the payment has been force-closed, we will claim the funds
560 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
561 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
562 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
564 fee_earned_msat: crate::c_types::derived::COption_u64Z,
565 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
567 claim_from_onchain_tx: bool,
569 /// Used to indicate that a channel with the given `channel_id` is in the process of closure.
571 /// The channel_id of the channel which has been closed. Note that on-chain transactions
572 /// resolving the channel are likely still awaiting confirmation.
573 channel_id: crate::c_types::ThirtyTwoBytes,
574 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
575 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
576 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
577 /// `user_channel_id` will be 0 for an inbound channel.
578 /// This will always be zero for objects serialized with LDK versions prior to 0.0.102.
580 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
581 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
582 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
583 user_channel_id: u64,
584 /// The reason the channel was closed.
585 reason: crate::lightning::util::events::ClosureReason,
587 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
588 /// inputs for another purpose.
590 /// The channel_id of the channel which has been closed.
591 channel_id: crate::c_types::ThirtyTwoBytes,
592 /// The full transaction received from the user
593 transaction: crate::c_types::Transaction,
595 /// Indicates that a path for an outbound payment was successful.
597 /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
598 /// [`Event::PaymentSent`] for obtaining the payment preimage.
599 PaymentPathSuccessful {
600 /// The id returned by [`ChannelManager::send_payment`] and used with
601 /// [`ChannelManager::retry_payment`].
603 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
604 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
605 payment_id: crate::c_types::ThirtyTwoBytes,
606 /// The hash that was given to [`ChannelManager::send_payment`].
608 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
610 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
611 payment_hash: crate::c_types::ThirtyTwoBytes,
612 /// The payment path that was successful.
614 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
615 path: crate::c_types::derived::CVec_RouteHopZ,
617 /// Indicates a request to open a new channel by a peer.
619 /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the
620 /// request, call [`ChannelManager::force_close_channel`].
622 /// The event is only triggered when a new open channel request is received and the
623 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
625 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
626 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel
627 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
629 /// The temporary channel ID of the channel requested to be opened.
631 /// When responding to the request, the `temporary_channel_id` should be passed
632 /// back to the ChannelManager with [`ChannelManager::accept_inbound_channel`] to accept,
633 /// or to [`ChannelManager::force_close_channel`] to reject.
635 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
636 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel
637 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
638 /// The node_id of the counterparty requesting to open the channel.
639 counterparty_node_id: crate::c_types::PublicKey,
640 /// The channel value of the requested channel.
641 funding_satoshis: u64,
642 /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
644 /// The features that this channel will operate with. If you reject the channel, a
645 /// well-behaved counterparty may automatically re-attempt the channel with a new set of
648 /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
649 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
652 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
653 channel_type: crate::lightning::ln::features::ChannelTypeFeatures,
656 use lightning::util::events::Event as nativeEvent;
659 pub(crate) fn to_native(&self) -> nativeEvent {
661 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
662 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
663 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
664 let mut output_script_nonref = (*output_script).clone();
665 let mut user_channel_id_nonref = (*user_channel_id).clone();
666 nativeEvent::FundingGenerationReady {
667 temporary_channel_id: temporary_channel_id_nonref.data,
668 channel_value_satoshis: channel_value_satoshis_nonref,
669 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
670 user_channel_id: user_channel_id_nonref,
673 Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
674 let mut payment_hash_nonref = (*payment_hash).clone();
675 let mut amt_nonref = (*amt).clone();
676 let mut purpose_nonref = (*purpose).clone();
677 nativeEvent::PaymentReceived {
678 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
680 purpose: purpose_nonref.into_native(),
683 Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
684 let mut payment_id_nonref = (*payment_id).clone();
685 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
686 let mut payment_preimage_nonref = (*payment_preimage).clone();
687 let mut payment_hash_nonref = (*payment_hash).clone();
688 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
689 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
690 nativeEvent::PaymentSent {
691 payment_id: local_payment_id_nonref,
692 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
693 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
694 fee_paid_msat: local_fee_paid_msat_nonref,
697 Event::PaymentPathFailed {ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, ref retry, } => {
698 let mut payment_id_nonref = (*payment_id).clone();
699 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
700 let mut payment_hash_nonref = (*payment_hash).clone();
701 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
702 let mut network_update_nonref = (*network_update).clone();
703 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() }) } };
704 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
705 let mut path_nonref = (*path).clone();
706 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()) } }); };
707 let mut short_channel_id_nonref = (*short_channel_id).clone();
708 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
709 let mut retry_nonref = (*retry).clone();
710 let mut local_retry_nonref = if retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry_nonref.take_inner()) } }) };
711 nativeEvent::PaymentPathFailed {
712 payment_id: local_payment_id_nonref,
713 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
714 rejected_by_dest: rejected_by_dest_nonref,
715 network_update: local_network_update_nonref,
716 all_paths_failed: all_paths_failed_nonref,
717 path: local_path_nonref,
718 short_channel_id: local_short_channel_id_nonref,
719 retry: local_retry_nonref,
722 Event::PaymentFailed {ref payment_id, ref payment_hash, } => {
723 let mut payment_id_nonref = (*payment_id).clone();
724 let mut payment_hash_nonref = (*payment_hash).clone();
725 nativeEvent::PaymentFailed {
726 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
727 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
730 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
731 let mut time_forwardable_nonref = (*time_forwardable).clone();
732 nativeEvent::PendingHTLCsForwardable {
733 time_forwardable: core::time::Duration::from_secs(time_forwardable_nonref),
736 Event::SpendableOutputs {ref outputs, } => {
737 let mut outputs_nonref = (*outputs).clone();
738 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
739 nativeEvent::SpendableOutputs {
740 outputs: local_outputs_nonref,
743 Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
744 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
745 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
746 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
747 nativeEvent::PaymentForwarded {
748 fee_earned_msat: local_fee_earned_msat_nonref,
749 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
752 Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
753 let mut channel_id_nonref = (*channel_id).clone();
754 let mut user_channel_id_nonref = (*user_channel_id).clone();
755 let mut reason_nonref = (*reason).clone();
756 nativeEvent::ChannelClosed {
757 channel_id: channel_id_nonref.data,
758 user_channel_id: user_channel_id_nonref,
759 reason: reason_nonref.into_native(),
762 Event::DiscardFunding {ref channel_id, ref transaction, } => {
763 let mut channel_id_nonref = (*channel_id).clone();
764 let mut transaction_nonref = (*transaction).clone();
765 nativeEvent::DiscardFunding {
766 channel_id: channel_id_nonref.data,
767 transaction: transaction_nonref.into_bitcoin(),
770 Event::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
771 let mut payment_id_nonref = (*payment_id).clone();
772 let mut payment_hash_nonref = (*payment_hash).clone();
773 let mut local_payment_hash_nonref = if payment_hash_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash_nonref.data) }) };
774 let mut path_nonref = (*path).clone();
775 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()) } }); };
776 nativeEvent::PaymentPathSuccessful {
777 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
778 payment_hash: local_payment_hash_nonref,
779 path: local_path_nonref,
782 Event::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
783 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
784 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
785 let mut funding_satoshis_nonref = (*funding_satoshis).clone();
786 let mut push_msat_nonref = (*push_msat).clone();
787 let mut channel_type_nonref = (*channel_type).clone();
788 nativeEvent::OpenChannelRequest {
789 temporary_channel_id: temporary_channel_id_nonref.data,
790 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
791 funding_satoshis: funding_satoshis_nonref,
792 push_msat: push_msat_nonref,
793 channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) },
799 pub(crate) fn into_native(self) -> nativeEvent {
801 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
802 nativeEvent::FundingGenerationReady {
803 temporary_channel_id: temporary_channel_id.data,
804 channel_value_satoshis: channel_value_satoshis,
805 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
806 user_channel_id: user_channel_id,
809 Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
810 nativeEvent::PaymentReceived {
811 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
813 purpose: purpose.into_native(),
816 Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
817 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
818 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
819 nativeEvent::PaymentSent {
820 payment_id: local_payment_id,
821 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
822 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
823 fee_paid_msat: local_fee_paid_msat,
826 Event::PaymentPathFailed {mut payment_id, mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, mut retry, } => {
827 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
828 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() }) } };
829 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
830 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
831 let mut local_retry = if retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry.take_inner()) } }) };
832 nativeEvent::PaymentPathFailed {
833 payment_id: local_payment_id,
834 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
835 rejected_by_dest: rejected_by_dest,
836 network_update: local_network_update,
837 all_paths_failed: all_paths_failed,
839 short_channel_id: local_short_channel_id,
843 Event::PaymentFailed {mut payment_id, mut payment_hash, } => {
844 nativeEvent::PaymentFailed {
845 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
846 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
849 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
850 nativeEvent::PendingHTLCsForwardable {
851 time_forwardable: core::time::Duration::from_secs(time_forwardable),
854 Event::SpendableOutputs {mut outputs, } => {
855 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
856 nativeEvent::SpendableOutputs {
857 outputs: local_outputs,
860 Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
861 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
862 nativeEvent::PaymentForwarded {
863 fee_earned_msat: local_fee_earned_msat,
864 claim_from_onchain_tx: claim_from_onchain_tx,
867 Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
868 nativeEvent::ChannelClosed {
869 channel_id: channel_id.data,
870 user_channel_id: user_channel_id,
871 reason: reason.into_native(),
874 Event::DiscardFunding {mut channel_id, mut transaction, } => {
875 nativeEvent::DiscardFunding {
876 channel_id: channel_id.data,
877 transaction: transaction.into_bitcoin(),
880 Event::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
881 let mut local_payment_hash = if payment_hash.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash.data) }) };
882 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
883 nativeEvent::PaymentPathSuccessful {
884 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
885 payment_hash: local_payment_hash,
889 Event::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
890 nativeEvent::OpenChannelRequest {
891 temporary_channel_id: temporary_channel_id.data,
892 counterparty_node_id: counterparty_node_id.into_rust(),
893 funding_satoshis: funding_satoshis,
894 push_msat: push_msat,
895 channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) },
901 pub(crate) fn from_native(native: &nativeEvent) -> Self {
903 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
904 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
905 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
906 let mut output_script_nonref = (*output_script).clone();
907 let mut user_channel_id_nonref = (*user_channel_id).clone();
908 Event::FundingGenerationReady {
909 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
910 channel_value_satoshis: channel_value_satoshis_nonref,
911 output_script: output_script_nonref.into_bytes().into(),
912 user_channel_id: user_channel_id_nonref,
915 nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
916 let mut payment_hash_nonref = (*payment_hash).clone();
917 let mut amt_nonref = (*amt).clone();
918 let mut purpose_nonref = (*purpose).clone();
919 Event::PaymentReceived {
920 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
922 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
925 nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
926 let mut payment_id_nonref = (*payment_id).clone();
927 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 } } };
928 let mut payment_preimage_nonref = (*payment_preimage).clone();
929 let mut payment_hash_nonref = (*payment_hash).clone();
930 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
931 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() }) };
933 payment_id: local_payment_id_nonref,
934 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
935 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
936 fee_paid_msat: local_fee_paid_msat_nonref,
939 nativeEvent::PaymentPathFailed {ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, ref retry, } => {
940 let mut payment_id_nonref = (*payment_id).clone();
941 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 } } };
942 let mut payment_hash_nonref = (*payment_hash).clone();
943 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
944 let mut network_update_nonref = (*network_update).clone();
945 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::network_graph::NetworkUpdate::native_into(network_update_nonref.unwrap()) }) };
946 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
947 let mut path_nonref = (*path).clone();
948 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 } }); };
949 let mut short_channel_id_nonref = (*short_channel_id).clone();
950 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() }) };
951 let mut retry_nonref = (*retry).clone();
952 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 };
953 Event::PaymentPathFailed {
954 payment_id: local_payment_id_nonref,
955 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
956 rejected_by_dest: rejected_by_dest_nonref,
957 network_update: local_network_update_nonref,
958 all_paths_failed: all_paths_failed_nonref,
959 path: local_path_nonref.into(),
960 short_channel_id: local_short_channel_id_nonref,
961 retry: local_retry_nonref,
964 nativeEvent::PaymentFailed {ref payment_id, ref payment_hash, } => {
965 let mut payment_id_nonref = (*payment_id).clone();
966 let mut payment_hash_nonref = (*payment_hash).clone();
967 Event::PaymentFailed {
968 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
969 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
972 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
973 let mut time_forwardable_nonref = (*time_forwardable).clone();
974 Event::PendingHTLCsForwardable {
975 time_forwardable: time_forwardable_nonref.as_secs(),
978 nativeEvent::SpendableOutputs {ref outputs, } => {
979 let mut outputs_nonref = (*outputs).clone();
980 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) }); };
981 Event::SpendableOutputs {
982 outputs: local_outputs_nonref.into(),
985 nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
986 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
987 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() }) };
988 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
989 Event::PaymentForwarded {
990 fee_earned_msat: local_fee_earned_msat_nonref,
991 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
994 nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
995 let mut channel_id_nonref = (*channel_id).clone();
996 let mut user_channel_id_nonref = (*user_channel_id).clone();
997 let mut reason_nonref = (*reason).clone();
998 Event::ChannelClosed {
999 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1000 user_channel_id: user_channel_id_nonref,
1001 reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
1004 nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
1005 let mut channel_id_nonref = (*channel_id).clone();
1006 let mut transaction_nonref = (*transaction).clone();
1007 Event::DiscardFunding {
1008 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1009 transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
1012 nativeEvent::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1013 let mut payment_id_nonref = (*payment_id).clone();
1014 let mut payment_hash_nonref = (*payment_hash).clone();
1015 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 } } };
1016 let mut path_nonref = (*path).clone();
1017 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 } }); };
1018 Event::PaymentPathSuccessful {
1019 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1020 payment_hash: local_payment_hash_nonref,
1021 path: local_path_nonref.into(),
1024 nativeEvent::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1025 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
1026 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
1027 let mut funding_satoshis_nonref = (*funding_satoshis).clone();
1028 let mut push_msat_nonref = (*push_msat).clone();
1029 let mut channel_type_nonref = (*channel_type).clone();
1030 Event::OpenChannelRequest {
1031 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1032 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1033 funding_satoshis: funding_satoshis_nonref,
1034 push_msat: push_msat_nonref,
1035 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true },
1041 pub(crate) fn native_into(native: nativeEvent) -> Self {
1043 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1044 Event::FundingGenerationReady {
1045 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1046 channel_value_satoshis: channel_value_satoshis,
1047 output_script: output_script.into_bytes().into(),
1048 user_channel_id: user_channel_id,
1051 nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
1052 Event::PaymentReceived {
1053 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1055 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
1058 nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1059 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 } } };
1060 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() }) };
1061 Event::PaymentSent {
1062 payment_id: local_payment_id,
1063 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
1064 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1065 fee_paid_msat: local_fee_paid_msat,
1068 nativeEvent::PaymentPathFailed {mut payment_id, mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, mut retry, } => {
1069 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 } } };
1070 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::network_graph::NetworkUpdate::native_into(network_update.unwrap()) }) };
1071 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 } }); };
1072 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() }) };
1073 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 };
1074 Event::PaymentPathFailed {
1075 payment_id: local_payment_id,
1076 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1077 rejected_by_dest: rejected_by_dest,
1078 network_update: local_network_update,
1079 all_paths_failed: all_paths_failed,
1080 path: local_path.into(),
1081 short_channel_id: local_short_channel_id,
1085 nativeEvent::PaymentFailed {mut payment_id, mut payment_hash, } => {
1086 Event::PaymentFailed {
1087 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1088 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1091 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
1092 Event::PendingHTLCsForwardable {
1093 time_forwardable: time_forwardable.as_secs(),
1096 nativeEvent::SpendableOutputs {mut outputs, } => {
1097 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
1098 Event::SpendableOutputs {
1099 outputs: local_outputs.into(),
1102 nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1103 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() }) };
1104 Event::PaymentForwarded {
1105 fee_earned_msat: local_fee_earned_msat,
1106 claim_from_onchain_tx: claim_from_onchain_tx,
1109 nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1110 Event::ChannelClosed {
1111 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1112 user_channel_id: user_channel_id,
1113 reason: crate::lightning::util::events::ClosureReason::native_into(reason),
1116 nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
1117 Event::DiscardFunding {
1118 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1119 transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
1122 nativeEvent::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1123 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 } } };
1124 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 } }); };
1125 Event::PaymentPathSuccessful {
1126 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1127 payment_hash: local_payment_hash,
1128 path: local_path.into(),
1131 nativeEvent::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1132 Event::OpenChannelRequest {
1133 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1134 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1135 funding_satoshis: funding_satoshis,
1136 push_msat: push_msat,
1137 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true },
1143 /// Frees any resources used by the Event
1145 pub extern "C" fn Event_free(this_ptr: Event) { }
1146 /// Creates a copy of the Event
1148 pub extern "C" fn Event_clone(orig: &Event) -> Event {
1152 /// Utility method to constructs a new FundingGenerationReady-variant Event
1153 pub extern "C" fn Event_funding_generation_ready(temporary_channel_id: crate::c_types::ThirtyTwoBytes, channel_value_satoshis: u64, output_script: crate::c_types::derived::CVec_u8Z, user_channel_id: u64) -> Event {
1154 Event::FundingGenerationReady {
1155 temporary_channel_id,
1156 channel_value_satoshis,
1162 /// Utility method to constructs a new PaymentReceived-variant Event
1163 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
1164 Event::PaymentReceived {
1171 /// Utility method to constructs a new PaymentSent-variant Event
1172 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 {
1173 Event::PaymentSent {
1181 /// Utility method to constructs a new PaymentPathFailed-variant Event
1182 pub extern "C" fn Event_payment_path_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, rejected_by_dest: bool, network_update: crate::c_types::derived::COption_NetworkUpdateZ, all_paths_failed: bool, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z, retry: crate::lightning::routing::router::RouteParameters) -> Event {
1183 Event::PaymentPathFailed {
1195 /// Utility method to constructs a new PaymentFailed-variant Event
1196 pub extern "C" fn Event_payment_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> Event {
1197 Event::PaymentFailed {
1203 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
1204 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
1205 Event::PendingHTLCsForwardable {
1210 /// Utility method to constructs a new SpendableOutputs-variant Event
1211 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
1212 Event::SpendableOutputs {
1217 /// Utility method to constructs a new PaymentForwarded-variant Event
1218 pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
1219 Event::PaymentForwarded {
1221 claim_from_onchain_tx,
1225 /// Utility method to constructs a new ChannelClosed-variant Event
1226 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: u64, reason: crate::lightning::util::events::ClosureReason) -> Event {
1227 Event::ChannelClosed {
1234 /// Utility method to constructs a new DiscardFunding-variant Event
1235 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
1236 Event::DiscardFunding {
1242 /// Utility method to constructs a new PaymentPathSuccessful-variant Event
1243 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 {
1244 Event::PaymentPathSuccessful {
1251 /// Utility method to constructs a new OpenChannelRequest-variant Event
1252 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 {
1253 Event::OpenChannelRequest {
1254 temporary_channel_id,
1255 counterparty_node_id,
1262 /// Serialize the Event object into a byte array which can be read by Event_read
1263 pub extern "C" fn Event_write(obj: &crate::lightning::util::events::Event) -> crate::c_types::derived::CVec_u8Z {
1264 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
1267 /// Read a Event from a byte array, created by Event_write
1268 pub extern "C" fn Event_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_EventZDecodeErrorZ {
1269 let res: Result<Option<lightning::util::events::Event>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
1270 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1273 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1274 /// broadcast to most peers).
1275 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1279 pub enum MessageSendEvent {
1280 /// Used to indicate that we've accepted a channel open and should send the accept_channel
1281 /// message provided to the given peer.
1283 /// The node_id of the node which should receive this message
1284 node_id: crate::c_types::PublicKey,
1285 /// The message which should be sent.
1286 msg: crate::lightning::ln::msgs::AcceptChannel,
1288 /// Used to indicate that we've initiated a channel open and should send the open_channel
1289 /// message provided to the given peer.
1291 /// The node_id of the node which should receive this message
1292 node_id: crate::c_types::PublicKey,
1293 /// The message which should be sent.
1294 msg: crate::lightning::ln::msgs::OpenChannel,
1296 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1297 SendFundingCreated {
1298 /// The node_id of the node which should receive this message
1299 node_id: crate::c_types::PublicKey,
1300 /// The message which should be sent.
1301 msg: crate::lightning::ln::msgs::FundingCreated,
1303 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
1305 /// The node_id of the node which should receive this message
1306 node_id: crate::c_types::PublicKey,
1307 /// The message which should be sent.
1308 msg: crate::lightning::ln::msgs::FundingSigned,
1310 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
1312 /// The node_id of the node which should receive these message(s)
1313 node_id: crate::c_types::PublicKey,
1314 /// The funding_locked message which should be sent.
1315 msg: crate::lightning::ln::msgs::FundingLocked,
1317 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1318 SendAnnouncementSignatures {
1319 /// The node_id of the node which should receive these message(s)
1320 node_id: crate::c_types::PublicKey,
1321 /// The announcement_signatures message which should be sent.
1322 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
1324 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1325 /// message should be sent to the peer with the given node_id.
1327 /// The node_id of the node which should receive these message(s)
1328 node_id: crate::c_types::PublicKey,
1329 /// The update messages which should be sent. ALL messages in the struct should be sent!
1330 updates: crate::lightning::ln::msgs::CommitmentUpdate,
1332 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1334 /// The node_id of the node which should receive this message
1335 node_id: crate::c_types::PublicKey,
1336 /// The message which should be sent.
1337 msg: crate::lightning::ln::msgs::RevokeAndACK,
1339 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1341 /// The node_id of the node which should receive this message
1342 node_id: crate::c_types::PublicKey,
1343 /// The message which should be sent.
1344 msg: crate::lightning::ln::msgs::ClosingSigned,
1346 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
1348 /// The node_id of the node which should receive this message
1349 node_id: crate::c_types::PublicKey,
1350 /// The message which should be sent.
1351 msg: crate::lightning::ln::msgs::Shutdown,
1353 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1354 SendChannelReestablish {
1355 /// The node_id of the node which should receive this message
1356 node_id: crate::c_types::PublicKey,
1357 /// The message which should be sent.
1358 msg: crate::lightning::ln::msgs::ChannelReestablish,
1360 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1361 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1363 /// Note that after doing so, you very likely (unless you did so very recently) want to call
1364 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
1365 /// This ensures that any nodes which see our channel_announcement also have a relevant
1366 /// node_announcement, including relevant feature flags which may be important for routing
1367 /// through or to us.
1368 BroadcastChannelAnnouncement {
1369 /// The channel_announcement which should be sent.
1370 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
1371 /// The followup channel_update which should be sent.
1372 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
1374 /// Used to indicate that a node_announcement should be broadcast to all peers.
1375 BroadcastNodeAnnouncement {
1376 /// The node_announcement which should be sent.
1377 msg: crate::lightning::ln::msgs::NodeAnnouncement,
1379 /// Used to indicate that a channel_update should be broadcast to all peers.
1380 BroadcastChannelUpdate {
1381 /// The channel_update which should be sent.
1382 msg: crate::lightning::ln::msgs::ChannelUpdate,
1384 /// Used to indicate that a channel_update should be sent to a single peer.
1385 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1386 /// private channel and we shouldn't be informing all of our peers of channel parameters.
1388 /// The node_id of the node which should receive this message
1389 node_id: crate::c_types::PublicKey,
1390 /// The channel_update which should be sent.
1391 msg: crate::lightning::ln::msgs::ChannelUpdate,
1393 /// Broadcast an error downstream to be handled
1395 /// The node_id of the node which should receive this message
1396 node_id: crate::c_types::PublicKey,
1397 /// The action which should be taken.
1398 action: crate::lightning::ln::msgs::ErrorAction,
1400 /// Query a peer for channels with funding transaction UTXOs in a block range.
1401 SendChannelRangeQuery {
1402 /// The node_id of this message recipient
1403 node_id: crate::c_types::PublicKey,
1404 /// The query_channel_range which should be sent.
1405 msg: crate::lightning::ln::msgs::QueryChannelRange,
1407 /// Request routing gossip messages from a peer for a list of channels identified by
1408 /// their short_channel_ids.
1410 /// The node_id of this message recipient
1411 node_id: crate::c_types::PublicKey,
1412 /// The query_short_channel_ids which should be sent.
1413 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
1415 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1416 /// emitted during processing of the query.
1417 SendReplyChannelRange {
1418 /// The node_id of this message recipient
1419 node_id: crate::c_types::PublicKey,
1420 /// The reply_channel_range which should be sent.
1421 msg: crate::lightning::ln::msgs::ReplyChannelRange,
1423 /// Sends a timestamp filter for inbound gossip. This should be sent on each new connection to
1424 /// enable receiving gossip messages from the peer.
1425 SendGossipTimestampFilter {
1426 /// The node_id of this message recipient
1427 node_id: crate::c_types::PublicKey,
1428 /// The gossip_timestamp_filter which should be sent.
1429 msg: crate::lightning::ln::msgs::GossipTimestampFilter,
1432 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
1433 impl MessageSendEvent {
1435 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
1437 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1438 let mut node_id_nonref = (*node_id).clone();
1439 let mut msg_nonref = (*msg).clone();
1440 nativeMessageSendEvent::SendAcceptChannel {
1441 node_id: node_id_nonref.into_rust(),
1442 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1445 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1446 let mut node_id_nonref = (*node_id).clone();
1447 let mut msg_nonref = (*msg).clone();
1448 nativeMessageSendEvent::SendOpenChannel {
1449 node_id: node_id_nonref.into_rust(),
1450 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1453 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1454 let mut node_id_nonref = (*node_id).clone();
1455 let mut msg_nonref = (*msg).clone();
1456 nativeMessageSendEvent::SendFundingCreated {
1457 node_id: node_id_nonref.into_rust(),
1458 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1461 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1462 let mut node_id_nonref = (*node_id).clone();
1463 let mut msg_nonref = (*msg).clone();
1464 nativeMessageSendEvent::SendFundingSigned {
1465 node_id: node_id_nonref.into_rust(),
1466 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1469 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1470 let mut node_id_nonref = (*node_id).clone();
1471 let mut msg_nonref = (*msg).clone();
1472 nativeMessageSendEvent::SendFundingLocked {
1473 node_id: node_id_nonref.into_rust(),
1474 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1477 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1478 let mut node_id_nonref = (*node_id).clone();
1479 let mut msg_nonref = (*msg).clone();
1480 nativeMessageSendEvent::SendAnnouncementSignatures {
1481 node_id: node_id_nonref.into_rust(),
1482 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1485 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1486 let mut node_id_nonref = (*node_id).clone();
1487 let mut updates_nonref = (*updates).clone();
1488 nativeMessageSendEvent::UpdateHTLCs {
1489 node_id: node_id_nonref.into_rust(),
1490 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
1493 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1494 let mut node_id_nonref = (*node_id).clone();
1495 let mut msg_nonref = (*msg).clone();
1496 nativeMessageSendEvent::SendRevokeAndACK {
1497 node_id: node_id_nonref.into_rust(),
1498 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1501 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1502 let mut node_id_nonref = (*node_id).clone();
1503 let mut msg_nonref = (*msg).clone();
1504 nativeMessageSendEvent::SendClosingSigned {
1505 node_id: node_id_nonref.into_rust(),
1506 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1509 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1510 let mut node_id_nonref = (*node_id).clone();
1511 let mut msg_nonref = (*msg).clone();
1512 nativeMessageSendEvent::SendShutdown {
1513 node_id: node_id_nonref.into_rust(),
1514 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1517 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1518 let mut node_id_nonref = (*node_id).clone();
1519 let mut msg_nonref = (*msg).clone();
1520 nativeMessageSendEvent::SendChannelReestablish {
1521 node_id: node_id_nonref.into_rust(),
1522 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1525 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1526 let mut msg_nonref = (*msg).clone();
1527 let mut update_msg_nonref = (*update_msg).clone();
1528 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1529 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1530 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
1533 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1534 let mut msg_nonref = (*msg).clone();
1535 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1536 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1539 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1540 let mut msg_nonref = (*msg).clone();
1541 nativeMessageSendEvent::BroadcastChannelUpdate {
1542 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1545 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1546 let mut node_id_nonref = (*node_id).clone();
1547 let mut msg_nonref = (*msg).clone();
1548 nativeMessageSendEvent::SendChannelUpdate {
1549 node_id: node_id_nonref.into_rust(),
1550 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1553 MessageSendEvent::HandleError {ref node_id, ref action, } => {
1554 let mut node_id_nonref = (*node_id).clone();
1555 let mut action_nonref = (*action).clone();
1556 nativeMessageSendEvent::HandleError {
1557 node_id: node_id_nonref.into_rust(),
1558 action: action_nonref.into_native(),
1561 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1562 let mut node_id_nonref = (*node_id).clone();
1563 let mut msg_nonref = (*msg).clone();
1564 nativeMessageSendEvent::SendChannelRangeQuery {
1565 node_id: node_id_nonref.into_rust(),
1566 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1569 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1570 let mut node_id_nonref = (*node_id).clone();
1571 let mut msg_nonref = (*msg).clone();
1572 nativeMessageSendEvent::SendShortIdsQuery {
1573 node_id: node_id_nonref.into_rust(),
1574 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1577 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1578 let mut node_id_nonref = (*node_id).clone();
1579 let mut msg_nonref = (*msg).clone();
1580 nativeMessageSendEvent::SendReplyChannelRange {
1581 node_id: node_id_nonref.into_rust(),
1582 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1585 MessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
1586 let mut node_id_nonref = (*node_id).clone();
1587 let mut msg_nonref = (*msg).clone();
1588 nativeMessageSendEvent::SendGossipTimestampFilter {
1589 node_id: node_id_nonref.into_rust(),
1590 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1596 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
1598 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1599 nativeMessageSendEvent::SendAcceptChannel {
1600 node_id: node_id.into_rust(),
1601 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1604 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1605 nativeMessageSendEvent::SendOpenChannel {
1606 node_id: node_id.into_rust(),
1607 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1610 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1611 nativeMessageSendEvent::SendFundingCreated {
1612 node_id: node_id.into_rust(),
1613 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1616 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1617 nativeMessageSendEvent::SendFundingSigned {
1618 node_id: node_id.into_rust(),
1619 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1622 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1623 nativeMessageSendEvent::SendFundingLocked {
1624 node_id: node_id.into_rust(),
1625 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1628 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1629 nativeMessageSendEvent::SendAnnouncementSignatures {
1630 node_id: node_id.into_rust(),
1631 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1634 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1635 nativeMessageSendEvent::UpdateHTLCs {
1636 node_id: node_id.into_rust(),
1637 updates: *unsafe { Box::from_raw(updates.take_inner()) },
1640 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1641 nativeMessageSendEvent::SendRevokeAndACK {
1642 node_id: node_id.into_rust(),
1643 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1646 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1647 nativeMessageSendEvent::SendClosingSigned {
1648 node_id: node_id.into_rust(),
1649 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1652 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1653 nativeMessageSendEvent::SendShutdown {
1654 node_id: node_id.into_rust(),
1655 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1658 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1659 nativeMessageSendEvent::SendChannelReestablish {
1660 node_id: node_id.into_rust(),
1661 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1664 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1665 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1666 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1667 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
1670 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1671 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1672 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1675 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1676 nativeMessageSendEvent::BroadcastChannelUpdate {
1677 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1680 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1681 nativeMessageSendEvent::SendChannelUpdate {
1682 node_id: node_id.into_rust(),
1683 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1686 MessageSendEvent::HandleError {mut node_id, mut action, } => {
1687 nativeMessageSendEvent::HandleError {
1688 node_id: node_id.into_rust(),
1689 action: action.into_native(),
1692 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1693 nativeMessageSendEvent::SendChannelRangeQuery {
1694 node_id: node_id.into_rust(),
1695 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1698 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1699 nativeMessageSendEvent::SendShortIdsQuery {
1700 node_id: node_id.into_rust(),
1701 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1704 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1705 nativeMessageSendEvent::SendReplyChannelRange {
1706 node_id: node_id.into_rust(),
1707 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1710 MessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
1711 nativeMessageSendEvent::SendGossipTimestampFilter {
1712 node_id: node_id.into_rust(),
1713 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1719 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
1721 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1722 let mut node_id_nonref = (*node_id).clone();
1723 let mut msg_nonref = (*msg).clone();
1724 MessageSendEvent::SendAcceptChannel {
1725 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1726 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1729 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1730 let mut node_id_nonref = (*node_id).clone();
1731 let mut msg_nonref = (*msg).clone();
1732 MessageSendEvent::SendOpenChannel {
1733 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1734 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1737 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1738 let mut node_id_nonref = (*node_id).clone();
1739 let mut msg_nonref = (*msg).clone();
1740 MessageSendEvent::SendFundingCreated {
1741 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1742 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1745 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1746 let mut node_id_nonref = (*node_id).clone();
1747 let mut msg_nonref = (*msg).clone();
1748 MessageSendEvent::SendFundingSigned {
1749 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1750 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1753 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1754 let mut node_id_nonref = (*node_id).clone();
1755 let mut msg_nonref = (*msg).clone();
1756 MessageSendEvent::SendFundingLocked {
1757 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1758 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1761 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1762 let mut node_id_nonref = (*node_id).clone();
1763 let mut msg_nonref = (*msg).clone();
1764 MessageSendEvent::SendAnnouncementSignatures {
1765 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1766 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1769 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1770 let mut node_id_nonref = (*node_id).clone();
1771 let mut updates_nonref = (*updates).clone();
1772 MessageSendEvent::UpdateHTLCs {
1773 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1774 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
1777 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1778 let mut node_id_nonref = (*node_id).clone();
1779 let mut msg_nonref = (*msg).clone();
1780 MessageSendEvent::SendRevokeAndACK {
1781 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1782 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1785 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1786 let mut node_id_nonref = (*node_id).clone();
1787 let mut msg_nonref = (*msg).clone();
1788 MessageSendEvent::SendClosingSigned {
1789 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1790 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1793 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1794 let mut node_id_nonref = (*node_id).clone();
1795 let mut msg_nonref = (*msg).clone();
1796 MessageSendEvent::SendShutdown {
1797 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1798 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1801 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1802 let mut node_id_nonref = (*node_id).clone();
1803 let mut msg_nonref = (*msg).clone();
1804 MessageSendEvent::SendChannelReestablish {
1805 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1806 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1809 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1810 let mut msg_nonref = (*msg).clone();
1811 let mut update_msg_nonref = (*update_msg).clone();
1812 MessageSendEvent::BroadcastChannelAnnouncement {
1813 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1814 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
1817 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1818 let mut msg_nonref = (*msg).clone();
1819 MessageSendEvent::BroadcastNodeAnnouncement {
1820 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1823 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1824 let mut msg_nonref = (*msg).clone();
1825 MessageSendEvent::BroadcastChannelUpdate {
1826 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1829 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1830 let mut node_id_nonref = (*node_id).clone();
1831 let mut msg_nonref = (*msg).clone();
1832 MessageSendEvent::SendChannelUpdate {
1833 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1834 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1837 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
1838 let mut node_id_nonref = (*node_id).clone();
1839 let mut action_nonref = (*action).clone();
1840 MessageSendEvent::HandleError {
1841 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1842 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
1845 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1846 let mut node_id_nonref = (*node_id).clone();
1847 let mut msg_nonref = (*msg).clone();
1848 MessageSendEvent::SendChannelRangeQuery {
1849 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1850 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1853 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1854 let mut node_id_nonref = (*node_id).clone();
1855 let mut msg_nonref = (*msg).clone();
1856 MessageSendEvent::SendShortIdsQuery {
1857 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1858 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1861 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1862 let mut node_id_nonref = (*node_id).clone();
1863 let mut msg_nonref = (*msg).clone();
1864 MessageSendEvent::SendReplyChannelRange {
1865 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1866 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1869 nativeMessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
1870 let mut node_id_nonref = (*node_id).clone();
1871 let mut msg_nonref = (*msg).clone();
1872 MessageSendEvent::SendGossipTimestampFilter {
1873 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1874 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1880 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
1882 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1883 MessageSendEvent::SendAcceptChannel {
1884 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1885 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1888 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1889 MessageSendEvent::SendOpenChannel {
1890 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1891 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1894 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1895 MessageSendEvent::SendFundingCreated {
1896 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1897 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
1900 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1901 MessageSendEvent::SendFundingSigned {
1902 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1903 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1906 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1907 MessageSendEvent::SendFundingLocked {
1908 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1909 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg), is_owned: true },
1912 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1913 MessageSendEvent::SendAnnouncementSignatures {
1914 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1915 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
1918 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1919 MessageSendEvent::UpdateHTLCs {
1920 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1921 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
1924 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1925 MessageSendEvent::SendRevokeAndACK {
1926 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1927 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
1930 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1931 MessageSendEvent::SendClosingSigned {
1932 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1933 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1936 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1937 MessageSendEvent::SendShutdown {
1938 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1939 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
1942 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1943 MessageSendEvent::SendChannelReestablish {
1944 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1945 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
1948 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1949 MessageSendEvent::BroadcastChannelAnnouncement {
1950 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1951 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
1954 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1955 MessageSendEvent::BroadcastNodeAnnouncement {
1956 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1959 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1960 MessageSendEvent::BroadcastChannelUpdate {
1961 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1964 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1965 MessageSendEvent::SendChannelUpdate {
1966 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1967 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1970 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1971 MessageSendEvent::HandleError {
1972 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1973 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1976 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1977 MessageSendEvent::SendChannelRangeQuery {
1978 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1979 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1982 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1983 MessageSendEvent::SendShortIdsQuery {
1984 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1985 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
1988 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1989 MessageSendEvent::SendReplyChannelRange {
1990 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1991 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1994 nativeMessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
1995 MessageSendEvent::SendGossipTimestampFilter {
1996 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1997 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg), is_owned: true },
2003 /// Frees any resources used by the MessageSendEvent
2005 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
2006 /// Creates a copy of the MessageSendEvent
2008 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
2012 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
2013 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
2014 MessageSendEvent::SendAcceptChannel {
2020 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
2021 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
2022 MessageSendEvent::SendOpenChannel {
2028 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
2029 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
2030 MessageSendEvent::SendFundingCreated {
2036 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
2037 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
2038 MessageSendEvent::SendFundingSigned {
2044 /// Utility method to constructs a new SendFundingLocked-variant MessageSendEvent
2045 pub extern "C" fn MessageSendEvent_send_funding_locked(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingLocked) -> MessageSendEvent {
2046 MessageSendEvent::SendFundingLocked {
2052 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
2053 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
2054 MessageSendEvent::SendAnnouncementSignatures {
2060 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
2061 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
2062 MessageSendEvent::UpdateHTLCs {
2068 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
2069 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
2070 MessageSendEvent::SendRevokeAndACK {
2076 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
2077 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
2078 MessageSendEvent::SendClosingSigned {
2084 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
2085 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
2086 MessageSendEvent::SendShutdown {
2092 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
2093 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
2094 MessageSendEvent::SendChannelReestablish {
2100 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
2101 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2102 MessageSendEvent::BroadcastChannelAnnouncement {
2108 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
2109 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
2110 MessageSendEvent::BroadcastNodeAnnouncement {
2115 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
2116 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2117 MessageSendEvent::BroadcastChannelUpdate {
2122 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
2123 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2124 MessageSendEvent::SendChannelUpdate {
2130 /// Utility method to constructs a new HandleError-variant MessageSendEvent
2131 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
2132 MessageSendEvent::HandleError {
2138 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
2139 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
2140 MessageSendEvent::SendChannelRangeQuery {
2146 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
2147 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
2148 MessageSendEvent::SendShortIdsQuery {
2154 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
2155 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
2156 MessageSendEvent::SendReplyChannelRange {
2162 /// Utility method to constructs a new SendGossipTimestampFilter-variant MessageSendEvent
2163 pub extern "C" fn MessageSendEvent_send_gossip_timestamp_filter(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::GossipTimestampFilter) -> MessageSendEvent {
2164 MessageSendEvent::SendGossipTimestampFilter {
2169 /// A trait indicating an object may generate message send events
2171 pub struct MessageSendEventsProvider {
2172 /// An opaque pointer which is passed to your function implementations as an argument.
2173 /// This has no meaning in the LDK, and can be NULL or any other value.
2174 pub this_arg: *mut c_void,
2175 /// Gets the list of pending events which were generated by previous actions, clearing the list
2178 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
2179 /// Frees any resources associated with this object given its this_arg pointer.
2180 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2181 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2183 unsafe impl Send for MessageSendEventsProvider {}
2184 unsafe impl Sync for MessageSendEventsProvider {}
2186 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
2187 MessageSendEventsProvider {
2188 this_arg: orig.this_arg,
2189 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
2190 free: Clone::clone(&orig.free),
2194 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
2195 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
2196 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
2197 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
2198 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
2203 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2204 // directly as a Deref trait in higher-level structs:
2205 impl core::ops::Deref for MessageSendEventsProvider {
2207 fn deref(&self) -> &Self {
2211 /// Calls the free function if one is set
2213 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
2214 impl Drop for MessageSendEventsProvider {
2215 fn drop(&mut self) {
2216 if let Some(f) = self.free {
2221 /// A trait indicating an object may generate events.
2223 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
2227 /// See [`process_pending_events`] for requirements around event processing.
2229 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
2230 /// event since the last invocation. The handler must either act upon the event immediately
2231 /// or preserve it for later handling.
2233 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
2234 /// consult the provider's documentation on the implication of processing events and how a handler
2235 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
2236 /// [`ChainMonitor::process_pending_events`]).
2238 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
2241 /// [`process_pending_events`]: Self::process_pending_events
2242 /// [`handle_event`]: EventHandler::handle_event
2243 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
2244 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
2246 pub struct EventsProvider {
2247 /// An opaque pointer which is passed to your function implementations as an argument.
2248 /// This has no meaning in the LDK, and can be NULL or any other value.
2249 pub this_arg: *mut c_void,
2250 /// Processes any events generated since the last call using the given event handler.
2252 /// Subsequent calls must only process new events. However, handlers must be capable of handling
2253 /// duplicate events across process restarts. This may occur if the provider was recovered from
2254 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
2255 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
2256 /// Frees any resources associated with this object given its this_arg pointer.
2257 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2258 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2260 unsafe impl Send for EventsProvider {}
2261 unsafe impl Sync for EventsProvider {}
2263 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
2265 this_arg: orig.this_arg,
2266 process_pending_events: Clone::clone(&orig.process_pending_events),
2267 free: Clone::clone(&orig.free),
2271 use lightning::util::events::EventsProvider as rustEventsProvider;
2272 /// Calls the free function if one is set
2274 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
2275 impl Drop for EventsProvider {
2276 fn drop(&mut self) {
2277 if let Some(f) = self.free {
2282 /// A trait implemented for objects handling events from [`EventsProvider`].
2284 pub struct EventHandler {
2285 /// An opaque pointer which is passed to your function implementations as an argument.
2286 /// This has no meaning in the LDK, and can be NULL or any other value.
2287 pub this_arg: *mut c_void,
2288 /// Handles the given [`Event`].
2290 /// See [`EventsProvider`] for details that must be considered when implementing this method.
2291 pub handle_event: extern "C" fn (this_arg: *const c_void, event: &crate::lightning::util::events::Event),
2292 /// Frees any resources associated with this object given its this_arg pointer.
2293 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2294 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2296 unsafe impl Send for EventHandler {}
2297 unsafe impl Sync for EventHandler {}
2299 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
2301 this_arg: orig.this_arg,
2302 handle_event: Clone::clone(&orig.handle_event),
2303 free: Clone::clone(&orig.free),
2307 use lightning::util::events::EventHandler as rustEventHandler;
2308 impl rustEventHandler for EventHandler {
2309 fn handle_event(&self, mut event: &lightning::util::events::Event) {
2310 (self.handle_event)(self.this_arg, &crate::lightning::util::events::Event::from_native(event))
2314 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2315 // directly as a Deref trait in higher-level structs:
2316 impl core::ops::Deref for EventHandler {
2318 fn deref(&self) -> &Self {
2322 /// Calls the free function if one is set
2324 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
2325 impl Drop for EventHandler {
2326 fn drop(&mut self) {
2327 if let Some(f) = self.free {