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 preimage to the hash given to ChannelManager::send_payment.
401 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
402 /// store it somehow!
403 payment_preimage: crate::c_types::ThirtyTwoBytes,
404 /// The hash which was given to [`ChannelManager::send_payment`].
406 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
407 payment_hash: crate::c_types::ThirtyTwoBytes,
409 /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
410 /// something. You may wish to retry with a different route.
412 /// The hash which was given to ChannelManager::send_payment.
413 payment_hash: crate::c_types::ThirtyTwoBytes,
414 /// Indicates the payment was rejected for some reason by the recipient. This implies that
415 /// the payment has failed, not just the route in question. If this is not set, you may
416 /// retry the payment via a different route.
417 rejected_by_dest: bool,
418 /// Any failure information conveyed via the Onion return packet by a node along the failed
421 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
422 /// account the update. [`NetGraphMsgHandler`] is capable of doing this.
424 /// [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph
425 /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
426 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
427 /// For both single-path and multi-path payments, this is set if all paths of the payment have
428 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
429 /// larger MPP payment were still in flight when this event was generated.
430 all_paths_failed: bool,
431 /// The payment path that failed.
432 path: crate::c_types::derived::CVec_RouteHopZ,
433 /// The channel responsible for the failed payment path.
435 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
436 /// retried. May be `None` for older [`Event`] serializations.
437 short_channel_id: crate::c_types::derived::COption_u64Z,
439 /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
440 /// time in the future.
441 PendingHTLCsForwardable {
442 /// The minimum amount of time that should be waited prior to calling
443 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
444 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
445 /// now + 5*time_forwardable).
446 time_forwardable: u64,
448 /// Used to indicate that an output which you should know how to spend was confirmed on chain
449 /// and is now spendable.
450 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
451 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
452 /// somewhere and spend them when you create on-chain transactions.
454 /// The outputs which you should store as spendable by you.
455 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
457 /// This event is generated when a payment has been successfully forwarded through us and a
458 /// forwarding fee earned.
460 /// The fee, in milli-satoshis, which was earned as a result of the payment.
462 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
463 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
464 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
465 /// claimed the full value in millisatoshis from the source. In this case,
466 /// `claim_from_onchain_tx` will be set.
468 /// If the channel which sent us the payment has been force-closed, we will claim the funds
469 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
470 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
471 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
473 fee_earned_msat: crate::c_types::derived::COption_u64Z,
474 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
476 claim_from_onchain_tx: bool,
478 /// Used to indicate that a channel with the given `channel_id` is in the process of closure.
480 /// The channel_id of the channel which has been closed. Note that on-chain transactions
481 /// resolving the channel are likely still awaiting confirmation.
482 channel_id: crate::c_types::ThirtyTwoBytes,
483 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
484 /// an inbound channel. This will always be zero for objects serialized with LDK versions
485 /// prior to 0.0.102.
487 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
488 user_channel_id: u64,
489 /// The reason the channel was closed.
490 reason: crate::lightning::util::events::ClosureReason,
492 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
493 /// inputs for another purpose.
495 /// The channel_id of the channel which has been closed.
496 channel_id: crate::c_types::ThirtyTwoBytes,
497 /// The full transaction received from the user
498 transaction: crate::c_types::Transaction,
501 use lightning::util::events::Event as nativeEvent;
504 pub(crate) fn to_native(&self) -> nativeEvent {
506 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
507 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
508 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
509 let mut output_script_nonref = (*output_script).clone();
510 let mut user_channel_id_nonref = (*user_channel_id).clone();
511 nativeEvent::FundingGenerationReady {
512 temporary_channel_id: temporary_channel_id_nonref.data,
513 channel_value_satoshis: channel_value_satoshis_nonref,
514 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
515 user_channel_id: user_channel_id_nonref,
518 Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
519 let mut payment_hash_nonref = (*payment_hash).clone();
520 let mut amt_nonref = (*amt).clone();
521 let mut purpose_nonref = (*purpose).clone();
522 nativeEvent::PaymentReceived {
523 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
525 purpose: purpose_nonref.into_native(),
528 Event::PaymentSent {ref payment_preimage, ref payment_hash, } => {
529 let mut payment_preimage_nonref = (*payment_preimage).clone();
530 let mut payment_hash_nonref = (*payment_hash).clone();
531 nativeEvent::PaymentSent {
532 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
533 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
536 Event::PaymentPathFailed {ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, } => {
537 let mut payment_hash_nonref = (*payment_hash).clone();
538 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
539 let mut network_update_nonref = (*network_update).clone();
540 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() }) } };
541 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
542 let mut path_nonref = (*path).clone();
543 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()) } }); };
544 let mut short_channel_id_nonref = (*short_channel_id).clone();
545 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
546 nativeEvent::PaymentPathFailed {
547 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
548 rejected_by_dest: rejected_by_dest_nonref,
549 network_update: local_network_update_nonref,
550 all_paths_failed: all_paths_failed_nonref,
551 path: local_path_nonref,
552 short_channel_id: local_short_channel_id_nonref,
555 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
556 let mut time_forwardable_nonref = (*time_forwardable).clone();
557 nativeEvent::PendingHTLCsForwardable {
558 time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
561 Event::SpendableOutputs {ref outputs, } => {
562 let mut outputs_nonref = (*outputs).clone();
563 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
564 nativeEvent::SpendableOutputs {
565 outputs: local_outputs_nonref,
568 Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
569 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
570 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
571 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
572 nativeEvent::PaymentForwarded {
573 fee_earned_msat: local_fee_earned_msat_nonref,
574 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
577 Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
578 let mut channel_id_nonref = (*channel_id).clone();
579 let mut user_channel_id_nonref = (*user_channel_id).clone();
580 let mut reason_nonref = (*reason).clone();
581 nativeEvent::ChannelClosed {
582 channel_id: channel_id_nonref.data,
583 user_channel_id: user_channel_id_nonref,
584 reason: reason_nonref.into_native(),
587 Event::DiscardFunding {ref channel_id, ref transaction, } => {
588 let mut channel_id_nonref = (*channel_id).clone();
589 let mut transaction_nonref = (*transaction).clone();
590 nativeEvent::DiscardFunding {
591 channel_id: channel_id_nonref.data,
592 transaction: transaction_nonref.into_bitcoin(),
598 pub(crate) fn into_native(self) -> nativeEvent {
600 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
601 nativeEvent::FundingGenerationReady {
602 temporary_channel_id: temporary_channel_id.data,
603 channel_value_satoshis: channel_value_satoshis,
604 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
605 user_channel_id: user_channel_id,
608 Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
609 nativeEvent::PaymentReceived {
610 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
612 purpose: purpose.into_native(),
615 Event::PaymentSent {mut payment_preimage, mut payment_hash, } => {
616 nativeEvent::PaymentSent {
617 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
618 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
621 Event::PaymentPathFailed {mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, } => {
622 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() }) } };
623 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
624 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
625 nativeEvent::PaymentPathFailed {
626 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
627 rejected_by_dest: rejected_by_dest,
628 network_update: local_network_update,
629 all_paths_failed: all_paths_failed,
631 short_channel_id: local_short_channel_id,
634 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
635 nativeEvent::PendingHTLCsForwardable {
636 time_forwardable: std::time::Duration::from_secs(time_forwardable),
639 Event::SpendableOutputs {mut outputs, } => {
640 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
641 nativeEvent::SpendableOutputs {
642 outputs: local_outputs,
645 Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
646 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
647 nativeEvent::PaymentForwarded {
648 fee_earned_msat: local_fee_earned_msat,
649 claim_from_onchain_tx: claim_from_onchain_tx,
652 Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
653 nativeEvent::ChannelClosed {
654 channel_id: channel_id.data,
655 user_channel_id: user_channel_id,
656 reason: reason.into_native(),
659 Event::DiscardFunding {mut channel_id, mut transaction, } => {
660 nativeEvent::DiscardFunding {
661 channel_id: channel_id.data,
662 transaction: transaction.into_bitcoin(),
668 pub(crate) fn from_native(native: &nativeEvent) -> Self {
670 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
671 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
672 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
673 let mut output_script_nonref = (*output_script).clone();
674 let mut user_channel_id_nonref = (*user_channel_id).clone();
675 Event::FundingGenerationReady {
676 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
677 channel_value_satoshis: channel_value_satoshis_nonref,
678 output_script: output_script_nonref.into_bytes().into(),
679 user_channel_id: user_channel_id_nonref,
682 nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
683 let mut payment_hash_nonref = (*payment_hash).clone();
684 let mut amt_nonref = (*amt).clone();
685 let mut purpose_nonref = (*purpose).clone();
686 Event::PaymentReceived {
687 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
689 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
692 nativeEvent::PaymentSent {ref payment_preimage, ref payment_hash, } => {
693 let mut payment_preimage_nonref = (*payment_preimage).clone();
694 let mut payment_hash_nonref = (*payment_hash).clone();
696 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
697 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
700 nativeEvent::PaymentPathFailed {ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, } => {
701 let mut payment_hash_nonref = (*payment_hash).clone();
702 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
703 let mut network_update_nonref = (*network_update).clone();
704 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()) }) };
705 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
706 let mut path_nonref = (*path).clone();
707 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 } }); };
708 let mut short_channel_id_nonref = (*short_channel_id).clone();
709 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() }) };
710 Event::PaymentPathFailed {
711 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
712 rejected_by_dest: rejected_by_dest_nonref,
713 network_update: local_network_update_nonref,
714 all_paths_failed: all_paths_failed_nonref,
715 path: local_path_nonref.into(),
716 short_channel_id: local_short_channel_id_nonref,
719 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
720 let mut time_forwardable_nonref = (*time_forwardable).clone();
721 Event::PendingHTLCsForwardable {
722 time_forwardable: time_forwardable_nonref.as_secs(),
725 nativeEvent::SpendableOutputs {ref outputs, } => {
726 let mut outputs_nonref = (*outputs).clone();
727 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) }); };
728 Event::SpendableOutputs {
729 outputs: local_outputs_nonref.into(),
732 nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
733 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
734 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() }) };
735 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
736 Event::PaymentForwarded {
737 fee_earned_msat: local_fee_earned_msat_nonref,
738 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
741 nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
742 let mut channel_id_nonref = (*channel_id).clone();
743 let mut user_channel_id_nonref = (*user_channel_id).clone();
744 let mut reason_nonref = (*reason).clone();
745 Event::ChannelClosed {
746 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
747 user_channel_id: user_channel_id_nonref,
748 reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
751 nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
752 let mut channel_id_nonref = (*channel_id).clone();
753 let mut transaction_nonref = (*transaction).clone();
754 Event::DiscardFunding {
755 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
756 transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
762 pub(crate) fn native_into(native: nativeEvent) -> Self {
764 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
765 Event::FundingGenerationReady {
766 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
767 channel_value_satoshis: channel_value_satoshis,
768 output_script: output_script.into_bytes().into(),
769 user_channel_id: user_channel_id,
772 nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
773 Event::PaymentReceived {
774 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
776 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
779 nativeEvent::PaymentSent {mut payment_preimage, mut payment_hash, } => {
781 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
782 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
785 nativeEvent::PaymentPathFailed {mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, } => {
786 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()) }) };
787 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 } }); };
788 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() }) };
789 Event::PaymentPathFailed {
790 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
791 rejected_by_dest: rejected_by_dest,
792 network_update: local_network_update,
793 all_paths_failed: all_paths_failed,
794 path: local_path.into(),
795 short_channel_id: local_short_channel_id,
798 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
799 Event::PendingHTLCsForwardable {
800 time_forwardable: time_forwardable.as_secs(),
803 nativeEvent::SpendableOutputs {mut outputs, } => {
804 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
805 Event::SpendableOutputs {
806 outputs: local_outputs.into(),
809 nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
810 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() }) };
811 Event::PaymentForwarded {
812 fee_earned_msat: local_fee_earned_msat,
813 claim_from_onchain_tx: claim_from_onchain_tx,
816 nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
817 Event::ChannelClosed {
818 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
819 user_channel_id: user_channel_id,
820 reason: crate::lightning::util::events::ClosureReason::native_into(reason),
823 nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
824 Event::DiscardFunding {
825 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
826 transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
832 /// Frees any resources used by the Event
834 pub extern "C" fn Event_free(this_ptr: Event) { }
835 /// Creates a copy of the Event
837 pub extern "C" fn Event_clone(orig: &Event) -> Event {
841 /// Utility method to constructs a new FundingGenerationReady-variant Event
842 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 {
843 Event::FundingGenerationReady {
844 temporary_channel_id,
845 channel_value_satoshis,
851 /// Utility method to constructs a new PaymentReceived-variant Event
852 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
853 Event::PaymentReceived {
860 /// Utility method to constructs a new PaymentSent-variant Event
861 pub extern "C" fn Event_payment_sent(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> Event {
868 /// Utility method to constructs a new PaymentPathFailed-variant Event
869 pub extern "C" fn Event_payment_path_failed(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) -> Event {
870 Event::PaymentPathFailed {
880 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
881 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
882 Event::PendingHTLCsForwardable {
887 /// Utility method to constructs a new SpendableOutputs-variant Event
888 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
889 Event::SpendableOutputs {
894 /// Utility method to constructs a new PaymentForwarded-variant Event
895 pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
896 Event::PaymentForwarded {
898 claim_from_onchain_tx,
902 /// Utility method to constructs a new ChannelClosed-variant Event
903 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: u64, reason: crate::lightning::util::events::ClosureReason) -> Event {
904 Event::ChannelClosed {
911 /// Utility method to constructs a new DiscardFunding-variant Event
912 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
913 Event::DiscardFunding {
919 /// Serialize the Event object into a byte array which can be read by Event_read
920 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
921 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
923 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
924 /// broadcast to most peers).
925 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
929 pub enum MessageSendEvent {
930 /// Used to indicate that we've accepted a channel open and should send the accept_channel
931 /// message provided to the given peer.
933 /// The node_id of the node which should receive this message
934 node_id: crate::c_types::PublicKey,
935 /// The message which should be sent.
936 msg: crate::lightning::ln::msgs::AcceptChannel,
938 /// Used to indicate that we've initiated a channel open and should send the open_channel
939 /// message provided to the given peer.
941 /// The node_id of the node which should receive this message
942 node_id: crate::c_types::PublicKey,
943 /// The message which should be sent.
944 msg: crate::lightning::ln::msgs::OpenChannel,
946 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
948 /// The node_id of the node which should receive this message
949 node_id: crate::c_types::PublicKey,
950 /// The message which should be sent.
951 msg: crate::lightning::ln::msgs::FundingCreated,
953 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
955 /// The node_id of the node which should receive this message
956 node_id: crate::c_types::PublicKey,
957 /// The message which should be sent.
958 msg: crate::lightning::ln::msgs::FundingSigned,
960 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
962 /// The node_id of the node which should receive these message(s)
963 node_id: crate::c_types::PublicKey,
964 /// The funding_locked message which should be sent.
965 msg: crate::lightning::ln::msgs::FundingLocked,
967 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
968 SendAnnouncementSignatures {
969 /// The node_id of the node which should receive these message(s)
970 node_id: crate::c_types::PublicKey,
971 /// The announcement_signatures message which should be sent.
972 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
974 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
975 /// message should be sent to the peer with the given node_id.
977 /// The node_id of the node which should receive these message(s)
978 node_id: crate::c_types::PublicKey,
979 /// The update messages which should be sent. ALL messages in the struct should be sent!
980 updates: crate::lightning::ln::msgs::CommitmentUpdate,
982 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
984 /// The node_id of the node which should receive this message
985 node_id: crate::c_types::PublicKey,
986 /// The message which should be sent.
987 msg: crate::lightning::ln::msgs::RevokeAndACK,
989 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
991 /// The node_id of the node which should receive this message
992 node_id: crate::c_types::PublicKey,
993 /// The message which should be sent.
994 msg: crate::lightning::ln::msgs::ClosingSigned,
996 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
998 /// The node_id of the node which should receive this message
999 node_id: crate::c_types::PublicKey,
1000 /// The message which should be sent.
1001 msg: crate::lightning::ln::msgs::Shutdown,
1003 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1004 SendChannelReestablish {
1005 /// The node_id of the node which should receive this message
1006 node_id: crate::c_types::PublicKey,
1007 /// The message which should be sent.
1008 msg: crate::lightning::ln::msgs::ChannelReestablish,
1010 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1011 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1013 /// Note that after doing so, you very likely (unless you did so very recently) want to call
1014 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
1015 /// This ensures that any nodes which see our channel_announcement also have a relevant
1016 /// node_announcement, including relevant feature flags which may be important for routing
1017 /// through or to us.
1018 BroadcastChannelAnnouncement {
1019 /// The channel_announcement which should be sent.
1020 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
1021 /// The followup channel_update which should be sent.
1022 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
1024 /// Used to indicate that a node_announcement should be broadcast to all peers.
1025 BroadcastNodeAnnouncement {
1026 /// The node_announcement which should be sent.
1027 msg: crate::lightning::ln::msgs::NodeAnnouncement,
1029 /// Used to indicate that a channel_update should be broadcast to all peers.
1030 BroadcastChannelUpdate {
1031 /// The channel_update which should be sent.
1032 msg: crate::lightning::ln::msgs::ChannelUpdate,
1034 /// Used to indicate that a channel_update should be sent to a single peer.
1035 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1036 /// private channel and we shouldn't be informing all of our peers of channel parameters.
1038 /// The node_id of the node which should receive this message
1039 node_id: crate::c_types::PublicKey,
1040 /// The channel_update which should be sent.
1041 msg: crate::lightning::ln::msgs::ChannelUpdate,
1043 /// Broadcast an error downstream to be handled
1045 /// The node_id of the node which should receive this message
1046 node_id: crate::c_types::PublicKey,
1047 /// The action which should be taken.
1048 action: crate::lightning::ln::msgs::ErrorAction,
1050 /// Query a peer for channels with funding transaction UTXOs in a block range.
1051 SendChannelRangeQuery {
1052 /// The node_id of this message recipient
1053 node_id: crate::c_types::PublicKey,
1054 /// The query_channel_range which should be sent.
1055 msg: crate::lightning::ln::msgs::QueryChannelRange,
1057 /// Request routing gossip messages from a peer for a list of channels identified by
1058 /// their short_channel_ids.
1060 /// The node_id of this message recipient
1061 node_id: crate::c_types::PublicKey,
1062 /// The query_short_channel_ids which should be sent.
1063 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
1065 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1066 /// emitted during processing of the query.
1067 SendReplyChannelRange {
1068 /// The node_id of this message recipient
1069 node_id: crate::c_types::PublicKey,
1070 /// The reply_channel_range which should be sent.
1071 msg: crate::lightning::ln::msgs::ReplyChannelRange,
1074 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
1075 impl MessageSendEvent {
1077 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
1079 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1080 let mut node_id_nonref = (*node_id).clone();
1081 let mut msg_nonref = (*msg).clone();
1082 nativeMessageSendEvent::SendAcceptChannel {
1083 node_id: node_id_nonref.into_rust(),
1084 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1087 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1088 let mut node_id_nonref = (*node_id).clone();
1089 let mut msg_nonref = (*msg).clone();
1090 nativeMessageSendEvent::SendOpenChannel {
1091 node_id: node_id_nonref.into_rust(),
1092 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1095 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1096 let mut node_id_nonref = (*node_id).clone();
1097 let mut msg_nonref = (*msg).clone();
1098 nativeMessageSendEvent::SendFundingCreated {
1099 node_id: node_id_nonref.into_rust(),
1100 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1103 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1104 let mut node_id_nonref = (*node_id).clone();
1105 let mut msg_nonref = (*msg).clone();
1106 nativeMessageSendEvent::SendFundingSigned {
1107 node_id: node_id_nonref.into_rust(),
1108 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1111 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1112 let mut node_id_nonref = (*node_id).clone();
1113 let mut msg_nonref = (*msg).clone();
1114 nativeMessageSendEvent::SendFundingLocked {
1115 node_id: node_id_nonref.into_rust(),
1116 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1119 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1120 let mut node_id_nonref = (*node_id).clone();
1121 let mut msg_nonref = (*msg).clone();
1122 nativeMessageSendEvent::SendAnnouncementSignatures {
1123 node_id: node_id_nonref.into_rust(),
1124 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1127 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1128 let mut node_id_nonref = (*node_id).clone();
1129 let mut updates_nonref = (*updates).clone();
1130 nativeMessageSendEvent::UpdateHTLCs {
1131 node_id: node_id_nonref.into_rust(),
1132 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
1135 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1136 let mut node_id_nonref = (*node_id).clone();
1137 let mut msg_nonref = (*msg).clone();
1138 nativeMessageSendEvent::SendRevokeAndACK {
1139 node_id: node_id_nonref.into_rust(),
1140 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1143 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1144 let mut node_id_nonref = (*node_id).clone();
1145 let mut msg_nonref = (*msg).clone();
1146 nativeMessageSendEvent::SendClosingSigned {
1147 node_id: node_id_nonref.into_rust(),
1148 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1151 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1152 let mut node_id_nonref = (*node_id).clone();
1153 let mut msg_nonref = (*msg).clone();
1154 nativeMessageSendEvent::SendShutdown {
1155 node_id: node_id_nonref.into_rust(),
1156 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1159 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1160 let mut node_id_nonref = (*node_id).clone();
1161 let mut msg_nonref = (*msg).clone();
1162 nativeMessageSendEvent::SendChannelReestablish {
1163 node_id: node_id_nonref.into_rust(),
1164 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1167 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1168 let mut msg_nonref = (*msg).clone();
1169 let mut update_msg_nonref = (*update_msg).clone();
1170 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1171 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1172 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
1175 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1176 let mut msg_nonref = (*msg).clone();
1177 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1178 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1181 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1182 let mut msg_nonref = (*msg).clone();
1183 nativeMessageSendEvent::BroadcastChannelUpdate {
1184 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1187 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1188 let mut node_id_nonref = (*node_id).clone();
1189 let mut msg_nonref = (*msg).clone();
1190 nativeMessageSendEvent::SendChannelUpdate {
1191 node_id: node_id_nonref.into_rust(),
1192 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1195 MessageSendEvent::HandleError {ref node_id, ref action, } => {
1196 let mut node_id_nonref = (*node_id).clone();
1197 let mut action_nonref = (*action).clone();
1198 nativeMessageSendEvent::HandleError {
1199 node_id: node_id_nonref.into_rust(),
1200 action: action_nonref.into_native(),
1203 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1204 let mut node_id_nonref = (*node_id).clone();
1205 let mut msg_nonref = (*msg).clone();
1206 nativeMessageSendEvent::SendChannelRangeQuery {
1207 node_id: node_id_nonref.into_rust(),
1208 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1211 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1212 let mut node_id_nonref = (*node_id).clone();
1213 let mut msg_nonref = (*msg).clone();
1214 nativeMessageSendEvent::SendShortIdsQuery {
1215 node_id: node_id_nonref.into_rust(),
1216 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1219 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1220 let mut node_id_nonref = (*node_id).clone();
1221 let mut msg_nonref = (*msg).clone();
1222 nativeMessageSendEvent::SendReplyChannelRange {
1223 node_id: node_id_nonref.into_rust(),
1224 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1230 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
1232 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1233 nativeMessageSendEvent::SendAcceptChannel {
1234 node_id: node_id.into_rust(),
1235 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1238 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1239 nativeMessageSendEvent::SendOpenChannel {
1240 node_id: node_id.into_rust(),
1241 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1244 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1245 nativeMessageSendEvent::SendFundingCreated {
1246 node_id: node_id.into_rust(),
1247 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1250 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1251 nativeMessageSendEvent::SendFundingSigned {
1252 node_id: node_id.into_rust(),
1253 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1256 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1257 nativeMessageSendEvent::SendFundingLocked {
1258 node_id: node_id.into_rust(),
1259 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1262 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1263 nativeMessageSendEvent::SendAnnouncementSignatures {
1264 node_id: node_id.into_rust(),
1265 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1268 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1269 nativeMessageSendEvent::UpdateHTLCs {
1270 node_id: node_id.into_rust(),
1271 updates: *unsafe { Box::from_raw(updates.take_inner()) },
1274 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1275 nativeMessageSendEvent::SendRevokeAndACK {
1276 node_id: node_id.into_rust(),
1277 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1280 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1281 nativeMessageSendEvent::SendClosingSigned {
1282 node_id: node_id.into_rust(),
1283 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1286 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1287 nativeMessageSendEvent::SendShutdown {
1288 node_id: node_id.into_rust(),
1289 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1292 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1293 nativeMessageSendEvent::SendChannelReestablish {
1294 node_id: node_id.into_rust(),
1295 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1298 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1299 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1300 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1301 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
1304 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1305 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1306 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1309 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1310 nativeMessageSendEvent::BroadcastChannelUpdate {
1311 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1314 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1315 nativeMessageSendEvent::SendChannelUpdate {
1316 node_id: node_id.into_rust(),
1317 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1320 MessageSendEvent::HandleError {mut node_id, mut action, } => {
1321 nativeMessageSendEvent::HandleError {
1322 node_id: node_id.into_rust(),
1323 action: action.into_native(),
1326 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1327 nativeMessageSendEvent::SendChannelRangeQuery {
1328 node_id: node_id.into_rust(),
1329 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1332 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1333 nativeMessageSendEvent::SendShortIdsQuery {
1334 node_id: node_id.into_rust(),
1335 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1338 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1339 nativeMessageSendEvent::SendReplyChannelRange {
1340 node_id: node_id.into_rust(),
1341 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1347 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
1349 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1350 let mut node_id_nonref = (*node_id).clone();
1351 let mut msg_nonref = (*msg).clone();
1352 MessageSendEvent::SendAcceptChannel {
1353 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1354 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1357 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1358 let mut node_id_nonref = (*node_id).clone();
1359 let mut msg_nonref = (*msg).clone();
1360 MessageSendEvent::SendOpenChannel {
1361 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1362 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1365 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1366 let mut node_id_nonref = (*node_id).clone();
1367 let mut msg_nonref = (*msg).clone();
1368 MessageSendEvent::SendFundingCreated {
1369 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1370 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1373 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1374 let mut node_id_nonref = (*node_id).clone();
1375 let mut msg_nonref = (*msg).clone();
1376 MessageSendEvent::SendFundingSigned {
1377 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1378 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1381 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1382 let mut node_id_nonref = (*node_id).clone();
1383 let mut msg_nonref = (*msg).clone();
1384 MessageSendEvent::SendFundingLocked {
1385 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1386 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1389 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1390 let mut node_id_nonref = (*node_id).clone();
1391 let mut msg_nonref = (*msg).clone();
1392 MessageSendEvent::SendAnnouncementSignatures {
1393 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1394 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1397 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1398 let mut node_id_nonref = (*node_id).clone();
1399 let mut updates_nonref = (*updates).clone();
1400 MessageSendEvent::UpdateHTLCs {
1401 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1402 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
1405 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1406 let mut node_id_nonref = (*node_id).clone();
1407 let mut msg_nonref = (*msg).clone();
1408 MessageSendEvent::SendRevokeAndACK {
1409 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1410 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1413 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1414 let mut node_id_nonref = (*node_id).clone();
1415 let mut msg_nonref = (*msg).clone();
1416 MessageSendEvent::SendClosingSigned {
1417 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1418 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1421 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1422 let mut node_id_nonref = (*node_id).clone();
1423 let mut msg_nonref = (*msg).clone();
1424 MessageSendEvent::SendShutdown {
1425 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1426 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1429 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1430 let mut node_id_nonref = (*node_id).clone();
1431 let mut msg_nonref = (*msg).clone();
1432 MessageSendEvent::SendChannelReestablish {
1433 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1434 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1437 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1438 let mut msg_nonref = (*msg).clone();
1439 let mut update_msg_nonref = (*update_msg).clone();
1440 MessageSendEvent::BroadcastChannelAnnouncement {
1441 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1442 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
1445 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1446 let mut msg_nonref = (*msg).clone();
1447 MessageSendEvent::BroadcastNodeAnnouncement {
1448 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1451 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1452 let mut msg_nonref = (*msg).clone();
1453 MessageSendEvent::BroadcastChannelUpdate {
1454 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1457 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1458 let mut node_id_nonref = (*node_id).clone();
1459 let mut msg_nonref = (*msg).clone();
1460 MessageSendEvent::SendChannelUpdate {
1461 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1462 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1465 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
1466 let mut node_id_nonref = (*node_id).clone();
1467 let mut action_nonref = (*action).clone();
1468 MessageSendEvent::HandleError {
1469 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1470 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
1473 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1474 let mut node_id_nonref = (*node_id).clone();
1475 let mut msg_nonref = (*msg).clone();
1476 MessageSendEvent::SendChannelRangeQuery {
1477 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1478 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1481 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1482 let mut node_id_nonref = (*node_id).clone();
1483 let mut msg_nonref = (*msg).clone();
1484 MessageSendEvent::SendShortIdsQuery {
1485 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1486 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1489 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1490 let mut node_id_nonref = (*node_id).clone();
1491 let mut msg_nonref = (*msg).clone();
1492 MessageSendEvent::SendReplyChannelRange {
1493 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1494 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1500 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
1502 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1503 MessageSendEvent::SendAcceptChannel {
1504 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1505 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1508 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1509 MessageSendEvent::SendOpenChannel {
1510 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1511 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1514 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1515 MessageSendEvent::SendFundingCreated {
1516 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1517 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
1520 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1521 MessageSendEvent::SendFundingSigned {
1522 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1523 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1526 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1527 MessageSendEvent::SendFundingLocked {
1528 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1529 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg), is_owned: true },
1532 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1533 MessageSendEvent::SendAnnouncementSignatures {
1534 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1535 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
1538 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1539 MessageSendEvent::UpdateHTLCs {
1540 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1541 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
1544 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1545 MessageSendEvent::SendRevokeAndACK {
1546 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1547 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
1550 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1551 MessageSendEvent::SendClosingSigned {
1552 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1553 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1556 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1557 MessageSendEvent::SendShutdown {
1558 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1559 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
1562 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1563 MessageSendEvent::SendChannelReestablish {
1564 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1565 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
1568 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1569 MessageSendEvent::BroadcastChannelAnnouncement {
1570 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1571 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
1574 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1575 MessageSendEvent::BroadcastNodeAnnouncement {
1576 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1579 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1580 MessageSendEvent::BroadcastChannelUpdate {
1581 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1584 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1585 MessageSendEvent::SendChannelUpdate {
1586 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1587 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1590 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1591 MessageSendEvent::HandleError {
1592 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1593 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1596 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1597 MessageSendEvent::SendChannelRangeQuery {
1598 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1599 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1602 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1603 MessageSendEvent::SendShortIdsQuery {
1604 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1605 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
1608 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1609 MessageSendEvent::SendReplyChannelRange {
1610 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1611 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1617 /// Frees any resources used by the MessageSendEvent
1619 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1620 /// Creates a copy of the MessageSendEvent
1622 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1626 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
1627 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
1628 MessageSendEvent::SendAcceptChannel {
1634 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
1635 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
1636 MessageSendEvent::SendOpenChannel {
1642 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
1643 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
1644 MessageSendEvent::SendFundingCreated {
1650 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
1651 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
1652 MessageSendEvent::SendFundingSigned {
1658 /// Utility method to constructs a new SendFundingLocked-variant MessageSendEvent
1659 pub extern "C" fn MessageSendEvent_send_funding_locked(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingLocked) -> MessageSendEvent {
1660 MessageSendEvent::SendFundingLocked {
1666 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
1667 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
1668 MessageSendEvent::SendAnnouncementSignatures {
1674 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
1675 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
1676 MessageSendEvent::UpdateHTLCs {
1682 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
1683 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
1684 MessageSendEvent::SendRevokeAndACK {
1690 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
1691 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
1692 MessageSendEvent::SendClosingSigned {
1698 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
1699 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
1700 MessageSendEvent::SendShutdown {
1706 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
1707 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
1708 MessageSendEvent::SendChannelReestablish {
1714 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
1715 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1716 MessageSendEvent::BroadcastChannelAnnouncement {
1722 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
1723 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
1724 MessageSendEvent::BroadcastNodeAnnouncement {
1729 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
1730 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1731 MessageSendEvent::BroadcastChannelUpdate {
1736 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
1737 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1738 MessageSendEvent::SendChannelUpdate {
1744 /// Utility method to constructs a new HandleError-variant MessageSendEvent
1745 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
1746 MessageSendEvent::HandleError {
1752 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
1753 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
1754 MessageSendEvent::SendChannelRangeQuery {
1760 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
1761 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
1762 MessageSendEvent::SendShortIdsQuery {
1768 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
1769 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
1770 MessageSendEvent::SendReplyChannelRange {
1775 /// A trait indicating an object may generate message send events
1777 pub struct MessageSendEventsProvider {
1778 /// An opaque pointer which is passed to your function implementations as an argument.
1779 /// This has no meaning in the LDK, and can be NULL or any other value.
1780 pub this_arg: *mut c_void,
1781 /// Gets the list of pending events which were generated by previous actions, clearing the list
1784 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1785 /// Frees any resources associated with this object given its this_arg pointer.
1786 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1787 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1789 unsafe impl Send for MessageSendEventsProvider {}
1790 unsafe impl Sync for MessageSendEventsProvider {}
1792 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
1793 MessageSendEventsProvider {
1794 this_arg: orig.this_arg,
1795 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
1796 free: Clone::clone(&orig.free),
1800 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1801 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1802 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1803 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1804 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1809 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1810 // directly as a Deref trait in higher-level structs:
1811 impl std::ops::Deref for MessageSendEventsProvider {
1813 fn deref(&self) -> &Self {
1817 /// Calls the free function if one is set
1819 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1820 impl Drop for MessageSendEventsProvider {
1821 fn drop(&mut self) {
1822 if let Some(f) = self.free {
1827 /// A trait indicating an object may generate events.
1829 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1833 /// See [`process_pending_events`] for requirements around event processing.
1835 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1836 /// event since the last invocation. The handler must either act upon the event immediately
1837 /// or preserve it for later handling.
1839 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1840 /// consult the provider's documentation on the implication of processing events and how a handler
1841 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1842 /// [`ChainMonitor::process_pending_events`]).
1844 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1847 /// [`process_pending_events`]: Self::process_pending_events
1848 /// [`handle_event`]: EventHandler::handle_event
1849 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1850 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1852 pub struct EventsProvider {
1853 /// An opaque pointer which is passed to your function implementations as an argument.
1854 /// This has no meaning in the LDK, and can be NULL or any other value.
1855 pub this_arg: *mut c_void,
1856 /// Processes any events generated since the last call using the given event handler.
1858 /// Subsequent calls must only process new events. However, handlers must be capable of handling
1859 /// duplicate events across process restarts. This may occur if the provider was recovered from
1860 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1861 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1862 /// Frees any resources associated with this object given its this_arg pointer.
1863 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1864 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1866 unsafe impl Send for EventsProvider {}
1867 unsafe impl Sync for EventsProvider {}
1869 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
1871 this_arg: orig.this_arg,
1872 process_pending_events: Clone::clone(&orig.process_pending_events),
1873 free: Clone::clone(&orig.free),
1877 use lightning::util::events::EventsProvider as rustEventsProvider;
1878 /// Calls the free function if one is set
1880 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1881 impl Drop for EventsProvider {
1882 fn drop(&mut self) {
1883 if let Some(f) = self.free {
1888 /// A trait implemented for objects handling events from [`EventsProvider`].
1890 pub struct EventHandler {
1891 /// An opaque pointer which is passed to your function implementations as an argument.
1892 /// This has no meaning in the LDK, and can be NULL or any other value.
1893 pub this_arg: *mut c_void,
1894 /// Handles the given [`Event`].
1896 /// See [`EventsProvider`] for details that must be considered when implementing this method.
1897 pub handle_event: extern "C" fn (this_arg: *const c_void, event: &crate::lightning::util::events::Event),
1898 /// Frees any resources associated with this object given its this_arg pointer.
1899 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1900 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1902 unsafe impl Send for EventHandler {}
1903 unsafe impl Sync for EventHandler {}
1905 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
1907 this_arg: orig.this_arg,
1908 handle_event: Clone::clone(&orig.handle_event),
1909 free: Clone::clone(&orig.free),
1913 use lightning::util::events::EventHandler as rustEventHandler;
1914 impl rustEventHandler for EventHandler {
1915 fn handle_event(&self, mut event: &lightning::util::events::Event) {
1916 (self.handle_event)(self.this_arg, &crate::lightning::util::events::Event::from_native(event))
1920 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1921 // directly as a Deref trait in higher-level structs:
1922 impl std::ops::Deref for EventHandler {
1924 fn deref(&self) -> &Self {
1928 /// Calls the free function if one is set
1930 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
1931 impl Drop for EventHandler {
1932 fn drop(&mut self) {
1933 if let Some(f) = self.free {