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 value passed in to ChannelManager::create_channel
369 user_channel_id: u64,
371 /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
372 /// ChannelManager::claim_funds to get it....
373 /// Note that if the preimage is not known or the amount paid is incorrect, you should call
374 /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid
375 /// network congestion.
376 /// The amount paid should be considered 'incorrect' when it is less than or more than twice
377 /// the amount expected.
378 /// If you fail to call either ChannelManager::claim_funds or
379 /// ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be
380 /// automatically failed.
382 /// The hash for which the preimage should be handed to the ChannelManager.
383 payment_hash: crate::c_types::ThirtyTwoBytes,
384 /// The value, in thousandths of a satoshi, that this payment is for. Note that you must
385 /// compare this to the expected value before accepting the payment (as otherwise you are
386 /// providing proof-of-payment for less than the value you expected!).
388 /// Information for claiming this received payment, based on whether the purpose of the
389 /// payment is to pay an invoice or to send a spontaneous payment.
390 purpose: crate::lightning::util::events::PaymentPurpose,
392 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
393 /// and we got back the payment preimage for it).
395 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
396 /// event. In this situation, you SHOULD treat this payment as having succeeded.
398 /// The preimage to the hash given to ChannelManager::send_payment.
399 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
400 /// store it somehow!
401 payment_preimage: crate::c_types::ThirtyTwoBytes,
403 /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
404 /// something. You may wish to retry with a different route.
406 /// The hash which was given to ChannelManager::send_payment.
407 payment_hash: crate::c_types::ThirtyTwoBytes,
408 /// Indicates the payment was rejected for some reason by the recipient. This implies that
409 /// the payment has failed, not just the route in question. If this is not set, you may
410 /// retry the payment via a different route.
411 rejected_by_dest: bool,
412 /// Any failure information conveyed via the Onion return packet by a node along the failed
415 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
416 /// account the update. [`NetGraphMsgHandler`] is capable of doing this.
418 /// [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph
419 /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
420 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
421 /// For both single-path and multi-path payments, this is set if all paths of the payment have
422 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
423 /// larger MPP payment were still in flight when this event was generated.
424 all_paths_failed: bool,
425 /// The payment path that failed.
426 path: crate::c_types::derived::CVec_RouteHopZ,
428 /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
429 /// time in the future.
430 PendingHTLCsForwardable {
431 /// The minimum amount of time that should be waited prior to calling
432 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
433 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
434 /// now + 5*time_forwardable).
435 time_forwardable: u64,
437 /// Used to indicate that an output which you should know how to spend was confirmed on chain
438 /// and is now spendable.
439 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
440 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
441 /// somewhere and spend them when you create on-chain transactions.
443 /// The outputs which you should store as spendable by you.
444 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
446 /// This event is generated when a payment has been successfully forwarded through us and a
447 /// forwarding fee earned.
449 /// The fee, in milli-satoshis, which was earned as a result of the payment.
451 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
452 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
453 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
454 /// claimed the full value in millisatoshis from the source. In this case,
455 /// `claim_from_onchain_tx` will be set.
457 /// If the channel which sent us the payment has been force-closed, we will claim the funds
458 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
459 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
460 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
462 fee_earned_msat: crate::c_types::derived::COption_u64Z,
463 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
465 claim_from_onchain_tx: bool,
467 /// Used to indicate that a channel with the given `channel_id` is in the process of closure.
469 /// The channel_id of the channel which has been closed. Note that on-chain transactions
470 /// resolving the channel are likely still awaiting confirmation.
471 channel_id: crate::c_types::ThirtyTwoBytes,
472 /// The reason the channel was closed.
473 reason: crate::lightning::util::events::ClosureReason,
476 use lightning::util::events::Event as nativeEvent;
479 pub(crate) fn to_native(&self) -> nativeEvent {
481 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
482 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
483 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
484 let mut output_script_nonref = (*output_script).clone();
485 let mut user_channel_id_nonref = (*user_channel_id).clone();
486 nativeEvent::FundingGenerationReady {
487 temporary_channel_id: temporary_channel_id_nonref.data,
488 channel_value_satoshis: channel_value_satoshis_nonref,
489 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
490 user_channel_id: user_channel_id_nonref,
493 Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
494 let mut payment_hash_nonref = (*payment_hash).clone();
495 let mut amt_nonref = (*amt).clone();
496 let mut purpose_nonref = (*purpose).clone();
497 nativeEvent::PaymentReceived {
498 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
500 purpose: purpose_nonref.into_native(),
503 Event::PaymentSent {ref payment_preimage, } => {
504 let mut payment_preimage_nonref = (*payment_preimage).clone();
505 nativeEvent::PaymentSent {
506 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
509 Event::PaymentPathFailed {ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, } => {
510 let mut payment_hash_nonref = (*payment_hash).clone();
511 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
512 let mut network_update_nonref = (*network_update).clone();
513 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() }) } };
514 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
515 let mut path_nonref = (*path).clone();
516 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()) } }); };
517 nativeEvent::PaymentPathFailed {
518 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
519 rejected_by_dest: rejected_by_dest_nonref,
520 network_update: local_network_update_nonref,
521 all_paths_failed: all_paths_failed_nonref,
522 path: local_path_nonref,
525 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
526 let mut time_forwardable_nonref = (*time_forwardable).clone();
527 nativeEvent::PendingHTLCsForwardable {
528 time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
531 Event::SpendableOutputs {ref outputs, } => {
532 let mut outputs_nonref = (*outputs).clone();
533 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
534 nativeEvent::SpendableOutputs {
535 outputs: local_outputs_nonref,
538 Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
539 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
540 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
541 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
542 nativeEvent::PaymentForwarded {
543 fee_earned_msat: local_fee_earned_msat_nonref,
544 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
547 Event::ChannelClosed {ref channel_id, ref reason, } => {
548 let mut channel_id_nonref = (*channel_id).clone();
549 let mut reason_nonref = (*reason).clone();
550 nativeEvent::ChannelClosed {
551 channel_id: channel_id_nonref.data,
552 reason: reason_nonref.into_native(),
558 pub(crate) fn into_native(self) -> nativeEvent {
560 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
561 nativeEvent::FundingGenerationReady {
562 temporary_channel_id: temporary_channel_id.data,
563 channel_value_satoshis: channel_value_satoshis,
564 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
565 user_channel_id: user_channel_id,
568 Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
569 nativeEvent::PaymentReceived {
570 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
572 purpose: purpose.into_native(),
575 Event::PaymentSent {mut payment_preimage, } => {
576 nativeEvent::PaymentSent {
577 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
580 Event::PaymentPathFailed {mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, } => {
581 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() }) } };
582 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
583 nativeEvent::PaymentPathFailed {
584 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
585 rejected_by_dest: rejected_by_dest,
586 network_update: local_network_update,
587 all_paths_failed: all_paths_failed,
591 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
592 nativeEvent::PendingHTLCsForwardable {
593 time_forwardable: std::time::Duration::from_secs(time_forwardable),
596 Event::SpendableOutputs {mut outputs, } => {
597 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
598 nativeEvent::SpendableOutputs {
599 outputs: local_outputs,
602 Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
603 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
604 nativeEvent::PaymentForwarded {
605 fee_earned_msat: local_fee_earned_msat,
606 claim_from_onchain_tx: claim_from_onchain_tx,
609 Event::ChannelClosed {mut channel_id, mut reason, } => {
610 nativeEvent::ChannelClosed {
611 channel_id: channel_id.data,
612 reason: reason.into_native(),
618 pub(crate) fn from_native(native: &nativeEvent) -> Self {
620 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
621 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
622 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
623 let mut output_script_nonref = (*output_script).clone();
624 let mut user_channel_id_nonref = (*user_channel_id).clone();
625 Event::FundingGenerationReady {
626 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
627 channel_value_satoshis: channel_value_satoshis_nonref,
628 output_script: output_script_nonref.into_bytes().into(),
629 user_channel_id: user_channel_id_nonref,
632 nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
633 let mut payment_hash_nonref = (*payment_hash).clone();
634 let mut amt_nonref = (*amt).clone();
635 let mut purpose_nonref = (*purpose).clone();
636 Event::PaymentReceived {
637 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
639 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
642 nativeEvent::PaymentSent {ref payment_preimage, } => {
643 let mut payment_preimage_nonref = (*payment_preimage).clone();
645 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
648 nativeEvent::PaymentPathFailed {ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, } => {
649 let mut payment_hash_nonref = (*payment_hash).clone();
650 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
651 let mut network_update_nonref = (*network_update).clone();
652 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()) }) };
653 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
654 let mut path_nonref = (*path).clone();
655 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 } }); };
656 Event::PaymentPathFailed {
657 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
658 rejected_by_dest: rejected_by_dest_nonref,
659 network_update: local_network_update_nonref,
660 all_paths_failed: all_paths_failed_nonref,
661 path: local_path_nonref.into(),
664 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
665 let mut time_forwardable_nonref = (*time_forwardable).clone();
666 Event::PendingHTLCsForwardable {
667 time_forwardable: time_forwardable_nonref.as_secs(),
670 nativeEvent::SpendableOutputs {ref outputs, } => {
671 let mut outputs_nonref = (*outputs).clone();
672 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) }); };
673 Event::SpendableOutputs {
674 outputs: local_outputs_nonref.into(),
677 nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
678 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
679 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() }) };
680 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
681 Event::PaymentForwarded {
682 fee_earned_msat: local_fee_earned_msat_nonref,
683 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
686 nativeEvent::ChannelClosed {ref channel_id, ref reason, } => {
687 let mut channel_id_nonref = (*channel_id).clone();
688 let mut reason_nonref = (*reason).clone();
689 Event::ChannelClosed {
690 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
691 reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
697 pub(crate) fn native_into(native: nativeEvent) -> Self {
699 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
700 Event::FundingGenerationReady {
701 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
702 channel_value_satoshis: channel_value_satoshis,
703 output_script: output_script.into_bytes().into(),
704 user_channel_id: user_channel_id,
707 nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
708 Event::PaymentReceived {
709 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
711 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
714 nativeEvent::PaymentSent {mut payment_preimage, } => {
716 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
719 nativeEvent::PaymentPathFailed {mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, } => {
720 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()) }) };
721 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 } }); };
722 Event::PaymentPathFailed {
723 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
724 rejected_by_dest: rejected_by_dest,
725 network_update: local_network_update,
726 all_paths_failed: all_paths_failed,
727 path: local_path.into(),
730 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
731 Event::PendingHTLCsForwardable {
732 time_forwardable: time_forwardable.as_secs(),
735 nativeEvent::SpendableOutputs {mut outputs, } => {
736 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
737 Event::SpendableOutputs {
738 outputs: local_outputs.into(),
741 nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
742 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() }) };
743 Event::PaymentForwarded {
744 fee_earned_msat: local_fee_earned_msat,
745 claim_from_onchain_tx: claim_from_onchain_tx,
748 nativeEvent::ChannelClosed {mut channel_id, mut reason, } => {
749 Event::ChannelClosed {
750 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
751 reason: crate::lightning::util::events::ClosureReason::native_into(reason),
757 /// Frees any resources used by the Event
759 pub extern "C" fn Event_free(this_ptr: Event) { }
760 /// Creates a copy of the Event
762 pub extern "C" fn Event_clone(orig: &Event) -> Event {
766 /// Utility method to constructs a new FundingGenerationReady-variant Event
767 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 {
768 Event::FundingGenerationReady {
769 temporary_channel_id,
770 channel_value_satoshis,
776 /// Utility method to constructs a new PaymentReceived-variant Event
777 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
778 Event::PaymentReceived {
785 /// Utility method to constructs a new PaymentSent-variant Event
786 pub extern "C" fn Event_payment_sent(payment_preimage: crate::c_types::ThirtyTwoBytes) -> Event {
792 /// Utility method to constructs a new PaymentPathFailed-variant Event
793 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) -> Event {
794 Event::PaymentPathFailed {
803 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
804 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
805 Event::PendingHTLCsForwardable {
810 /// Utility method to constructs a new SpendableOutputs-variant Event
811 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
812 Event::SpendableOutputs {
817 /// Utility method to constructs a new PaymentForwarded-variant Event
818 pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
819 Event::PaymentForwarded {
821 claim_from_onchain_tx,
825 /// Utility method to constructs a new ChannelClosed-variant Event
826 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, reason: crate::lightning::util::events::ClosureReason) -> Event {
827 Event::ChannelClosed {
833 /// Serialize the Event object into a byte array which can be read by Event_read
834 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
835 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
837 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
838 /// broadcast to most peers).
839 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
843 pub enum MessageSendEvent {
844 /// Used to indicate that we've accepted a channel open and should send the accept_channel
845 /// message provided to the given peer.
847 /// The node_id of the node which should receive this message
848 node_id: crate::c_types::PublicKey,
849 /// The message which should be sent.
850 msg: crate::lightning::ln::msgs::AcceptChannel,
852 /// Used to indicate that we've initiated a channel open and should send the open_channel
853 /// message provided to the given peer.
855 /// The node_id of the node which should receive this message
856 node_id: crate::c_types::PublicKey,
857 /// The message which should be sent.
858 msg: crate::lightning::ln::msgs::OpenChannel,
860 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
862 /// The node_id of the node which should receive this message
863 node_id: crate::c_types::PublicKey,
864 /// The message which should be sent.
865 msg: crate::lightning::ln::msgs::FundingCreated,
867 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
869 /// The node_id of the node which should receive this message
870 node_id: crate::c_types::PublicKey,
871 /// The message which should be sent.
872 msg: crate::lightning::ln::msgs::FundingSigned,
874 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
876 /// The node_id of the node which should receive these message(s)
877 node_id: crate::c_types::PublicKey,
878 /// The funding_locked message which should be sent.
879 msg: crate::lightning::ln::msgs::FundingLocked,
881 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
882 SendAnnouncementSignatures {
883 /// The node_id of the node which should receive these message(s)
884 node_id: crate::c_types::PublicKey,
885 /// The announcement_signatures message which should be sent.
886 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
888 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
889 /// message should be sent to the peer with the given node_id.
891 /// The node_id of the node which should receive these message(s)
892 node_id: crate::c_types::PublicKey,
893 /// The update messages which should be sent. ALL messages in the struct should be sent!
894 updates: crate::lightning::ln::msgs::CommitmentUpdate,
896 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
898 /// The node_id of the node which should receive this message
899 node_id: crate::c_types::PublicKey,
900 /// The message which should be sent.
901 msg: crate::lightning::ln::msgs::RevokeAndACK,
903 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
905 /// The node_id of the node which should receive this message
906 node_id: crate::c_types::PublicKey,
907 /// The message which should be sent.
908 msg: crate::lightning::ln::msgs::ClosingSigned,
910 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
912 /// The node_id of the node which should receive this message
913 node_id: crate::c_types::PublicKey,
914 /// The message which should be sent.
915 msg: crate::lightning::ln::msgs::Shutdown,
917 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
918 SendChannelReestablish {
919 /// The node_id of the node which should receive this message
920 node_id: crate::c_types::PublicKey,
921 /// The message which should be sent.
922 msg: crate::lightning::ln::msgs::ChannelReestablish,
924 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
925 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
927 /// Note that after doing so, you very likely (unless you did so very recently) want to call
928 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
929 /// This ensures that any nodes which see our channel_announcement also have a relevant
930 /// node_announcement, including relevant feature flags which may be important for routing
931 /// through or to us.
932 BroadcastChannelAnnouncement {
933 /// The channel_announcement which should be sent.
934 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
935 /// The followup channel_update which should be sent.
936 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
938 /// Used to indicate that a node_announcement should be broadcast to all peers.
939 BroadcastNodeAnnouncement {
940 /// The node_announcement which should be sent.
941 msg: crate::lightning::ln::msgs::NodeAnnouncement,
943 /// Used to indicate that a channel_update should be broadcast to all peers.
944 BroadcastChannelUpdate {
945 /// The channel_update which should be sent.
946 msg: crate::lightning::ln::msgs::ChannelUpdate,
948 /// Used to indicate that a channel_update should be sent to a single peer.
949 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
950 /// private channel and we shouldn't be informing all of our peers of channel parameters.
952 /// The node_id of the node which should receive this message
953 node_id: crate::c_types::PublicKey,
954 /// The channel_update which should be sent.
955 msg: crate::lightning::ln::msgs::ChannelUpdate,
957 /// Broadcast an error downstream to be handled
959 /// The node_id of the node which should receive this message
960 node_id: crate::c_types::PublicKey,
961 /// The action which should be taken.
962 action: crate::lightning::ln::msgs::ErrorAction,
964 /// Query a peer for channels with funding transaction UTXOs in a block range.
965 SendChannelRangeQuery {
966 /// The node_id of this message recipient
967 node_id: crate::c_types::PublicKey,
968 /// The query_channel_range which should be sent.
969 msg: crate::lightning::ln::msgs::QueryChannelRange,
971 /// Request routing gossip messages from a peer for a list of channels identified by
972 /// their short_channel_ids.
974 /// The node_id of this message recipient
975 node_id: crate::c_types::PublicKey,
976 /// The query_short_channel_ids which should be sent.
977 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
979 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
980 /// emitted during processing of the query.
981 SendReplyChannelRange {
982 /// The node_id of this message recipient
983 node_id: crate::c_types::PublicKey,
984 /// The reply_channel_range which should be sent.
985 msg: crate::lightning::ln::msgs::ReplyChannelRange,
988 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
989 impl MessageSendEvent {
991 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
993 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
994 let mut node_id_nonref = (*node_id).clone();
995 let mut msg_nonref = (*msg).clone();
996 nativeMessageSendEvent::SendAcceptChannel {
997 node_id: node_id_nonref.into_rust(),
998 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1001 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1002 let mut node_id_nonref = (*node_id).clone();
1003 let mut msg_nonref = (*msg).clone();
1004 nativeMessageSendEvent::SendOpenChannel {
1005 node_id: node_id_nonref.into_rust(),
1006 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1009 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1010 let mut node_id_nonref = (*node_id).clone();
1011 let mut msg_nonref = (*msg).clone();
1012 nativeMessageSendEvent::SendFundingCreated {
1013 node_id: node_id_nonref.into_rust(),
1014 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1017 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1018 let mut node_id_nonref = (*node_id).clone();
1019 let mut msg_nonref = (*msg).clone();
1020 nativeMessageSendEvent::SendFundingSigned {
1021 node_id: node_id_nonref.into_rust(),
1022 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1025 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1026 let mut node_id_nonref = (*node_id).clone();
1027 let mut msg_nonref = (*msg).clone();
1028 nativeMessageSendEvent::SendFundingLocked {
1029 node_id: node_id_nonref.into_rust(),
1030 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1033 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1034 let mut node_id_nonref = (*node_id).clone();
1035 let mut msg_nonref = (*msg).clone();
1036 nativeMessageSendEvent::SendAnnouncementSignatures {
1037 node_id: node_id_nonref.into_rust(),
1038 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1041 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1042 let mut node_id_nonref = (*node_id).clone();
1043 let mut updates_nonref = (*updates).clone();
1044 nativeMessageSendEvent::UpdateHTLCs {
1045 node_id: node_id_nonref.into_rust(),
1046 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
1049 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1050 let mut node_id_nonref = (*node_id).clone();
1051 let mut msg_nonref = (*msg).clone();
1052 nativeMessageSendEvent::SendRevokeAndACK {
1053 node_id: node_id_nonref.into_rust(),
1054 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1057 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1058 let mut node_id_nonref = (*node_id).clone();
1059 let mut msg_nonref = (*msg).clone();
1060 nativeMessageSendEvent::SendClosingSigned {
1061 node_id: node_id_nonref.into_rust(),
1062 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1065 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1066 let mut node_id_nonref = (*node_id).clone();
1067 let mut msg_nonref = (*msg).clone();
1068 nativeMessageSendEvent::SendShutdown {
1069 node_id: node_id_nonref.into_rust(),
1070 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1073 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1074 let mut node_id_nonref = (*node_id).clone();
1075 let mut msg_nonref = (*msg).clone();
1076 nativeMessageSendEvent::SendChannelReestablish {
1077 node_id: node_id_nonref.into_rust(),
1078 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1081 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1082 let mut msg_nonref = (*msg).clone();
1083 let mut update_msg_nonref = (*update_msg).clone();
1084 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1085 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1086 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
1089 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1090 let mut msg_nonref = (*msg).clone();
1091 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1092 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1095 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1096 let mut msg_nonref = (*msg).clone();
1097 nativeMessageSendEvent::BroadcastChannelUpdate {
1098 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1101 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1102 let mut node_id_nonref = (*node_id).clone();
1103 let mut msg_nonref = (*msg).clone();
1104 nativeMessageSendEvent::SendChannelUpdate {
1105 node_id: node_id_nonref.into_rust(),
1106 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1109 MessageSendEvent::HandleError {ref node_id, ref action, } => {
1110 let mut node_id_nonref = (*node_id).clone();
1111 let mut action_nonref = (*action).clone();
1112 nativeMessageSendEvent::HandleError {
1113 node_id: node_id_nonref.into_rust(),
1114 action: action_nonref.into_native(),
1117 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1118 let mut node_id_nonref = (*node_id).clone();
1119 let mut msg_nonref = (*msg).clone();
1120 nativeMessageSendEvent::SendChannelRangeQuery {
1121 node_id: node_id_nonref.into_rust(),
1122 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1125 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1126 let mut node_id_nonref = (*node_id).clone();
1127 let mut msg_nonref = (*msg).clone();
1128 nativeMessageSendEvent::SendShortIdsQuery {
1129 node_id: node_id_nonref.into_rust(),
1130 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1133 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1134 let mut node_id_nonref = (*node_id).clone();
1135 let mut msg_nonref = (*msg).clone();
1136 nativeMessageSendEvent::SendReplyChannelRange {
1137 node_id: node_id_nonref.into_rust(),
1138 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1144 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
1146 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1147 nativeMessageSendEvent::SendAcceptChannel {
1148 node_id: node_id.into_rust(),
1149 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1152 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1153 nativeMessageSendEvent::SendOpenChannel {
1154 node_id: node_id.into_rust(),
1155 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1158 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1159 nativeMessageSendEvent::SendFundingCreated {
1160 node_id: node_id.into_rust(),
1161 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1164 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1165 nativeMessageSendEvent::SendFundingSigned {
1166 node_id: node_id.into_rust(),
1167 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1170 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1171 nativeMessageSendEvent::SendFundingLocked {
1172 node_id: node_id.into_rust(),
1173 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1176 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1177 nativeMessageSendEvent::SendAnnouncementSignatures {
1178 node_id: node_id.into_rust(),
1179 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1182 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1183 nativeMessageSendEvent::UpdateHTLCs {
1184 node_id: node_id.into_rust(),
1185 updates: *unsafe { Box::from_raw(updates.take_inner()) },
1188 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1189 nativeMessageSendEvent::SendRevokeAndACK {
1190 node_id: node_id.into_rust(),
1191 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1194 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1195 nativeMessageSendEvent::SendClosingSigned {
1196 node_id: node_id.into_rust(),
1197 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1200 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1201 nativeMessageSendEvent::SendShutdown {
1202 node_id: node_id.into_rust(),
1203 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1206 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1207 nativeMessageSendEvent::SendChannelReestablish {
1208 node_id: node_id.into_rust(),
1209 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1212 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1213 nativeMessageSendEvent::BroadcastChannelAnnouncement {
1214 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1215 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
1218 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1219 nativeMessageSendEvent::BroadcastNodeAnnouncement {
1220 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1223 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1224 nativeMessageSendEvent::BroadcastChannelUpdate {
1225 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1228 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1229 nativeMessageSendEvent::SendChannelUpdate {
1230 node_id: node_id.into_rust(),
1231 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1234 MessageSendEvent::HandleError {mut node_id, mut action, } => {
1235 nativeMessageSendEvent::HandleError {
1236 node_id: node_id.into_rust(),
1237 action: action.into_native(),
1240 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1241 nativeMessageSendEvent::SendChannelRangeQuery {
1242 node_id: node_id.into_rust(),
1243 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1246 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1247 nativeMessageSendEvent::SendShortIdsQuery {
1248 node_id: node_id.into_rust(),
1249 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1252 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1253 nativeMessageSendEvent::SendReplyChannelRange {
1254 node_id: node_id.into_rust(),
1255 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1261 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
1263 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1264 let mut node_id_nonref = (*node_id).clone();
1265 let mut msg_nonref = (*msg).clone();
1266 MessageSendEvent::SendAcceptChannel {
1267 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1268 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1271 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1272 let mut node_id_nonref = (*node_id).clone();
1273 let mut msg_nonref = (*msg).clone();
1274 MessageSendEvent::SendOpenChannel {
1275 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1276 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1279 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1280 let mut node_id_nonref = (*node_id).clone();
1281 let mut msg_nonref = (*msg).clone();
1282 MessageSendEvent::SendFundingCreated {
1283 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1284 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1287 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1288 let mut node_id_nonref = (*node_id).clone();
1289 let mut msg_nonref = (*msg).clone();
1290 MessageSendEvent::SendFundingSigned {
1291 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1292 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1295 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1296 let mut node_id_nonref = (*node_id).clone();
1297 let mut msg_nonref = (*msg).clone();
1298 MessageSendEvent::SendFundingLocked {
1299 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1300 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1303 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1304 let mut node_id_nonref = (*node_id).clone();
1305 let mut msg_nonref = (*msg).clone();
1306 MessageSendEvent::SendAnnouncementSignatures {
1307 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1308 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1311 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1312 let mut node_id_nonref = (*node_id).clone();
1313 let mut updates_nonref = (*updates).clone();
1314 MessageSendEvent::UpdateHTLCs {
1315 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1316 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
1319 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1320 let mut node_id_nonref = (*node_id).clone();
1321 let mut msg_nonref = (*msg).clone();
1322 MessageSendEvent::SendRevokeAndACK {
1323 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1324 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1327 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1328 let mut node_id_nonref = (*node_id).clone();
1329 let mut msg_nonref = (*msg).clone();
1330 MessageSendEvent::SendClosingSigned {
1331 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1332 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1335 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1336 let mut node_id_nonref = (*node_id).clone();
1337 let mut msg_nonref = (*msg).clone();
1338 MessageSendEvent::SendShutdown {
1339 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1340 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1343 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1344 let mut node_id_nonref = (*node_id).clone();
1345 let mut msg_nonref = (*msg).clone();
1346 MessageSendEvent::SendChannelReestablish {
1347 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1348 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1351 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1352 let mut msg_nonref = (*msg).clone();
1353 let mut update_msg_nonref = (*update_msg).clone();
1354 MessageSendEvent::BroadcastChannelAnnouncement {
1355 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1356 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
1359 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1360 let mut msg_nonref = (*msg).clone();
1361 MessageSendEvent::BroadcastNodeAnnouncement {
1362 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1365 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1366 let mut msg_nonref = (*msg).clone();
1367 MessageSendEvent::BroadcastChannelUpdate {
1368 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1371 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1372 let mut node_id_nonref = (*node_id).clone();
1373 let mut msg_nonref = (*msg).clone();
1374 MessageSendEvent::SendChannelUpdate {
1375 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1376 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1379 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
1380 let mut node_id_nonref = (*node_id).clone();
1381 let mut action_nonref = (*action).clone();
1382 MessageSendEvent::HandleError {
1383 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1384 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
1387 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1388 let mut node_id_nonref = (*node_id).clone();
1389 let mut msg_nonref = (*msg).clone();
1390 MessageSendEvent::SendChannelRangeQuery {
1391 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1392 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1395 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1396 let mut node_id_nonref = (*node_id).clone();
1397 let mut msg_nonref = (*msg).clone();
1398 MessageSendEvent::SendShortIdsQuery {
1399 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1400 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1403 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1404 let mut node_id_nonref = (*node_id).clone();
1405 let mut msg_nonref = (*msg).clone();
1406 MessageSendEvent::SendReplyChannelRange {
1407 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1408 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1414 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
1416 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1417 MessageSendEvent::SendAcceptChannel {
1418 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1419 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1422 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1423 MessageSendEvent::SendOpenChannel {
1424 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1425 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1428 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1429 MessageSendEvent::SendFundingCreated {
1430 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1431 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
1434 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1435 MessageSendEvent::SendFundingSigned {
1436 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1437 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1440 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1441 MessageSendEvent::SendFundingLocked {
1442 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1443 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg), is_owned: true },
1446 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1447 MessageSendEvent::SendAnnouncementSignatures {
1448 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1449 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
1452 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1453 MessageSendEvent::UpdateHTLCs {
1454 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1455 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
1458 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1459 MessageSendEvent::SendRevokeAndACK {
1460 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1461 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
1464 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1465 MessageSendEvent::SendClosingSigned {
1466 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1467 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1470 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1471 MessageSendEvent::SendShutdown {
1472 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1473 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
1476 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1477 MessageSendEvent::SendChannelReestablish {
1478 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1479 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
1482 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1483 MessageSendEvent::BroadcastChannelAnnouncement {
1484 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1485 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
1488 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1489 MessageSendEvent::BroadcastNodeAnnouncement {
1490 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1493 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1494 MessageSendEvent::BroadcastChannelUpdate {
1495 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1498 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1499 MessageSendEvent::SendChannelUpdate {
1500 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1501 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1504 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1505 MessageSendEvent::HandleError {
1506 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1507 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1510 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1511 MessageSendEvent::SendChannelRangeQuery {
1512 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1513 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1516 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1517 MessageSendEvent::SendShortIdsQuery {
1518 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1519 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
1522 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1523 MessageSendEvent::SendReplyChannelRange {
1524 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1525 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1531 /// Frees any resources used by the MessageSendEvent
1533 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1534 /// Creates a copy of the MessageSendEvent
1536 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1540 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
1541 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
1542 MessageSendEvent::SendAcceptChannel {
1548 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
1549 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
1550 MessageSendEvent::SendOpenChannel {
1556 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
1557 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
1558 MessageSendEvent::SendFundingCreated {
1564 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
1565 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
1566 MessageSendEvent::SendFundingSigned {
1572 /// Utility method to constructs a new SendFundingLocked-variant MessageSendEvent
1573 pub extern "C" fn MessageSendEvent_send_funding_locked(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingLocked) -> MessageSendEvent {
1574 MessageSendEvent::SendFundingLocked {
1580 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
1581 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
1582 MessageSendEvent::SendAnnouncementSignatures {
1588 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
1589 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
1590 MessageSendEvent::UpdateHTLCs {
1596 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
1597 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
1598 MessageSendEvent::SendRevokeAndACK {
1604 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
1605 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
1606 MessageSendEvent::SendClosingSigned {
1612 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
1613 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
1614 MessageSendEvent::SendShutdown {
1620 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
1621 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
1622 MessageSendEvent::SendChannelReestablish {
1628 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
1629 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1630 MessageSendEvent::BroadcastChannelAnnouncement {
1636 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
1637 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
1638 MessageSendEvent::BroadcastNodeAnnouncement {
1643 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
1644 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1645 MessageSendEvent::BroadcastChannelUpdate {
1650 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
1651 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1652 MessageSendEvent::SendChannelUpdate {
1658 /// Utility method to constructs a new HandleError-variant MessageSendEvent
1659 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
1660 MessageSendEvent::HandleError {
1666 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
1667 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
1668 MessageSendEvent::SendChannelRangeQuery {
1674 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
1675 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
1676 MessageSendEvent::SendShortIdsQuery {
1682 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
1683 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
1684 MessageSendEvent::SendReplyChannelRange {
1689 /// A trait indicating an object may generate message send events
1691 pub struct MessageSendEventsProvider {
1692 /// An opaque pointer which is passed to your function implementations as an argument.
1693 /// This has no meaning in the LDK, and can be NULL or any other value.
1694 pub this_arg: *mut c_void,
1695 /// Gets the list of pending events which were generated by previous actions, clearing the list
1698 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1699 /// Frees any resources associated with this object given its this_arg pointer.
1700 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1701 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1703 unsafe impl Send for MessageSendEventsProvider {}
1704 unsafe impl Sync for MessageSendEventsProvider {}
1706 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
1707 MessageSendEventsProvider {
1708 this_arg: orig.this_arg,
1709 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
1710 free: Clone::clone(&orig.free),
1714 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1715 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1716 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1717 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1718 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1723 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1724 // directly as a Deref trait in higher-level structs:
1725 impl std::ops::Deref for MessageSendEventsProvider {
1727 fn deref(&self) -> &Self {
1731 /// Calls the free function if one is set
1733 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1734 impl Drop for MessageSendEventsProvider {
1735 fn drop(&mut self) {
1736 if let Some(f) = self.free {
1741 /// A trait indicating an object may generate events.
1743 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1747 /// See [`process_pending_events`] for requirements around event processing.
1749 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1750 /// event since the last invocation. The handler must either act upon the event immediately
1751 /// or preserve it for later handling.
1753 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1754 /// consult the provider's documentation on the implication of processing events and how a handler
1755 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1756 /// [`ChainMonitor::process_pending_events`]).
1758 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1761 /// [`process_pending_events`]: Self::process_pending_events
1762 /// [`handle_event`]: EventHandler::handle_event
1763 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1764 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1766 pub struct EventsProvider {
1767 /// An opaque pointer which is passed to your function implementations as an argument.
1768 /// This has no meaning in the LDK, and can be NULL or any other value.
1769 pub this_arg: *mut c_void,
1770 /// Processes any events generated since the last call using the given event handler.
1772 /// Subsequent calls must only process new events. However, handlers must be capable of handling
1773 /// duplicate events across process restarts. This may occur if the provider was recovered from
1774 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1775 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1776 /// Frees any resources associated with this object given its this_arg pointer.
1777 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1778 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1780 unsafe impl Send for EventsProvider {}
1781 unsafe impl Sync for EventsProvider {}
1783 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
1785 this_arg: orig.this_arg,
1786 process_pending_events: Clone::clone(&orig.process_pending_events),
1787 free: Clone::clone(&orig.free),
1791 use lightning::util::events::EventsProvider as rustEventsProvider;
1792 /// Calls the free function if one is set
1794 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1795 impl Drop for EventsProvider {
1796 fn drop(&mut self) {
1797 if let Some(f) = self.free {
1802 /// A trait implemented for objects handling events from [`EventsProvider`].
1804 pub struct EventHandler {
1805 /// An opaque pointer which is passed to your function implementations as an argument.
1806 /// This has no meaning in the LDK, and can be NULL or any other value.
1807 pub this_arg: *mut c_void,
1808 /// Handles the given [`Event`].
1810 /// See [`EventsProvider`] for details that must be considered when implementing this method.
1811 pub handle_event: extern "C" fn (this_arg: *const c_void, event: &crate::lightning::util::events::Event),
1812 /// Frees any resources associated with this object given its this_arg pointer.
1813 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1814 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1816 unsafe impl Send for EventHandler {}
1817 unsafe impl Sync for EventHandler {}
1819 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
1821 this_arg: orig.this_arg,
1822 handle_event: Clone::clone(&orig.handle_event),
1823 free: Clone::clone(&orig.free),
1827 use lightning::util::events::EventHandler as rustEventHandler;
1828 impl rustEventHandler for EventHandler {
1829 fn handle_event(&self, mut event: &lightning::util::events::Event) {
1830 (self.handle_event)(self.this_arg, &crate::lightning::util::events::Event::from_native(event))
1834 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1835 // directly as a Deref trait in higher-level structs:
1836 impl std::ops::Deref for EventHandler {
1838 fn deref(&self) -> &Self {
1842 /// Calls the free function if one is set
1844 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
1845 impl Drop for EventHandler {
1846 fn drop(&mut self) {
1847 if let Some(f) = self.free {