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())
346 /// An Event which you should probably take some action in response to.
348 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
349 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
350 /// written as it makes no sense to respond to it after reconnecting to peers).
355 /// Used to indicate that the client should generate a funding transaction with the given
356 /// parameters and then call ChannelManager::funding_transaction_generated.
357 /// Generated in ChannelManager message handling.
358 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
359 /// counterparty can steal your funds!
360 FundingGenerationReady {
361 /// The random channel_id we picked which you'll need to pass into
362 /// ChannelManager::funding_transaction_generated.
363 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
364 /// The value, in satoshis, that the output should have.
365 channel_value_satoshis: u64,
366 /// The script which should be used in the transaction output.
367 output_script: crate::c_types::derived::CVec_u8Z,
368 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
369 /// an inbound channel.
371 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
372 user_channel_id: u64,
374 /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
375 /// [`ChannelManager::claim_funds`] to get it....
376 /// Note that if the preimage is not known, you should call
377 /// [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid
378 /// network congestion.
379 /// If you fail to call either [`ChannelManager::claim_funds`] or
380 /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be
381 /// automatically failed.
383 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
384 /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
386 /// The hash for which the preimage should be handed to the ChannelManager.
387 payment_hash: crate::c_types::ThirtyTwoBytes,
388 /// The value, in thousandths of a satoshi, that this payment is for.
390 /// Information for claiming this received payment, based on whether the purpose of the
391 /// payment is to pay an invoice or to send a spontaneous payment.
392 purpose: crate::lightning::util::events::PaymentPurpose,
394 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
395 /// and we got back the payment preimage for it).
397 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
398 /// event. In this situation, you SHOULD treat this payment as having succeeded.
400 /// The id returned by [`ChannelManager::send_payment`] and used with
401 /// [`ChannelManager::retry_payment`].
403 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
404 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
406 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
407 payment_id: crate::c_types::ThirtyTwoBytes,
408 /// The preimage to the hash given to ChannelManager::send_payment.
409 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
410 /// store it somehow!
411 payment_preimage: crate::c_types::ThirtyTwoBytes,
412 /// The hash which was given to [`ChannelManager::send_payment`].
414 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
415 payment_hash: crate::c_types::ThirtyTwoBytes,
416 /// The total fee which was spent at intermediate hops in this payment, across all paths.
418 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
419 /// overpayment to the recipient node.
421 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
422 /// overstate the amount paid, though this is unlikely.
424 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
425 fee_paid_msat: crate::c_types::derived::COption_u64Z,
427 /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
428 /// something. You may wish to retry with a different route.
430 /// The id returned by [`ChannelManager::send_payment`] and used with
431 /// [`ChannelManager::retry_payment`].
433 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
434 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
436 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
437 payment_id: crate::c_types::ThirtyTwoBytes,
438 /// The hash which was given to ChannelManager::send_payment.
439 payment_hash: crate::c_types::ThirtyTwoBytes,
440 /// Indicates the payment was rejected for some reason by the recipient. This implies that
441 /// the payment has failed, not just the route in question. If this is not set, you may
442 /// retry the payment via a different route.
443 rejected_by_dest: bool,
444 /// Any failure information conveyed via the Onion return packet by a node along the failed
447 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
448 /// account the update. [`NetGraphMsgHandler`] is capable of doing this.
450 /// [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph
451 /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
452 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
453 /// For both single-path and multi-path payments, this is set if all paths of the payment have
454 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
455 /// larger MPP payment were still in flight when this event was generated.
456 all_paths_failed: bool,
457 /// The payment path that failed.
458 path: crate::c_types::derived::CVec_RouteHopZ,
459 /// The channel responsible for the failed payment path.
461 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
462 /// retried. May be `None` for older [`Event`] serializations.
463 short_channel_id: crate::c_types::derived::COption_u64Z,
464 /// Parameters needed to compute a new [`Route`] when retrying the failed payment path.
466 /// See [`find_route`] for details.
468 /// [`Route`]: crate::routing::router::Route
469 /// [`find_route`]: crate::routing::router::find_route
471 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
472 retry: crate::lightning::routing::router::RouteParameters,
474 /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
475 /// time in the future.
476 PendingHTLCsForwardable {
477 /// The minimum amount of time that should be waited prior to calling
478 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
479 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
480 /// now + 5*time_forwardable).
481 time_forwardable: u64,
483 /// Used to indicate that an output which you should know how to spend was confirmed on chain
484 /// and is now spendable.
485 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
486 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
487 /// somewhere and spend them when you create on-chain transactions.
489 /// The outputs which you should store as spendable by you.
490 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
492 /// This event is generated when a payment has been successfully forwarded through us and a
493 /// forwarding fee earned.
495 /// The fee, in milli-satoshis, which was earned as a result of the payment.
497 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
498 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
499 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
500 /// claimed the full value in millisatoshis from the source. In this case,
501 /// `claim_from_onchain_tx` will be set.
503 /// If the channel which sent us the payment has been force-closed, we will claim the funds
504 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
505 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
506 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
508 fee_earned_msat: crate::c_types::derived::COption_u64Z,
509 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
511 claim_from_onchain_tx: bool,
513 /// Used to indicate that a channel with the given `channel_id` is in the process of closure.
515 /// The channel_id of the channel which has been closed. Note that on-chain transactions
516 /// resolving the channel are likely still awaiting confirmation.
517 channel_id: crate::c_types::ThirtyTwoBytes,
518 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
519 /// an inbound channel. This will always be zero for objects serialized with LDK versions
520 /// prior to 0.0.102.
522 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
523 user_channel_id: u64,
524 /// The reason the channel was closed.
525 reason: crate::lightning::util::events::ClosureReason,
527 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
528 /// inputs for another purpose.
530 /// The channel_id of the channel which has been closed.
531 channel_id: crate::c_types::ThirtyTwoBytes,
532 /// The full transaction received from the user
533 transaction: crate::c_types::Transaction,
536 use lightning::util::events::Event as nativeEvent;
539 pub(crate) fn to_native(&self) -> nativeEvent {
541 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
542 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
543 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
544 let mut output_script_nonref = (*output_script).clone();
545 let mut user_channel_id_nonref = (*user_channel_id).clone();
546 nativeEvent::FundingGenerationReady {
547 temporary_channel_id: temporary_channel_id_nonref.data,
548 channel_value_satoshis: channel_value_satoshis_nonref,
549 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
550 user_channel_id: user_channel_id_nonref,
553 Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
554 let mut payment_hash_nonref = (*payment_hash).clone();
555 let mut amt_nonref = (*amt).clone();
556 let mut purpose_nonref = (*purpose).clone();
557 nativeEvent::PaymentReceived {
558 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
560 purpose: purpose_nonref.into_native(),
563 Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
564 let mut payment_id_nonref = (*payment_id).clone();
565 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
566 let mut payment_preimage_nonref = (*payment_preimage).clone();
567 let mut payment_hash_nonref = (*payment_hash).clone();
568 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
569 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
570 nativeEvent::PaymentSent {
571 payment_id: local_payment_id_nonref,
572 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
573 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
574 fee_paid_msat: local_fee_paid_msat_nonref,
577 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, } => {
578 let mut payment_id_nonref = (*payment_id).clone();
579 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
580 let mut payment_hash_nonref = (*payment_hash).clone();
581 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
582 let mut network_update_nonref = (*network_update).clone();
583 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() }) } };
584 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
585 let mut path_nonref = (*path).clone();
586 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()) } }); };
587 let mut short_channel_id_nonref = (*short_channel_id).clone();
588 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
589 let mut retry_nonref = (*retry).clone();
590 let mut local_retry_nonref = if retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry_nonref.take_inner()) } }) };
591 nativeEvent::PaymentPathFailed {
592 payment_id: local_payment_id_nonref,
593 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
594 rejected_by_dest: rejected_by_dest_nonref,
595 network_update: local_network_update_nonref,
596 all_paths_failed: all_paths_failed_nonref,
597 path: local_path_nonref,
598 short_channel_id: local_short_channel_id_nonref,
599 retry: local_retry_nonref,
602 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
603 let mut time_forwardable_nonref = (*time_forwardable).clone();
604 nativeEvent::PendingHTLCsForwardable {
605 time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
608 Event::SpendableOutputs {ref outputs, } => {
609 let mut outputs_nonref = (*outputs).clone();
610 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
611 nativeEvent::SpendableOutputs {
612 outputs: local_outputs_nonref,
615 Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
616 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
617 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
618 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
619 nativeEvent::PaymentForwarded {
620 fee_earned_msat: local_fee_earned_msat_nonref,
621 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
624 Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
625 let mut channel_id_nonref = (*channel_id).clone();
626 let mut user_channel_id_nonref = (*user_channel_id).clone();
627 let mut reason_nonref = (*reason).clone();
628 nativeEvent::ChannelClosed {
629 channel_id: channel_id_nonref.data,
630 user_channel_id: user_channel_id_nonref,
631 reason: reason_nonref.into_native(),
634 Event::DiscardFunding {ref channel_id, ref transaction, } => {
635 let mut channel_id_nonref = (*channel_id).clone();
636 let mut transaction_nonref = (*transaction).clone();
637 nativeEvent::DiscardFunding {
638 channel_id: channel_id_nonref.data,
639 transaction: transaction_nonref.into_bitcoin(),
645 pub(crate) fn into_native(self) -> nativeEvent {
647 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
648 nativeEvent::FundingGenerationReady {
649 temporary_channel_id: temporary_channel_id.data,
650 channel_value_satoshis: channel_value_satoshis,
651 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
652 user_channel_id: user_channel_id,
655 Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
656 nativeEvent::PaymentReceived {
657 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
659 purpose: purpose.into_native(),
662 Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
663 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
664 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
665 nativeEvent::PaymentSent {
666 payment_id: local_payment_id,
667 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
668 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
669 fee_paid_msat: local_fee_paid_msat,
672 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, } => {
673 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
674 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() }) } };
675 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
676 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
677 let mut local_retry = if retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry.take_inner()) } }) };
678 nativeEvent::PaymentPathFailed {
679 payment_id: local_payment_id,
680 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
681 rejected_by_dest: rejected_by_dest,
682 network_update: local_network_update,
683 all_paths_failed: all_paths_failed,
685 short_channel_id: local_short_channel_id,
689 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
690 nativeEvent::PendingHTLCsForwardable {
691 time_forwardable: std::time::Duration::from_secs(time_forwardable),
694 Event::SpendableOutputs {mut outputs, } => {
695 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
696 nativeEvent::SpendableOutputs {
697 outputs: local_outputs,
700 Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
701 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
702 nativeEvent::PaymentForwarded {
703 fee_earned_msat: local_fee_earned_msat,
704 claim_from_onchain_tx: claim_from_onchain_tx,
707 Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
708 nativeEvent::ChannelClosed {
709 channel_id: channel_id.data,
710 user_channel_id: user_channel_id,
711 reason: reason.into_native(),
714 Event::DiscardFunding {mut channel_id, mut transaction, } => {
715 nativeEvent::DiscardFunding {
716 channel_id: channel_id.data,
717 transaction: transaction.into_bitcoin(),
723 pub(crate) fn from_native(native: &nativeEvent) -> Self {
725 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
726 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
727 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
728 let mut output_script_nonref = (*output_script).clone();
729 let mut user_channel_id_nonref = (*user_channel_id).clone();
730 Event::FundingGenerationReady {
731 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
732 channel_value_satoshis: channel_value_satoshis_nonref,
733 output_script: output_script_nonref.into_bytes().into(),
734 user_channel_id: user_channel_id_nonref,
737 nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
738 let mut payment_hash_nonref = (*payment_hash).clone();
739 let mut amt_nonref = (*amt).clone();
740 let mut purpose_nonref = (*purpose).clone();
741 Event::PaymentReceived {
742 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
744 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
747 nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
748 let mut payment_id_nonref = (*payment_id).clone();
749 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 } } };
750 let mut payment_preimage_nonref = (*payment_preimage).clone();
751 let mut payment_hash_nonref = (*payment_hash).clone();
752 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
753 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() }) };
755 payment_id: local_payment_id_nonref,
756 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
757 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
758 fee_paid_msat: local_fee_paid_msat_nonref,
761 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, } => {
762 let mut payment_id_nonref = (*payment_id).clone();
763 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 } } };
764 let mut payment_hash_nonref = (*payment_hash).clone();
765 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
766 let mut network_update_nonref = (*network_update).clone();
767 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()) }) };
768 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
769 let mut path_nonref = (*path).clone();
770 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 } }); };
771 let mut short_channel_id_nonref = (*short_channel_id).clone();
772 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() }) };
773 let mut retry_nonref = (*retry).clone();
774 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 };
775 Event::PaymentPathFailed {
776 payment_id: local_payment_id_nonref,
777 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
778 rejected_by_dest: rejected_by_dest_nonref,
779 network_update: local_network_update_nonref,
780 all_paths_failed: all_paths_failed_nonref,
781 path: local_path_nonref.into(),
782 short_channel_id: local_short_channel_id_nonref,
783 retry: local_retry_nonref,
786 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
787 let mut time_forwardable_nonref = (*time_forwardable).clone();
788 Event::PendingHTLCsForwardable {
789 time_forwardable: time_forwardable_nonref.as_secs(),
792 nativeEvent::SpendableOutputs {ref outputs, } => {
793 let mut outputs_nonref = (*outputs).clone();
794 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) }); };
795 Event::SpendableOutputs {
796 outputs: local_outputs_nonref.into(),
799 nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
800 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
801 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() }) };
802 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
803 Event::PaymentForwarded {
804 fee_earned_msat: local_fee_earned_msat_nonref,
805 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
808 nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
809 let mut channel_id_nonref = (*channel_id).clone();
810 let mut user_channel_id_nonref = (*user_channel_id).clone();
811 let mut reason_nonref = (*reason).clone();
812 Event::ChannelClosed {
813 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
814 user_channel_id: user_channel_id_nonref,
815 reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
818 nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
819 let mut channel_id_nonref = (*channel_id).clone();
820 let mut transaction_nonref = (*transaction).clone();
821 Event::DiscardFunding {
822 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
823 transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
829 pub(crate) fn native_into(native: nativeEvent) -> Self {
831 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
832 Event::FundingGenerationReady {
833 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
834 channel_value_satoshis: channel_value_satoshis,
835 output_script: output_script.into_bytes().into(),
836 user_channel_id: user_channel_id,
839 nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
840 Event::PaymentReceived {
841 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
843 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
846 nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
847 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 } } };
848 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() }) };
850 payment_id: local_payment_id,
851 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
852 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
853 fee_paid_msat: local_fee_paid_msat,
856 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, } => {
857 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 } } };
858 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()) }) };
859 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 } }); };
860 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() }) };
861 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 };
862 Event::PaymentPathFailed {
863 payment_id: local_payment_id,
864 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
865 rejected_by_dest: rejected_by_dest,
866 network_update: local_network_update,
867 all_paths_failed: all_paths_failed,
868 path: local_path.into(),
869 short_channel_id: local_short_channel_id,
873 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
874 Event::PendingHTLCsForwardable {
875 time_forwardable: time_forwardable.as_secs(),
878 nativeEvent::SpendableOutputs {mut outputs, } => {
879 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
880 Event::SpendableOutputs {
881 outputs: local_outputs.into(),
884 nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
885 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() }) };
886 Event::PaymentForwarded {
887 fee_earned_msat: local_fee_earned_msat,
888 claim_from_onchain_tx: claim_from_onchain_tx,
891 nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
892 Event::ChannelClosed {
893 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
894 user_channel_id: user_channel_id,
895 reason: crate::lightning::util::events::ClosureReason::native_into(reason),
898 nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
899 Event::DiscardFunding {
900 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
901 transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
907 /// Frees any resources used by the Event
909 pub extern "C" fn Event_free(this_ptr: Event) { }
910 /// Creates a copy of the Event
912 pub extern "C" fn Event_clone(orig: &Event) -> Event {
916 /// Utility method to constructs a new FundingGenerationReady-variant Event
917 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 {
918 Event::FundingGenerationReady {
919 temporary_channel_id,
920 channel_value_satoshis,
926 /// Utility method to constructs a new PaymentReceived-variant Event
927 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
928 Event::PaymentReceived {
935 /// Utility method to constructs a new PaymentSent-variant Event
936 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 {
945 /// Utility method to constructs a new PaymentPathFailed-variant Event
946 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 {
947 Event::PaymentPathFailed {
959 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
960 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
961 Event::PendingHTLCsForwardable {
966 /// Utility method to constructs a new SpendableOutputs-variant Event
967 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
968 Event::SpendableOutputs {
973 /// Utility method to constructs a new PaymentForwarded-variant Event
974 pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
975 Event::PaymentForwarded {
977 claim_from_onchain_tx,
981 /// Utility method to constructs a new ChannelClosed-variant Event
982 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: u64, reason: crate::lightning::util::events::ClosureReason) -> Event {
983 Event::ChannelClosed {
990 /// Utility method to constructs a new DiscardFunding-variant Event
991 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
992 Event::DiscardFunding {
998 /// Serialize the Event object into a byte array which can be read by Event_read
999 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
1000 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
1002 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1003 /// broadcast to most peers).
1004 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1008 pub enum MessageSendEvent {
1009 /// Used to indicate that we've accepted a channel open and should send the accept_channel
1010 /// message provided to the given peer.
1012 /// The node_id of the node which should receive this message
1013 node_id: crate::c_types::PublicKey,
1014 /// The message which should be sent.
1015 msg: crate::lightning::ln::msgs::AcceptChannel,
1017 /// Used to indicate that we've initiated a channel open and should send the open_channel
1018 /// message provided to the given peer.
1020 /// The node_id of the node which should receive this message
1021 node_id: crate::c_types::PublicKey,
1022 /// The message which should be sent.
1023 msg: crate::lightning::ln::msgs::OpenChannel,
1025 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1026 SendFundingCreated {
1027 /// The node_id of the node which should receive this message
1028 node_id: crate::c_types::PublicKey,
1029 /// The message which should be sent.
1030 msg: crate::lightning::ln::msgs::FundingCreated,
1032 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
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::FundingSigned,
1039 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
1041 /// The node_id of the node which should receive these message(s)
1042 node_id: crate::c_types::PublicKey,
1043 /// The funding_locked message which should be sent.
1044 msg: crate::lightning::ln::msgs::FundingLocked,
1046 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1047 SendAnnouncementSignatures {
1048 /// The node_id of the node which should receive these message(s)
1049 node_id: crate::c_types::PublicKey,
1050 /// The announcement_signatures message which should be sent.
1051 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
1053 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1054 /// message should be sent to the peer with the given node_id.
1056 /// The node_id of the node which should receive these message(s)
1057 node_id: crate::c_types::PublicKey,
1058 /// The update messages which should be sent. ALL messages in the struct should be sent!
1059 updates: crate::lightning::ln::msgs::CommitmentUpdate,
1061 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1063 /// The node_id of the node which should receive this message
1064 node_id: crate::c_types::PublicKey,
1065 /// The message which should be sent.
1066 msg: crate::lightning::ln::msgs::RevokeAndACK,
1068 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1070 /// The node_id of the node which should receive this message
1071 node_id: crate::c_types::PublicKey,
1072 /// The message which should be sent.
1073 msg: crate::lightning::ln::msgs::ClosingSigned,
1075 /// Used to indicate that a shutdown 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::Shutdown,
1082 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1083 SendChannelReestablish {
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::ChannelReestablish,
1089 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1090 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1092 /// Note that after doing so, you very likely (unless you did so very recently) want to call
1093 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
1094 /// This ensures that any nodes which see our channel_announcement also have a relevant
1095 /// node_announcement, including relevant feature flags which may be important for routing
1096 /// through or to us.
1097 BroadcastChannelAnnouncement {
1098 /// The channel_announcement which should be sent.
1099 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
1100 /// The followup channel_update which should be sent.
1101 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
1103 /// Used to indicate that a node_announcement should be broadcast to all peers.
1104 BroadcastNodeAnnouncement {
1105 /// The node_announcement which should be sent.
1106 msg: crate::lightning::ln::msgs::NodeAnnouncement,
1108 /// Used to indicate that a channel_update should be broadcast to all peers.
1109 BroadcastChannelUpdate {
1110 /// The channel_update which should be sent.
1111 msg: crate::lightning::ln::msgs::ChannelUpdate,
1113 /// Used to indicate that a channel_update should be sent to a single peer.
1114 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1115 /// private channel and we shouldn't be informing all of our peers of channel parameters.
1117 /// The node_id of the node which should receive this message
1118 node_id: crate::c_types::PublicKey,
1119 /// The channel_update which should be sent.
1120 msg: crate::lightning::ln::msgs::ChannelUpdate,
1122 /// Broadcast an error downstream to be handled
1124 /// The node_id of the node which should receive this message
1125 node_id: crate::c_types::PublicKey,
1126 /// The action which should be taken.
1127 action: crate::lightning::ln::msgs::ErrorAction,
1129 /// Query a peer for channels with funding transaction UTXOs in a block range.
1130 SendChannelRangeQuery {
1131 /// The node_id of this message recipient
1132 node_id: crate::c_types::PublicKey,
1133 /// The query_channel_range which should be sent.
1134 msg: crate::lightning::ln::msgs::QueryChannelRange,
1136 /// Request routing gossip messages from a peer for a list of channels identified by
1137 /// their short_channel_ids.
1139 /// The node_id of this message recipient
1140 node_id: crate::c_types::PublicKey,
1141 /// The query_short_channel_ids which should be sent.
1142 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
1144 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1145 /// emitted during processing of the query.
1146 SendReplyChannelRange {
1147 /// The node_id of this message recipient
1148 node_id: crate::c_types::PublicKey,
1149 /// The reply_channel_range which should be sent.
1150 msg: crate::lightning::ln::msgs::ReplyChannelRange,
1153 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
1154 impl MessageSendEvent {
1156 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
1158 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1159 let mut node_id_nonref = (*node_id).clone();
1160 let mut msg_nonref = (*msg).clone();
1161 nativeMessageSendEvent::SendAcceptChannel {
1162 node_id: node_id_nonref.into_rust(),
1163 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1166 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1167 let mut node_id_nonref = (*node_id).clone();
1168 let mut msg_nonref = (*msg).clone();
1169 nativeMessageSendEvent::SendOpenChannel {
1170 node_id: node_id_nonref.into_rust(),
1171 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1174 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1175 let mut node_id_nonref = (*node_id).clone();
1176 let mut msg_nonref = (*msg).clone();
1177 nativeMessageSendEvent::SendFundingCreated {
1178 node_id: node_id_nonref.into_rust(),
1179 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1182 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1183 let mut node_id_nonref = (*node_id).clone();
1184 let mut msg_nonref = (*msg).clone();
1185 nativeMessageSendEvent::SendFundingSigned {
1186 node_id: node_id_nonref.into_rust(),
1187 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1190 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1191 let mut node_id_nonref = (*node_id).clone();
1192 let mut msg_nonref = (*msg).clone();
1193 nativeMessageSendEvent::SendFundingLocked {
1194 node_id: node_id_nonref.into_rust(),
1195 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1198 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1199 let mut node_id_nonref = (*node_id).clone();
1200 let mut msg_nonref = (*msg).clone();
1201 nativeMessageSendEvent::SendAnnouncementSignatures {
1202 node_id: node_id_nonref.into_rust(),
1203 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1206 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1207 let mut node_id_nonref = (*node_id).clone();
1208 let mut updates_nonref = (*updates).clone();
1209 nativeMessageSendEvent::UpdateHTLCs {
1210 node_id: node_id_nonref.into_rust(),
1211 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
1214 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1215 let mut node_id_nonref = (*node_id).clone();
1216 let mut msg_nonref = (*msg).clone();
1217 nativeMessageSendEvent::SendRevokeAndACK {
1218 node_id: node_id_nonref.into_rust(),
1219 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1222 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1223 let mut node_id_nonref = (*node_id).clone();
1224 let mut msg_nonref = (*msg).clone();
1225 nativeMessageSendEvent::SendClosingSigned {
1226 node_id: node_id_nonref.into_rust(),
1227 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1230 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1231 let mut node_id_nonref = (*node_id).clone();
1232 let mut msg_nonref = (*msg).clone();
1233 nativeMessageSendEvent::SendShutdown {
1234 node_id: node_id_nonref.into_rust(),
1235 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1238 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1239 let mut node_id_nonref = (*node_id).clone();
1240 let mut msg_nonref = (*msg).clone();
1241 nativeMessageSendEvent::SendChannelReestablish {
1242 node_id: node_id_nonref.into_rust(),
1243 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1246 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1247 let mut msg_nonref = (*msg).clone();
1248 let mut update_msg_nonref = (*update_msg).clone();
1249 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1250 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1251 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
1254 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1255 let mut msg_nonref = (*msg).clone();
1256 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1257 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1260 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1261 let mut msg_nonref = (*msg).clone();
1262 nativeMessageSendEvent::BroadcastChannelUpdate {
1263 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1266 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1267 let mut node_id_nonref = (*node_id).clone();
1268 let mut msg_nonref = (*msg).clone();
1269 nativeMessageSendEvent::SendChannelUpdate {
1270 node_id: node_id_nonref.into_rust(),
1271 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1274 MessageSendEvent::HandleError {ref node_id, ref action, } => {
1275 let mut node_id_nonref = (*node_id).clone();
1276 let mut action_nonref = (*action).clone();
1277 nativeMessageSendEvent::HandleError {
1278 node_id: node_id_nonref.into_rust(),
1279 action: action_nonref.into_native(),
1282 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1283 let mut node_id_nonref = (*node_id).clone();
1284 let mut msg_nonref = (*msg).clone();
1285 nativeMessageSendEvent::SendChannelRangeQuery {
1286 node_id: node_id_nonref.into_rust(),
1287 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1290 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1291 let mut node_id_nonref = (*node_id).clone();
1292 let mut msg_nonref = (*msg).clone();
1293 nativeMessageSendEvent::SendShortIdsQuery {
1294 node_id: node_id_nonref.into_rust(),
1295 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1298 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1299 let mut node_id_nonref = (*node_id).clone();
1300 let mut msg_nonref = (*msg).clone();
1301 nativeMessageSendEvent::SendReplyChannelRange {
1302 node_id: node_id_nonref.into_rust(),
1303 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1309 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
1311 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1312 nativeMessageSendEvent::SendAcceptChannel {
1313 node_id: node_id.into_rust(),
1314 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1317 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1318 nativeMessageSendEvent::SendOpenChannel {
1319 node_id: node_id.into_rust(),
1320 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1323 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1324 nativeMessageSendEvent::SendFundingCreated {
1325 node_id: node_id.into_rust(),
1326 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1329 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1330 nativeMessageSendEvent::SendFundingSigned {
1331 node_id: node_id.into_rust(),
1332 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1335 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1336 nativeMessageSendEvent::SendFundingLocked {
1337 node_id: node_id.into_rust(),
1338 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1341 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1342 nativeMessageSendEvent::SendAnnouncementSignatures {
1343 node_id: node_id.into_rust(),
1344 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1347 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1348 nativeMessageSendEvent::UpdateHTLCs {
1349 node_id: node_id.into_rust(),
1350 updates: *unsafe { Box::from_raw(updates.take_inner()) },
1353 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1354 nativeMessageSendEvent::SendRevokeAndACK {
1355 node_id: node_id.into_rust(),
1356 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1359 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1360 nativeMessageSendEvent::SendClosingSigned {
1361 node_id: node_id.into_rust(),
1362 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1365 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1366 nativeMessageSendEvent::SendShutdown {
1367 node_id: node_id.into_rust(),
1368 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1371 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1372 nativeMessageSendEvent::SendChannelReestablish {
1373 node_id: node_id.into_rust(),
1374 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1377 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1378 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1379 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1380 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
1383 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1384 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1385 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1388 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1389 nativeMessageSendEvent::BroadcastChannelUpdate {
1390 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1393 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1394 nativeMessageSendEvent::SendChannelUpdate {
1395 node_id: node_id.into_rust(),
1396 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1399 MessageSendEvent::HandleError {mut node_id, mut action, } => {
1400 nativeMessageSendEvent::HandleError {
1401 node_id: node_id.into_rust(),
1402 action: action.into_native(),
1405 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1406 nativeMessageSendEvent::SendChannelRangeQuery {
1407 node_id: node_id.into_rust(),
1408 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1411 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1412 nativeMessageSendEvent::SendShortIdsQuery {
1413 node_id: node_id.into_rust(),
1414 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1417 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1418 nativeMessageSendEvent::SendReplyChannelRange {
1419 node_id: node_id.into_rust(),
1420 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1426 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
1428 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1429 let mut node_id_nonref = (*node_id).clone();
1430 let mut msg_nonref = (*msg).clone();
1431 MessageSendEvent::SendAcceptChannel {
1432 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1433 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1436 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1437 let mut node_id_nonref = (*node_id).clone();
1438 let mut msg_nonref = (*msg).clone();
1439 MessageSendEvent::SendOpenChannel {
1440 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1441 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1444 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1445 let mut node_id_nonref = (*node_id).clone();
1446 let mut msg_nonref = (*msg).clone();
1447 MessageSendEvent::SendFundingCreated {
1448 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1449 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1452 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1453 let mut node_id_nonref = (*node_id).clone();
1454 let mut msg_nonref = (*msg).clone();
1455 MessageSendEvent::SendFundingSigned {
1456 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1457 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1460 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1461 let mut node_id_nonref = (*node_id).clone();
1462 let mut msg_nonref = (*msg).clone();
1463 MessageSendEvent::SendFundingLocked {
1464 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1465 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1468 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1469 let mut node_id_nonref = (*node_id).clone();
1470 let mut msg_nonref = (*msg).clone();
1471 MessageSendEvent::SendAnnouncementSignatures {
1472 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1473 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1476 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1477 let mut node_id_nonref = (*node_id).clone();
1478 let mut updates_nonref = (*updates).clone();
1479 MessageSendEvent::UpdateHTLCs {
1480 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1481 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
1484 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1485 let mut node_id_nonref = (*node_id).clone();
1486 let mut msg_nonref = (*msg).clone();
1487 MessageSendEvent::SendRevokeAndACK {
1488 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1489 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1492 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1493 let mut node_id_nonref = (*node_id).clone();
1494 let mut msg_nonref = (*msg).clone();
1495 MessageSendEvent::SendClosingSigned {
1496 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1497 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1500 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1501 let mut node_id_nonref = (*node_id).clone();
1502 let mut msg_nonref = (*msg).clone();
1503 MessageSendEvent::SendShutdown {
1504 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1505 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1508 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1509 let mut node_id_nonref = (*node_id).clone();
1510 let mut msg_nonref = (*msg).clone();
1511 MessageSendEvent::SendChannelReestablish {
1512 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1513 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1516 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1517 let mut msg_nonref = (*msg).clone();
1518 let mut update_msg_nonref = (*update_msg).clone();
1519 MessageSendEvent::BroadcastChannelAnnouncement {
1520 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1521 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
1524 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1525 let mut msg_nonref = (*msg).clone();
1526 MessageSendEvent::BroadcastNodeAnnouncement {
1527 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1530 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1531 let mut msg_nonref = (*msg).clone();
1532 MessageSendEvent::BroadcastChannelUpdate {
1533 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1536 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1537 let mut node_id_nonref = (*node_id).clone();
1538 let mut msg_nonref = (*msg).clone();
1539 MessageSendEvent::SendChannelUpdate {
1540 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1541 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1544 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
1545 let mut node_id_nonref = (*node_id).clone();
1546 let mut action_nonref = (*action).clone();
1547 MessageSendEvent::HandleError {
1548 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1549 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
1552 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1553 let mut node_id_nonref = (*node_id).clone();
1554 let mut msg_nonref = (*msg).clone();
1555 MessageSendEvent::SendChannelRangeQuery {
1556 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1557 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1560 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1561 let mut node_id_nonref = (*node_id).clone();
1562 let mut msg_nonref = (*msg).clone();
1563 MessageSendEvent::SendShortIdsQuery {
1564 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1565 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1568 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1569 let mut node_id_nonref = (*node_id).clone();
1570 let mut msg_nonref = (*msg).clone();
1571 MessageSendEvent::SendReplyChannelRange {
1572 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1573 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1579 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
1581 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1582 MessageSendEvent::SendAcceptChannel {
1583 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1584 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1587 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1588 MessageSendEvent::SendOpenChannel {
1589 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1590 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1593 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1594 MessageSendEvent::SendFundingCreated {
1595 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1596 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
1599 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1600 MessageSendEvent::SendFundingSigned {
1601 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1602 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1605 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1606 MessageSendEvent::SendFundingLocked {
1607 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1608 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg), is_owned: true },
1611 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1612 MessageSendEvent::SendAnnouncementSignatures {
1613 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1614 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
1617 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1618 MessageSendEvent::UpdateHTLCs {
1619 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1620 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
1623 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1624 MessageSendEvent::SendRevokeAndACK {
1625 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1626 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
1629 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1630 MessageSendEvent::SendClosingSigned {
1631 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1632 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1635 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1636 MessageSendEvent::SendShutdown {
1637 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1638 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
1641 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1642 MessageSendEvent::SendChannelReestablish {
1643 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1644 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
1647 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1648 MessageSendEvent::BroadcastChannelAnnouncement {
1649 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1650 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
1653 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1654 MessageSendEvent::BroadcastNodeAnnouncement {
1655 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1658 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1659 MessageSendEvent::BroadcastChannelUpdate {
1660 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1663 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1664 MessageSendEvent::SendChannelUpdate {
1665 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1666 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1669 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1670 MessageSendEvent::HandleError {
1671 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1672 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1675 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1676 MessageSendEvent::SendChannelRangeQuery {
1677 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1678 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1681 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1682 MessageSendEvent::SendShortIdsQuery {
1683 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1684 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
1687 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1688 MessageSendEvent::SendReplyChannelRange {
1689 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1690 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1696 /// Frees any resources used by the MessageSendEvent
1698 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1699 /// Creates a copy of the MessageSendEvent
1701 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1705 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
1706 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
1707 MessageSendEvent::SendAcceptChannel {
1713 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
1714 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
1715 MessageSendEvent::SendOpenChannel {
1721 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
1722 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
1723 MessageSendEvent::SendFundingCreated {
1729 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
1730 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
1731 MessageSendEvent::SendFundingSigned {
1737 /// Utility method to constructs a new SendFundingLocked-variant MessageSendEvent
1738 pub extern "C" fn MessageSendEvent_send_funding_locked(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingLocked) -> MessageSendEvent {
1739 MessageSendEvent::SendFundingLocked {
1745 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
1746 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
1747 MessageSendEvent::SendAnnouncementSignatures {
1753 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
1754 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
1755 MessageSendEvent::UpdateHTLCs {
1761 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
1762 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
1763 MessageSendEvent::SendRevokeAndACK {
1769 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
1770 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
1771 MessageSendEvent::SendClosingSigned {
1777 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
1778 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
1779 MessageSendEvent::SendShutdown {
1785 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
1786 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
1787 MessageSendEvent::SendChannelReestablish {
1793 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
1794 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1795 MessageSendEvent::BroadcastChannelAnnouncement {
1801 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
1802 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
1803 MessageSendEvent::BroadcastNodeAnnouncement {
1808 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
1809 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1810 MessageSendEvent::BroadcastChannelUpdate {
1815 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
1816 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1817 MessageSendEvent::SendChannelUpdate {
1823 /// Utility method to constructs a new HandleError-variant MessageSendEvent
1824 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
1825 MessageSendEvent::HandleError {
1831 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
1832 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
1833 MessageSendEvent::SendChannelRangeQuery {
1839 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
1840 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
1841 MessageSendEvent::SendShortIdsQuery {
1847 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
1848 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
1849 MessageSendEvent::SendReplyChannelRange {
1854 /// A trait indicating an object may generate message send events
1856 pub struct MessageSendEventsProvider {
1857 /// An opaque pointer which is passed to your function implementations as an argument.
1858 /// This has no meaning in the LDK, and can be NULL or any other value.
1859 pub this_arg: *mut c_void,
1860 /// Gets the list of pending events which were generated by previous actions, clearing the list
1863 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1864 /// Frees any resources associated with this object given its this_arg pointer.
1865 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1866 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1868 unsafe impl Send for MessageSendEventsProvider {}
1869 unsafe impl Sync for MessageSendEventsProvider {}
1871 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
1872 MessageSendEventsProvider {
1873 this_arg: orig.this_arg,
1874 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
1875 free: Clone::clone(&orig.free),
1879 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1880 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1881 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1882 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1883 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1888 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1889 // directly as a Deref trait in higher-level structs:
1890 impl std::ops::Deref for MessageSendEventsProvider {
1892 fn deref(&self) -> &Self {
1896 /// Calls the free function if one is set
1898 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1899 impl Drop for MessageSendEventsProvider {
1900 fn drop(&mut self) {
1901 if let Some(f) = self.free {
1906 /// A trait indicating an object may generate events.
1908 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1912 /// See [`process_pending_events`] for requirements around event processing.
1914 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1915 /// event since the last invocation. The handler must either act upon the event immediately
1916 /// or preserve it for later handling.
1918 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1919 /// consult the provider's documentation on the implication of processing events and how a handler
1920 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1921 /// [`ChainMonitor::process_pending_events`]).
1923 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1926 /// [`process_pending_events`]: Self::process_pending_events
1927 /// [`handle_event`]: EventHandler::handle_event
1928 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1929 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1931 pub struct EventsProvider {
1932 /// An opaque pointer which is passed to your function implementations as an argument.
1933 /// This has no meaning in the LDK, and can be NULL or any other value.
1934 pub this_arg: *mut c_void,
1935 /// Processes any events generated since the last call using the given event handler.
1937 /// Subsequent calls must only process new events. However, handlers must be capable of handling
1938 /// duplicate events across process restarts. This may occur if the provider was recovered from
1939 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1940 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1941 /// Frees any resources associated with this object given its this_arg pointer.
1942 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1943 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1945 unsafe impl Send for EventsProvider {}
1946 unsafe impl Sync for EventsProvider {}
1948 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
1950 this_arg: orig.this_arg,
1951 process_pending_events: Clone::clone(&orig.process_pending_events),
1952 free: Clone::clone(&orig.free),
1956 use lightning::util::events::EventsProvider as rustEventsProvider;
1957 /// Calls the free function if one is set
1959 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1960 impl Drop for EventsProvider {
1961 fn drop(&mut self) {
1962 if let Some(f) = self.free {
1967 /// A trait implemented for objects handling events from [`EventsProvider`].
1969 pub struct EventHandler {
1970 /// An opaque pointer which is passed to your function implementations as an argument.
1971 /// This has no meaning in the LDK, and can be NULL or any other value.
1972 pub this_arg: *mut c_void,
1973 /// Handles the given [`Event`].
1975 /// See [`EventsProvider`] for details that must be considered when implementing this method.
1976 pub handle_event: extern "C" fn (this_arg: *const c_void, event: &crate::lightning::util::events::Event),
1977 /// Frees any resources associated with this object given its this_arg pointer.
1978 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1979 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1981 unsafe impl Send for EventHandler {}
1982 unsafe impl Sync for EventHandler {}
1984 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
1986 this_arg: orig.this_arg,
1987 handle_event: Clone::clone(&orig.handle_event),
1988 free: Clone::clone(&orig.free),
1992 use lightning::util::events::EventHandler as rustEventHandler;
1993 impl rustEventHandler for EventHandler {
1994 fn handle_event(&self, mut event: &lightning::util::events::Event) {
1995 (self.handle_event)(self.this_arg, &crate::lightning::util::events::Event::from_native(event))
1999 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2000 // directly as a Deref trait in higher-level structs:
2001 impl std::ops::Deref for EventHandler {
2003 fn deref(&self) -> &Self {
2007 /// Calls the free function if one is set
2009 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
2010 impl Drop for EventHandler {
2011 fn drop(&mut self) {
2012 if let Some(f) = self.free {