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 std::str::FromStr;
18 use core::convert::Infallible;
19 use bitcoin::hashes::Hash;
20 use crate::c_types::*;
22 /// Some information provided on receipt of payment depends on whether the payment received is a
23 /// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
27 pub enum PaymentPurpose {
28 /// Information for receiving a payment that we generated an invoice for.
30 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
31 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
32 /// [`ChannelManager::claim_funds`].
34 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
35 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
37 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
38 payment_preimage: crate::c_types::ThirtyTwoBytes,
39 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
40 /// number of deanonymization attacks during the routing process.
41 /// It is provided here for your reference, however its accuracy is enforced directly by
42 /// [`ChannelManager`] using the values you previously provided to
43 /// [`ChannelManager::create_inbound_payment`] or
44 /// [`ChannelManager::create_inbound_payment_for_hash`].
46 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
47 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
48 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
49 payment_secret: crate::c_types::ThirtyTwoBytes,
50 /// This is the `user_payment_id` which was provided to
51 /// [`ChannelManager::create_inbound_payment_for_hash`] or
52 /// [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is
53 /// simply copied here. It may be used to correlate PaymentReceived events with invoice
54 /// metadata stored elsewhere.
56 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
57 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
60 /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
61 /// (the payee) providing a preimage.
62 SpontaneousPayment(crate::c_types::ThirtyTwoBytes),
64 use lightning::util::events::PaymentPurpose as nativePaymentPurpose;
67 pub(crate) fn to_native(&self) -> nativePaymentPurpose {
69 PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
70 let mut payment_preimage_nonref = (*payment_preimage).clone();
71 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
72 let mut payment_secret_nonref = (*payment_secret).clone();
73 let mut user_payment_id_nonref = (*user_payment_id).clone();
74 nativePaymentPurpose::InvoicePayment {
75 payment_preimage: local_payment_preimage_nonref,
76 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
77 user_payment_id: user_payment_id_nonref,
80 PaymentPurpose::SpontaneousPayment (ref a, ) => {
81 let mut a_nonref = (*a).clone();
82 nativePaymentPurpose::SpontaneousPayment (
83 ::lightning::ln::PaymentPreimage(a_nonref.data),
89 pub(crate) fn into_native(self) -> nativePaymentPurpose {
91 PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
92 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
93 nativePaymentPurpose::InvoicePayment {
94 payment_preimage: local_payment_preimage,
95 payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
96 user_payment_id: user_payment_id,
99 PaymentPurpose::SpontaneousPayment (mut a, ) => {
100 nativePaymentPurpose::SpontaneousPayment (
101 ::lightning::ln::PaymentPreimage(a.data),
107 pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
109 nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
110 let mut payment_preimage_nonref = (*payment_preimage).clone();
111 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 } } };
112 let mut payment_secret_nonref = (*payment_secret).clone();
113 let mut user_payment_id_nonref = (*user_payment_id).clone();
114 PaymentPurpose::InvoicePayment {
115 payment_preimage: local_payment_preimage_nonref,
116 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
117 user_payment_id: user_payment_id_nonref,
120 nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
121 let mut a_nonref = (*a).clone();
122 PaymentPurpose::SpontaneousPayment (
123 crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
129 pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
131 nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
132 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 } } };
133 PaymentPurpose::InvoicePayment {
134 payment_preimage: local_payment_preimage,
135 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
136 user_payment_id: user_payment_id,
139 nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
140 PaymentPurpose::SpontaneousPayment (
141 crate::c_types::ThirtyTwoBytes { data: a.0 },
147 /// Frees any resources used by the PaymentPurpose
149 pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
150 /// Creates a copy of the PaymentPurpose
152 pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
156 /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
157 pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes, user_payment_id: u64) -> PaymentPurpose {
158 PaymentPurpose::InvoicePayment {
165 /// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
166 pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
167 PaymentPurpose::SpontaneousPayment(a, )
169 /// The reason the channel was closed. See individual variants more details.
173 pub enum ClosureReason {
174 /// Closure generated from receiving a peer error message.
176 /// Our counterparty may have broadcasted their latest commitment state, and we have
178 CounterpartyForceClosed {
179 /// The error which the peer sent us.
181 /// The string should be sanitized before it is used (e.g emitted to logs
182 /// or printed to stdout). Otherwise, a well crafted error message may exploit
183 /// a security vulnerability in the terminal emulator or the logging subsystem.
184 peer_msg: crate::c_types::Str,
186 /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
188 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
190 /// The channel was closed after negotiating a cooperative close and we've now broadcasted
191 /// the cooperative close transaction. Note the shutdown may have been initiated by us.
193 /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
194 /// commitment transaction came from our counterparty, but it may also have come from
195 /// a copy of our own `ChannelMonitor`.
196 CommitmentTxConfirmed,
197 /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
199 /// A developer-readable error message which we generated.
200 err: crate::c_types::Str,
202 /// The `PeerManager` informed us that we've disconnected from the peer. We close channels
203 /// if the `PeerManager` informed us that it is unlikely we'll be able to connect to the
204 /// peer again in the future or if the peer disconnected before we finished negotiating
205 /// the channel open. The first case may be caused by incompatible features which our
206 /// counterparty, or we, require.
208 /// Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than
209 /// the ChannelManager deserialized.
210 OutdatedChannelManager,
212 use lightning::util::events::ClosureReason as nativeClosureReason;
215 pub(crate) fn to_native(&self) -> nativeClosureReason {
217 ClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
218 let mut peer_msg_nonref = (*peer_msg).clone();
219 nativeClosureReason::CounterpartyForceClosed {
220 peer_msg: peer_msg_nonref.into_string(),
223 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
224 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
225 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
226 ClosureReason::ProcessingError {ref err, } => {
227 let mut err_nonref = (*err).clone();
228 nativeClosureReason::ProcessingError {
229 err: err_nonref.into_string(),
232 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
233 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
237 pub(crate) fn into_native(self) -> nativeClosureReason {
239 ClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
240 nativeClosureReason::CounterpartyForceClosed {
241 peer_msg: peer_msg.into_string(),
244 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
245 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
246 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
247 ClosureReason::ProcessingError {mut err, } => {
248 nativeClosureReason::ProcessingError {
249 err: err.into_string(),
252 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
253 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
257 pub(crate) fn from_native(native: &nativeClosureReason) -> Self {
259 nativeClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
260 let mut peer_msg_nonref = (*peer_msg).clone();
261 ClosureReason::CounterpartyForceClosed {
262 peer_msg: peer_msg_nonref.into(),
265 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
266 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
267 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
268 nativeClosureReason::ProcessingError {ref err, } => {
269 let mut err_nonref = (*err).clone();
270 ClosureReason::ProcessingError {
271 err: err_nonref.into(),
274 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
275 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
279 pub(crate) fn native_into(native: nativeClosureReason) -> Self {
281 nativeClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
282 ClosureReason::CounterpartyForceClosed {
283 peer_msg: peer_msg.into(),
286 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
287 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
288 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
289 nativeClosureReason::ProcessingError {mut err, } => {
290 ClosureReason::ProcessingError {
294 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
295 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
299 /// Frees any resources used by the ClosureReason
301 pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { }
302 /// Creates a copy of the ClosureReason
304 pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason {
308 /// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
309 pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::c_types::Str) -> ClosureReason {
310 ClosureReason::CounterpartyForceClosed {
315 /// Utility method to constructs a new HolderForceClosed-variant ClosureReason
316 pub extern "C" fn ClosureReason_holder_force_closed() -> ClosureReason {
317 ClosureReason::HolderForceClosed}
319 /// Utility method to constructs a new CooperativeClosure-variant ClosureReason
320 pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason {
321 ClosureReason::CooperativeClosure}
323 /// Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
324 pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason {
325 ClosureReason::CommitmentTxConfirmed}
327 /// Utility method to constructs a new ProcessingError-variant ClosureReason
328 pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason {
329 ClosureReason::ProcessingError {
334 /// Utility method to constructs a new DisconnectedPeer-variant ClosureReason
335 pub extern "C" fn ClosureReason_disconnected_peer() -> ClosureReason {
336 ClosureReason::DisconnectedPeer}
338 /// Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
339 pub extern "C" fn ClosureReason_outdated_channel_manager() -> ClosureReason {
340 ClosureReason::OutdatedChannelManager}
342 /// Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
343 pub extern "C" fn ClosureReason_write(obj: &ClosureReason) -> crate::c_types::derived::CVec_u8Z {
344 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
347 /// Read a ClosureReason from a byte array, created by ClosureReason_write
348 pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_ClosureReasonZDecodeErrorZ {
349 let res: Result<Option<lightning::util::events::ClosureReason>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
350 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() };
353 /// An Event which you should probably take some action in response to.
355 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
356 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
357 /// written as it makes no sense to respond to it after reconnecting to peers).
362 /// Used to indicate that the client should generate a funding transaction with the given
363 /// parameters and then call ChannelManager::funding_transaction_generated.
364 /// Generated in ChannelManager message handling.
365 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
366 /// counterparty can steal your funds!
367 FundingGenerationReady {
368 /// The random channel_id we picked which you'll need to pass into
369 /// ChannelManager::funding_transaction_generated.
370 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
371 /// The value, in satoshis, that the output should have.
372 channel_value_satoshis: u64,
373 /// The script which should be used in the transaction output.
374 output_script: crate::c_types::derived::CVec_u8Z,
375 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
376 /// an inbound channel.
378 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
379 user_channel_id: u64,
381 /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
382 /// [`ChannelManager::claim_funds`] to get it....
383 /// Note that if the preimage is not known, you should call
384 /// [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid
385 /// network congestion.
386 /// If you fail to call either [`ChannelManager::claim_funds`] or
387 /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be
388 /// automatically failed.
390 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
391 /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
393 /// The hash for which the preimage should be handed to the ChannelManager.
394 payment_hash: crate::c_types::ThirtyTwoBytes,
395 /// The value, in thousandths of a satoshi, that this payment is for.
397 /// Information for claiming this received payment, based on whether the purpose of the
398 /// payment is to pay an invoice or to send a spontaneous payment.
399 purpose: crate::lightning::util::events::PaymentPurpose,
401 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
402 /// and we got back the payment preimage for it).
404 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
405 /// event. In this situation, you SHOULD treat this payment as having succeeded.
407 /// The id returned by [`ChannelManager::send_payment`] and used with
408 /// [`ChannelManager::retry_payment`].
410 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
411 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
413 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
414 payment_id: crate::c_types::ThirtyTwoBytes,
415 /// The preimage to the hash given to ChannelManager::send_payment.
416 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
417 /// store it somehow!
418 payment_preimage: crate::c_types::ThirtyTwoBytes,
419 /// The hash which was given to [`ChannelManager::send_payment`].
421 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
422 payment_hash: crate::c_types::ThirtyTwoBytes,
423 /// The total fee which was spent at intermediate hops in this payment, across all paths.
425 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
426 /// overpayment to the recipient node.
428 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
429 /// overstate the amount paid, though this is unlikely.
431 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
432 fee_paid_msat: crate::c_types::derived::COption_u64Z,
434 /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
435 /// something. You may wish to retry with a different route.
437 /// The id returned by [`ChannelManager::send_payment`] and used with
438 /// [`ChannelManager::retry_payment`].
440 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
441 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
443 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
444 payment_id: crate::c_types::ThirtyTwoBytes,
445 /// The hash which was given to ChannelManager::send_payment.
446 payment_hash: crate::c_types::ThirtyTwoBytes,
447 /// Indicates the payment was rejected for some reason by the recipient. This implies that
448 /// the payment has failed, not just the route in question. If this is not set, you may
449 /// retry the payment via a different route.
450 rejected_by_dest: bool,
451 /// Any failure information conveyed via the Onion return packet by a node along the failed
454 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
455 /// account the update. [`NetGraphMsgHandler`] is capable of doing this.
457 /// [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph
458 /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
459 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
460 /// For both single-path and multi-path payments, this is set if all paths of the payment have
461 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
462 /// larger MPP payment were still in flight when this event was generated.
463 all_paths_failed: bool,
464 /// The payment path that failed.
465 path: crate::c_types::derived::CVec_RouteHopZ,
466 /// The channel responsible for the failed payment path.
468 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
469 /// retried. May be `None` for older [`Event`] serializations.
470 short_channel_id: crate::c_types::derived::COption_u64Z,
471 /// Parameters needed to compute a new [`Route`] when retrying the failed payment path.
473 /// See [`find_route`] for details.
475 /// [`Route`]: crate::routing::router::Route
476 /// [`find_route`]: crate::routing::router::find_route
478 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
479 retry: crate::lightning::routing::router::RouteParameters,
481 /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
482 /// time in the future.
483 PendingHTLCsForwardable {
484 /// The minimum amount of time that should be waited prior to calling
485 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
486 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
487 /// now + 5*time_forwardable).
488 time_forwardable: u64,
490 /// Used to indicate that an output which you should know how to spend was confirmed on chain
491 /// and is now spendable.
492 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
493 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
494 /// somewhere and spend them when you create on-chain transactions.
496 /// The outputs which you should store as spendable by you.
497 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
499 /// This event is generated when a payment has been successfully forwarded through us and a
500 /// forwarding fee earned.
502 /// The fee, in milli-satoshis, which was earned as a result of the payment.
504 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
505 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
506 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
507 /// claimed the full value in millisatoshis from the source. In this case,
508 /// `claim_from_onchain_tx` will be set.
510 /// If the channel which sent us the payment has been force-closed, we will claim the funds
511 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
512 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
513 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
515 fee_earned_msat: crate::c_types::derived::COption_u64Z,
516 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
518 claim_from_onchain_tx: bool,
520 /// Used to indicate that a channel with the given `channel_id` is in the process of closure.
522 /// The channel_id of the channel which has been closed. Note that on-chain transactions
523 /// resolving the channel are likely still awaiting confirmation.
524 channel_id: crate::c_types::ThirtyTwoBytes,
525 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
526 /// an inbound channel. This will always be zero for objects serialized with LDK versions
527 /// prior to 0.0.102.
529 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
530 user_channel_id: u64,
531 /// The reason the channel was closed.
532 reason: crate::lightning::util::events::ClosureReason,
534 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
535 /// inputs for another purpose.
537 /// The channel_id of the channel which has been closed.
538 channel_id: crate::c_types::ThirtyTwoBytes,
539 /// The full transaction received from the user
540 transaction: crate::c_types::Transaction,
543 use lightning::util::events::Event as nativeEvent;
546 pub(crate) fn to_native(&self) -> nativeEvent {
548 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
549 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
550 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
551 let mut output_script_nonref = (*output_script).clone();
552 let mut user_channel_id_nonref = (*user_channel_id).clone();
553 nativeEvent::FundingGenerationReady {
554 temporary_channel_id: temporary_channel_id_nonref.data,
555 channel_value_satoshis: channel_value_satoshis_nonref,
556 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
557 user_channel_id: user_channel_id_nonref,
560 Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
561 let mut payment_hash_nonref = (*payment_hash).clone();
562 let mut amt_nonref = (*amt).clone();
563 let mut purpose_nonref = (*purpose).clone();
564 nativeEvent::PaymentReceived {
565 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
567 purpose: purpose_nonref.into_native(),
570 Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
571 let mut payment_id_nonref = (*payment_id).clone();
572 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
573 let mut payment_preimage_nonref = (*payment_preimage).clone();
574 let mut payment_hash_nonref = (*payment_hash).clone();
575 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
576 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
577 nativeEvent::PaymentSent {
578 payment_id: local_payment_id_nonref,
579 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
580 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
581 fee_paid_msat: local_fee_paid_msat_nonref,
584 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, } => {
585 let mut payment_id_nonref = (*payment_id).clone();
586 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
587 let mut payment_hash_nonref = (*payment_hash).clone();
588 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
589 let mut network_update_nonref = (*network_update).clone();
590 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() }) } };
591 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
592 let mut path_nonref = (*path).clone();
593 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()) } }); };
594 let mut short_channel_id_nonref = (*short_channel_id).clone();
595 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
596 let mut retry_nonref = (*retry).clone();
597 let mut local_retry_nonref = if retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry_nonref.take_inner()) } }) };
598 nativeEvent::PaymentPathFailed {
599 payment_id: local_payment_id_nonref,
600 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
601 rejected_by_dest: rejected_by_dest_nonref,
602 network_update: local_network_update_nonref,
603 all_paths_failed: all_paths_failed_nonref,
604 path: local_path_nonref,
605 short_channel_id: local_short_channel_id_nonref,
606 retry: local_retry_nonref,
609 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
610 let mut time_forwardable_nonref = (*time_forwardable).clone();
611 nativeEvent::PendingHTLCsForwardable {
612 time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
615 Event::SpendableOutputs {ref outputs, } => {
616 let mut outputs_nonref = (*outputs).clone();
617 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
618 nativeEvent::SpendableOutputs {
619 outputs: local_outputs_nonref,
622 Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
623 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
624 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
625 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
626 nativeEvent::PaymentForwarded {
627 fee_earned_msat: local_fee_earned_msat_nonref,
628 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
631 Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
632 let mut channel_id_nonref = (*channel_id).clone();
633 let mut user_channel_id_nonref = (*user_channel_id).clone();
634 let mut reason_nonref = (*reason).clone();
635 nativeEvent::ChannelClosed {
636 channel_id: channel_id_nonref.data,
637 user_channel_id: user_channel_id_nonref,
638 reason: reason_nonref.into_native(),
641 Event::DiscardFunding {ref channel_id, ref transaction, } => {
642 let mut channel_id_nonref = (*channel_id).clone();
643 let mut transaction_nonref = (*transaction).clone();
644 nativeEvent::DiscardFunding {
645 channel_id: channel_id_nonref.data,
646 transaction: transaction_nonref.into_bitcoin(),
652 pub(crate) fn into_native(self) -> nativeEvent {
654 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
655 nativeEvent::FundingGenerationReady {
656 temporary_channel_id: temporary_channel_id.data,
657 channel_value_satoshis: channel_value_satoshis,
658 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
659 user_channel_id: user_channel_id,
662 Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
663 nativeEvent::PaymentReceived {
664 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
666 purpose: purpose.into_native(),
669 Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
670 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
671 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
672 nativeEvent::PaymentSent {
673 payment_id: local_payment_id,
674 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
675 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
676 fee_paid_msat: local_fee_paid_msat,
679 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, } => {
680 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
681 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() }) } };
682 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
683 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
684 let mut local_retry = if retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry.take_inner()) } }) };
685 nativeEvent::PaymentPathFailed {
686 payment_id: local_payment_id,
687 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
688 rejected_by_dest: rejected_by_dest,
689 network_update: local_network_update,
690 all_paths_failed: all_paths_failed,
692 short_channel_id: local_short_channel_id,
696 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
697 nativeEvent::PendingHTLCsForwardable {
698 time_forwardable: std::time::Duration::from_secs(time_forwardable),
701 Event::SpendableOutputs {mut outputs, } => {
702 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
703 nativeEvent::SpendableOutputs {
704 outputs: local_outputs,
707 Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
708 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
709 nativeEvent::PaymentForwarded {
710 fee_earned_msat: local_fee_earned_msat,
711 claim_from_onchain_tx: claim_from_onchain_tx,
714 Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
715 nativeEvent::ChannelClosed {
716 channel_id: channel_id.data,
717 user_channel_id: user_channel_id,
718 reason: reason.into_native(),
721 Event::DiscardFunding {mut channel_id, mut transaction, } => {
722 nativeEvent::DiscardFunding {
723 channel_id: channel_id.data,
724 transaction: transaction.into_bitcoin(),
730 pub(crate) fn from_native(native: &nativeEvent) -> Self {
732 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
733 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
734 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
735 let mut output_script_nonref = (*output_script).clone();
736 let mut user_channel_id_nonref = (*user_channel_id).clone();
737 Event::FundingGenerationReady {
738 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
739 channel_value_satoshis: channel_value_satoshis_nonref,
740 output_script: output_script_nonref.into_bytes().into(),
741 user_channel_id: user_channel_id_nonref,
744 nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
745 let mut payment_hash_nonref = (*payment_hash).clone();
746 let mut amt_nonref = (*amt).clone();
747 let mut purpose_nonref = (*purpose).clone();
748 Event::PaymentReceived {
749 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
751 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
754 nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
755 let mut payment_id_nonref = (*payment_id).clone();
756 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 } } };
757 let mut payment_preimage_nonref = (*payment_preimage).clone();
758 let mut payment_hash_nonref = (*payment_hash).clone();
759 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
760 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() }) };
762 payment_id: local_payment_id_nonref,
763 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
764 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
765 fee_paid_msat: local_fee_paid_msat_nonref,
768 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, } => {
769 let mut payment_id_nonref = (*payment_id).clone();
770 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 } } };
771 let mut payment_hash_nonref = (*payment_hash).clone();
772 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
773 let mut network_update_nonref = (*network_update).clone();
774 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()) }) };
775 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
776 let mut path_nonref = (*path).clone();
777 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 } }); };
778 let mut short_channel_id_nonref = (*short_channel_id).clone();
779 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() }) };
780 let mut retry_nonref = (*retry).clone();
781 let mut local_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if retry_nonref.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((retry_nonref.unwrap())) } }, is_owned: true };
782 Event::PaymentPathFailed {
783 payment_id: local_payment_id_nonref,
784 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
785 rejected_by_dest: rejected_by_dest_nonref,
786 network_update: local_network_update_nonref,
787 all_paths_failed: all_paths_failed_nonref,
788 path: local_path_nonref.into(),
789 short_channel_id: local_short_channel_id_nonref,
790 retry: local_retry_nonref,
793 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
794 let mut time_forwardable_nonref = (*time_forwardable).clone();
795 Event::PendingHTLCsForwardable {
796 time_forwardable: time_forwardable_nonref.as_secs(),
799 nativeEvent::SpendableOutputs {ref outputs, } => {
800 let mut outputs_nonref = (*outputs).clone();
801 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) }); };
802 Event::SpendableOutputs {
803 outputs: local_outputs_nonref.into(),
806 nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
807 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
808 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() }) };
809 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
810 Event::PaymentForwarded {
811 fee_earned_msat: local_fee_earned_msat_nonref,
812 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
815 nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
816 let mut channel_id_nonref = (*channel_id).clone();
817 let mut user_channel_id_nonref = (*user_channel_id).clone();
818 let mut reason_nonref = (*reason).clone();
819 Event::ChannelClosed {
820 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
821 user_channel_id: user_channel_id_nonref,
822 reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
825 nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
826 let mut channel_id_nonref = (*channel_id).clone();
827 let mut transaction_nonref = (*transaction).clone();
828 Event::DiscardFunding {
829 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
830 transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
836 pub(crate) fn native_into(native: nativeEvent) -> Self {
838 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
839 Event::FundingGenerationReady {
840 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
841 channel_value_satoshis: channel_value_satoshis,
842 output_script: output_script.into_bytes().into(),
843 user_channel_id: user_channel_id,
846 nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
847 Event::PaymentReceived {
848 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
850 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
853 nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
854 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 } } };
855 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() }) };
857 payment_id: local_payment_id,
858 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
859 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
860 fee_paid_msat: local_fee_paid_msat,
863 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, } => {
864 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 } } };
865 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()) }) };
866 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 } }); };
867 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() }) };
868 let mut local_retry = crate::lightning::routing::router::RouteParameters { inner: if retry.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((retry.unwrap())) } }, is_owned: true };
869 Event::PaymentPathFailed {
870 payment_id: local_payment_id,
871 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
872 rejected_by_dest: rejected_by_dest,
873 network_update: local_network_update,
874 all_paths_failed: all_paths_failed,
875 path: local_path.into(),
876 short_channel_id: local_short_channel_id,
880 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
881 Event::PendingHTLCsForwardable {
882 time_forwardable: time_forwardable.as_secs(),
885 nativeEvent::SpendableOutputs {mut outputs, } => {
886 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
887 Event::SpendableOutputs {
888 outputs: local_outputs.into(),
891 nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
892 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() }) };
893 Event::PaymentForwarded {
894 fee_earned_msat: local_fee_earned_msat,
895 claim_from_onchain_tx: claim_from_onchain_tx,
898 nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
899 Event::ChannelClosed {
900 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
901 user_channel_id: user_channel_id,
902 reason: crate::lightning::util::events::ClosureReason::native_into(reason),
905 nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
906 Event::DiscardFunding {
907 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
908 transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
914 /// Frees any resources used by the Event
916 pub extern "C" fn Event_free(this_ptr: Event) { }
917 /// Creates a copy of the Event
919 pub extern "C" fn Event_clone(orig: &Event) -> Event {
923 /// Utility method to constructs a new FundingGenerationReady-variant Event
924 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 {
925 Event::FundingGenerationReady {
926 temporary_channel_id,
927 channel_value_satoshis,
933 /// Utility method to constructs a new PaymentReceived-variant Event
934 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
935 Event::PaymentReceived {
942 /// Utility method to constructs a new PaymentSent-variant Event
943 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 {
952 /// Utility method to constructs a new PaymentPathFailed-variant Event
953 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 {
954 Event::PaymentPathFailed {
966 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
967 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
968 Event::PendingHTLCsForwardable {
973 /// Utility method to constructs a new SpendableOutputs-variant Event
974 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
975 Event::SpendableOutputs {
980 /// Utility method to constructs a new PaymentForwarded-variant Event
981 pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
982 Event::PaymentForwarded {
984 claim_from_onchain_tx,
988 /// Utility method to constructs a new ChannelClosed-variant Event
989 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: u64, reason: crate::lightning::util::events::ClosureReason) -> Event {
990 Event::ChannelClosed {
997 /// Utility method to constructs a new DiscardFunding-variant Event
998 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
999 Event::DiscardFunding {
1005 /// Serialize the Event object into a byte array which can be read by Event_read
1006 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
1007 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
1010 /// Read a Event from a byte array, created by Event_write
1011 pub extern "C" fn Event_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_EventZDecodeErrorZ {
1012 let res: Result<Option<lightning::util::events::Event>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
1013 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() };
1016 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1017 /// broadcast to most peers).
1018 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1022 pub enum MessageSendEvent {
1023 /// Used to indicate that we've accepted a channel open and should send the accept_channel
1024 /// message provided to the given peer.
1026 /// The node_id of the node which should receive this message
1027 node_id: crate::c_types::PublicKey,
1028 /// The message which should be sent.
1029 msg: crate::lightning::ln::msgs::AcceptChannel,
1031 /// Used to indicate that we've initiated a channel open and should send the open_channel
1032 /// message provided to the given peer.
1034 /// The node_id of the node which should receive this message
1035 node_id: crate::c_types::PublicKey,
1036 /// The message which should be sent.
1037 msg: crate::lightning::ln::msgs::OpenChannel,
1039 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1040 SendFundingCreated {
1041 /// The node_id of the node which should receive this message
1042 node_id: crate::c_types::PublicKey,
1043 /// The message which should be sent.
1044 msg: crate::lightning::ln::msgs::FundingCreated,
1046 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
1048 /// The node_id of the node which should receive this message
1049 node_id: crate::c_types::PublicKey,
1050 /// The message which should be sent.
1051 msg: crate::lightning::ln::msgs::FundingSigned,
1053 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
1055 /// The node_id of the node which should receive these message(s)
1056 node_id: crate::c_types::PublicKey,
1057 /// The funding_locked message which should be sent.
1058 msg: crate::lightning::ln::msgs::FundingLocked,
1060 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1061 SendAnnouncementSignatures {
1062 /// The node_id of the node which should receive these message(s)
1063 node_id: crate::c_types::PublicKey,
1064 /// The announcement_signatures message which should be sent.
1065 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
1067 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1068 /// message should be sent to the peer with the given node_id.
1070 /// The node_id of the node which should receive these message(s)
1071 node_id: crate::c_types::PublicKey,
1072 /// The update messages which should be sent. ALL messages in the struct should be sent!
1073 updates: crate::lightning::ln::msgs::CommitmentUpdate,
1075 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1077 /// The node_id of the node which should receive this message
1078 node_id: crate::c_types::PublicKey,
1079 /// The message which should be sent.
1080 msg: crate::lightning::ln::msgs::RevokeAndACK,
1082 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1084 /// The node_id of the node which should receive this message
1085 node_id: crate::c_types::PublicKey,
1086 /// The message which should be sent.
1087 msg: crate::lightning::ln::msgs::ClosingSigned,
1089 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
1091 /// The node_id of the node which should receive this message
1092 node_id: crate::c_types::PublicKey,
1093 /// The message which should be sent.
1094 msg: crate::lightning::ln::msgs::Shutdown,
1096 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1097 SendChannelReestablish {
1098 /// The node_id of the node which should receive this message
1099 node_id: crate::c_types::PublicKey,
1100 /// The message which should be sent.
1101 msg: crate::lightning::ln::msgs::ChannelReestablish,
1103 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1104 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1106 /// Note that after doing so, you very likely (unless you did so very recently) want to call
1107 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
1108 /// This ensures that any nodes which see our channel_announcement also have a relevant
1109 /// node_announcement, including relevant feature flags which may be important for routing
1110 /// through or to us.
1111 BroadcastChannelAnnouncement {
1112 /// The channel_announcement which should be sent.
1113 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
1114 /// The followup channel_update which should be sent.
1115 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
1117 /// Used to indicate that a node_announcement should be broadcast to all peers.
1118 BroadcastNodeAnnouncement {
1119 /// The node_announcement which should be sent.
1120 msg: crate::lightning::ln::msgs::NodeAnnouncement,
1122 /// Used to indicate that a channel_update should be broadcast to all peers.
1123 BroadcastChannelUpdate {
1124 /// The channel_update which should be sent.
1125 msg: crate::lightning::ln::msgs::ChannelUpdate,
1127 /// Used to indicate that a channel_update should be sent to a single peer.
1128 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1129 /// private channel and we shouldn't be informing all of our peers of channel parameters.
1131 /// The node_id of the node which should receive this message
1132 node_id: crate::c_types::PublicKey,
1133 /// The channel_update which should be sent.
1134 msg: crate::lightning::ln::msgs::ChannelUpdate,
1136 /// Broadcast an error downstream to be handled
1138 /// The node_id of the node which should receive this message
1139 node_id: crate::c_types::PublicKey,
1140 /// The action which should be taken.
1141 action: crate::lightning::ln::msgs::ErrorAction,
1143 /// Query a peer for channels with funding transaction UTXOs in a block range.
1144 SendChannelRangeQuery {
1145 /// The node_id of this message recipient
1146 node_id: crate::c_types::PublicKey,
1147 /// The query_channel_range which should be sent.
1148 msg: crate::lightning::ln::msgs::QueryChannelRange,
1150 /// Request routing gossip messages from a peer for a list of channels identified by
1151 /// their short_channel_ids.
1153 /// The node_id of this message recipient
1154 node_id: crate::c_types::PublicKey,
1155 /// The query_short_channel_ids which should be sent.
1156 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
1158 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1159 /// emitted during processing of the query.
1160 SendReplyChannelRange {
1161 /// The node_id of this message recipient
1162 node_id: crate::c_types::PublicKey,
1163 /// The reply_channel_range which should be sent.
1164 msg: crate::lightning::ln::msgs::ReplyChannelRange,
1167 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
1168 impl MessageSendEvent {
1170 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
1172 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1173 let mut node_id_nonref = (*node_id).clone();
1174 let mut msg_nonref = (*msg).clone();
1175 nativeMessageSendEvent::SendAcceptChannel {
1176 node_id: node_id_nonref.into_rust(),
1177 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1180 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1181 let mut node_id_nonref = (*node_id).clone();
1182 let mut msg_nonref = (*msg).clone();
1183 nativeMessageSendEvent::SendOpenChannel {
1184 node_id: node_id_nonref.into_rust(),
1185 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1188 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1189 let mut node_id_nonref = (*node_id).clone();
1190 let mut msg_nonref = (*msg).clone();
1191 nativeMessageSendEvent::SendFundingCreated {
1192 node_id: node_id_nonref.into_rust(),
1193 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1196 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1197 let mut node_id_nonref = (*node_id).clone();
1198 let mut msg_nonref = (*msg).clone();
1199 nativeMessageSendEvent::SendFundingSigned {
1200 node_id: node_id_nonref.into_rust(),
1201 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1204 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1205 let mut node_id_nonref = (*node_id).clone();
1206 let mut msg_nonref = (*msg).clone();
1207 nativeMessageSendEvent::SendFundingLocked {
1208 node_id: node_id_nonref.into_rust(),
1209 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1212 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1213 let mut node_id_nonref = (*node_id).clone();
1214 let mut msg_nonref = (*msg).clone();
1215 nativeMessageSendEvent::SendAnnouncementSignatures {
1216 node_id: node_id_nonref.into_rust(),
1217 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1220 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1221 let mut node_id_nonref = (*node_id).clone();
1222 let mut updates_nonref = (*updates).clone();
1223 nativeMessageSendEvent::UpdateHTLCs {
1224 node_id: node_id_nonref.into_rust(),
1225 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
1228 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1229 let mut node_id_nonref = (*node_id).clone();
1230 let mut msg_nonref = (*msg).clone();
1231 nativeMessageSendEvent::SendRevokeAndACK {
1232 node_id: node_id_nonref.into_rust(),
1233 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1236 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1237 let mut node_id_nonref = (*node_id).clone();
1238 let mut msg_nonref = (*msg).clone();
1239 nativeMessageSendEvent::SendClosingSigned {
1240 node_id: node_id_nonref.into_rust(),
1241 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1244 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1245 let mut node_id_nonref = (*node_id).clone();
1246 let mut msg_nonref = (*msg).clone();
1247 nativeMessageSendEvent::SendShutdown {
1248 node_id: node_id_nonref.into_rust(),
1249 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1252 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1253 let mut node_id_nonref = (*node_id).clone();
1254 let mut msg_nonref = (*msg).clone();
1255 nativeMessageSendEvent::SendChannelReestablish {
1256 node_id: node_id_nonref.into_rust(),
1257 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1260 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1261 let mut msg_nonref = (*msg).clone();
1262 let mut update_msg_nonref = (*update_msg).clone();
1263 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1264 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1265 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
1268 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1269 let mut msg_nonref = (*msg).clone();
1270 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1271 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1274 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1275 let mut msg_nonref = (*msg).clone();
1276 nativeMessageSendEvent::BroadcastChannelUpdate {
1277 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1280 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1281 let mut node_id_nonref = (*node_id).clone();
1282 let mut msg_nonref = (*msg).clone();
1283 nativeMessageSendEvent::SendChannelUpdate {
1284 node_id: node_id_nonref.into_rust(),
1285 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1288 MessageSendEvent::HandleError {ref node_id, ref action, } => {
1289 let mut node_id_nonref = (*node_id).clone();
1290 let mut action_nonref = (*action).clone();
1291 nativeMessageSendEvent::HandleError {
1292 node_id: node_id_nonref.into_rust(),
1293 action: action_nonref.into_native(),
1296 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1297 let mut node_id_nonref = (*node_id).clone();
1298 let mut msg_nonref = (*msg).clone();
1299 nativeMessageSendEvent::SendChannelRangeQuery {
1300 node_id: node_id_nonref.into_rust(),
1301 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1304 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1305 let mut node_id_nonref = (*node_id).clone();
1306 let mut msg_nonref = (*msg).clone();
1307 nativeMessageSendEvent::SendShortIdsQuery {
1308 node_id: node_id_nonref.into_rust(),
1309 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1312 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1313 let mut node_id_nonref = (*node_id).clone();
1314 let mut msg_nonref = (*msg).clone();
1315 nativeMessageSendEvent::SendReplyChannelRange {
1316 node_id: node_id_nonref.into_rust(),
1317 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1323 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
1325 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1326 nativeMessageSendEvent::SendAcceptChannel {
1327 node_id: node_id.into_rust(),
1328 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1331 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1332 nativeMessageSendEvent::SendOpenChannel {
1333 node_id: node_id.into_rust(),
1334 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1337 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1338 nativeMessageSendEvent::SendFundingCreated {
1339 node_id: node_id.into_rust(),
1340 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1343 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1344 nativeMessageSendEvent::SendFundingSigned {
1345 node_id: node_id.into_rust(),
1346 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1349 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1350 nativeMessageSendEvent::SendFundingLocked {
1351 node_id: node_id.into_rust(),
1352 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1355 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1356 nativeMessageSendEvent::SendAnnouncementSignatures {
1357 node_id: node_id.into_rust(),
1358 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1361 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1362 nativeMessageSendEvent::UpdateHTLCs {
1363 node_id: node_id.into_rust(),
1364 updates: *unsafe { Box::from_raw(updates.take_inner()) },
1367 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1368 nativeMessageSendEvent::SendRevokeAndACK {
1369 node_id: node_id.into_rust(),
1370 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1373 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1374 nativeMessageSendEvent::SendClosingSigned {
1375 node_id: node_id.into_rust(),
1376 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1379 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1380 nativeMessageSendEvent::SendShutdown {
1381 node_id: node_id.into_rust(),
1382 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1385 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1386 nativeMessageSendEvent::SendChannelReestablish {
1387 node_id: node_id.into_rust(),
1388 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1391 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1392 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1393 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1394 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
1397 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1398 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1399 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1402 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1403 nativeMessageSendEvent::BroadcastChannelUpdate {
1404 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1407 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1408 nativeMessageSendEvent::SendChannelUpdate {
1409 node_id: node_id.into_rust(),
1410 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1413 MessageSendEvent::HandleError {mut node_id, mut action, } => {
1414 nativeMessageSendEvent::HandleError {
1415 node_id: node_id.into_rust(),
1416 action: action.into_native(),
1419 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1420 nativeMessageSendEvent::SendChannelRangeQuery {
1421 node_id: node_id.into_rust(),
1422 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1425 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1426 nativeMessageSendEvent::SendShortIdsQuery {
1427 node_id: node_id.into_rust(),
1428 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1431 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1432 nativeMessageSendEvent::SendReplyChannelRange {
1433 node_id: node_id.into_rust(),
1434 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1440 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
1442 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1443 let mut node_id_nonref = (*node_id).clone();
1444 let mut msg_nonref = (*msg).clone();
1445 MessageSendEvent::SendAcceptChannel {
1446 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1447 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1450 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1451 let mut node_id_nonref = (*node_id).clone();
1452 let mut msg_nonref = (*msg).clone();
1453 MessageSendEvent::SendOpenChannel {
1454 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1455 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1458 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1459 let mut node_id_nonref = (*node_id).clone();
1460 let mut msg_nonref = (*msg).clone();
1461 MessageSendEvent::SendFundingCreated {
1462 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1463 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1466 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1467 let mut node_id_nonref = (*node_id).clone();
1468 let mut msg_nonref = (*msg).clone();
1469 MessageSendEvent::SendFundingSigned {
1470 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1471 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1474 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1475 let mut node_id_nonref = (*node_id).clone();
1476 let mut msg_nonref = (*msg).clone();
1477 MessageSendEvent::SendFundingLocked {
1478 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1479 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1482 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1483 let mut node_id_nonref = (*node_id).clone();
1484 let mut msg_nonref = (*msg).clone();
1485 MessageSendEvent::SendAnnouncementSignatures {
1486 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1487 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1490 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1491 let mut node_id_nonref = (*node_id).clone();
1492 let mut updates_nonref = (*updates).clone();
1493 MessageSendEvent::UpdateHTLCs {
1494 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1495 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
1498 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1499 let mut node_id_nonref = (*node_id).clone();
1500 let mut msg_nonref = (*msg).clone();
1501 MessageSendEvent::SendRevokeAndACK {
1502 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1503 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1506 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1507 let mut node_id_nonref = (*node_id).clone();
1508 let mut msg_nonref = (*msg).clone();
1509 MessageSendEvent::SendClosingSigned {
1510 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1511 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1514 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1515 let mut node_id_nonref = (*node_id).clone();
1516 let mut msg_nonref = (*msg).clone();
1517 MessageSendEvent::SendShutdown {
1518 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1519 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1522 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1523 let mut node_id_nonref = (*node_id).clone();
1524 let mut msg_nonref = (*msg).clone();
1525 MessageSendEvent::SendChannelReestablish {
1526 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1527 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1530 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1531 let mut msg_nonref = (*msg).clone();
1532 let mut update_msg_nonref = (*update_msg).clone();
1533 MessageSendEvent::BroadcastChannelAnnouncement {
1534 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1535 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
1538 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1539 let mut msg_nonref = (*msg).clone();
1540 MessageSendEvent::BroadcastNodeAnnouncement {
1541 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1544 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1545 let mut msg_nonref = (*msg).clone();
1546 MessageSendEvent::BroadcastChannelUpdate {
1547 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1550 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1551 let mut node_id_nonref = (*node_id).clone();
1552 let mut msg_nonref = (*msg).clone();
1553 MessageSendEvent::SendChannelUpdate {
1554 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1555 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1558 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
1559 let mut node_id_nonref = (*node_id).clone();
1560 let mut action_nonref = (*action).clone();
1561 MessageSendEvent::HandleError {
1562 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1563 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
1566 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1567 let mut node_id_nonref = (*node_id).clone();
1568 let mut msg_nonref = (*msg).clone();
1569 MessageSendEvent::SendChannelRangeQuery {
1570 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1571 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1574 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1575 let mut node_id_nonref = (*node_id).clone();
1576 let mut msg_nonref = (*msg).clone();
1577 MessageSendEvent::SendShortIdsQuery {
1578 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1579 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1582 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1583 let mut node_id_nonref = (*node_id).clone();
1584 let mut msg_nonref = (*msg).clone();
1585 MessageSendEvent::SendReplyChannelRange {
1586 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1587 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1593 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
1595 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1596 MessageSendEvent::SendAcceptChannel {
1597 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1598 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1601 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1602 MessageSendEvent::SendOpenChannel {
1603 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1604 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1607 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1608 MessageSendEvent::SendFundingCreated {
1609 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1610 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
1613 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1614 MessageSendEvent::SendFundingSigned {
1615 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1616 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1619 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1620 MessageSendEvent::SendFundingLocked {
1621 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1622 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg), is_owned: true },
1625 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1626 MessageSendEvent::SendAnnouncementSignatures {
1627 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1628 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
1631 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1632 MessageSendEvent::UpdateHTLCs {
1633 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1634 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
1637 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1638 MessageSendEvent::SendRevokeAndACK {
1639 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1640 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
1643 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1644 MessageSendEvent::SendClosingSigned {
1645 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1646 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1649 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1650 MessageSendEvent::SendShutdown {
1651 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1652 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
1655 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1656 MessageSendEvent::SendChannelReestablish {
1657 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1658 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
1661 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1662 MessageSendEvent::BroadcastChannelAnnouncement {
1663 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1664 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
1667 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1668 MessageSendEvent::BroadcastNodeAnnouncement {
1669 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1672 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1673 MessageSendEvent::BroadcastChannelUpdate {
1674 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1677 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1678 MessageSendEvent::SendChannelUpdate {
1679 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1680 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1683 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1684 MessageSendEvent::HandleError {
1685 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1686 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1689 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1690 MessageSendEvent::SendChannelRangeQuery {
1691 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1692 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1695 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1696 MessageSendEvent::SendShortIdsQuery {
1697 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1698 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
1701 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1702 MessageSendEvent::SendReplyChannelRange {
1703 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1704 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1710 /// Frees any resources used by the MessageSendEvent
1712 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1713 /// Creates a copy of the MessageSendEvent
1715 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1719 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
1720 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
1721 MessageSendEvent::SendAcceptChannel {
1727 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
1728 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
1729 MessageSendEvent::SendOpenChannel {
1735 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
1736 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
1737 MessageSendEvent::SendFundingCreated {
1743 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
1744 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
1745 MessageSendEvent::SendFundingSigned {
1751 /// Utility method to constructs a new SendFundingLocked-variant MessageSendEvent
1752 pub extern "C" fn MessageSendEvent_send_funding_locked(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingLocked) -> MessageSendEvent {
1753 MessageSendEvent::SendFundingLocked {
1759 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
1760 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
1761 MessageSendEvent::SendAnnouncementSignatures {
1767 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
1768 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
1769 MessageSendEvent::UpdateHTLCs {
1775 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
1776 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
1777 MessageSendEvent::SendRevokeAndACK {
1783 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
1784 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
1785 MessageSendEvent::SendClosingSigned {
1791 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
1792 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
1793 MessageSendEvent::SendShutdown {
1799 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
1800 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
1801 MessageSendEvent::SendChannelReestablish {
1807 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
1808 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1809 MessageSendEvent::BroadcastChannelAnnouncement {
1815 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
1816 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
1817 MessageSendEvent::BroadcastNodeAnnouncement {
1822 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
1823 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1824 MessageSendEvent::BroadcastChannelUpdate {
1829 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
1830 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1831 MessageSendEvent::SendChannelUpdate {
1837 /// Utility method to constructs a new HandleError-variant MessageSendEvent
1838 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
1839 MessageSendEvent::HandleError {
1845 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
1846 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
1847 MessageSendEvent::SendChannelRangeQuery {
1853 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
1854 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
1855 MessageSendEvent::SendShortIdsQuery {
1861 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
1862 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
1863 MessageSendEvent::SendReplyChannelRange {
1868 /// A trait indicating an object may generate message send events
1870 pub struct MessageSendEventsProvider {
1871 /// An opaque pointer which is passed to your function implementations as an argument.
1872 /// This has no meaning in the LDK, and can be NULL or any other value.
1873 pub this_arg: *mut c_void,
1874 /// Gets the list of pending events which were generated by previous actions, clearing the list
1877 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1878 /// Frees any resources associated with this object given its this_arg pointer.
1879 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1880 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1882 unsafe impl Send for MessageSendEventsProvider {}
1883 unsafe impl Sync for MessageSendEventsProvider {}
1885 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
1886 MessageSendEventsProvider {
1887 this_arg: orig.this_arg,
1888 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
1889 free: Clone::clone(&orig.free),
1893 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1894 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1895 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1896 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1897 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1902 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1903 // directly as a Deref trait in higher-level structs:
1904 impl std::ops::Deref for MessageSendEventsProvider {
1906 fn deref(&self) -> &Self {
1910 /// Calls the free function if one is set
1912 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1913 impl Drop for MessageSendEventsProvider {
1914 fn drop(&mut self) {
1915 if let Some(f) = self.free {
1920 /// A trait indicating an object may generate events.
1922 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1926 /// See [`process_pending_events`] for requirements around event processing.
1928 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1929 /// event since the last invocation. The handler must either act upon the event immediately
1930 /// or preserve it for later handling.
1932 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1933 /// consult the provider's documentation on the implication of processing events and how a handler
1934 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1935 /// [`ChainMonitor::process_pending_events`]).
1937 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1940 /// [`process_pending_events`]: Self::process_pending_events
1941 /// [`handle_event`]: EventHandler::handle_event
1942 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1943 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1945 pub struct EventsProvider {
1946 /// An opaque pointer which is passed to your function implementations as an argument.
1947 /// This has no meaning in the LDK, and can be NULL or any other value.
1948 pub this_arg: *mut c_void,
1949 /// Processes any events generated since the last call using the given event handler.
1951 /// Subsequent calls must only process new events. However, handlers must be capable of handling
1952 /// duplicate events across process restarts. This may occur if the provider was recovered from
1953 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1954 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1955 /// Frees any resources associated with this object given its this_arg pointer.
1956 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1957 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1959 unsafe impl Send for EventsProvider {}
1960 unsafe impl Sync for EventsProvider {}
1962 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
1964 this_arg: orig.this_arg,
1965 process_pending_events: Clone::clone(&orig.process_pending_events),
1966 free: Clone::clone(&orig.free),
1970 use lightning::util::events::EventsProvider as rustEventsProvider;
1971 /// Calls the free function if one is set
1973 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1974 impl Drop for EventsProvider {
1975 fn drop(&mut self) {
1976 if let Some(f) = self.free {
1981 /// A trait implemented for objects handling events from [`EventsProvider`].
1983 pub struct EventHandler {
1984 /// An opaque pointer which is passed to your function implementations as an argument.
1985 /// This has no meaning in the LDK, and can be NULL or any other value.
1986 pub this_arg: *mut c_void,
1987 /// Handles the given [`Event`].
1989 /// See [`EventsProvider`] for details that must be considered when implementing this method.
1990 pub handle_event: extern "C" fn (this_arg: *const c_void, event: &crate::lightning::util::events::Event),
1991 /// Frees any resources associated with this object given its this_arg pointer.
1992 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1993 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1995 unsafe impl Send for EventHandler {}
1996 unsafe impl Sync for EventHandler {}
1998 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
2000 this_arg: orig.this_arg,
2001 handle_event: Clone::clone(&orig.handle_event),
2002 free: Clone::clone(&orig.free),
2006 use lightning::util::events::EventHandler as rustEventHandler;
2007 impl rustEventHandler for EventHandler {
2008 fn handle_event(&self, mut event: &lightning::util::events::Event) {
2009 (self.handle_event)(self.this_arg, &crate::lightning::util::events::Event::from_native(event))
2013 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2014 // directly as a Deref trait in higher-level structs:
2015 impl std::ops::Deref for EventHandler {
2017 fn deref(&self) -> &Self {
2021 /// Calls the free function if one is set
2023 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
2024 impl Drop for EventHandler {
2025 fn drop(&mut self) {
2026 if let Some(f) = self.free {