1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Events are returned from various bits in the library which indicate some action must be taken
12 //! Because we don't have a built-in runtime, it's up to the client to call events at a time in the
13 //! future, as well as generate and broadcast funding transactions handle payment preimages and a
16 use alloc::str::FromStr;
17 use core::ffi::c_void;
18 use core::convert::Infallible;
19 use bitcoin::hashes::Hash;
20 use crate::c_types::*;
21 #[cfg(feature="no-std")]
22 use alloc::{vec::Vec, boxed::Box};
24 /// Some information provided on receipt of payment depends on whether the payment received is a
25 /// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
29 pub enum PaymentPurpose {
30 /// Information for receiving a payment that we generated an invoice for.
32 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
33 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
34 /// [`ChannelManager::claim_funds`].
36 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
37 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
39 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
40 payment_preimage: crate::c_types::ThirtyTwoBytes,
41 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
42 /// number of deanonymization attacks during the routing process.
43 /// It is provided here for your reference, however its accuracy is enforced directly by
44 /// [`ChannelManager`] using the values you previously provided to
45 /// [`ChannelManager::create_inbound_payment`] or
46 /// [`ChannelManager::create_inbound_payment_for_hash`].
48 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
49 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
50 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
51 payment_secret: crate::c_types::ThirtyTwoBytes,
53 /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
54 /// (the payee) providing a preimage.
56 crate::c_types::ThirtyTwoBytes),
58 use lightning::util::events::PaymentPurpose as PaymentPurposeImport;
59 pub(crate) type nativePaymentPurpose = PaymentPurposeImport;
63 pub(crate) fn to_native(&self) -> nativePaymentPurpose {
65 PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
66 let mut payment_preimage_nonref = (*payment_preimage).clone();
67 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
68 let mut payment_secret_nonref = (*payment_secret).clone();
69 nativePaymentPurpose::InvoicePayment {
70 payment_preimage: local_payment_preimage_nonref,
71 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
74 PaymentPurpose::SpontaneousPayment (ref a, ) => {
75 let mut a_nonref = (*a).clone();
76 nativePaymentPurpose::SpontaneousPayment (
77 ::lightning::ln::PaymentPreimage(a_nonref.data),
83 pub(crate) fn into_native(self) -> nativePaymentPurpose {
85 PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
86 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
87 nativePaymentPurpose::InvoicePayment {
88 payment_preimage: local_payment_preimage,
89 payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
92 PaymentPurpose::SpontaneousPayment (mut a, ) => {
93 nativePaymentPurpose::SpontaneousPayment (
94 ::lightning::ln::PaymentPreimage(a.data),
100 pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
102 nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, } => {
103 let mut payment_preimage_nonref = (*payment_preimage).clone();
104 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 } } };
105 let mut payment_secret_nonref = (*payment_secret).clone();
106 PaymentPurpose::InvoicePayment {
107 payment_preimage: local_payment_preimage_nonref,
108 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
111 nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
112 let mut a_nonref = (*a).clone();
113 PaymentPurpose::SpontaneousPayment (
114 crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
120 pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
122 nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, } => {
123 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 } } };
124 PaymentPurpose::InvoicePayment {
125 payment_preimage: local_payment_preimage,
126 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
129 nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
130 PaymentPurpose::SpontaneousPayment (
131 crate::c_types::ThirtyTwoBytes { data: a.0 },
137 /// Frees any resources used by the PaymentPurpose
139 pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
140 /// Creates a copy of the PaymentPurpose
142 pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
146 /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
147 pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
148 PaymentPurpose::InvoicePayment {
154 /// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
155 pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
156 PaymentPurpose::SpontaneousPayment(a, )
159 /// Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
160 pub extern "C" fn PaymentPurpose_write(obj: &crate::lightning::util::events::PaymentPurpose) -> crate::c_types::derived::CVec_u8Z {
161 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
164 /// Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
165 pub extern "C" fn PaymentPurpose_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentPurposeDecodeErrorZ {
166 let res: Result<lightning::util::events::PaymentPurpose, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
167 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::events::PaymentPurpose::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
170 /// The reason the channel was closed. See individual variants more details.
174 pub enum ClosureReason {
175 /// Closure generated from receiving a peer error message.
177 /// Our counterparty may have broadcasted their latest commitment state, and we have
179 CounterpartyForceClosed {
180 /// The error which the peer sent us.
182 /// The string should be sanitized before it is used (e.g emitted to logs
183 /// or printed to stdout). Otherwise, a well crafted error message may exploit
184 /// a security vulnerability in the terminal emulator or the logging subsystem.
185 peer_msg: crate::c_types::Str,
187 /// Closure generated from [`ChannelManager::force_close_channel`], called by the user.
189 /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel.
191 /// The channel was closed after negotiating a cooperative close and we've now broadcasted
192 /// the cooperative close transaction. Note the shutdown may have been initiated by us.
194 /// A commitment transaction was confirmed on chain, closing the channel. Most likely this
195 /// commitment transaction came from our counterparty, but it may also have come from
196 /// a copy of our own `ChannelMonitor`.
197 CommitmentTxConfirmed,
198 /// The funding transaction failed to confirm in a timely manner on an inbound channel.
200 /// Closure generated from processing an event, likely a HTLC forward/relay/reception.
202 /// A developer-readable error message which we generated.
203 err: crate::c_types::Str,
205 /// The peer disconnected prior to funding completing. In this case the spec mandates that we
206 /// forget the channel entirely - we can attempt again if the peer reconnects.
208 /// In LDK versions prior to 0.0.107 this could also occur if we were unable to connect to the
209 /// peer because of mutual incompatibility between us and our channel counterparty.
211 /// Closure generated from `ChannelManager::read` if the ChannelMonitor is newer than
212 /// the ChannelManager deserialized.
213 OutdatedChannelManager,
215 use lightning::util::events::ClosureReason as ClosureReasonImport;
216 pub(crate) type nativeClosureReason = ClosureReasonImport;
220 pub(crate) fn to_native(&self) -> nativeClosureReason {
222 ClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
223 let mut peer_msg_nonref = (*peer_msg).clone();
224 nativeClosureReason::CounterpartyForceClosed {
225 peer_msg: peer_msg_nonref.into_string(),
228 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
229 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
230 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
231 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
232 ClosureReason::ProcessingError {ref err, } => {
233 let mut err_nonref = (*err).clone();
234 nativeClosureReason::ProcessingError {
235 err: err_nonref.into_string(),
238 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
239 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
243 pub(crate) fn into_native(self) -> nativeClosureReason {
245 ClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
246 nativeClosureReason::CounterpartyForceClosed {
247 peer_msg: peer_msg.into_string(),
250 ClosureReason::HolderForceClosed => nativeClosureReason::HolderForceClosed,
251 ClosureReason::CooperativeClosure => nativeClosureReason::CooperativeClosure,
252 ClosureReason::CommitmentTxConfirmed => nativeClosureReason::CommitmentTxConfirmed,
253 ClosureReason::FundingTimedOut => nativeClosureReason::FundingTimedOut,
254 ClosureReason::ProcessingError {mut err, } => {
255 nativeClosureReason::ProcessingError {
256 err: err.into_string(),
259 ClosureReason::DisconnectedPeer => nativeClosureReason::DisconnectedPeer,
260 ClosureReason::OutdatedChannelManager => nativeClosureReason::OutdatedChannelManager,
264 pub(crate) fn from_native(native: &nativeClosureReason) -> Self {
266 nativeClosureReason::CounterpartyForceClosed {ref peer_msg, } => {
267 let mut peer_msg_nonref = (*peer_msg).clone();
268 ClosureReason::CounterpartyForceClosed {
269 peer_msg: peer_msg_nonref.into(),
272 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
273 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
274 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
275 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
276 nativeClosureReason::ProcessingError {ref err, } => {
277 let mut err_nonref = (*err).clone();
278 ClosureReason::ProcessingError {
279 err: err_nonref.into(),
282 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
283 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
287 pub(crate) fn native_into(native: nativeClosureReason) -> Self {
289 nativeClosureReason::CounterpartyForceClosed {mut peer_msg, } => {
290 ClosureReason::CounterpartyForceClosed {
291 peer_msg: peer_msg.into(),
294 nativeClosureReason::HolderForceClosed => ClosureReason::HolderForceClosed,
295 nativeClosureReason::CooperativeClosure => ClosureReason::CooperativeClosure,
296 nativeClosureReason::CommitmentTxConfirmed => ClosureReason::CommitmentTxConfirmed,
297 nativeClosureReason::FundingTimedOut => ClosureReason::FundingTimedOut,
298 nativeClosureReason::ProcessingError {mut err, } => {
299 ClosureReason::ProcessingError {
303 nativeClosureReason::DisconnectedPeer => ClosureReason::DisconnectedPeer,
304 nativeClosureReason::OutdatedChannelManager => ClosureReason::OutdatedChannelManager,
308 /// Frees any resources used by the ClosureReason
310 pub extern "C" fn ClosureReason_free(this_ptr: ClosureReason) { }
311 /// Creates a copy of the ClosureReason
313 pub extern "C" fn ClosureReason_clone(orig: &ClosureReason) -> ClosureReason {
317 /// Utility method to constructs a new CounterpartyForceClosed-variant ClosureReason
318 pub extern "C" fn ClosureReason_counterparty_force_closed(peer_msg: crate::c_types::Str) -> ClosureReason {
319 ClosureReason::CounterpartyForceClosed {
324 /// Utility method to constructs a new HolderForceClosed-variant ClosureReason
325 pub extern "C" fn ClosureReason_holder_force_closed() -> ClosureReason {
326 ClosureReason::HolderForceClosed}
328 /// Utility method to constructs a new CooperativeClosure-variant ClosureReason
329 pub extern "C" fn ClosureReason_cooperative_closure() -> ClosureReason {
330 ClosureReason::CooperativeClosure}
332 /// Utility method to constructs a new CommitmentTxConfirmed-variant ClosureReason
333 pub extern "C" fn ClosureReason_commitment_tx_confirmed() -> ClosureReason {
334 ClosureReason::CommitmentTxConfirmed}
336 /// Utility method to constructs a new FundingTimedOut-variant ClosureReason
337 pub extern "C" fn ClosureReason_funding_timed_out() -> ClosureReason {
338 ClosureReason::FundingTimedOut}
340 /// Utility method to constructs a new ProcessingError-variant ClosureReason
341 pub extern "C" fn ClosureReason_processing_error(err: crate::c_types::Str) -> ClosureReason {
342 ClosureReason::ProcessingError {
347 /// Utility method to constructs a new DisconnectedPeer-variant ClosureReason
348 pub extern "C" fn ClosureReason_disconnected_peer() -> ClosureReason {
349 ClosureReason::DisconnectedPeer}
351 /// Utility method to constructs a new OutdatedChannelManager-variant ClosureReason
352 pub extern "C" fn ClosureReason_outdated_channel_manager() -> ClosureReason {
353 ClosureReason::OutdatedChannelManager}
355 /// Serialize the ClosureReason object into a byte array which can be read by ClosureReason_read
356 pub extern "C" fn ClosureReason_write(obj: &crate::lightning::util::events::ClosureReason) -> crate::c_types::derived::CVec_u8Z {
357 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
360 /// Read a ClosureReason from a byte array, created by ClosureReason_write
361 pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_ClosureReasonZDecodeErrorZ {
362 let res: Result<Option<lightning::util::events::ClosureReason>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
363 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_ClosureReasonZ::None } else { crate::c_types::derived::COption_ClosureReasonZ::Some( { crate::lightning::util::events::ClosureReason::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
366 /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
370 pub enum HTLCDestination {
371 /// We tried forwarding to a channel but failed to do so. An example of such an instance is when
372 /// there is insufficient capacity in our outbound channel.
374 /// The `node_id` of the next node. For backwards compatibility, this field is
375 /// marked as optional, versions prior to 0.0.110 may not always be able to provide
376 /// counterparty node information.
378 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
379 node_id: crate::c_types::PublicKey,
380 /// The outgoing `channel_id` between us and the next node.
381 channel_id: crate::c_types::ThirtyTwoBytes,
383 /// Scenario where we are unsure of the next node to forward the HTLC to.
385 /// Short channel id we are requesting to forward an HTLC to.
386 requested_forward_scid: u64,
388 /// Failure scenario where an HTLC may have been forwarded to be intended for us,
389 /// but is invalid for some reason, so we reject it.
391 /// Some of the reasons may include:
393 /// * Expected MPP amount to claim does not equal HTLC total
394 /// * Claimable amount does not match expected amount
396 /// The payment hash of the payment we attempted to process.
397 payment_hash: crate::c_types::ThirtyTwoBytes,
400 use lightning::util::events::HTLCDestination as HTLCDestinationImport;
401 pub(crate) type nativeHTLCDestination = HTLCDestinationImport;
403 impl HTLCDestination {
405 pub(crate) fn to_native(&self) -> nativeHTLCDestination {
407 HTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
408 let mut node_id_nonref = (*node_id).clone();
409 let mut local_node_id_nonref = if node_id_nonref.is_null() { None } else { Some( { node_id_nonref.into_rust() }) };
410 let mut channel_id_nonref = (*channel_id).clone();
411 nativeHTLCDestination::NextHopChannel {
412 node_id: local_node_id_nonref,
413 channel_id: channel_id_nonref.data,
416 HTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
417 let mut requested_forward_scid_nonref = (*requested_forward_scid).clone();
418 nativeHTLCDestination::UnknownNextHop {
419 requested_forward_scid: requested_forward_scid_nonref,
422 HTLCDestination::FailedPayment {ref payment_hash, } => {
423 let mut payment_hash_nonref = (*payment_hash).clone();
424 nativeHTLCDestination::FailedPayment {
425 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
431 pub(crate) fn into_native(self) -> nativeHTLCDestination {
433 HTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
434 let mut local_node_id = if node_id.is_null() { None } else { Some( { node_id.into_rust() }) };
435 nativeHTLCDestination::NextHopChannel {
436 node_id: local_node_id,
437 channel_id: channel_id.data,
440 HTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
441 nativeHTLCDestination::UnknownNextHop {
442 requested_forward_scid: requested_forward_scid,
445 HTLCDestination::FailedPayment {mut payment_hash, } => {
446 nativeHTLCDestination::FailedPayment {
447 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
453 pub(crate) fn from_native(native: &nativeHTLCDestination) -> Self {
455 nativeHTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => {
456 let mut node_id_nonref = (*node_id).clone();
457 let mut local_node_id_nonref = if node_id_nonref.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(node_id_nonref.unwrap())) } };
458 let mut channel_id_nonref = (*channel_id).clone();
459 HTLCDestination::NextHopChannel {
460 node_id: local_node_id_nonref,
461 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
464 nativeHTLCDestination::UnknownNextHop {ref requested_forward_scid, } => {
465 let mut requested_forward_scid_nonref = (*requested_forward_scid).clone();
466 HTLCDestination::UnknownNextHop {
467 requested_forward_scid: requested_forward_scid_nonref,
470 nativeHTLCDestination::FailedPayment {ref payment_hash, } => {
471 let mut payment_hash_nonref = (*payment_hash).clone();
472 HTLCDestination::FailedPayment {
473 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
479 pub(crate) fn native_into(native: nativeHTLCDestination) -> Self {
481 nativeHTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => {
482 let mut local_node_id = if node_id.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(node_id.unwrap())) } };
483 HTLCDestination::NextHopChannel {
484 node_id: local_node_id,
485 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
488 nativeHTLCDestination::UnknownNextHop {mut requested_forward_scid, } => {
489 HTLCDestination::UnknownNextHop {
490 requested_forward_scid: requested_forward_scid,
493 nativeHTLCDestination::FailedPayment {mut payment_hash, } => {
494 HTLCDestination::FailedPayment {
495 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
501 /// Frees any resources used by the HTLCDestination
503 pub extern "C" fn HTLCDestination_free(this_ptr: HTLCDestination) { }
504 /// Creates a copy of the HTLCDestination
506 pub extern "C" fn HTLCDestination_clone(orig: &HTLCDestination) -> HTLCDestination {
510 /// Utility method to constructs a new NextHopChannel-variant HTLCDestination
511 pub extern "C" fn HTLCDestination_next_hop_channel(node_id: crate::c_types::PublicKey, channel_id: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
512 HTLCDestination::NextHopChannel {
518 /// Utility method to constructs a new UnknownNextHop-variant HTLCDestination
519 pub extern "C" fn HTLCDestination_unknown_next_hop(requested_forward_scid: u64) -> HTLCDestination {
520 HTLCDestination::UnknownNextHop {
521 requested_forward_scid,
525 /// Utility method to constructs a new FailedPayment-variant HTLCDestination
526 pub extern "C" fn HTLCDestination_failed_payment(payment_hash: crate::c_types::ThirtyTwoBytes) -> HTLCDestination {
527 HTLCDestination::FailedPayment {
532 /// Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
533 pub extern "C" fn HTLCDestination_write(obj: &crate::lightning::util::events::HTLCDestination) -> crate::c_types::derived::CVec_u8Z {
534 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
537 /// Read a HTLCDestination from a byte array, created by HTLCDestination_write
538 pub extern "C" fn HTLCDestination_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_HTLCDestinationZDecodeErrorZ {
539 let res: Result<Option<lightning::util::events::HTLCDestination>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
540 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_HTLCDestinationZ::None } else { crate::c_types::derived::COption_HTLCDestinationZ::Some( { crate::lightning::util::events::HTLCDestination::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
543 /// An Event which you should probably take some action in response to.
545 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
546 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
547 /// written as it makes no sense to respond to it after reconnecting to peers).
552 /// Used to indicate that the client should generate a funding transaction with the given
553 /// parameters and then call [`ChannelManager::funding_transaction_generated`].
554 /// Generated in [`ChannelManager`] message handling.
555 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
556 /// counterparty can steal your funds!
558 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
559 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
560 FundingGenerationReady {
561 /// The random channel_id we picked which you'll need to pass into
562 /// [`ChannelManager::funding_transaction_generated`].
564 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
565 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
566 /// The counterparty's node_id, which you'll need to pass back into
567 /// [`ChannelManager::funding_transaction_generated`].
569 /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
570 counterparty_node_id: crate::c_types::PublicKey,
571 /// The value, in satoshis, that the output should have.
572 channel_value_satoshis: u64,
573 /// The script which should be used in the transaction output.
574 output_script: crate::c_types::derived::CVec_u8Z,
575 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or 0 for
576 /// an inbound channel.
578 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
579 user_channel_id: u64,
581 /// Indicates we've received (an offer of) money! Just gotta dig out that payment preimage and
582 /// feed it to [`ChannelManager::claim_funds`] to get it....
584 /// Note that if the preimage is not known, you should call
585 /// [`ChannelManager::fail_htlc_backwards`] to free up resources for this HTLC and avoid
586 /// network congestion.
587 /// If you fail to call either [`ChannelManager::claim_funds`] or
588 /// [`ChannelManager::fail_htlc_backwards`] within the HTLC's timeout, the HTLC will be
589 /// automatically failed.
592 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
593 /// `PaymentReceived` events may be generated for the same payment.
595 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
596 /// [`ChannelManager::fail_htlc_backwards`]: crate::ln::channelmanager::ChannelManager::fail_htlc_backwards
598 /// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
599 /// not stop you from registering duplicate payment hashes for inbound payments.
600 payment_hash: crate::c_types::ThirtyTwoBytes,
601 /// The value, in thousandths of a satoshi, that this payment is for.
603 /// Information for claiming this received payment, based on whether the purpose of the
604 /// payment is to pay an invoice or to send a spontaneous payment.
605 purpose: crate::lightning::util::events::PaymentPurpose,
607 /// Indicates a payment has been claimed and we've received money!
609 /// This most likely occurs when [`ChannelManager::claim_funds`] has been called in response
610 /// to an [`Event::PaymentReceived`]. However, if we previously crashed during a
611 /// [`ChannelManager::claim_funds`] call you may see this event without a corresponding
612 /// [`Event::PaymentReceived`] event.
615 /// LDK will not stop an inbound payment from being paid multiple times, so multiple
616 /// `PaymentReceived` events may be generated for the same payment. If you then call
617 /// [`ChannelManager::claim_funds`] twice for the same [`Event::PaymentReceived`] you may get
618 /// multiple `PaymentClaimed` events.
620 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
622 /// The payment hash of the claimed payment. Note that LDK will not stop you from
623 /// registering duplicate payment hashes for inbound payments.
624 payment_hash: crate::c_types::ThirtyTwoBytes,
625 /// The value, in thousandths of a satoshi, that this payment is for.
627 /// The purpose of this claimed payment, i.e. whether the payment was for an invoice or a
628 /// spontaneous payment.
629 purpose: crate::lightning::util::events::PaymentPurpose,
631 /// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
632 /// and we got back the payment preimage for it).
634 /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
635 /// event. In this situation, you SHOULD treat this payment as having succeeded.
637 /// The id returned by [`ChannelManager::send_payment`] and used with
638 /// [`ChannelManager::retry_payment`].
640 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
641 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
643 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
644 payment_id: crate::c_types::ThirtyTwoBytes,
645 /// The preimage to the hash given to ChannelManager::send_payment.
646 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
647 /// store it somehow!
648 payment_preimage: crate::c_types::ThirtyTwoBytes,
649 /// The hash that was given to [`ChannelManager::send_payment`].
651 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
652 payment_hash: crate::c_types::ThirtyTwoBytes,
653 /// The total fee which was spent at intermediate hops in this payment, across all paths.
655 /// Note that, like [`Route::get_total_fees`] this does *not* include any potential
656 /// overpayment to the recipient node.
658 /// If the recipient or an intermediate node misbehaves and gives us free money, this may
659 /// overstate the amount paid, though this is unlikely.
661 /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees
662 fee_paid_msat: crate::c_types::derived::COption_u64Z,
664 /// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
665 /// provide failure information for each MPP part in the payment.
667 /// This event is provided once there are no further pending HTLCs for the payment and the
668 /// payment is no longer retryable, either due to a several-block timeout or because
669 /// [`ChannelManager::abandon_payment`] was previously called for the corresponding payment.
671 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
673 /// The id returned by [`ChannelManager::send_payment`] and used with
674 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
676 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
677 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
678 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
679 payment_id: crate::c_types::ThirtyTwoBytes,
680 /// The hash that was given to [`ChannelManager::send_payment`].
682 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
683 payment_hash: crate::c_types::ThirtyTwoBytes,
685 /// Indicates that a path for an outbound payment was successful.
687 /// Always generated after [`Event::PaymentSent`] and thus useful for scoring channels. See
688 /// [`Event::PaymentSent`] for obtaining the payment preimage.
689 PaymentPathSuccessful {
690 /// The id returned by [`ChannelManager::send_payment`] and used with
691 /// [`ChannelManager::retry_payment`].
693 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
694 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
695 payment_id: crate::c_types::ThirtyTwoBytes,
696 /// The hash that was given to [`ChannelManager::send_payment`].
698 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
700 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
701 payment_hash: crate::c_types::ThirtyTwoBytes,
702 /// The payment path that was successful.
704 /// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
705 path: crate::c_types::derived::CVec_RouteHopZ,
707 /// Indicates an outbound HTLC we sent failed. Probably some intermediary node dropped
708 /// something. You may wish to retry with a different route.
710 /// Note that this does *not* indicate that all paths for an MPP payment have failed, see
711 /// [`Event::PaymentFailed`] and [`all_paths_failed`].
713 /// [`all_paths_failed`]: Self::PaymentPathFailed::all_paths_failed
715 /// The id returned by [`ChannelManager::send_payment`] and used with
716 /// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
718 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
719 /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
720 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
722 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
723 payment_id: crate::c_types::ThirtyTwoBytes,
724 /// The hash that was given to [`ChannelManager::send_payment`].
726 /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
727 payment_hash: crate::c_types::ThirtyTwoBytes,
728 /// Indicates the payment was rejected for some reason by the recipient. This implies that
729 /// the payment has failed, not just the route in question. If this is not set, you may
730 /// retry the payment via a different route.
731 rejected_by_dest: bool,
732 /// Any failure information conveyed via the Onion return packet by a node along the failed
735 /// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
736 /// account the update.
738 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
739 network_update: crate::c_types::derived::COption_NetworkUpdateZ,
740 /// For both single-path and multi-path payments, this is set if all paths of the payment have
741 /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
742 /// larger MPP payment were still in flight when this event was generated.
744 /// Note that if you are retrying individual MPP parts, using this value to determine if a
745 /// payment has fully failed is race-y. Because multiple failures can happen prior to events
746 /// being processed, you may retry in response to a first failure, with a second failure
747 /// (with `all_paths_failed` set) still pending. Then, when the second failure is processed
748 /// you will see `all_paths_failed` set even though the retry of the first failure still
749 /// has an associated in-flight HTLC. See (1) for an example of such a failure.
751 /// If you wish to retry individual MPP parts and learn when a payment has failed, you must
752 /// call [`ChannelManager::abandon_payment`] and wait for a [`Event::PaymentFailed`] event.
754 /// (1) <https://github.com/lightningdevkit/rust-lightning/issues/1164>
756 /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
757 all_paths_failed: bool,
758 /// The payment path that failed.
759 path: crate::c_types::derived::CVec_RouteHopZ,
760 /// The channel responsible for the failed payment path.
762 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
763 /// may not refer to a channel in the public network graph. These aliases may also collide
764 /// with channels in the public network graph.
766 /// If this is `Some`, then the corresponding channel should be avoided when the payment is
767 /// retried. May be `None` for older [`Event`] serializations.
768 short_channel_id: crate::c_types::derived::COption_u64Z,
769 /// Parameters needed to compute a new [`Route`] when retrying the failed payment path.
771 /// See [`find_route`] for details.
773 /// [`Route`]: crate::routing::router::Route
774 /// [`find_route`]: crate::routing::router::find_route
776 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
777 retry: crate::lightning::routing::router::RouteParameters,
779 /// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
781 /// The id returned by [`ChannelManager::send_probe`].
783 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
784 payment_id: crate::c_types::ThirtyTwoBytes,
785 /// The hash generated by [`ChannelManager::send_probe`].
787 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
788 payment_hash: crate::c_types::ThirtyTwoBytes,
789 /// The payment path that was successful.
790 path: crate::c_types::derived::CVec_RouteHopZ,
792 /// Indicates that a probe payment we sent failed at an intermediary node on the path.
794 /// The id returned by [`ChannelManager::send_probe`].
796 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
797 payment_id: crate::c_types::ThirtyTwoBytes,
798 /// The hash generated by [`ChannelManager::send_probe`].
800 /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
801 payment_hash: crate::c_types::ThirtyTwoBytes,
802 /// The payment path that failed.
803 path: crate::c_types::derived::CVec_RouteHopZ,
804 /// The channel responsible for the failed probe.
806 /// Note that for route hints or for the first hop in a path this may be an SCID alias and
807 /// may not refer to a channel in the public network graph. These aliases may also collide
808 /// with channels in the public network graph.
809 short_channel_id: crate::c_types::derived::COption_u64Z,
811 /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
812 /// a time in the future.
814 /// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
815 PendingHTLCsForwardable {
816 /// The minimum amount of time that should be waited prior to calling
817 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
818 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
819 /// now + 5*time_forwardable).
820 time_forwardable: u64,
822 /// Used to indicate that an output which you should know how to spend was confirmed on chain
823 /// and is now spendable.
824 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
825 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
826 /// somewhere and spend them when you create on-chain transactions.
828 /// The outputs which you should store as spendable by you.
829 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
831 /// This event is generated when a payment has been successfully forwarded through us and a
832 /// forwarding fee earned.
834 /// The incoming channel between the previous node and us. This is only `None` for events
835 /// generated or serialized by versions prior to 0.0.107.
837 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
838 prev_channel_id: crate::c_types::ThirtyTwoBytes,
839 /// The outgoing channel between the next node and us. This is only `None` for events
840 /// generated or serialized by versions prior to 0.0.107.
842 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
843 next_channel_id: crate::c_types::ThirtyTwoBytes,
844 /// The fee, in milli-satoshis, which was earned as a result of the payment.
846 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
847 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
848 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
849 /// claimed the full value in millisatoshis from the source. In this case,
850 /// `claim_from_onchain_tx` will be set.
852 /// If the channel which sent us the payment has been force-closed, we will claim the funds
853 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
854 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
855 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
857 fee_earned_msat: crate::c_types::derived::COption_u64Z,
858 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
860 claim_from_onchain_tx: bool,
862 /// Used to indicate that a previously opened channel with the given `channel_id` is in the
863 /// process of closure.
865 /// The channel_id of the channel which has been closed. Note that on-chain transactions
866 /// resolving the channel are likely still awaiting confirmation.
867 channel_id: crate::c_types::ThirtyTwoBytes,
868 /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
869 /// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
870 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
871 /// `user_channel_id` will be 0 for an inbound channel.
872 /// This will always be zero for objects serialized with LDK versions prior to 0.0.102.
874 /// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
875 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
876 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
877 user_channel_id: u64,
878 /// The reason the channel was closed.
879 reason: crate::lightning::util::events::ClosureReason,
881 /// Used to indicate to the user that they can abandon the funding transaction and recycle the
882 /// inputs for another purpose.
884 /// The channel_id of the channel which has been closed.
885 channel_id: crate::c_types::ThirtyTwoBytes,
886 /// The full transaction received from the user
887 transaction: crate::c_types::Transaction,
889 /// Indicates a request to open a new channel by a peer.
891 /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the
892 /// request, call [`ChannelManager::force_close_without_broadcasting_txn`].
894 /// The event is only triggered when a new open channel request is received and the
895 /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
897 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
898 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
899 /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
901 /// The temporary channel ID of the channel requested to be opened.
903 /// When responding to the request, the `temporary_channel_id` should be passed
904 /// back to the ChannelManager through [`ChannelManager::accept_inbound_channel`] to accept,
905 /// or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject.
907 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
908 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
909 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
910 /// The node_id of the counterparty requesting to open the channel.
912 /// When responding to the request, the `counterparty_node_id` should be passed
913 /// back to the `ChannelManager` through [`ChannelManager::accept_inbound_channel`] to
914 /// accept the request, or through [`ChannelManager::force_close_without_broadcasting_txn`] to reject the
917 /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
918 /// [`ChannelManager::force_close_without_broadcasting_txn`]: crate::ln::channelmanager::ChannelManager::force_close_without_broadcasting_txn
919 counterparty_node_id: crate::c_types::PublicKey,
920 /// The channel value of the requested channel.
921 funding_satoshis: u64,
922 /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
924 /// The features that this channel will operate with. If you reject the channel, a
925 /// well-behaved counterparty may automatically re-attempt the channel with a new set of
928 /// Note that if [`ChannelTypeFeatures::supports_scid_privacy`] returns true on this type,
929 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
932 /// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
933 /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
934 /// 0.0.107. Channels setting this type also need to get manually accepted via
935 /// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
936 /// or will be rejected otherwise.
938 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
939 channel_type: crate::lightning::ln::features::ChannelTypeFeatures,
941 /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to
944 /// Some scenarios where this event may be sent include:
945 /// * Insufficient capacity in the outbound channel
946 /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
947 /// * When an unknown SCID is requested for forwarding a payment.
948 /// * Claiming an amount for an MPP payment that exceeds the HTLC total
949 /// * The HTLC has timed out
951 /// This event, however, does not get generated if an HTLC fails to meet the forwarding
952 /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
954 /// The channel over which the HTLC was received.
955 prev_channel_id: crate::c_types::ThirtyTwoBytes,
956 /// Destination of the HTLC that failed to be processed.
957 failed_next_destination: crate::lightning::util::events::HTLCDestination,
960 use lightning::util::events::Event as EventImport;
961 pub(crate) type nativeEvent = EventImport;
965 pub(crate) fn to_native(&self) -> nativeEvent {
967 Event::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
968 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
969 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
970 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
971 let mut output_script_nonref = (*output_script).clone();
972 let mut user_channel_id_nonref = (*user_channel_id).clone();
973 nativeEvent::FundingGenerationReady {
974 temporary_channel_id: temporary_channel_id_nonref.data,
975 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
976 channel_value_satoshis: channel_value_satoshis_nonref,
977 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
978 user_channel_id: user_channel_id_nonref,
981 Event::PaymentReceived {ref payment_hash, ref amount_msat, ref purpose, } => {
982 let mut payment_hash_nonref = (*payment_hash).clone();
983 let mut amount_msat_nonref = (*amount_msat).clone();
984 let mut purpose_nonref = (*purpose).clone();
985 nativeEvent::PaymentReceived {
986 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
987 amount_msat: amount_msat_nonref,
988 purpose: purpose_nonref.into_native(),
991 Event::PaymentClaimed {ref payment_hash, ref amount_msat, ref purpose, } => {
992 let mut payment_hash_nonref = (*payment_hash).clone();
993 let mut amount_msat_nonref = (*amount_msat).clone();
994 let mut purpose_nonref = (*purpose).clone();
995 nativeEvent::PaymentClaimed {
996 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
997 amount_msat: amount_msat_nonref,
998 purpose: purpose_nonref.into_native(),
1001 Event::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1002 let mut payment_id_nonref = (*payment_id).clone();
1003 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1004 let mut payment_preimage_nonref = (*payment_preimage).clone();
1005 let mut payment_hash_nonref = (*payment_hash).clone();
1006 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
1007 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_some() { Some( { fee_paid_msat_nonref.take() }) } else { None };
1008 nativeEvent::PaymentSent {
1009 payment_id: local_payment_id_nonref,
1010 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
1011 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1012 fee_paid_msat: local_fee_paid_msat_nonref,
1015 Event::PaymentFailed {ref payment_id, ref payment_hash, } => {
1016 let mut payment_id_nonref = (*payment_id).clone();
1017 let mut payment_hash_nonref = (*payment_hash).clone();
1018 nativeEvent::PaymentFailed {
1019 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1020 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1023 Event::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1024 let mut payment_id_nonref = (*payment_id).clone();
1025 let mut payment_hash_nonref = (*payment_hash).clone();
1026 let mut local_payment_hash_nonref = if payment_hash_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash_nonref.data) }) };
1027 let mut path_nonref = (*path).clone();
1028 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()) } }); };
1029 nativeEvent::PaymentPathSuccessful {
1030 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1031 payment_hash: local_payment_hash_nonref,
1032 path: local_path_nonref,
1035 Event::PaymentPathFailed {ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, ref retry, } => {
1036 let mut payment_id_nonref = (*payment_id).clone();
1037 let mut local_payment_id_nonref = if payment_id_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data) }) };
1038 let mut payment_hash_nonref = (*payment_hash).clone();
1039 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
1040 let mut network_update_nonref = (*network_update).clone();
1041 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() }) } };
1042 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
1043 let mut path_nonref = (*path).clone();
1044 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()) } }); };
1045 let mut short_channel_id_nonref = (*short_channel_id).clone();
1046 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1047 let mut retry_nonref = (*retry).clone();
1048 let mut local_retry_nonref = if retry_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry_nonref.take_inner()) } }) };
1049 nativeEvent::PaymentPathFailed {
1050 payment_id: local_payment_id_nonref,
1051 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1052 rejected_by_dest: rejected_by_dest_nonref,
1053 network_update: local_network_update_nonref,
1054 all_paths_failed: all_paths_failed_nonref,
1055 path: local_path_nonref,
1056 short_channel_id: local_short_channel_id_nonref,
1057 retry: local_retry_nonref,
1060 Event::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1061 let mut payment_id_nonref = (*payment_id).clone();
1062 let mut payment_hash_nonref = (*payment_hash).clone();
1063 let mut path_nonref = (*path).clone();
1064 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()) } }); };
1065 nativeEvent::ProbeSuccessful {
1066 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1067 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1068 path: local_path_nonref,
1071 Event::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1072 let mut payment_id_nonref = (*payment_id).clone();
1073 let mut payment_hash_nonref = (*payment_hash).clone();
1074 let mut path_nonref = (*path).clone();
1075 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()) } }); };
1076 let mut short_channel_id_nonref = (*short_channel_id).clone();
1077 let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None };
1078 nativeEvent::ProbeFailed {
1079 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data),
1080 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
1081 path: local_path_nonref,
1082 short_channel_id: local_short_channel_id_nonref,
1085 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
1086 let mut time_forwardable_nonref = (*time_forwardable).clone();
1087 nativeEvent::PendingHTLCsForwardable {
1088 time_forwardable: core::time::Duration::from_secs(time_forwardable_nonref),
1091 Event::SpendableOutputs {ref outputs, } => {
1092 let mut outputs_nonref = (*outputs).clone();
1093 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
1094 nativeEvent::SpendableOutputs {
1095 outputs: local_outputs_nonref,
1098 Event::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, } => {
1099 let mut prev_channel_id_nonref = (*prev_channel_id).clone();
1100 let mut local_prev_channel_id_nonref = if prev_channel_id_nonref.data == [0; 32] { None } else { Some( { prev_channel_id_nonref.data }) };
1101 let mut next_channel_id_nonref = (*next_channel_id).clone();
1102 let mut local_next_channel_id_nonref = if next_channel_id_nonref.data == [0; 32] { None } else { Some( { next_channel_id_nonref.data }) };
1103 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
1104 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
1105 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
1106 nativeEvent::PaymentForwarded {
1107 prev_channel_id: local_prev_channel_id_nonref,
1108 next_channel_id: local_next_channel_id_nonref,
1109 fee_earned_msat: local_fee_earned_msat_nonref,
1110 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1113 Event::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
1114 let mut channel_id_nonref = (*channel_id).clone();
1115 let mut user_channel_id_nonref = (*user_channel_id).clone();
1116 let mut reason_nonref = (*reason).clone();
1117 nativeEvent::ChannelClosed {
1118 channel_id: channel_id_nonref.data,
1119 user_channel_id: user_channel_id_nonref,
1120 reason: reason_nonref.into_native(),
1123 Event::DiscardFunding {ref channel_id, ref transaction, } => {
1124 let mut channel_id_nonref = (*channel_id).clone();
1125 let mut transaction_nonref = (*transaction).clone();
1126 nativeEvent::DiscardFunding {
1127 channel_id: channel_id_nonref.data,
1128 transaction: transaction_nonref.into_bitcoin(),
1131 Event::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1132 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
1133 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
1134 let mut funding_satoshis_nonref = (*funding_satoshis).clone();
1135 let mut push_msat_nonref = (*push_msat).clone();
1136 let mut channel_type_nonref = (*channel_type).clone();
1137 nativeEvent::OpenChannelRequest {
1138 temporary_channel_id: temporary_channel_id_nonref.data,
1139 counterparty_node_id: counterparty_node_id_nonref.into_rust(),
1140 funding_satoshis: funding_satoshis_nonref,
1141 push_msat: push_msat_nonref,
1142 channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) },
1145 Event::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
1146 let mut prev_channel_id_nonref = (*prev_channel_id).clone();
1147 let mut failed_next_destination_nonref = (*failed_next_destination).clone();
1148 nativeEvent::HTLCHandlingFailed {
1149 prev_channel_id: prev_channel_id_nonref.data,
1150 failed_next_destination: failed_next_destination_nonref.into_native(),
1156 pub(crate) fn into_native(self) -> nativeEvent {
1158 Event::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1159 nativeEvent::FundingGenerationReady {
1160 temporary_channel_id: temporary_channel_id.data,
1161 counterparty_node_id: counterparty_node_id.into_rust(),
1162 channel_value_satoshis: channel_value_satoshis,
1163 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
1164 user_channel_id: user_channel_id,
1167 Event::PaymentReceived {mut payment_hash, mut amount_msat, mut purpose, } => {
1168 nativeEvent::PaymentReceived {
1169 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1170 amount_msat: amount_msat,
1171 purpose: purpose.into_native(),
1174 Event::PaymentClaimed {mut payment_hash, mut amount_msat, mut purpose, } => {
1175 nativeEvent::PaymentClaimed {
1176 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1177 amount_msat: amount_msat,
1178 purpose: purpose.into_native(),
1181 Event::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1182 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1183 let mut local_fee_paid_msat = if fee_paid_msat.is_some() { Some( { fee_paid_msat.take() }) } else { None };
1184 nativeEvent::PaymentSent {
1185 payment_id: local_payment_id,
1186 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
1187 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1188 fee_paid_msat: local_fee_paid_msat,
1191 Event::PaymentFailed {mut payment_id, mut payment_hash, } => {
1192 nativeEvent::PaymentFailed {
1193 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1194 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1197 Event::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1198 let mut local_payment_hash = if payment_hash.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentHash(payment_hash.data) }) };
1199 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1200 nativeEvent::PaymentPathSuccessful {
1201 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1202 payment_hash: local_payment_hash,
1206 Event::PaymentPathFailed {mut payment_id, mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, mut retry, } => {
1207 let mut local_payment_id = if payment_id.data == [0; 32] { None } else { Some( { ::lightning::ln::channelmanager::PaymentId(payment_id.data) }) };
1208 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() }) } };
1209 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1210 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1211 let mut local_retry = if retry.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(retry.take_inner()) } }) };
1212 nativeEvent::PaymentPathFailed {
1213 payment_id: local_payment_id,
1214 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1215 rejected_by_dest: rejected_by_dest,
1216 network_update: local_network_update,
1217 all_paths_failed: all_paths_failed,
1219 short_channel_id: local_short_channel_id,
1223 Event::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1224 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1225 nativeEvent::ProbeSuccessful {
1226 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1227 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1231 Event::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
1232 let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1233 let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None };
1234 nativeEvent::ProbeFailed {
1235 payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data),
1236 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
1238 short_channel_id: local_short_channel_id,
1241 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
1242 nativeEvent::PendingHTLCsForwardable {
1243 time_forwardable: core::time::Duration::from_secs(time_forwardable),
1246 Event::SpendableOutputs {mut outputs, } => {
1247 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
1248 nativeEvent::SpendableOutputs {
1249 outputs: local_outputs,
1252 Event::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1253 let mut local_prev_channel_id = if prev_channel_id.data == [0; 32] { None } else { Some( { prev_channel_id.data }) };
1254 let mut local_next_channel_id = if next_channel_id.data == [0; 32] { None } else { Some( { next_channel_id.data }) };
1255 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
1256 nativeEvent::PaymentForwarded {
1257 prev_channel_id: local_prev_channel_id,
1258 next_channel_id: local_next_channel_id,
1259 fee_earned_msat: local_fee_earned_msat,
1260 claim_from_onchain_tx: claim_from_onchain_tx,
1263 Event::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1264 nativeEvent::ChannelClosed {
1265 channel_id: channel_id.data,
1266 user_channel_id: user_channel_id,
1267 reason: reason.into_native(),
1270 Event::DiscardFunding {mut channel_id, mut transaction, } => {
1271 nativeEvent::DiscardFunding {
1272 channel_id: channel_id.data,
1273 transaction: transaction.into_bitcoin(),
1276 Event::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1277 nativeEvent::OpenChannelRequest {
1278 temporary_channel_id: temporary_channel_id.data,
1279 counterparty_node_id: counterparty_node_id.into_rust(),
1280 funding_satoshis: funding_satoshis,
1281 push_msat: push_msat,
1282 channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) },
1285 Event::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
1286 nativeEvent::HTLCHandlingFailed {
1287 prev_channel_id: prev_channel_id.data,
1288 failed_next_destination: failed_next_destination.into_native(),
1294 pub(crate) fn from_native(native: &nativeEvent) -> Self {
1296 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
1297 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
1298 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
1299 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
1300 let mut output_script_nonref = (*output_script).clone();
1301 let mut user_channel_id_nonref = (*user_channel_id).clone();
1302 Event::FundingGenerationReady {
1303 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1304 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1305 channel_value_satoshis: channel_value_satoshis_nonref,
1306 output_script: output_script_nonref.into_bytes().into(),
1307 user_channel_id: user_channel_id_nonref,
1310 nativeEvent::PaymentReceived {ref payment_hash, ref amount_msat, ref purpose, } => {
1311 let mut payment_hash_nonref = (*payment_hash).clone();
1312 let mut amount_msat_nonref = (*amount_msat).clone();
1313 let mut purpose_nonref = (*purpose).clone();
1314 Event::PaymentReceived {
1315 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1316 amount_msat: amount_msat_nonref,
1317 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
1320 nativeEvent::PaymentClaimed {ref payment_hash, ref amount_msat, ref purpose, } => {
1321 let mut payment_hash_nonref = (*payment_hash).clone();
1322 let mut amount_msat_nonref = (*amount_msat).clone();
1323 let mut purpose_nonref = (*purpose).clone();
1324 Event::PaymentClaimed {
1325 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1326 amount_msat: amount_msat_nonref,
1327 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
1330 nativeEvent::PaymentSent {ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat, } => {
1331 let mut payment_id_nonref = (*payment_id).clone();
1332 let mut local_payment_id_nonref = if payment_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_id_nonref.unwrap()).0 } } };
1333 let mut payment_preimage_nonref = (*payment_preimage).clone();
1334 let mut payment_hash_nonref = (*payment_hash).clone();
1335 let mut fee_paid_msat_nonref = (*fee_paid_msat).clone();
1336 let mut local_fee_paid_msat_nonref = if fee_paid_msat_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_paid_msat_nonref.unwrap() }) };
1337 Event::PaymentSent {
1338 payment_id: local_payment_id_nonref,
1339 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
1340 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1341 fee_paid_msat: local_fee_paid_msat_nonref,
1344 nativeEvent::PaymentFailed {ref payment_id, ref payment_hash, } => {
1345 let mut payment_id_nonref = (*payment_id).clone();
1346 let mut payment_hash_nonref = (*payment_hash).clone();
1347 Event::PaymentFailed {
1348 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1349 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1352 nativeEvent::PaymentPathSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1353 let mut payment_id_nonref = (*payment_id).clone();
1354 let mut payment_hash_nonref = (*payment_hash).clone();
1355 let mut local_payment_hash_nonref = if payment_hash_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_hash_nonref.unwrap()).0 } } };
1356 let mut path_nonref = (*path).clone();
1357 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 } }); };
1358 Event::PaymentPathSuccessful {
1359 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1360 payment_hash: local_payment_hash_nonref,
1361 path: local_path_nonref.into(),
1364 nativeEvent::PaymentPathFailed {ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, ref retry, } => {
1365 let mut payment_id_nonref = (*payment_id).clone();
1366 let mut local_payment_id_nonref = if payment_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_id_nonref.unwrap()).0 } } };
1367 let mut payment_hash_nonref = (*payment_hash).clone();
1368 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
1369 let mut network_update_nonref = (*network_update).clone();
1370 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::gossip::NetworkUpdate::native_into(network_update_nonref.unwrap()) }) };
1371 let mut all_paths_failed_nonref = (*all_paths_failed).clone();
1372 let mut path_nonref = (*path).clone();
1373 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 } }); };
1374 let mut short_channel_id_nonref = (*short_channel_id).clone();
1375 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() }) };
1376 let mut retry_nonref = (*retry).clone();
1377 let mut local_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if retry_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((retry_nonref.unwrap())) } }, is_owned: true };
1378 Event::PaymentPathFailed {
1379 payment_id: local_payment_id_nonref,
1380 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1381 rejected_by_dest: rejected_by_dest_nonref,
1382 network_update: local_network_update_nonref,
1383 all_paths_failed: all_paths_failed_nonref,
1384 path: local_path_nonref.into(),
1385 short_channel_id: local_short_channel_id_nonref,
1386 retry: local_retry_nonref,
1389 nativeEvent::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => {
1390 let mut payment_id_nonref = (*payment_id).clone();
1391 let mut payment_hash_nonref = (*payment_hash).clone();
1392 let mut path_nonref = (*path).clone();
1393 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 } }); };
1394 Event::ProbeSuccessful {
1395 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1396 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1397 path: local_path_nonref.into(),
1400 nativeEvent::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => {
1401 let mut payment_id_nonref = (*payment_id).clone();
1402 let mut payment_hash_nonref = (*payment_hash).clone();
1403 let mut path_nonref = (*path).clone();
1404 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 } }); };
1405 let mut short_channel_id_nonref = (*short_channel_id).clone();
1406 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() }) };
1407 Event::ProbeFailed {
1408 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 },
1409 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
1410 path: local_path_nonref.into(),
1411 short_channel_id: local_short_channel_id_nonref,
1414 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
1415 let mut time_forwardable_nonref = (*time_forwardable).clone();
1416 Event::PendingHTLCsForwardable {
1417 time_forwardable: time_forwardable_nonref.as_secs(),
1420 nativeEvent::SpendableOutputs {ref outputs, } => {
1421 let mut outputs_nonref = (*outputs).clone();
1422 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) }); };
1423 Event::SpendableOutputs {
1424 outputs: local_outputs_nonref.into(),
1427 nativeEvent::PaymentForwarded {ref prev_channel_id, ref next_channel_id, ref fee_earned_msat, ref claim_from_onchain_tx, } => {
1428 let mut prev_channel_id_nonref = (*prev_channel_id).clone();
1429 let mut local_prev_channel_id_nonref = if prev_channel_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (prev_channel_id_nonref.unwrap()) } } };
1430 let mut next_channel_id_nonref = (*next_channel_id).clone();
1431 let mut local_next_channel_id_nonref = if next_channel_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (next_channel_id_nonref.unwrap()) } } };
1432 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
1433 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() }) };
1434 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
1435 Event::PaymentForwarded {
1436 prev_channel_id: local_prev_channel_id_nonref,
1437 next_channel_id: local_next_channel_id_nonref,
1438 fee_earned_msat: local_fee_earned_msat_nonref,
1439 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
1442 nativeEvent::ChannelClosed {ref channel_id, ref user_channel_id, ref reason, } => {
1443 let mut channel_id_nonref = (*channel_id).clone();
1444 let mut user_channel_id_nonref = (*user_channel_id).clone();
1445 let mut reason_nonref = (*reason).clone();
1446 Event::ChannelClosed {
1447 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1448 user_channel_id: user_channel_id_nonref,
1449 reason: crate::lightning::util::events::ClosureReason::native_into(reason_nonref),
1452 nativeEvent::DiscardFunding {ref channel_id, ref transaction, } => {
1453 let mut channel_id_nonref = (*channel_id).clone();
1454 let mut transaction_nonref = (*transaction).clone();
1455 Event::DiscardFunding {
1456 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref },
1457 transaction: crate::c_types::Transaction::from_bitcoin(&transaction_nonref),
1460 nativeEvent::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, ref channel_type, } => {
1461 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
1462 let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
1463 let mut funding_satoshis_nonref = (*funding_satoshis).clone();
1464 let mut push_msat_nonref = (*push_msat).clone();
1465 let mut channel_type_nonref = (*channel_type).clone();
1466 Event::OpenChannelRequest {
1467 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
1468 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
1469 funding_satoshis: funding_satoshis_nonref,
1470 push_msat: push_msat_nonref,
1471 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true },
1474 nativeEvent::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => {
1475 let mut prev_channel_id_nonref = (*prev_channel_id).clone();
1476 let mut failed_next_destination_nonref = (*failed_next_destination).clone();
1477 Event::HTLCHandlingFailed {
1478 prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id_nonref },
1479 failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination_nonref),
1485 pub(crate) fn native_into(native: nativeEvent) -> Self {
1487 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut counterparty_node_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
1488 Event::FundingGenerationReady {
1489 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1490 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1491 channel_value_satoshis: channel_value_satoshis,
1492 output_script: output_script.into_bytes().into(),
1493 user_channel_id: user_channel_id,
1496 nativeEvent::PaymentReceived {mut payment_hash, mut amount_msat, mut purpose, } => {
1497 Event::PaymentReceived {
1498 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1499 amount_msat: amount_msat,
1500 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
1503 nativeEvent::PaymentClaimed {mut payment_hash, mut amount_msat, mut purpose, } => {
1504 Event::PaymentClaimed {
1505 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1506 amount_msat: amount_msat,
1507 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
1510 nativeEvent::PaymentSent {mut payment_id, mut payment_preimage, mut payment_hash, mut fee_paid_msat, } => {
1511 let mut local_payment_id = if payment_id.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_id.unwrap()).0 } } };
1512 let mut local_fee_paid_msat = if fee_paid_msat.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { fee_paid_msat.unwrap() }) };
1513 Event::PaymentSent {
1514 payment_id: local_payment_id,
1515 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
1516 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1517 fee_paid_msat: local_fee_paid_msat,
1520 nativeEvent::PaymentFailed {mut payment_id, mut payment_hash, } => {
1521 Event::PaymentFailed {
1522 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1523 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1526 nativeEvent::PaymentPathSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1527 let mut local_payment_hash = if payment_hash.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_hash.unwrap()).0 } } };
1528 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 } }); };
1529 Event::PaymentPathSuccessful {
1530 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1531 payment_hash: local_payment_hash,
1532 path: local_path.into(),
1535 nativeEvent::PaymentPathFailed {mut payment_id, mut payment_hash, mut rejected_by_dest, mut network_update, mut all_paths_failed, mut path, mut short_channel_id, mut retry, } => {
1536 let mut local_payment_id = if payment_id.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_id.unwrap()).0 } } };
1537 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::gossip::NetworkUpdate::native_into(network_update.unwrap()) }) };
1538 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 } }); };
1539 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() }) };
1540 let mut local_retry = crate::lightning::routing::router::RouteParameters { inner: if retry.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((retry.unwrap())) } }, is_owned: true };
1541 Event::PaymentPathFailed {
1542 payment_id: local_payment_id,
1543 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1544 rejected_by_dest: rejected_by_dest,
1545 network_update: local_network_update,
1546 all_paths_failed: all_paths_failed,
1547 path: local_path.into(),
1548 short_channel_id: local_short_channel_id,
1552 nativeEvent::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => {
1553 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 } }); };
1554 Event::ProbeSuccessful {
1555 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1556 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1557 path: local_path.into(),
1560 nativeEvent::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => {
1561 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 } }); };
1562 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() }) };
1563 Event::ProbeFailed {
1564 payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 },
1565 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
1566 path: local_path.into(),
1567 short_channel_id: local_short_channel_id,
1570 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
1571 Event::PendingHTLCsForwardable {
1572 time_forwardable: time_forwardable.as_secs(),
1575 nativeEvent::SpendableOutputs {mut outputs, } => {
1576 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
1577 Event::SpendableOutputs {
1578 outputs: local_outputs.into(),
1581 nativeEvent::PaymentForwarded {mut prev_channel_id, mut next_channel_id, mut fee_earned_msat, mut claim_from_onchain_tx, } => {
1582 let mut local_prev_channel_id = if prev_channel_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (prev_channel_id.unwrap()) } } };
1583 let mut local_next_channel_id = if next_channel_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (next_channel_id.unwrap()) } } };
1584 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() }) };
1585 Event::PaymentForwarded {
1586 prev_channel_id: local_prev_channel_id,
1587 next_channel_id: local_next_channel_id,
1588 fee_earned_msat: local_fee_earned_msat,
1589 claim_from_onchain_tx: claim_from_onchain_tx,
1592 nativeEvent::ChannelClosed {mut channel_id, mut user_channel_id, mut reason, } => {
1593 Event::ChannelClosed {
1594 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1595 user_channel_id: user_channel_id,
1596 reason: crate::lightning::util::events::ClosureReason::native_into(reason),
1599 nativeEvent::DiscardFunding {mut channel_id, mut transaction, } => {
1600 Event::DiscardFunding {
1601 channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id },
1602 transaction: crate::c_types::Transaction::from_bitcoin(&transaction),
1605 nativeEvent::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, mut channel_type, } => {
1606 Event::OpenChannelRequest {
1607 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
1608 counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
1609 funding_satoshis: funding_satoshis,
1610 push_msat: push_msat,
1611 channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true },
1614 nativeEvent::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => {
1615 Event::HTLCHandlingFailed {
1616 prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id },
1617 failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination),
1623 /// Frees any resources used by the Event
1625 pub extern "C" fn Event_free(this_ptr: Event) { }
1626 /// Creates a copy of the Event
1628 pub extern "C" fn Event_clone(orig: &Event) -> Event {
1632 /// Utility method to constructs a new FundingGenerationReady-variant Event
1633 pub extern "C" fn Event_funding_generation_ready(temporary_channel_id: crate::c_types::ThirtyTwoBytes, counterparty_node_id: crate::c_types::PublicKey, channel_value_satoshis: u64, output_script: crate::c_types::derived::CVec_u8Z, user_channel_id: u64) -> Event {
1634 Event::FundingGenerationReady {
1635 temporary_channel_id,
1636 counterparty_node_id,
1637 channel_value_satoshis,
1643 /// Utility method to constructs a new PaymentReceived-variant Event
1644 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amount_msat: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
1645 Event::PaymentReceived {
1652 /// Utility method to constructs a new PaymentClaimed-variant Event
1653 pub extern "C" fn Event_payment_claimed(payment_hash: crate::c_types::ThirtyTwoBytes, amount_msat: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
1654 Event::PaymentClaimed {
1661 /// Utility method to constructs a new PaymentSent-variant Event
1662 pub extern "C" fn Event_payment_sent(payment_id: crate::c_types::ThirtyTwoBytes, payment_preimage: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, fee_paid_msat: crate::c_types::derived::COption_u64Z) -> Event {
1663 Event::PaymentSent {
1671 /// Utility method to constructs a new PaymentFailed-variant Event
1672 pub extern "C" fn Event_payment_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes) -> Event {
1673 Event::PaymentFailed {
1679 /// Utility method to constructs a new PaymentPathSuccessful-variant Event
1680 pub extern "C" fn Event_payment_path_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event {
1681 Event::PaymentPathSuccessful {
1688 /// Utility method to constructs a new PaymentPathFailed-variant Event
1689 pub extern "C" fn Event_payment_path_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, rejected_by_dest: bool, network_update: crate::c_types::derived::COption_NetworkUpdateZ, all_paths_failed: bool, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z, retry: crate::lightning::routing::router::RouteParameters) -> Event {
1690 Event::PaymentPathFailed {
1702 /// Utility method to constructs a new ProbeSuccessful-variant Event
1703 pub extern "C" fn Event_probe_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event {
1704 Event::ProbeSuccessful {
1711 /// Utility method to constructs a new ProbeFailed-variant Event
1712 pub extern "C" fn Event_probe_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z) -> Event {
1713 Event::ProbeFailed {
1721 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
1722 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
1723 Event::PendingHTLCsForwardable {
1728 /// Utility method to constructs a new SpendableOutputs-variant Event
1729 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
1730 Event::SpendableOutputs {
1735 /// Utility method to constructs a new PaymentForwarded-variant Event
1736 pub extern "C" fn Event_payment_forwarded(prev_channel_id: crate::c_types::ThirtyTwoBytes, next_channel_id: crate::c_types::ThirtyTwoBytes, fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
1737 Event::PaymentForwarded {
1741 claim_from_onchain_tx,
1745 /// Utility method to constructs a new ChannelClosed-variant Event
1746 pub extern "C" fn Event_channel_closed(channel_id: crate::c_types::ThirtyTwoBytes, user_channel_id: u64, reason: crate::lightning::util::events::ClosureReason) -> Event {
1747 Event::ChannelClosed {
1754 /// Utility method to constructs a new DiscardFunding-variant Event
1755 pub extern "C" fn Event_discard_funding(channel_id: crate::c_types::ThirtyTwoBytes, transaction: crate::c_types::Transaction) -> Event {
1756 Event::DiscardFunding {
1762 /// Utility method to constructs a new OpenChannelRequest-variant Event
1763 pub extern "C" fn Event_open_channel_request(temporary_channel_id: crate::c_types::ThirtyTwoBytes, counterparty_node_id: crate::c_types::PublicKey, funding_satoshis: u64, push_msat: u64, channel_type: crate::lightning::ln::features::ChannelTypeFeatures) -> Event {
1764 Event::OpenChannelRequest {
1765 temporary_channel_id,
1766 counterparty_node_id,
1773 /// Utility method to constructs a new HTLCHandlingFailed-variant Event
1774 pub extern "C" fn Event_htlchandling_failed(prev_channel_id: crate::c_types::ThirtyTwoBytes, failed_next_destination: crate::lightning::util::events::HTLCDestination) -> Event {
1775 Event::HTLCHandlingFailed {
1777 failed_next_destination,
1781 /// Serialize the Event object into a byte array which can be read by Event_read
1782 pub extern "C" fn Event_write(obj: &crate::lightning::util::events::Event) -> crate::c_types::derived::CVec_u8Z {
1783 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
1786 /// Read a Event from a byte array, created by Event_write
1787 pub extern "C" fn Event_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_EventZDecodeErrorZ {
1788 let res: Result<Option<lightning::util::events::Event>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
1789 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_EventZ::None } else { crate::c_types::derived::COption_EventZ::Some( { crate::lightning::util::events::Event::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1792 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
1793 /// broadcast to most peers).
1794 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
1798 pub enum MessageSendEvent {
1799 /// Used to indicate that we've accepted a channel open and should send the accept_channel
1800 /// message provided to the given peer.
1802 /// The node_id of the node which should receive this message
1803 node_id: crate::c_types::PublicKey,
1804 /// The message which should be sent.
1805 msg: crate::lightning::ln::msgs::AcceptChannel,
1807 /// Used to indicate that we've initiated a channel open and should send the open_channel
1808 /// message provided to the given peer.
1810 /// The node_id of the node which should receive this message
1811 node_id: crate::c_types::PublicKey,
1812 /// The message which should be sent.
1813 msg: crate::lightning::ln::msgs::OpenChannel,
1815 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
1816 SendFundingCreated {
1817 /// The node_id of the node which should receive this message
1818 node_id: crate::c_types::PublicKey,
1819 /// The message which should be sent.
1820 msg: crate::lightning::ln::msgs::FundingCreated,
1822 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
1824 /// The node_id of the node which should receive this message
1825 node_id: crate::c_types::PublicKey,
1826 /// The message which should be sent.
1827 msg: crate::lightning::ln::msgs::FundingSigned,
1829 /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
1831 /// The node_id of the node which should receive these message(s)
1832 node_id: crate::c_types::PublicKey,
1833 /// The channel_ready message which should be sent.
1834 msg: crate::lightning::ln::msgs::ChannelReady,
1836 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
1837 SendAnnouncementSignatures {
1838 /// The node_id of the node which should receive these message(s)
1839 node_id: crate::c_types::PublicKey,
1840 /// The announcement_signatures message which should be sent.
1841 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
1843 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
1844 /// message should be sent to the peer with the given node_id.
1846 /// The node_id of the node which should receive these message(s)
1847 node_id: crate::c_types::PublicKey,
1848 /// The update messages which should be sent. ALL messages in the struct should be sent!
1849 updates: crate::lightning::ln::msgs::CommitmentUpdate,
1851 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
1853 /// The node_id of the node which should receive this message
1854 node_id: crate::c_types::PublicKey,
1855 /// The message which should be sent.
1856 msg: crate::lightning::ln::msgs::RevokeAndACK,
1858 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
1860 /// The node_id of the node which should receive this message
1861 node_id: crate::c_types::PublicKey,
1862 /// The message which should be sent.
1863 msg: crate::lightning::ln::msgs::ClosingSigned,
1865 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
1867 /// The node_id of the node which should receive this message
1868 node_id: crate::c_types::PublicKey,
1869 /// The message which should be sent.
1870 msg: crate::lightning::ln::msgs::Shutdown,
1872 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
1873 SendChannelReestablish {
1874 /// The node_id of the node which should receive this message
1875 node_id: crate::c_types::PublicKey,
1876 /// The message which should be sent.
1877 msg: crate::lightning::ln::msgs::ChannelReestablish,
1879 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
1880 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
1882 /// Note that after doing so, you very likely (unless you did so very recently) want to call
1883 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
1884 /// This ensures that any nodes which see our channel_announcement also have a relevant
1885 /// node_announcement, including relevant feature flags which may be important for routing
1886 /// through or to us.
1887 BroadcastChannelAnnouncement {
1888 /// The channel_announcement which should be sent.
1889 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
1890 /// The followup channel_update which should be sent.
1891 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
1893 /// Used to indicate that a node_announcement should be broadcast to all peers.
1894 BroadcastNodeAnnouncement {
1895 /// The node_announcement which should be sent.
1896 msg: crate::lightning::ln::msgs::NodeAnnouncement,
1898 /// Used to indicate that a channel_update should be broadcast to all peers.
1899 BroadcastChannelUpdate {
1900 /// The channel_update which should be sent.
1901 msg: crate::lightning::ln::msgs::ChannelUpdate,
1903 /// Used to indicate that a channel_update should be sent to a single peer.
1904 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
1905 /// private channel and we shouldn't be informing all of our peers of channel parameters.
1907 /// The node_id of the node which should receive this message
1908 node_id: crate::c_types::PublicKey,
1909 /// The channel_update which should be sent.
1910 msg: crate::lightning::ln::msgs::ChannelUpdate,
1912 /// Broadcast an error downstream to be handled
1914 /// The node_id of the node which should receive this message
1915 node_id: crate::c_types::PublicKey,
1916 /// The action which should be taken.
1917 action: crate::lightning::ln::msgs::ErrorAction,
1919 /// Query a peer for channels with funding transaction UTXOs in a block range.
1920 SendChannelRangeQuery {
1921 /// The node_id of this message recipient
1922 node_id: crate::c_types::PublicKey,
1923 /// The query_channel_range which should be sent.
1924 msg: crate::lightning::ln::msgs::QueryChannelRange,
1926 /// Request routing gossip messages from a peer for a list of channels identified by
1927 /// their short_channel_ids.
1929 /// The node_id of this message recipient
1930 node_id: crate::c_types::PublicKey,
1931 /// The query_short_channel_ids which should be sent.
1932 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
1934 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
1935 /// emitted during processing of the query.
1936 SendReplyChannelRange {
1937 /// The node_id of this message recipient
1938 node_id: crate::c_types::PublicKey,
1939 /// The reply_channel_range which should be sent.
1940 msg: crate::lightning::ln::msgs::ReplyChannelRange,
1942 /// Sends a timestamp filter for inbound gossip. This should be sent on each new connection to
1943 /// enable receiving gossip messages from the peer.
1944 SendGossipTimestampFilter {
1945 /// The node_id of this message recipient
1946 node_id: crate::c_types::PublicKey,
1947 /// The gossip_timestamp_filter which should be sent.
1948 msg: crate::lightning::ln::msgs::GossipTimestampFilter,
1951 use lightning::util::events::MessageSendEvent as MessageSendEventImport;
1952 pub(crate) type nativeMessageSendEvent = MessageSendEventImport;
1954 impl MessageSendEvent {
1956 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
1958 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1959 let mut node_id_nonref = (*node_id).clone();
1960 let mut msg_nonref = (*msg).clone();
1961 nativeMessageSendEvent::SendAcceptChannel {
1962 node_id: node_id_nonref.into_rust(),
1963 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1966 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1967 let mut node_id_nonref = (*node_id).clone();
1968 let mut msg_nonref = (*msg).clone();
1969 nativeMessageSendEvent::SendOpenChannel {
1970 node_id: node_id_nonref.into_rust(),
1971 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1974 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1975 let mut node_id_nonref = (*node_id).clone();
1976 let mut msg_nonref = (*msg).clone();
1977 nativeMessageSendEvent::SendFundingCreated {
1978 node_id: node_id_nonref.into_rust(),
1979 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1982 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1983 let mut node_id_nonref = (*node_id).clone();
1984 let mut msg_nonref = (*msg).clone();
1985 nativeMessageSendEvent::SendFundingSigned {
1986 node_id: node_id_nonref.into_rust(),
1987 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1990 MessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
1991 let mut node_id_nonref = (*node_id).clone();
1992 let mut msg_nonref = (*msg).clone();
1993 nativeMessageSendEvent::SendChannelReady {
1994 node_id: node_id_nonref.into_rust(),
1995 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
1998 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1999 let mut node_id_nonref = (*node_id).clone();
2000 let mut msg_nonref = (*msg).clone();
2001 nativeMessageSendEvent::SendAnnouncementSignatures {
2002 node_id: node_id_nonref.into_rust(),
2003 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2006 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2007 let mut node_id_nonref = (*node_id).clone();
2008 let mut updates_nonref = (*updates).clone();
2009 nativeMessageSendEvent::UpdateHTLCs {
2010 node_id: node_id_nonref.into_rust(),
2011 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
2014 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2015 let mut node_id_nonref = (*node_id).clone();
2016 let mut msg_nonref = (*msg).clone();
2017 nativeMessageSendEvent::SendRevokeAndACK {
2018 node_id: node_id_nonref.into_rust(),
2019 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2022 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2023 let mut node_id_nonref = (*node_id).clone();
2024 let mut msg_nonref = (*msg).clone();
2025 nativeMessageSendEvent::SendClosingSigned {
2026 node_id: node_id_nonref.into_rust(),
2027 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2030 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
2031 let mut node_id_nonref = (*node_id).clone();
2032 let mut msg_nonref = (*msg).clone();
2033 nativeMessageSendEvent::SendShutdown {
2034 node_id: node_id_nonref.into_rust(),
2035 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2038 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
2039 let mut node_id_nonref = (*node_id).clone();
2040 let mut msg_nonref = (*msg).clone();
2041 nativeMessageSendEvent::SendChannelReestablish {
2042 node_id: node_id_nonref.into_rust(),
2043 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2046 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
2047 let mut msg_nonref = (*msg).clone();
2048 let mut update_msg_nonref = (*update_msg).clone();
2049 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2050 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2051 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
2054 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
2055 let mut msg_nonref = (*msg).clone();
2056 nativeMessageSendEvent::BroadcastNodeAnnouncement {
2057 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2060 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
2061 let mut msg_nonref = (*msg).clone();
2062 nativeMessageSendEvent::BroadcastChannelUpdate {
2063 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2066 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
2067 let mut node_id_nonref = (*node_id).clone();
2068 let mut msg_nonref = (*msg).clone();
2069 nativeMessageSendEvent::SendChannelUpdate {
2070 node_id: node_id_nonref.into_rust(),
2071 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2074 MessageSendEvent::HandleError {ref node_id, ref action, } => {
2075 let mut node_id_nonref = (*node_id).clone();
2076 let mut action_nonref = (*action).clone();
2077 nativeMessageSendEvent::HandleError {
2078 node_id: node_id_nonref.into_rust(),
2079 action: action_nonref.into_native(),
2082 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
2083 let mut node_id_nonref = (*node_id).clone();
2084 let mut msg_nonref = (*msg).clone();
2085 nativeMessageSendEvent::SendChannelRangeQuery {
2086 node_id: node_id_nonref.into_rust(),
2087 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2090 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
2091 let mut node_id_nonref = (*node_id).clone();
2092 let mut msg_nonref = (*msg).clone();
2093 nativeMessageSendEvent::SendShortIdsQuery {
2094 node_id: node_id_nonref.into_rust(),
2095 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2098 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
2099 let mut node_id_nonref = (*node_id).clone();
2100 let mut msg_nonref = (*msg).clone();
2101 nativeMessageSendEvent::SendReplyChannelRange {
2102 node_id: node_id_nonref.into_rust(),
2103 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2106 MessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
2107 let mut node_id_nonref = (*node_id).clone();
2108 let mut msg_nonref = (*msg).clone();
2109 nativeMessageSendEvent::SendGossipTimestampFilter {
2110 node_id: node_id_nonref.into_rust(),
2111 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
2117 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
2119 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
2120 nativeMessageSendEvent::SendAcceptChannel {
2121 node_id: node_id.into_rust(),
2122 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2125 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
2126 nativeMessageSendEvent::SendOpenChannel {
2127 node_id: node_id.into_rust(),
2128 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2131 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
2132 nativeMessageSendEvent::SendFundingCreated {
2133 node_id: node_id.into_rust(),
2134 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2137 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
2138 nativeMessageSendEvent::SendFundingSigned {
2139 node_id: node_id.into_rust(),
2140 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2143 MessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
2144 nativeMessageSendEvent::SendChannelReady {
2145 node_id: node_id.into_rust(),
2146 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2149 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
2150 nativeMessageSendEvent::SendAnnouncementSignatures {
2151 node_id: node_id.into_rust(),
2152 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2155 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
2156 nativeMessageSendEvent::UpdateHTLCs {
2157 node_id: node_id.into_rust(),
2158 updates: *unsafe { Box::from_raw(updates.take_inner()) },
2161 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
2162 nativeMessageSendEvent::SendRevokeAndACK {
2163 node_id: node_id.into_rust(),
2164 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2167 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
2168 nativeMessageSendEvent::SendClosingSigned {
2169 node_id: node_id.into_rust(),
2170 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2173 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
2174 nativeMessageSendEvent::SendShutdown {
2175 node_id: node_id.into_rust(),
2176 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2179 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
2180 nativeMessageSendEvent::SendChannelReestablish {
2181 node_id: node_id.into_rust(),
2182 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2185 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
2186 nativeMessageSendEvent::BroadcastChannelAnnouncement {
2187 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2188 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
2191 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
2192 nativeMessageSendEvent::BroadcastNodeAnnouncement {
2193 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2196 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
2197 nativeMessageSendEvent::BroadcastChannelUpdate {
2198 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2201 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
2202 nativeMessageSendEvent::SendChannelUpdate {
2203 node_id: node_id.into_rust(),
2204 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2207 MessageSendEvent::HandleError {mut node_id, mut action, } => {
2208 nativeMessageSendEvent::HandleError {
2209 node_id: node_id.into_rust(),
2210 action: action.into_native(),
2213 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
2214 nativeMessageSendEvent::SendChannelRangeQuery {
2215 node_id: node_id.into_rust(),
2216 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2219 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
2220 nativeMessageSendEvent::SendShortIdsQuery {
2221 node_id: node_id.into_rust(),
2222 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2225 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
2226 nativeMessageSendEvent::SendReplyChannelRange {
2227 node_id: node_id.into_rust(),
2228 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2231 MessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
2232 nativeMessageSendEvent::SendGossipTimestampFilter {
2233 node_id: node_id.into_rust(),
2234 msg: *unsafe { Box::from_raw(msg.take_inner()) },
2240 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
2242 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
2243 let mut node_id_nonref = (*node_id).clone();
2244 let mut msg_nonref = (*msg).clone();
2245 MessageSendEvent::SendAcceptChannel {
2246 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2247 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2250 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
2251 let mut node_id_nonref = (*node_id).clone();
2252 let mut msg_nonref = (*msg).clone();
2253 MessageSendEvent::SendOpenChannel {
2254 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2255 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2258 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
2259 let mut node_id_nonref = (*node_id).clone();
2260 let mut msg_nonref = (*msg).clone();
2261 MessageSendEvent::SendFundingCreated {
2262 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2263 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2266 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
2267 let mut node_id_nonref = (*node_id).clone();
2268 let mut msg_nonref = (*msg).clone();
2269 MessageSendEvent::SendFundingSigned {
2270 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2271 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2274 nativeMessageSendEvent::SendChannelReady {ref node_id, ref msg, } => {
2275 let mut node_id_nonref = (*node_id).clone();
2276 let mut msg_nonref = (*msg).clone();
2277 MessageSendEvent::SendChannelReady {
2278 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2279 msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2282 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
2283 let mut node_id_nonref = (*node_id).clone();
2284 let mut msg_nonref = (*msg).clone();
2285 MessageSendEvent::SendAnnouncementSignatures {
2286 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2287 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2290 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
2291 let mut node_id_nonref = (*node_id).clone();
2292 let mut updates_nonref = (*updates).clone();
2293 MessageSendEvent::UpdateHTLCs {
2294 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2295 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
2298 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
2299 let mut node_id_nonref = (*node_id).clone();
2300 let mut msg_nonref = (*msg).clone();
2301 MessageSendEvent::SendRevokeAndACK {
2302 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2303 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2306 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
2307 let mut node_id_nonref = (*node_id).clone();
2308 let mut msg_nonref = (*msg).clone();
2309 MessageSendEvent::SendClosingSigned {
2310 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2311 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2314 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
2315 let mut node_id_nonref = (*node_id).clone();
2316 let mut msg_nonref = (*msg).clone();
2317 MessageSendEvent::SendShutdown {
2318 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2319 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2322 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
2323 let mut node_id_nonref = (*node_id).clone();
2324 let mut msg_nonref = (*msg).clone();
2325 MessageSendEvent::SendChannelReestablish {
2326 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2327 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2330 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
2331 let mut msg_nonref = (*msg).clone();
2332 let mut update_msg_nonref = (*update_msg).clone();
2333 MessageSendEvent::BroadcastChannelAnnouncement {
2334 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2335 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
2338 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
2339 let mut msg_nonref = (*msg).clone();
2340 MessageSendEvent::BroadcastNodeAnnouncement {
2341 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2344 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
2345 let mut msg_nonref = (*msg).clone();
2346 MessageSendEvent::BroadcastChannelUpdate {
2347 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2350 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
2351 let mut node_id_nonref = (*node_id).clone();
2352 let mut msg_nonref = (*msg).clone();
2353 MessageSendEvent::SendChannelUpdate {
2354 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2355 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2358 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
2359 let mut node_id_nonref = (*node_id).clone();
2360 let mut action_nonref = (*action).clone();
2361 MessageSendEvent::HandleError {
2362 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2363 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
2366 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
2367 let mut node_id_nonref = (*node_id).clone();
2368 let mut msg_nonref = (*msg).clone();
2369 MessageSendEvent::SendChannelRangeQuery {
2370 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2371 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2374 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
2375 let mut node_id_nonref = (*node_id).clone();
2376 let mut msg_nonref = (*msg).clone();
2377 MessageSendEvent::SendShortIdsQuery {
2378 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2379 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2382 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
2383 let mut node_id_nonref = (*node_id).clone();
2384 let mut msg_nonref = (*msg).clone();
2385 MessageSendEvent::SendReplyChannelRange {
2386 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2387 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2390 nativeMessageSendEvent::SendGossipTimestampFilter {ref node_id, ref msg, } => {
2391 let mut node_id_nonref = (*node_id).clone();
2392 let mut msg_nonref = (*msg).clone();
2393 MessageSendEvent::SendGossipTimestampFilter {
2394 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
2395 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
2401 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
2403 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
2404 MessageSendEvent::SendAcceptChannel {
2405 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2406 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
2409 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
2410 MessageSendEvent::SendOpenChannel {
2411 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2412 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
2415 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
2416 MessageSendEvent::SendFundingCreated {
2417 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2418 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
2421 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
2422 MessageSendEvent::SendFundingSigned {
2423 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2424 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
2427 nativeMessageSendEvent::SendChannelReady {mut node_id, mut msg, } => {
2428 MessageSendEvent::SendChannelReady {
2429 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2430 msg: crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(msg), is_owned: true },
2433 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
2434 MessageSendEvent::SendAnnouncementSignatures {
2435 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2436 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
2439 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
2440 MessageSendEvent::UpdateHTLCs {
2441 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2442 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
2445 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
2446 MessageSendEvent::SendRevokeAndACK {
2447 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2448 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
2451 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
2452 MessageSendEvent::SendClosingSigned {
2453 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2454 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
2457 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
2458 MessageSendEvent::SendShutdown {
2459 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2460 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
2463 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
2464 MessageSendEvent::SendChannelReestablish {
2465 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2466 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
2469 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
2470 MessageSendEvent::BroadcastChannelAnnouncement {
2471 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
2472 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
2475 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
2476 MessageSendEvent::BroadcastNodeAnnouncement {
2477 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
2480 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
2481 MessageSendEvent::BroadcastChannelUpdate {
2482 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
2485 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
2486 MessageSendEvent::SendChannelUpdate {
2487 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2488 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
2491 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
2492 MessageSendEvent::HandleError {
2493 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2494 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
2497 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
2498 MessageSendEvent::SendChannelRangeQuery {
2499 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2500 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
2503 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
2504 MessageSendEvent::SendShortIdsQuery {
2505 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2506 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
2509 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
2510 MessageSendEvent::SendReplyChannelRange {
2511 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2512 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
2515 nativeMessageSendEvent::SendGossipTimestampFilter {mut node_id, mut msg, } => {
2516 MessageSendEvent::SendGossipTimestampFilter {
2517 node_id: crate::c_types::PublicKey::from_rust(&node_id),
2518 msg: crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(msg), is_owned: true },
2524 /// Frees any resources used by the MessageSendEvent
2526 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
2527 /// Creates a copy of the MessageSendEvent
2529 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
2533 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
2534 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
2535 MessageSendEvent::SendAcceptChannel {
2541 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
2542 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
2543 MessageSendEvent::SendOpenChannel {
2549 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
2550 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
2551 MessageSendEvent::SendFundingCreated {
2557 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
2558 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
2559 MessageSendEvent::SendFundingSigned {
2565 /// Utility method to constructs a new SendChannelReady-variant MessageSendEvent
2566 pub extern "C" fn MessageSendEvent_send_channel_ready(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReady) -> MessageSendEvent {
2567 MessageSendEvent::SendChannelReady {
2573 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
2574 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
2575 MessageSendEvent::SendAnnouncementSignatures {
2581 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
2582 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
2583 MessageSendEvent::UpdateHTLCs {
2589 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
2590 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
2591 MessageSendEvent::SendRevokeAndACK {
2597 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
2598 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
2599 MessageSendEvent::SendClosingSigned {
2605 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
2606 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
2607 MessageSendEvent::SendShutdown {
2613 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
2614 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
2615 MessageSendEvent::SendChannelReestablish {
2621 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
2622 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2623 MessageSendEvent::BroadcastChannelAnnouncement {
2629 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
2630 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
2631 MessageSendEvent::BroadcastNodeAnnouncement {
2636 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
2637 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2638 MessageSendEvent::BroadcastChannelUpdate {
2643 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
2644 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
2645 MessageSendEvent::SendChannelUpdate {
2651 /// Utility method to constructs a new HandleError-variant MessageSendEvent
2652 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
2653 MessageSendEvent::HandleError {
2659 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
2660 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
2661 MessageSendEvent::SendChannelRangeQuery {
2667 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
2668 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
2669 MessageSendEvent::SendShortIdsQuery {
2675 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
2676 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
2677 MessageSendEvent::SendReplyChannelRange {
2683 /// Utility method to constructs a new SendGossipTimestampFilter-variant MessageSendEvent
2684 pub extern "C" fn MessageSendEvent_send_gossip_timestamp_filter(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::GossipTimestampFilter) -> MessageSendEvent {
2685 MessageSendEvent::SendGossipTimestampFilter {
2690 /// A trait indicating an object may generate message send events
2692 pub struct MessageSendEventsProvider {
2693 /// An opaque pointer which is passed to your function implementations as an argument.
2694 /// This has no meaning in the LDK, and can be NULL or any other value.
2695 pub this_arg: *mut c_void,
2696 /// Gets the list of pending events which were generated by previous actions, clearing the list
2699 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
2700 /// Frees any resources associated with this object given its this_arg pointer.
2701 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2702 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2704 unsafe impl Send for MessageSendEventsProvider {}
2705 unsafe impl Sync for MessageSendEventsProvider {}
2707 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
2708 MessageSendEventsProvider {
2709 this_arg: orig.this_arg,
2710 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
2711 free: Clone::clone(&orig.free),
2715 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
2716 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
2717 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
2718 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
2719 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
2724 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2725 // directly as a Deref trait in higher-level structs:
2726 impl core::ops::Deref for MessageSendEventsProvider {
2728 fn deref(&self) -> &Self {
2732 /// Calls the free function if one is set
2734 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
2735 impl Drop for MessageSendEventsProvider {
2736 fn drop(&mut self) {
2737 if let Some(f) = self.free {
2742 /// A trait indicating an object may generate events.
2744 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
2748 /// See [`process_pending_events`] for requirements around event processing.
2750 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
2751 /// event since the last invocation. The handler must either act upon the event immediately
2752 /// or preserve it for later handling.
2754 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
2755 /// consult the provider's documentation on the implication of processing events and how a handler
2756 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
2757 /// [`ChainMonitor::process_pending_events`]).
2759 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
2762 /// [`process_pending_events`]: Self::process_pending_events
2763 /// [`handle_event`]: EventHandler::handle_event
2764 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
2765 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
2767 pub struct EventsProvider {
2768 /// An opaque pointer which is passed to your function implementations as an argument.
2769 /// This has no meaning in the LDK, and can be NULL or any other value.
2770 pub this_arg: *mut c_void,
2771 /// Processes any events generated since the last call using the given event handler.
2773 /// Subsequent calls must only process new events. However, handlers must be capable of handling
2774 /// duplicate events across process restarts. This may occur if the provider was recovered from
2775 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
2776 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
2777 /// Frees any resources associated with this object given its this_arg pointer.
2778 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2779 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2781 unsafe impl Send for EventsProvider {}
2782 unsafe impl Sync for EventsProvider {}
2784 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
2786 this_arg: orig.this_arg,
2787 process_pending_events: Clone::clone(&orig.process_pending_events),
2788 free: Clone::clone(&orig.free),
2792 use lightning::util::events::EventsProvider as rustEventsProvider;
2793 /// Calls the free function if one is set
2795 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
2796 impl Drop for EventsProvider {
2797 fn drop(&mut self) {
2798 if let Some(f) = self.free {
2803 /// A trait implemented for objects handling events from [`EventsProvider`].
2805 pub struct EventHandler {
2806 /// An opaque pointer which is passed to your function implementations as an argument.
2807 /// This has no meaning in the LDK, and can be NULL or any other value.
2808 pub this_arg: *mut c_void,
2809 /// Handles the given [`Event`].
2811 /// See [`EventsProvider`] for details that must be considered when implementing this method.
2812 pub handle_event: extern "C" fn (this_arg: *const c_void, event: &crate::lightning::util::events::Event),
2813 /// Frees any resources associated with this object given its this_arg pointer.
2814 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
2815 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
2817 unsafe impl Send for EventHandler {}
2818 unsafe impl Sync for EventHandler {}
2820 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
2822 this_arg: orig.this_arg,
2823 handle_event: Clone::clone(&orig.handle_event),
2824 free: Clone::clone(&orig.free),
2828 use lightning::util::events::EventHandler as rustEventHandler;
2829 impl rustEventHandler for EventHandler {
2830 fn handle_event(&self, mut event: &lightning::util::events::Event) {
2831 (self.handle_event)(self.this_arg, &crate::lightning::util::events::Event::from_native(event))
2835 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
2836 // directly as a Deref trait in higher-level structs:
2837 impl core::ops::Deref for EventHandler {
2839 fn deref(&self) -> &Self {
2843 /// Calls the free function if one is set
2845 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
2846 impl Drop for EventHandler {
2847 fn drop(&mut self) {
2848 if let Some(f) = self.free {