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: &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::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`], or 0 for
575 /// an inbound channel. This will always be zero for objects serialized with LDK versions
576 /// prior to 0.0.102.
578 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
579 user_channel_id: u64,
580 /// The reason the channel was closed.
581 reason: crate::lightning::util::events::ClosureReason,
583 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
584 /// inputs for another purpose.
586 /// The channel_id of the channel which has been closed.
587 channel_id: crate::c_types::ThirtyTwoBytes,
588 /// The full transaction received from the user
589 transaction: crate::c_types::Transaction,
591 /// Indicates that a path for an outbound payment was successful.
593 /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
594 /// [`Event::PaymentSent`] for obtaining the payment preimage.
595 PaymentPathSuccessful {
596 /// The id returned by [`ChannelManager::send_payment`] and used with
597 /// [`ChannelManager::retry_payment`].
599 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
600 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
601 payment_id: crate::c_types::ThirtyTwoBytes,
602 /// The hash that was given to [`ChannelManager::send_payment`].
604 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
606 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
607 payment_hash: crate::c_types::ThirtyTwoBytes,
608 /// The payment path that was successful.
610 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
611 path: crate::c_types::derived::CVec_RouteHopZ,
614 use lightning::util::events::Event as nativeEvent;
617 pub(crate) fn to_native(&self) -> nativeEvent {
619 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
620 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
621 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
622 let mut output_script_nonref = (*output_script).clone();
623 let mut user_channel_id_nonref = (*user_channel_id).clone();
624 nativeEvent::FundingGenerationReady {
625 temporary_channel_id: temporary_channel_id_nonref.data,
626 channel_value_satoshis: channel_value_satoshis_nonref,
627 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
628 user_channel_id: user_channel_id_nonref,
631 Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
632 let mut payment_hash_nonref = (*payment_hash).clone();
633 let mut amt_nonref = (*amt).clone();
634 let mut purpose_nonref = (*purpose).clone();
635 nativeEvent::PaymentReceived {
636 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
638 purpose: purpose_nonref.into_native(),
641 Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
642 let mut payment_id_nonref = (*payment_id).clone();
643 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
644 let mut payment_preimage_nonref = (*payment_preimage).clone();
645 let mut payment_hash_nonref = (*payment_hash).clone();
646 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
647 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
648 nativeEvent::PaymentSent {
649 payment_id: local_payment_id_nonref,
650 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
651 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
652 fee_paid_msat: local_fee_paid_msat_nonref,
655 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, } => {
656 let mut payment_id_nonref = (*payment_id).clone();
657 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
658 let mut payment_hash_nonref = (*payment_hash).clone();
659 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
660 let mut network_update_nonref = (*network_update).clone();
661 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() }) } };
662 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
663 let mut path_nonref = (*path).clone();
664 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()) } }); };
665 let mut short_channel_id_nonref = (*short_channel_id).clone();
666 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
667 let mut retry_nonref = (*retry).clone();
668 let mut local_retry_nonref = if retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry_nonref.take_inner()) } }) };
669 nativeEvent::PaymentPathFailed {
670 payment_id: local_payment_id_nonref,
671 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
672 rejected_by_dest: rejected_by_dest_nonref,
673 network_update: local_network_update_nonref,
674 all_paths_failed: all_paths_failed_nonref,
675 path: local_path_nonref,
676 short_channel_id: local_short_channel_id_nonref,
677 retry: local_retry_nonref,
680 Event::PaymentFailed {ref payment_id, ref payment_hash, } => {
681 let mut payment_id_nonref = (*payment_id).clone();
682 let mut payment_hash_nonref = (*payment_hash).clone();
683 nativeEvent::PaymentFailed {
684 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
685 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
688 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
689 let mut time_forwardable_nonref = (*time_forwardable).clone();
690 nativeEvent::PendingHTLCsForwardable {
691 time_forwardable: core::time::Duration::from_secs(time_forwardable_nonref),
694 Event::SpendableOutputs {ref outputs, } => {
695 let mut outputs_nonref = (*outputs).clone();
696 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
697 nativeEvent::SpendableOutputs {
698 outputs: local_outputs_nonref,
701 Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
702 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
703 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
704 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
705 nativeEvent::PaymentForwarded {
706 fee_earned_msat: local_fee_earned_msat_nonref,
707 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
710 Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
711 let mut channel_id_nonref = (*channel_id).clone();
712 let mut user_channel_id_nonref = (*user_channel_id).clone();
713 let mut reason_nonref = (*reason).clone();
714 nativeEvent::ChannelClosed {
715 channel_id: channel_id_nonref.data,
716 user_channel_id: user_channel_id_nonref,
717 reason: reason_nonref.into_native(),
720 Event::DiscardFunding {ref channel_id, ref transaction, } => {
721 let mut channel_id_nonref = (*channel_id).clone();
722 let mut transaction_nonref = (*transaction).clone();
723 nativeEvent::DiscardFunding {
724 channel_id: channel_id_nonref.data,
725 transaction: transaction_nonref.into_bitcoin(),
728 Event::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
729 let mut payment_id_nonref = (*payment_id).clone();
730 let mut payment_hash_nonref = (*payment_hash).clone();
731 let mut local_payment_hash_nonref = if payment_hash_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash_nonref.data) }) };
732 let mut path_nonref = (*path).clone();
733 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()) } }); };
734 nativeEvent::PaymentPathSuccessful {
735 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
736 payment_hash: local_payment_hash_nonref,
737 path: local_path_nonref,
743 pub(crate) fn into_native(self) -> nativeEvent {
745 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
746 nativeEvent::FundingGenerationReady {
747 temporary_channel_id: temporary_channel_id.data,
748 channel_value_satoshis: channel_value_satoshis,
749 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
750 user_channel_id: user_channel_id,
753 Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
754 nativeEvent::PaymentReceived {
755 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
757 purpose: purpose.into_native(),
760 Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
761 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
762 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
763 nativeEvent::PaymentSent {
764 payment_id: local_payment_id,
765 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
766 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
767 fee_paid_msat: local_fee_paid_msat,
770 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, } => {
771 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
772 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() }) } };
773 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
774 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
775 let mut local_retry = if retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry.take_inner()) } }) };
776 nativeEvent::PaymentPathFailed {
777 payment_id: local_payment_id,
778 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
779 rejected_by_dest: rejected_by_dest,
780 network_update: local_network_update,
781 all_paths_failed: all_paths_failed,
783 short_channel_id: local_short_channel_id,
787 Event::PaymentFailed {mut payment_id, mut payment_hash, } => {
788 nativeEvent::PaymentFailed {
789 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
790 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
793 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
794 nativeEvent::PendingHTLCsForwardable {
795 time_forwardable: core::time::Duration::from_secs(time_forwardable),
798 Event::SpendableOutputs {mut outputs, } => {
799 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
800 nativeEvent::SpendableOutputs {
801 outputs: local_outputs,
804 Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
805 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
806 nativeEvent::PaymentForwarded {
807 fee_earned_msat: local_fee_earned_msat,
808 claim_from_onchain_tx: claim_from_onchain_tx,
811 Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
812 nativeEvent::ChannelClosed {
813 channel_id: channel_id.data,
814 user_channel_id: user_channel_id,
815 reason: reason.into_native(),
818 Event::DiscardFunding {mut channel_id, mut transaction, } => {
819 nativeEvent::DiscardFunding {
820 channel_id: channel_id.data,
821 transaction: transaction.into_bitcoin(),
824 Event::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
825 let mut local_payment_hash = if payment_hash.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash.data) }) };
826 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
827 nativeEvent::PaymentPathSuccessful {
828 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
829 payment_hash: local_payment_hash,
836 pub(crate) fn from_native(native: &nativeEvent) -> Self {
838 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
839 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
840 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
841 let mut output_script_nonref = (*output_script).clone();
842 let mut user_channel_id_nonref = (*user_channel_id).clone();
843 Event::FundingGenerationReady {
844 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
845 channel_value_satoshis: channel_value_satoshis_nonref,
846 output_script: output_script_nonref.into_bytes().into(),
847 user_channel_id: user_channel_id_nonref,
850 nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
851 let mut payment_hash_nonref = (*payment_hash).clone();
852 let mut amt_nonref = (*amt).clone();
853 let mut purpose_nonref = (*purpose).clone();
854 Event::PaymentReceived {
855 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
857 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
860 nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
861 let mut payment_id_nonref = (*payment_id).clone();
862 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 } } };
863 let mut payment_preimage_nonref = (*payment_preimage).clone();
864 let mut payment_hash_nonref = (*payment_hash).clone();
865 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
866 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() }) };
868 payment_id: local_payment_id_nonref,
869 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
870 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
871 fee_paid_msat: local_fee_paid_msat_nonref,
874 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, } => {
875 let mut payment_id_nonref = (*payment_id).clone();
876 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 } } };
877 let mut payment_hash_nonref = (*payment_hash).clone();
878 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
879 let mut network_update_nonref = (*network_update).clone();
880 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()) }) };
881 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
882 let mut path_nonref = (*path).clone();
883 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 } }); };
884 let mut short_channel_id_nonref = (*short_channel_id).clone();
885 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() }) };
886 let mut retry_nonref = (*retry).clone();
887 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 };
888 Event::PaymentPathFailed {
889 payment_id: local_payment_id_nonref,
890 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
891 rejected_by_dest: rejected_by_dest_nonref,
892 network_update: local_network_update_nonref,
893 all_paths_failed: all_paths_failed_nonref,
894 path: local_path_nonref.into(),
895 short_channel_id: local_short_channel_id_nonref,
896 retry: local_retry_nonref,
899 nativeEvent::PaymentFailed {ref payment_id, ref payment_hash, } => {
900 let mut payment_id_nonref = (*payment_id).clone();
901 let mut payment_hash_nonref = (*payment_hash).clone();
902 Event::PaymentFailed {
903 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
904 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
907 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
908 let mut time_forwardable_nonref = (*time_forwardable).clone();
909 Event::PendingHTLCsForwardable {
910 time_forwardable: time_forwardable_nonref.as_secs(),
913 nativeEvent::SpendableOutputs {ref outputs, } => {
914 let mut outputs_nonref = (*outputs).clone();
915 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) }); };
916 Event::SpendableOutputs {
917 outputs: local_outputs_nonref.into(),
920 nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
921 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
922 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() }) };
923 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
924 Event::PaymentForwarded {
925 fee_earned_msat: local_fee_earned_msat_nonref,
926 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
929 nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
930 let mut channel_id_nonref = (*channel_id).clone();
931 let mut user_channel_id_nonref = (*user_channel_id).clone();
932 let mut reason_nonref = (*reason).clone();
933 Event::ChannelClosed {
934 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
935 user_channel_id: user_channel_id_nonref,
936 reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
939 nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
940 let mut channel_id_nonref = (*channel_id).clone();
941 let mut transaction_nonref = (*transaction).clone();
942 Event::DiscardFunding {
943 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
944 transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
947 nativeEvent::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
948 let mut payment_id_nonref = (*payment_id).clone();
949 let mut payment_hash_nonref = (*payment_hash).clone();
950 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 } } };
951 let mut path_nonref = (*path).clone();
952 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 } }); };
953 Event::PaymentPathSuccessful {
954 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
955 payment_hash: local_payment_hash_nonref,
956 path: local_path_nonref.into(),
962 pub(crate) fn native_into(native: nativeEvent) -> Self {
964 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
965 Event::FundingGenerationReady {
966 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
967 channel_value_satoshis: channel_value_satoshis,
968 output_script: output_script.into_bytes().into(),
969 user_channel_id: user_channel_id,
972 nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
973 Event::PaymentReceived {
974 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
976 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
979 nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
980 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 } } };
981 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() }) };
983 payment_id: local_payment_id,
984 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
985 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
986 fee_paid_msat: local_fee_paid_msat,
989 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, } => {
990 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 } } };
991 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()) }) };
992 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 } }); };
993 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() }) };
994 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 };
995 Event::PaymentPathFailed {
996 payment_id: local_payment_id,
997 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
998 rejected_by_dest: rejected_by_dest,
999 network_update: local_network_update,
1000 all_paths_failed: all_paths_failed,
1001 path: local_path.into(),
1002 short_channel_id: local_short_channel_id,
1006 nativeEvent::PaymentFailed {mut payment_id, mut payment_hash, } => {
1007 Event::PaymentFailed {
1008 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1009 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1012 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
1013 Event::PendingHTLCsForwardable {
1014 time_forwardable: time_forwardable.as_secs(),
1017 nativeEvent::SpendableOutputs {mut outputs, } => {
1018 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
1019 Event::SpendableOutputs {
1020 outputs: local_outputs.into(),
1023 nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1024 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() }) };
1025 Event::PaymentForwarded {
1026 fee_earned_msat: local_fee_earned_msat,
1027 claim_from_onchain_tx: claim_from_onchain_tx,
1030 nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1031 Event::ChannelClosed {
1032 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1033 user_channel_id: user_channel_id,
1034 reason: crate::lightning::util::events::ClosureReason::native_into(reason),
1037 nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
1038 Event::DiscardFunding {
1039 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1040 transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
1043 nativeEvent::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1044 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 } } };
1045 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 } }); };
1046 Event::PaymentPathSuccessful {
1047 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1048 payment_hash: local_payment_hash,
1049 path: local_path.into(),
1055 /// Frees any resources used by the Event
1057 pub extern "C" fn Event_free(this_ptr: Event) { }
1058 /// Creates a copy of the Event
1060 pub extern "C" fn Event_clone(orig: &Event) -> Event {
1064 /// Utility method to constructs a new FundingGenerationReady-variant Event
1065 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 {
1066 Event::FundingGenerationReady {
1067 temporary_channel_id,
1068 channel_value_satoshis,
1074 /// Utility method to constructs a new PaymentReceived-variant Event
1075 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
1076 Event::PaymentReceived {
1083 /// Utility method to constructs a new PaymentSent-variant Event
1084 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 {
1085 Event::PaymentSent {
1093 /// Utility method to constructs a new PaymentPathFailed-variant Event
1094 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 {
1095 Event::PaymentPathFailed {
1107 /// Utility method to constructs a new PaymentFailed-variant Event
1108 pub extern "C" fn Event_payment_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> Event {
1109 Event::PaymentFailed {
1115 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
1116 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
1117 Event::PendingHTLCsForwardable {
1122 /// Utility method to constructs a new SpendableOutputs-variant Event
1123 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
1124 Event::SpendableOutputs {
1129 /// Utility method to constructs a new PaymentForwarded-variant Event
1130 pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
1131 Event::PaymentForwarded {
1133 claim_from_onchain_tx,
1137 /// Utility method to constructs a new ChannelClosed-variant Event
1138 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: u64, reason: crate::lightning::util::events::ClosureReason) -> Event {
1139 Event::ChannelClosed {
1146 /// Utility method to constructs a new DiscardFunding-variant Event
1147 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
1148 Event::DiscardFunding {
1154 /// Utility method to constructs a new PaymentPathSuccessful-variant Event
1155 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 {
1156 Event::PaymentPathSuccessful {
1163 /// Serialize the Event object into a byte array which can be read by Event_read
1164 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
1165 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
1168 /// Read a Event from a byte array, created by Event_write
1169 pub extern "C" fn Event_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_EventZDecodeErrorZ {
1170 let res: Result<Option<lightning::util::events::Event>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
1171 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() };
1174 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1175 /// broadcast to most peers).
1176 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1180 pub enum MessageSendEvent {
1181 /// Used to indicate that we've accepted a channel open and should send the accept_channel
1182 /// message provided to the given peer.
1184 /// The node_id of the node which should receive this message
1185 node_id: crate::c_types::PublicKey,
1186 /// The message which should be sent.
1187 msg: crate::lightning::ln::msgs::AcceptChannel,
1189 /// Used to indicate that we've initiated a channel open and should send the open_channel
1190 /// message provided to the given peer.
1192 /// The node_id of the node which should receive this message
1193 node_id: crate::c_types::PublicKey,
1194 /// The message which should be sent.
1195 msg: crate::lightning::ln::msgs::OpenChannel,
1197 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1198 SendFundingCreated {
1199 /// The node_id of the node which should receive this message
1200 node_id: crate::c_types::PublicKey,
1201 /// The message which should be sent.
1202 msg: crate::lightning::ln::msgs::FundingCreated,
1204 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
1206 /// The node_id of the node which should receive this message
1207 node_id: crate::c_types::PublicKey,
1208 /// The message which should be sent.
1209 msg: crate::lightning::ln::msgs::FundingSigned,
1211 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
1213 /// The node_id of the node which should receive these message(s)
1214 node_id: crate::c_types::PublicKey,
1215 /// The funding_locked message which should be sent.
1216 msg: crate::lightning::ln::msgs::FundingLocked,
1218 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1219 SendAnnouncementSignatures {
1220 /// The node_id of the node which should receive these message(s)
1221 node_id: crate::c_types::PublicKey,
1222 /// The announcement_signatures message which should be sent.
1223 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
1225 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1226 /// message should be sent to the peer with the given node_id.
1228 /// The node_id of the node which should receive these message(s)
1229 node_id: crate::c_types::PublicKey,
1230 /// The update messages which should be sent. ALL messages in the struct should be sent!
1231 updates: crate::lightning::ln::msgs::CommitmentUpdate,
1233 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1235 /// The node_id of the node which should receive this message
1236 node_id: crate::c_types::PublicKey,
1237 /// The message which should be sent.
1238 msg: crate::lightning::ln::msgs::RevokeAndACK,
1240 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1242 /// The node_id of the node which should receive this message
1243 node_id: crate::c_types::PublicKey,
1244 /// The message which should be sent.
1245 msg: crate::lightning::ln::msgs::ClosingSigned,
1247 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
1249 /// The node_id of the node which should receive this message
1250 node_id: crate::c_types::PublicKey,
1251 /// The message which should be sent.
1252 msg: crate::lightning::ln::msgs::Shutdown,
1254 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1255 SendChannelReestablish {
1256 /// The node_id of the node which should receive this message
1257 node_id: crate::c_types::PublicKey,
1258 /// The message which should be sent.
1259 msg: crate::lightning::ln::msgs::ChannelReestablish,
1261 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1262 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1264 /// Note that after doing so, you very likely (unless you did so very recently) want to call
1265 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
1266 /// This ensures that any nodes which see our channel_announcement also have a relevant
1267 /// node_announcement, including relevant feature flags which may be important for routing
1268 /// through or to us.
1269 BroadcastChannelAnnouncement {
1270 /// The channel_announcement which should be sent.
1271 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
1272 /// The followup channel_update which should be sent.
1273 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
1275 /// Used to indicate that a node_announcement should be broadcast to all peers.
1276 BroadcastNodeAnnouncement {
1277 /// The node_announcement which should be sent.
1278 msg: crate::lightning::ln::msgs::NodeAnnouncement,
1280 /// Used to indicate that a channel_update should be broadcast to all peers.
1281 BroadcastChannelUpdate {
1282 /// The channel_update which should be sent.
1283 msg: crate::lightning::ln::msgs::ChannelUpdate,
1285 /// Used to indicate that a channel_update should be sent to a single peer.
1286 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1287 /// private channel and we shouldn't be informing all of our peers of channel parameters.
1289 /// The node_id of the node which should receive this message
1290 node_id: crate::c_types::PublicKey,
1291 /// The channel_update which should be sent.
1292 msg: crate::lightning::ln::msgs::ChannelUpdate,
1294 /// Broadcast an error downstream to be handled
1296 /// The node_id of the node which should receive this message
1297 node_id: crate::c_types::PublicKey,
1298 /// The action which should be taken.
1299 action: crate::lightning::ln::msgs::ErrorAction,
1301 /// Query a peer for channels with funding transaction UTXOs in a block range.
1302 SendChannelRangeQuery {
1303 /// The node_id of this message recipient
1304 node_id: crate::c_types::PublicKey,
1305 /// The query_channel_range which should be sent.
1306 msg: crate::lightning::ln::msgs::QueryChannelRange,
1308 /// Request routing gossip messages from a peer for a list of channels identified by
1309 /// their short_channel_ids.
1311 /// The node_id of this message recipient
1312 node_id: crate::c_types::PublicKey,
1313 /// The query_short_channel_ids which should be sent.
1314 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
1316 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1317 /// emitted during processing of the query.
1318 SendReplyChannelRange {
1319 /// The node_id of this message recipient
1320 node_id: crate::c_types::PublicKey,
1321 /// The reply_channel_range which should be sent.
1322 msg: crate::lightning::ln::msgs::ReplyChannelRange,
1325 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
1326 impl MessageSendEvent {
1328 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
1330 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1331 let mut node_id_nonref = (*node_id).clone();
1332 let mut msg_nonref = (*msg).clone();
1333 nativeMessageSendEvent::SendAcceptChannel {
1334 node_id: node_id_nonref.into_rust(),
1335 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1338 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1339 let mut node_id_nonref = (*node_id).clone();
1340 let mut msg_nonref = (*msg).clone();
1341 nativeMessageSendEvent::SendOpenChannel {
1342 node_id: node_id_nonref.into_rust(),
1343 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1346 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1347 let mut node_id_nonref = (*node_id).clone();
1348 let mut msg_nonref = (*msg).clone();
1349 nativeMessageSendEvent::SendFundingCreated {
1350 node_id: node_id_nonref.into_rust(),
1351 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1354 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1355 let mut node_id_nonref = (*node_id).clone();
1356 let mut msg_nonref = (*msg).clone();
1357 nativeMessageSendEvent::SendFundingSigned {
1358 node_id: node_id_nonref.into_rust(),
1359 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1362 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1363 let mut node_id_nonref = (*node_id).clone();
1364 let mut msg_nonref = (*msg).clone();
1365 nativeMessageSendEvent::SendFundingLocked {
1366 node_id: node_id_nonref.into_rust(),
1367 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1370 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1371 let mut node_id_nonref = (*node_id).clone();
1372 let mut msg_nonref = (*msg).clone();
1373 nativeMessageSendEvent::SendAnnouncementSignatures {
1374 node_id: node_id_nonref.into_rust(),
1375 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1378 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1379 let mut node_id_nonref = (*node_id).clone();
1380 let mut updates_nonref = (*updates).clone();
1381 nativeMessageSendEvent::UpdateHTLCs {
1382 node_id: node_id_nonref.into_rust(),
1383 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
1386 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1387 let mut node_id_nonref = (*node_id).clone();
1388 let mut msg_nonref = (*msg).clone();
1389 nativeMessageSendEvent::SendRevokeAndACK {
1390 node_id: node_id_nonref.into_rust(),
1391 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1394 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1395 let mut node_id_nonref = (*node_id).clone();
1396 let mut msg_nonref = (*msg).clone();
1397 nativeMessageSendEvent::SendClosingSigned {
1398 node_id: node_id_nonref.into_rust(),
1399 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1402 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1403 let mut node_id_nonref = (*node_id).clone();
1404 let mut msg_nonref = (*msg).clone();
1405 nativeMessageSendEvent::SendShutdown {
1406 node_id: node_id_nonref.into_rust(),
1407 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1410 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1411 let mut node_id_nonref = (*node_id).clone();
1412 let mut msg_nonref = (*msg).clone();
1413 nativeMessageSendEvent::SendChannelReestablish {
1414 node_id: node_id_nonref.into_rust(),
1415 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1418 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1419 let mut msg_nonref = (*msg).clone();
1420 let mut update_msg_nonref = (*update_msg).clone();
1421 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1422 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1423 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
1426 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1427 let mut msg_nonref = (*msg).clone();
1428 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1429 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1432 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1433 let mut msg_nonref = (*msg).clone();
1434 nativeMessageSendEvent::BroadcastChannelUpdate {
1435 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1438 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1439 let mut node_id_nonref = (*node_id).clone();
1440 let mut msg_nonref = (*msg).clone();
1441 nativeMessageSendEvent::SendChannelUpdate {
1442 node_id: node_id_nonref.into_rust(),
1443 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1446 MessageSendEvent::HandleError {ref node_id, ref action, } => {
1447 let mut node_id_nonref = (*node_id).clone();
1448 let mut action_nonref = (*action).clone();
1449 nativeMessageSendEvent::HandleError {
1450 node_id: node_id_nonref.into_rust(),
1451 action: action_nonref.into_native(),
1454 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1455 let mut node_id_nonref = (*node_id).clone();
1456 let mut msg_nonref = (*msg).clone();
1457 nativeMessageSendEvent::SendChannelRangeQuery {
1458 node_id: node_id_nonref.into_rust(),
1459 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1462 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1463 let mut node_id_nonref = (*node_id).clone();
1464 let mut msg_nonref = (*msg).clone();
1465 nativeMessageSendEvent::SendShortIdsQuery {
1466 node_id: node_id_nonref.into_rust(),
1467 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1470 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1471 let mut node_id_nonref = (*node_id).clone();
1472 let mut msg_nonref = (*msg).clone();
1473 nativeMessageSendEvent::SendReplyChannelRange {
1474 node_id: node_id_nonref.into_rust(),
1475 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1481 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
1483 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1484 nativeMessageSendEvent::SendAcceptChannel {
1485 node_id: node_id.into_rust(),
1486 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1489 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1490 nativeMessageSendEvent::SendOpenChannel {
1491 node_id: node_id.into_rust(),
1492 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1495 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1496 nativeMessageSendEvent::SendFundingCreated {
1497 node_id: node_id.into_rust(),
1498 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1501 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1502 nativeMessageSendEvent::SendFundingSigned {
1503 node_id: node_id.into_rust(),
1504 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1507 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1508 nativeMessageSendEvent::SendFundingLocked {
1509 node_id: node_id.into_rust(),
1510 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1513 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1514 nativeMessageSendEvent::SendAnnouncementSignatures {
1515 node_id: node_id.into_rust(),
1516 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1519 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1520 nativeMessageSendEvent::UpdateHTLCs {
1521 node_id: node_id.into_rust(),
1522 updates: *unsafe { Box::from_raw(updates.take_inner()) },
1525 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1526 nativeMessageSendEvent::SendRevokeAndACK {
1527 node_id: node_id.into_rust(),
1528 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1531 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1532 nativeMessageSendEvent::SendClosingSigned {
1533 node_id: node_id.into_rust(),
1534 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1537 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1538 nativeMessageSendEvent::SendShutdown {
1539 node_id: node_id.into_rust(),
1540 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1543 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1544 nativeMessageSendEvent::SendChannelReestablish {
1545 node_id: node_id.into_rust(),
1546 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1549 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1550 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1551 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1552 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
1555 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1556 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1557 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1560 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1561 nativeMessageSendEvent::BroadcastChannelUpdate {
1562 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1565 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1566 nativeMessageSendEvent::SendChannelUpdate {
1567 node_id: node_id.into_rust(),
1568 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1571 MessageSendEvent::HandleError {mut node_id, mut action, } => {
1572 nativeMessageSendEvent::HandleError {
1573 node_id: node_id.into_rust(),
1574 action: action.into_native(),
1577 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1578 nativeMessageSendEvent::SendChannelRangeQuery {
1579 node_id: node_id.into_rust(),
1580 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1583 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1584 nativeMessageSendEvent::SendShortIdsQuery {
1585 node_id: node_id.into_rust(),
1586 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1589 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1590 nativeMessageSendEvent::SendReplyChannelRange {
1591 node_id: node_id.into_rust(),
1592 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1598 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
1600 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1601 let mut node_id_nonref = (*node_id).clone();
1602 let mut msg_nonref = (*msg).clone();
1603 MessageSendEvent::SendAcceptChannel {
1604 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1605 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1608 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1609 let mut node_id_nonref = (*node_id).clone();
1610 let mut msg_nonref = (*msg).clone();
1611 MessageSendEvent::SendOpenChannel {
1612 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1613 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1616 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1617 let mut node_id_nonref = (*node_id).clone();
1618 let mut msg_nonref = (*msg).clone();
1619 MessageSendEvent::SendFundingCreated {
1620 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1621 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1624 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1625 let mut node_id_nonref = (*node_id).clone();
1626 let mut msg_nonref = (*msg).clone();
1627 MessageSendEvent::SendFundingSigned {
1628 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1629 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1632 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1633 let mut node_id_nonref = (*node_id).clone();
1634 let mut msg_nonref = (*msg).clone();
1635 MessageSendEvent::SendFundingLocked {
1636 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1637 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1640 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1641 let mut node_id_nonref = (*node_id).clone();
1642 let mut msg_nonref = (*msg).clone();
1643 MessageSendEvent::SendAnnouncementSignatures {
1644 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1645 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1648 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1649 let mut node_id_nonref = (*node_id).clone();
1650 let mut updates_nonref = (*updates).clone();
1651 MessageSendEvent::UpdateHTLCs {
1652 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1653 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
1656 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1657 let mut node_id_nonref = (*node_id).clone();
1658 let mut msg_nonref = (*msg).clone();
1659 MessageSendEvent::SendRevokeAndACK {
1660 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1661 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1664 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1665 let mut node_id_nonref = (*node_id).clone();
1666 let mut msg_nonref = (*msg).clone();
1667 MessageSendEvent::SendClosingSigned {
1668 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1669 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1672 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1673 let mut node_id_nonref = (*node_id).clone();
1674 let mut msg_nonref = (*msg).clone();
1675 MessageSendEvent::SendShutdown {
1676 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1677 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1680 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1681 let mut node_id_nonref = (*node_id).clone();
1682 let mut msg_nonref = (*msg).clone();
1683 MessageSendEvent::SendChannelReestablish {
1684 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1685 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1688 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1689 let mut msg_nonref = (*msg).clone();
1690 let mut update_msg_nonref = (*update_msg).clone();
1691 MessageSendEvent::BroadcastChannelAnnouncement {
1692 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1693 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
1696 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1697 let mut msg_nonref = (*msg).clone();
1698 MessageSendEvent::BroadcastNodeAnnouncement {
1699 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1702 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1703 let mut msg_nonref = (*msg).clone();
1704 MessageSendEvent::BroadcastChannelUpdate {
1705 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1708 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1709 let mut node_id_nonref = (*node_id).clone();
1710 let mut msg_nonref = (*msg).clone();
1711 MessageSendEvent::SendChannelUpdate {
1712 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1713 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1716 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
1717 let mut node_id_nonref = (*node_id).clone();
1718 let mut action_nonref = (*action).clone();
1719 MessageSendEvent::HandleError {
1720 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1721 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
1724 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1725 let mut node_id_nonref = (*node_id).clone();
1726 let mut msg_nonref = (*msg).clone();
1727 MessageSendEvent::SendChannelRangeQuery {
1728 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1729 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1732 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1733 let mut node_id_nonref = (*node_id).clone();
1734 let mut msg_nonref = (*msg).clone();
1735 MessageSendEvent::SendShortIdsQuery {
1736 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1737 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1740 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1741 let mut node_id_nonref = (*node_id).clone();
1742 let mut msg_nonref = (*msg).clone();
1743 MessageSendEvent::SendReplyChannelRange {
1744 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1745 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1751 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
1753 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1754 MessageSendEvent::SendAcceptChannel {
1755 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1756 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1759 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1760 MessageSendEvent::SendOpenChannel {
1761 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1762 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1765 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1766 MessageSendEvent::SendFundingCreated {
1767 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1768 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
1771 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1772 MessageSendEvent::SendFundingSigned {
1773 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1774 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1777 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1778 MessageSendEvent::SendFundingLocked {
1779 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1780 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg), is_owned: true },
1783 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1784 MessageSendEvent::SendAnnouncementSignatures {
1785 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1786 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
1789 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1790 MessageSendEvent::UpdateHTLCs {
1791 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1792 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
1795 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1796 MessageSendEvent::SendRevokeAndACK {
1797 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1798 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
1801 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1802 MessageSendEvent::SendClosingSigned {
1803 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1804 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1807 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1808 MessageSendEvent::SendShutdown {
1809 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1810 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
1813 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1814 MessageSendEvent::SendChannelReestablish {
1815 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1816 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
1819 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1820 MessageSendEvent::BroadcastChannelAnnouncement {
1821 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1822 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
1825 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1826 MessageSendEvent::BroadcastNodeAnnouncement {
1827 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1830 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1831 MessageSendEvent::BroadcastChannelUpdate {
1832 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1835 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1836 MessageSendEvent::SendChannelUpdate {
1837 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1838 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1841 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1842 MessageSendEvent::HandleError {
1843 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1844 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1847 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1848 MessageSendEvent::SendChannelRangeQuery {
1849 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1850 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1853 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1854 MessageSendEvent::SendShortIdsQuery {
1855 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1856 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
1859 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1860 MessageSendEvent::SendReplyChannelRange {
1861 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1862 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1868 /// Frees any resources used by the MessageSendEvent
1870 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1871 /// Creates a copy of the MessageSendEvent
1873 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1877 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
1878 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
1879 MessageSendEvent::SendAcceptChannel {
1885 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
1886 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
1887 MessageSendEvent::SendOpenChannel {
1893 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
1894 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
1895 MessageSendEvent::SendFundingCreated {
1901 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
1902 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
1903 MessageSendEvent::SendFundingSigned {
1909 /// Utility method to constructs a new SendFundingLocked-variant MessageSendEvent
1910 pub extern "C" fn MessageSendEvent_send_funding_locked(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingLocked) -> MessageSendEvent {
1911 MessageSendEvent::SendFundingLocked {
1917 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
1918 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
1919 MessageSendEvent::SendAnnouncementSignatures {
1925 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
1926 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
1927 MessageSendEvent::UpdateHTLCs {
1933 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
1934 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
1935 MessageSendEvent::SendRevokeAndACK {
1941 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
1942 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
1943 MessageSendEvent::SendClosingSigned {
1949 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
1950 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
1951 MessageSendEvent::SendShutdown {
1957 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
1958 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
1959 MessageSendEvent::SendChannelReestablish {
1965 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
1966 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1967 MessageSendEvent::BroadcastChannelAnnouncement {
1973 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
1974 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
1975 MessageSendEvent::BroadcastNodeAnnouncement {
1980 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
1981 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1982 MessageSendEvent::BroadcastChannelUpdate {
1987 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
1988 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1989 MessageSendEvent::SendChannelUpdate {
1995 /// Utility method to constructs a new HandleError-variant MessageSendEvent
1996 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
1997 MessageSendEvent::HandleError {
2003 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
2004 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
2005 MessageSendEvent::SendChannelRangeQuery {
2011 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
2012 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
2013 MessageSendEvent::SendShortIdsQuery {
2019 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
2020 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
2021 MessageSendEvent::SendReplyChannelRange {
2026 /// A trait indicating an object may generate message send events
2028 pub struct MessageSendEventsProvider {
2029 /// An opaque pointer which is passed to your function implementations as an argument.
2030 /// This has no meaning in the LDK, and can be NULL or any other value.
2031 pub this_arg: *mut c_void,
2032 /// Gets the list of pending events which were generated by previous actions, clearing the list
2035 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
2036 /// Frees any resources associated with this object given its this_arg pointer.
2037 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2038 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2040 unsafe impl Send for MessageSendEventsProvider {}
2041 unsafe impl Sync for MessageSendEventsProvider {}
2043 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
2044 MessageSendEventsProvider {
2045 this_arg: orig.this_arg,
2046 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
2047 free: Clone::clone(&orig.free),
2051 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
2052 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
2053 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
2054 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
2055 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
2060 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2061 // directly as a Deref trait in higher-level structs:
2062 impl core::ops::Deref for MessageSendEventsProvider {
2064 fn deref(&self) -> &Self {
2068 /// Calls the free function if one is set
2070 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
2071 impl Drop for MessageSendEventsProvider {
2072 fn drop(&mut self) {
2073 if let Some(f) = self.free {
2078 /// A trait indicating an object may generate events.
2080 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
2084 /// See [`process_pending_events`] for requirements around event processing.
2086 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
2087 /// event since the last invocation. The handler must either act upon the event immediately
2088 /// or preserve it for later handling.
2090 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
2091 /// consult the provider's documentation on the implication of processing events and how a handler
2092 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
2093 /// [`ChainMonitor::process_pending_events`]).
2095 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
2098 /// [`process_pending_events`]: Self::process_pending_events
2099 /// [`handle_event`]: EventHandler::handle_event
2100 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
2101 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
2103 pub struct EventsProvider {
2104 /// An opaque pointer which is passed to your function implementations as an argument.
2105 /// This has no meaning in the LDK, and can be NULL or any other value.
2106 pub this_arg: *mut c_void,
2107 /// Processes any events generated since the last call using the given event handler.
2109 /// Subsequent calls must only process new events. However, handlers must be capable of handling
2110 /// duplicate events across process restarts. This may occur if the provider was recovered from
2111 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
2112 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
2113 /// Frees any resources associated with this object given its this_arg pointer.
2114 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2115 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2117 unsafe impl Send for EventsProvider {}
2118 unsafe impl Sync for EventsProvider {}
2120 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
2122 this_arg: orig.this_arg,
2123 process_pending_events: Clone::clone(&orig.process_pending_events),
2124 free: Clone::clone(&orig.free),
2128 use lightning::util::events::EventsProvider as rustEventsProvider;
2129 /// Calls the free function if one is set
2131 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
2132 impl Drop for EventsProvider {
2133 fn drop(&mut self) {
2134 if let Some(f) = self.free {
2139 /// A trait implemented for objects handling events from [`EventsProvider`].
2141 pub struct EventHandler {
2142 /// An opaque pointer which is passed to your function implementations as an argument.
2143 /// This has no meaning in the LDK, and can be NULL or any other value.
2144 pub this_arg: *mut c_void,
2145 /// Handles the given [`Event`].
2147 /// See [`EventsProvider`] for details that must be considered when implementing this method.
2148 pub handle_event: extern "C" fn (this_arg: *const c_void, event: &crate::lightning::util::events::Event),
2149 /// Frees any resources associated with this object given its this_arg pointer.
2150 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2151 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2153 unsafe impl Send for EventHandler {}
2154 unsafe impl Sync for EventHandler {}
2156 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
2158 this_arg: orig.this_arg,
2159 handle_event: Clone::clone(&orig.handle_event),
2160 free: Clone::clone(&orig.free),
2164 use lightning::util::events::EventHandler as rustEventHandler;
2165 impl rustEventHandler for EventHandler {
2166 fn handle_event(&self, mut event: &lightning::util::events::Event) {
2167 (self.handle_event)(self.this_arg, &crate::lightning::util::events::Event::from_native(event))
2171 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2172 // directly as a Deref trait in higher-level structs:
2173 impl core::ops::Deref for EventHandler {
2175 fn deref(&self) -> &Self {
2179 /// Calls the free function if one is set
2181 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
2182 impl Drop for EventHandler {
2183 fn drop(&mut self) {
2184 if let Some(f) = self.free {