1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Events are returned from various bits in the library which indicate some action must be taken
12 //! Because we don't have a built-in runtime, it's up to the client to call events at a time in the
13 //! future, as well as generate and broadcast funding transactions handle payment preimages and a
16 use std::str::FromStr;
18 use bitcoin::hashes::Hash;
19 use crate::c_types::*;
21 /// Some information provided on receipt of payment depends on whether the payment received is a
22 /// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
26 pub enum PaymentPurpose {
27 /// Information for receiving a payment that we generated an invoice for.
29 /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
30 /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
31 /// [`ChannelManager::claim_funds`].
33 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
34 /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
36 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
37 payment_preimage: crate::c_types::ThirtyTwoBytes,
38 /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
39 /// number of deanonymization attacks during the routing process.
40 /// It is provided here for your reference, however its accuracy is enforced directly by
41 /// [`ChannelManager`] using the values you previously provided to
42 /// [`ChannelManager::create_inbound_payment`] or
43 /// [`ChannelManager::create_inbound_payment_for_hash`].
45 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
46 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
47 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
48 payment_secret: crate::c_types::ThirtyTwoBytes,
49 /// This is the `user_payment_id` which was provided to
50 /// [`ChannelManager::create_inbound_payment_for_hash`] or
51 /// [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is
52 /// simply copied here. It may be used to correlate PaymentReceived events with invoice
53 /// metadata stored elsewhere.
55 /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
56 /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
59 /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
60 /// (the payee) providing a preimage.
61 SpontaneousPayment(crate::c_types::ThirtyTwoBytes),
63 use lightning::util::events::PaymentPurpose as nativePaymentPurpose;
66 pub(crate) fn to_native(&self) -> nativePaymentPurpose {
68 PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
69 let mut payment_preimage_nonref = (*payment_preimage).clone();
70 let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
71 let mut payment_secret_nonref = (*payment_secret).clone();
72 let mut user_payment_id_nonref = (*user_payment_id).clone();
73 nativePaymentPurpose::InvoicePayment {
74 payment_preimage: local_payment_preimage_nonref,
75 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
76 user_payment_id: user_payment_id_nonref,
79 PaymentPurpose::SpontaneousPayment (ref a, ) => {
80 let mut a_nonref = (*a).clone();
81 nativePaymentPurpose::SpontaneousPayment (
82 ::lightning::ln::PaymentPreimage(a_nonref.data),
88 pub(crate) fn into_native(self) -> nativePaymentPurpose {
90 PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
91 let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
92 nativePaymentPurpose::InvoicePayment {
93 payment_preimage: local_payment_preimage,
94 payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
95 user_payment_id: user_payment_id,
98 PaymentPurpose::SpontaneousPayment (mut a, ) => {
99 nativePaymentPurpose::SpontaneousPayment (
100 ::lightning::ln::PaymentPreimage(a.data),
106 pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
108 nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
109 let mut payment_preimage_nonref = (*payment_preimage).clone();
110 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 } } };
111 let mut payment_secret_nonref = (*payment_secret).clone();
112 let mut user_payment_id_nonref = (*user_payment_id).clone();
113 PaymentPurpose::InvoicePayment {
114 payment_preimage: local_payment_preimage_nonref,
115 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
116 user_payment_id: user_payment_id_nonref,
119 nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
120 let mut a_nonref = (*a).clone();
121 PaymentPurpose::SpontaneousPayment (
122 crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
128 pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
130 nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
131 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 } } };
132 PaymentPurpose::InvoicePayment {
133 payment_preimage: local_payment_preimage,
134 payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
135 user_payment_id: user_payment_id,
138 nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
139 PaymentPurpose::SpontaneousPayment (
140 crate::c_types::ThirtyTwoBytes { data: a.0 },
146 /// Frees any resources used by the PaymentPurpose
148 pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
149 /// Creates a copy of the PaymentPurpose
151 pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
155 /// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
156 pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes, user_payment_id: u64) -> PaymentPurpose {
157 PaymentPurpose::InvoicePayment {
164 /// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
165 pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
166 PaymentPurpose::SpontaneousPayment(a, )
168 /// An Event which you should probably take some action in response to.
170 /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use
171 /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never
172 /// written as it makes no sense to respond to it after reconnecting to peers).
177 /// Used to indicate that the client should generate a funding transaction with the given
178 /// parameters and then call ChannelManager::funding_transaction_generated.
179 /// Generated in ChannelManager message handling.
180 /// Note that *all inputs* in the funding transaction must spend SegWit outputs or your
181 /// counterparty can steal your funds!
182 FundingGenerationReady {
183 /// The random channel_id we picked which you'll need to pass into
184 /// ChannelManager::funding_transaction_generated.
185 temporary_channel_id: crate::c_types::ThirtyTwoBytes,
186 /// The value, in satoshis, that the output should have.
187 channel_value_satoshis: u64,
188 /// The script which should be used in the transaction output.
189 output_script: crate::c_types::derived::CVec_u8Z,
190 /// The value passed in to ChannelManager::create_channel
191 user_channel_id: u64,
193 /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to
194 /// ChannelManager::claim_funds to get it....
195 /// Note that if the preimage is not known or the amount paid is incorrect, you should call
196 /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid
197 /// network congestion.
198 /// The amount paid should be considered 'incorrect' when it is less than or more than twice
199 /// the amount expected.
200 /// If you fail to call either ChannelManager::claim_funds or
201 /// ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be
202 /// automatically failed.
204 /// The hash for which the preimage should be handed to the ChannelManager.
205 payment_hash: crate::c_types::ThirtyTwoBytes,
206 /// The value, in thousandths of a satoshi, that this payment is for. Note that you must
207 /// compare this to the expected value before accepting the payment (as otherwise you are
208 /// providing proof-of-payment for less than the value you expected!).
210 /// Information for claiming this received payment, based on whether the purpose of the
211 /// payment is to pay an invoice or to send a spontaneous payment.
212 purpose: crate::lightning::util::events::PaymentPurpose,
214 /// Indicates an outbound payment we made succeeded (ie it made it all the way to its target
215 /// and we got back the payment preimage for it).
217 /// The preimage to the hash given to ChannelManager::send_payment.
218 /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
219 /// store it somehow!
220 payment_preimage: crate::c_types::ThirtyTwoBytes,
222 /// Indicates an outbound payment we made failed. Probably some intermediary node dropped
223 /// something. You may wish to retry with a different route.
225 /// The hash which was given to ChannelManager::send_payment.
226 payment_hash: crate::c_types::ThirtyTwoBytes,
227 /// Indicates the payment was rejected for some reason by the recipient. This implies that
228 /// the payment has failed, not just the route in question. If this is not set, you may
229 /// retry the payment via a different route.
230 rejected_by_dest: bool,
232 /// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
233 /// time in the future.
234 PendingHTLCsForwardable {
235 /// The minimum amount of time that should be waited prior to calling
236 /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
237 /// you should wait a random amount of time in roughly the range (now + time_forwardable,
238 /// now + 5*time_forwardable).
239 time_forwardable: u64,
241 /// Used to indicate that an output which you should know how to spend was confirmed on chain
242 /// and is now spendable.
243 /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
244 /// counterparty spending them due to some kind of timeout. Thus, you need to store them
245 /// somewhere and spend them when you create on-chain transactions.
247 /// The outputs which you should store as spendable by you.
248 outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ,
250 /// This event is generated when a payment has been successfully forwarded through us and a
251 /// forwarding fee earned.
253 /// The fee, in milli-satoshis, which was earned as a result of the payment.
255 /// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC
256 /// was pending, the amount the next hop claimed will have been rounded down to the nearest
257 /// whole satoshi. Thus, the fee calculated here may be higher than expected as we still
258 /// claimed the full value in millisatoshis from the source. In this case,
259 /// `claim_from_onchain_tx` will be set.
261 /// If the channel which sent us the payment has been force-closed, we will claim the funds
262 /// via an on-chain transaction. In that case we do not yet know the on-chain transaction
263 /// fees which we will spend and will instead set this to `None`. It is possible duplicate
264 /// `PaymentForwarded` events are generated for the same payment iff `fee_earned_msat` is
266 fee_earned_msat: crate::c_types::derived::COption_u64Z,
267 /// If this is `true`, the forwarded HTLC was claimed by our counterparty via an on-chain
269 claim_from_onchain_tx: bool,
272 use lightning::util::events::Event as nativeEvent;
275 pub(crate) fn to_native(&self) -> nativeEvent {
277 Event::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
278 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
279 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
280 let mut output_script_nonref = (*output_script).clone();
281 let mut user_channel_id_nonref = (*user_channel_id).clone();
282 nativeEvent::FundingGenerationReady {
283 temporary_channel_id: temporary_channel_id_nonref.data,
284 channel_value_satoshis: channel_value_satoshis_nonref,
285 output_script: ::bitcoin::blockdata::script::Script::from(output_script_nonref.into_rust()),
286 user_channel_id: user_channel_id_nonref,
289 Event::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
290 let mut payment_hash_nonref = (*payment_hash).clone();
291 let mut amt_nonref = (*amt).clone();
292 let mut purpose_nonref = (*purpose).clone();
293 nativeEvent::PaymentReceived {
294 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
296 purpose: purpose_nonref.into_native(),
299 Event::PaymentSent {ref payment_preimage, } => {
300 let mut payment_preimage_nonref = (*payment_preimage).clone();
301 nativeEvent::PaymentSent {
302 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
305 Event::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
306 let mut payment_hash_nonref = (*payment_hash).clone();
307 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
308 nativeEvent::PaymentFailed {
309 payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
310 rejected_by_dest: rejected_by_dest_nonref,
313 Event::PendingHTLCsForwardable {ref time_forwardable, } => {
314 let mut time_forwardable_nonref = (*time_forwardable).clone();
315 nativeEvent::PendingHTLCsForwardable {
316 time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
319 Event::SpendableOutputs {ref outputs, } => {
320 let mut outputs_nonref = (*outputs).clone();
321 let mut local_outputs_nonref = Vec::new(); for mut item in outputs_nonref.into_rust().drain(..) { local_outputs_nonref.push( { item.into_native() }); };
322 nativeEvent::SpendableOutputs {
323 outputs: local_outputs_nonref,
326 Event::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
327 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
328 let mut local_fee_earned_msat_nonref = if fee_earned_msat_nonref.is_some() { Some( { fee_earned_msat_nonref.take() }) } else { None };
329 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
330 nativeEvent::PaymentForwarded {
331 fee_earned_msat: local_fee_earned_msat_nonref,
332 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
338 pub(crate) fn into_native(self) -> nativeEvent {
340 Event::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
341 nativeEvent::FundingGenerationReady {
342 temporary_channel_id: temporary_channel_id.data,
343 channel_value_satoshis: channel_value_satoshis,
344 output_script: ::bitcoin::blockdata::script::Script::from(output_script.into_rust()),
345 user_channel_id: user_channel_id,
348 Event::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
349 nativeEvent::PaymentReceived {
350 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
352 purpose: purpose.into_native(),
355 Event::PaymentSent {mut payment_preimage, } => {
356 nativeEvent::PaymentSent {
357 payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
360 Event::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
361 nativeEvent::PaymentFailed {
362 payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
363 rejected_by_dest: rejected_by_dest,
366 Event::PendingHTLCsForwardable {mut time_forwardable, } => {
367 nativeEvent::PendingHTLCsForwardable {
368 time_forwardable: std::time::Duration::from_secs(time_forwardable),
371 Event::SpendableOutputs {mut outputs, } => {
372 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_native() }); };
373 nativeEvent::SpendableOutputs {
374 outputs: local_outputs,
377 Event::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
378 let mut local_fee_earned_msat = if fee_earned_msat.is_some() { Some( { fee_earned_msat.take() }) } else { None };
379 nativeEvent::PaymentForwarded {
380 fee_earned_msat: local_fee_earned_msat,
381 claim_from_onchain_tx: claim_from_onchain_tx,
387 pub(crate) fn from_native(native: &nativeEvent) -> Self {
389 nativeEvent::FundingGenerationReady {ref temporary_channel_id, ref channel_value_satoshis, ref output_script, ref user_channel_id, } => {
390 let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
391 let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone();
392 let mut output_script_nonref = (*output_script).clone();
393 let mut user_channel_id_nonref = (*user_channel_id).clone();
394 Event::FundingGenerationReady {
395 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
396 channel_value_satoshis: channel_value_satoshis_nonref,
397 output_script: output_script_nonref.into_bytes().into(),
398 user_channel_id: user_channel_id_nonref,
401 nativeEvent::PaymentReceived {ref payment_hash, ref amt, ref purpose, } => {
402 let mut payment_hash_nonref = (*payment_hash).clone();
403 let mut amt_nonref = (*amt).clone();
404 let mut purpose_nonref = (*purpose).clone();
405 Event::PaymentReceived {
406 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
408 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose_nonref),
411 nativeEvent::PaymentSent {ref payment_preimage, } => {
412 let mut payment_preimage_nonref = (*payment_preimage).clone();
414 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
417 nativeEvent::PaymentFailed {ref payment_hash, ref rejected_by_dest, } => {
418 let mut payment_hash_nonref = (*payment_hash).clone();
419 let mut rejected_by_dest_nonref = (*rejected_by_dest).clone();
420 Event::PaymentFailed {
421 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
422 rejected_by_dest: rejected_by_dest_nonref,
425 nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => {
426 let mut time_forwardable_nonref = (*time_forwardable).clone();
427 Event::PendingHTLCsForwardable {
428 time_forwardable: time_forwardable_nonref.as_secs(),
431 nativeEvent::SpendableOutputs {ref outputs, } => {
432 let mut outputs_nonref = (*outputs).clone();
433 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) }); };
434 Event::SpendableOutputs {
435 outputs: local_outputs_nonref.into(),
438 nativeEvent::PaymentForwarded {ref fee_earned_msat, ref claim_from_onchain_tx, } => {
439 let mut fee_earned_msat_nonref = (*fee_earned_msat).clone();
440 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()) } };
441 let mut claim_from_onchain_tx_nonref = (*claim_from_onchain_tx).clone();
442 Event::PaymentForwarded {
443 fee_earned_msat: local_fee_earned_msat_nonref,
444 claim_from_onchain_tx: claim_from_onchain_tx_nonref,
450 pub(crate) fn native_into(native: nativeEvent) -> Self {
452 nativeEvent::FundingGenerationReady {mut temporary_channel_id, mut channel_value_satoshis, mut output_script, mut user_channel_id, } => {
453 Event::FundingGenerationReady {
454 temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
455 channel_value_satoshis: channel_value_satoshis,
456 output_script: output_script.into_bytes().into(),
457 user_channel_id: user_channel_id,
460 nativeEvent::PaymentReceived {mut payment_hash, mut amt, mut purpose, } => {
461 Event::PaymentReceived {
462 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
464 purpose: crate::lightning::util::events::PaymentPurpose::native_into(purpose),
467 nativeEvent::PaymentSent {mut payment_preimage, } => {
469 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
472 nativeEvent::PaymentFailed {mut payment_hash, mut rejected_by_dest, } => {
473 Event::PaymentFailed {
474 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
475 rejected_by_dest: rejected_by_dest,
478 nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => {
479 Event::PendingHTLCsForwardable {
480 time_forwardable: time_forwardable.as_secs(),
483 nativeEvent::SpendableOutputs {mut outputs, } => {
484 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(item) }); };
485 Event::SpendableOutputs {
486 outputs: local_outputs.into(),
489 nativeEvent::PaymentForwarded {mut fee_earned_msat, mut claim_from_onchain_tx, } => {
490 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()) } };
491 Event::PaymentForwarded {
492 fee_earned_msat: local_fee_earned_msat,
493 claim_from_onchain_tx: claim_from_onchain_tx,
499 /// Frees any resources used by the Event
501 pub extern "C" fn Event_free(this_ptr: Event) { }
502 /// Creates a copy of the Event
504 pub extern "C" fn Event_clone(orig: &Event) -> Event {
508 /// Utility method to constructs a new FundingGenerationReady-variant Event
509 pub extern "C" fn Event_funding_generation_ready(temporary_channel_id: crate::c_types::ThirtyTwoBytes, channel_value_satoshis: u64, output_script: crate::c_types::derived::CVec_u8Z, user_channel_id: u64) -> Event {
510 Event::FundingGenerationReady {
511 temporary_channel_id,
512 channel_value_satoshis,
518 /// Utility method to constructs a new PaymentReceived-variant Event
519 pub extern "C" fn Event_payment_received(payment_hash: crate::c_types::ThirtyTwoBytes, amt: u64, purpose: crate::lightning::util::events::PaymentPurpose) -> Event {
520 Event::PaymentReceived {
527 /// Utility method to constructs a new PaymentSent-variant Event
528 pub extern "C" fn Event_payment_sent(payment_preimage: crate::c_types::ThirtyTwoBytes) -> Event {
534 /// Utility method to constructs a new PaymentFailed-variant Event
535 pub extern "C" fn Event_payment_failed(payment_hash: crate::c_types::ThirtyTwoBytes, rejected_by_dest: bool) -> Event {
536 Event::PaymentFailed {
542 /// Utility method to constructs a new PendingHTLCsForwardable-variant Event
543 pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event {
544 Event::PendingHTLCsForwardable {
549 /// Utility method to constructs a new SpendableOutputs-variant Event
550 pub extern "C" fn Event_spendable_outputs(outputs: crate::c_types::derived::CVec_SpendableOutputDescriptorZ) -> Event {
551 Event::SpendableOutputs {
556 /// Utility method to constructs a new PaymentForwarded-variant Event
557 pub extern "C" fn Event_payment_forwarded(fee_earned_msat: crate::c_types::derived::COption_u64Z, claim_from_onchain_tx: bool) -> Event {
558 Event::PaymentForwarded {
560 claim_from_onchain_tx,
564 /// Serialize the Event object into a byte array which can be read by Event_read
565 pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
566 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
568 /// An event generated by ChannelManager which indicates a message should be sent to a peer (or
569 /// broadcast to most peers).
570 /// These events are handled by PeerManager::process_events if you are using a PeerManager.
574 pub enum MessageSendEvent {
575 /// Used to indicate that we've accepted a channel open and should send the accept_channel
576 /// message provided to the given peer.
578 /// The node_id of the node which should receive this message
579 node_id: crate::c_types::PublicKey,
580 /// The message which should be sent.
581 msg: crate::lightning::ln::msgs::AcceptChannel,
583 /// Used to indicate that we've initiated a channel open and should send the open_channel
584 /// message provided to the given peer.
586 /// The node_id of the node which should receive this message
587 node_id: crate::c_types::PublicKey,
588 /// The message which should be sent.
589 msg: crate::lightning::ln::msgs::OpenChannel,
591 /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
593 /// The node_id of the node which should receive this message
594 node_id: crate::c_types::PublicKey,
595 /// The message which should be sent.
596 msg: crate::lightning::ln::msgs::FundingCreated,
598 /// Used to indicate that a funding_signed message should be sent to the peer with the given node_id.
600 /// The node_id of the node which should receive this message
601 node_id: crate::c_types::PublicKey,
602 /// The message which should be sent.
603 msg: crate::lightning::ln::msgs::FundingSigned,
605 /// Used to indicate that a funding_locked message should be sent to the peer with the given node_id.
607 /// The node_id of the node which should receive these message(s)
608 node_id: crate::c_types::PublicKey,
609 /// The funding_locked message which should be sent.
610 msg: crate::lightning::ln::msgs::FundingLocked,
612 /// Used to indicate that an announcement_signatures message should be sent to the peer with the given node_id.
613 SendAnnouncementSignatures {
614 /// The node_id of the node which should receive these message(s)
615 node_id: crate::c_types::PublicKey,
616 /// The announcement_signatures message which should be sent.
617 msg: crate::lightning::ln::msgs::AnnouncementSignatures,
619 /// Used to indicate that a series of HTLC update messages, as well as a commitment_signed
620 /// message should be sent to the peer with the given node_id.
622 /// The node_id of the node which should receive these message(s)
623 node_id: crate::c_types::PublicKey,
624 /// The update messages which should be sent. ALL messages in the struct should be sent!
625 updates: crate::lightning::ln::msgs::CommitmentUpdate,
627 /// Used to indicate that a revoke_and_ack message should be sent to the peer with the given node_id.
629 /// The node_id of the node which should receive this message
630 node_id: crate::c_types::PublicKey,
631 /// The message which should be sent.
632 msg: crate::lightning::ln::msgs::RevokeAndACK,
634 /// Used to indicate that a closing_signed message should be sent to the peer with the given node_id.
636 /// The node_id of the node which should receive this message
637 node_id: crate::c_types::PublicKey,
638 /// The message which should be sent.
639 msg: crate::lightning::ln::msgs::ClosingSigned,
641 /// Used to indicate that a shutdown message should be sent to the peer with the given node_id.
643 /// The node_id of the node which should receive this message
644 node_id: crate::c_types::PublicKey,
645 /// The message which should be sent.
646 msg: crate::lightning::ln::msgs::Shutdown,
648 /// Used to indicate that a channel_reestablish message should be sent to the peer with the given node_id.
649 SendChannelReestablish {
650 /// The node_id of the node which should receive this message
651 node_id: crate::c_types::PublicKey,
652 /// The message which should be sent.
653 msg: crate::lightning::ln::msgs::ChannelReestablish,
655 /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
656 /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
658 /// Note that after doing so, you very likely (unless you did so very recently) want to call
659 /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
660 /// This ensures that any nodes which see our channel_announcement also have a relevant
661 /// node_announcement, including relevant feature flags which may be important for routing
662 /// through or to us.
663 BroadcastChannelAnnouncement {
664 /// The channel_announcement which should be sent.
665 msg: crate::lightning::ln::msgs::ChannelAnnouncement,
666 /// The followup channel_update which should be sent.
667 update_msg: crate::lightning::ln::msgs::ChannelUpdate,
669 /// Used to indicate that a node_announcement should be broadcast to all peers.
670 BroadcastNodeAnnouncement {
671 /// The node_announcement which should be sent.
672 msg: crate::lightning::ln::msgs::NodeAnnouncement,
674 /// Used to indicate that a channel_update should be broadcast to all peers.
675 BroadcastChannelUpdate {
676 /// The channel_update which should be sent.
677 msg: crate::lightning::ln::msgs::ChannelUpdate,
679 /// Used to indicate that a channel_update should be sent to a single peer.
680 /// In contrast to [`Self::BroadcastChannelUpdate`], this is used when the channel is a
681 /// private channel and we shouldn't be informing all of our peers of channel parameters.
683 /// The node_id of the node which should receive this message
684 node_id: crate::c_types::PublicKey,
685 /// The channel_update which should be sent.
686 msg: crate::lightning::ln::msgs::ChannelUpdate,
688 /// Broadcast an error downstream to be handled
690 /// The node_id of the node which should receive this message
691 node_id: crate::c_types::PublicKey,
692 /// The action which should be taken.
693 action: crate::lightning::ln::msgs::ErrorAction,
695 /// When a payment fails we may receive updates back from the hop where it failed. In such
696 /// cases this event is generated so that we can inform the network graph of this information.
697 PaymentFailureNetworkUpdate {
698 /// The channel/node update which should be sent to NetGraphMsgHandler
699 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate,
701 /// Query a peer for channels with funding transaction UTXOs in a block range.
702 SendChannelRangeQuery {
703 /// The node_id of this message recipient
704 node_id: crate::c_types::PublicKey,
705 /// The query_channel_range which should be sent.
706 msg: crate::lightning::ln::msgs::QueryChannelRange,
708 /// Request routing gossip messages from a peer for a list of channels identified by
709 /// their short_channel_ids.
711 /// The node_id of this message recipient
712 node_id: crate::c_types::PublicKey,
713 /// The query_short_channel_ids which should be sent.
714 msg: crate::lightning::ln::msgs::QueryShortChannelIds,
716 /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events
717 /// emitted during processing of the query.
718 SendReplyChannelRange {
719 /// The node_id of this message recipient
720 node_id: crate::c_types::PublicKey,
721 /// The reply_channel_range which should be sent.
722 msg: crate::lightning::ln::msgs::ReplyChannelRange,
725 use lightning::util::events::MessageSendEvent as nativeMessageSendEvent;
726 impl MessageSendEvent {
728 pub(crate) fn to_native(&self) -> nativeMessageSendEvent {
730 MessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
731 let mut node_id_nonref = (*node_id).clone();
732 let mut msg_nonref = (*msg).clone();
733 nativeMessageSendEvent::SendAcceptChannel {
734 node_id: node_id_nonref.into_rust(),
735 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
738 MessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
739 let mut node_id_nonref = (*node_id).clone();
740 let mut msg_nonref = (*msg).clone();
741 nativeMessageSendEvent::SendOpenChannel {
742 node_id: node_id_nonref.into_rust(),
743 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
746 MessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
747 let mut node_id_nonref = (*node_id).clone();
748 let mut msg_nonref = (*msg).clone();
749 nativeMessageSendEvent::SendFundingCreated {
750 node_id: node_id_nonref.into_rust(),
751 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
754 MessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
755 let mut node_id_nonref = (*node_id).clone();
756 let mut msg_nonref = (*msg).clone();
757 nativeMessageSendEvent::SendFundingSigned {
758 node_id: node_id_nonref.into_rust(),
759 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
762 MessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
763 let mut node_id_nonref = (*node_id).clone();
764 let mut msg_nonref = (*msg).clone();
765 nativeMessageSendEvent::SendFundingLocked {
766 node_id: node_id_nonref.into_rust(),
767 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
770 MessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
771 let mut node_id_nonref = (*node_id).clone();
772 let mut msg_nonref = (*msg).clone();
773 nativeMessageSendEvent::SendAnnouncementSignatures {
774 node_id: node_id_nonref.into_rust(),
775 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
778 MessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
779 let mut node_id_nonref = (*node_id).clone();
780 let mut updates_nonref = (*updates).clone();
781 nativeMessageSendEvent::UpdateHTLCs {
782 node_id: node_id_nonref.into_rust(),
783 updates: *unsafe { Box::from_raw(updates_nonref.take_inner()) },
786 MessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
787 let mut node_id_nonref = (*node_id).clone();
788 let mut msg_nonref = (*msg).clone();
789 nativeMessageSendEvent::SendRevokeAndACK {
790 node_id: node_id_nonref.into_rust(),
791 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
794 MessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
795 let mut node_id_nonref = (*node_id).clone();
796 let mut msg_nonref = (*msg).clone();
797 nativeMessageSendEvent::SendClosingSigned {
798 node_id: node_id_nonref.into_rust(),
799 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
802 MessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
803 let mut node_id_nonref = (*node_id).clone();
804 let mut msg_nonref = (*msg).clone();
805 nativeMessageSendEvent::SendShutdown {
806 node_id: node_id_nonref.into_rust(),
807 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
810 MessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
811 let mut node_id_nonref = (*node_id).clone();
812 let mut msg_nonref = (*msg).clone();
813 nativeMessageSendEvent::SendChannelReestablish {
814 node_id: node_id_nonref.into_rust(),
815 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
818 MessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
819 let mut msg_nonref = (*msg).clone();
820 let mut update_msg_nonref = (*update_msg).clone();
821 nativeMessageSendEvent::BroadcastChannelAnnouncement {
822 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
823 update_msg: *unsafe { Box::from_raw(update_msg_nonref.take_inner()) },
826 MessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
827 let mut msg_nonref = (*msg).clone();
828 nativeMessageSendEvent::BroadcastNodeAnnouncement {
829 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
832 MessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
833 let mut msg_nonref = (*msg).clone();
834 nativeMessageSendEvent::BroadcastChannelUpdate {
835 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
838 MessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
839 let mut node_id_nonref = (*node_id).clone();
840 let mut msg_nonref = (*msg).clone();
841 nativeMessageSendEvent::SendChannelUpdate {
842 node_id: node_id_nonref.into_rust(),
843 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
846 MessageSendEvent::HandleError {ref node_id, ref action, } => {
847 let mut node_id_nonref = (*node_id).clone();
848 let mut action_nonref = (*action).clone();
849 nativeMessageSendEvent::HandleError {
850 node_id: node_id_nonref.into_rust(),
851 action: action_nonref.into_native(),
854 MessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
855 let mut update_nonref = (*update).clone();
856 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
857 update: update_nonref.into_native(),
860 MessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
861 let mut node_id_nonref = (*node_id).clone();
862 let mut msg_nonref = (*msg).clone();
863 nativeMessageSendEvent::SendChannelRangeQuery {
864 node_id: node_id_nonref.into_rust(),
865 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
868 MessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
869 let mut node_id_nonref = (*node_id).clone();
870 let mut msg_nonref = (*msg).clone();
871 nativeMessageSendEvent::SendShortIdsQuery {
872 node_id: node_id_nonref.into_rust(),
873 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
876 MessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
877 let mut node_id_nonref = (*node_id).clone();
878 let mut msg_nonref = (*msg).clone();
879 nativeMessageSendEvent::SendReplyChannelRange {
880 node_id: node_id_nonref.into_rust(),
881 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
887 pub(crate) fn into_native(self) -> nativeMessageSendEvent {
889 MessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
890 nativeMessageSendEvent::SendAcceptChannel {
891 node_id: node_id.into_rust(),
892 msg: *unsafe { Box::from_raw(msg.take_inner()) },
895 MessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
896 nativeMessageSendEvent::SendOpenChannel {
897 node_id: node_id.into_rust(),
898 msg: *unsafe { Box::from_raw(msg.take_inner()) },
901 MessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
902 nativeMessageSendEvent::SendFundingCreated {
903 node_id: node_id.into_rust(),
904 msg: *unsafe { Box::from_raw(msg.take_inner()) },
907 MessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
908 nativeMessageSendEvent::SendFundingSigned {
909 node_id: node_id.into_rust(),
910 msg: *unsafe { Box::from_raw(msg.take_inner()) },
913 MessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
914 nativeMessageSendEvent::SendFundingLocked {
915 node_id: node_id.into_rust(),
916 msg: *unsafe { Box::from_raw(msg.take_inner()) },
919 MessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
920 nativeMessageSendEvent::SendAnnouncementSignatures {
921 node_id: node_id.into_rust(),
922 msg: *unsafe { Box::from_raw(msg.take_inner()) },
925 MessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
926 nativeMessageSendEvent::UpdateHTLCs {
927 node_id: node_id.into_rust(),
928 updates: *unsafe { Box::from_raw(updates.take_inner()) },
931 MessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
932 nativeMessageSendEvent::SendRevokeAndACK {
933 node_id: node_id.into_rust(),
934 msg: *unsafe { Box::from_raw(msg.take_inner()) },
937 MessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
938 nativeMessageSendEvent::SendClosingSigned {
939 node_id: node_id.into_rust(),
940 msg: *unsafe { Box::from_raw(msg.take_inner()) },
943 MessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
944 nativeMessageSendEvent::SendShutdown {
945 node_id: node_id.into_rust(),
946 msg: *unsafe { Box::from_raw(msg.take_inner()) },
949 MessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
950 nativeMessageSendEvent::SendChannelReestablish {
951 node_id: node_id.into_rust(),
952 msg: *unsafe { Box::from_raw(msg.take_inner()) },
955 MessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
956 nativeMessageSendEvent::BroadcastChannelAnnouncement {
957 msg: *unsafe { Box::from_raw(msg.take_inner()) },
958 update_msg: *unsafe { Box::from_raw(update_msg.take_inner()) },
961 MessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
962 nativeMessageSendEvent::BroadcastNodeAnnouncement {
963 msg: *unsafe { Box::from_raw(msg.take_inner()) },
966 MessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
967 nativeMessageSendEvent::BroadcastChannelUpdate {
968 msg: *unsafe { Box::from_raw(msg.take_inner()) },
971 MessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
972 nativeMessageSendEvent::SendChannelUpdate {
973 node_id: node_id.into_rust(),
974 msg: *unsafe { Box::from_raw(msg.take_inner()) },
977 MessageSendEvent::HandleError {mut node_id, mut action, } => {
978 nativeMessageSendEvent::HandleError {
979 node_id: node_id.into_rust(),
980 action: action.into_native(),
983 MessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
984 nativeMessageSendEvent::PaymentFailureNetworkUpdate {
985 update: update.into_native(),
988 MessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
989 nativeMessageSendEvent::SendChannelRangeQuery {
990 node_id: node_id.into_rust(),
991 msg: *unsafe { Box::from_raw(msg.take_inner()) },
994 MessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
995 nativeMessageSendEvent::SendShortIdsQuery {
996 node_id: node_id.into_rust(),
997 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1000 MessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1001 nativeMessageSendEvent::SendReplyChannelRange {
1002 node_id: node_id.into_rust(),
1003 msg: *unsafe { Box::from_raw(msg.take_inner()) },
1009 pub(crate) fn from_native(native: &nativeMessageSendEvent) -> Self {
1011 nativeMessageSendEvent::SendAcceptChannel {ref node_id, ref msg, } => {
1012 let mut node_id_nonref = (*node_id).clone();
1013 let mut msg_nonref = (*msg).clone();
1014 MessageSendEvent::SendAcceptChannel {
1015 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1016 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1019 nativeMessageSendEvent::SendOpenChannel {ref node_id, ref msg, } => {
1020 let mut node_id_nonref = (*node_id).clone();
1021 let mut msg_nonref = (*msg).clone();
1022 MessageSendEvent::SendOpenChannel {
1023 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1024 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1027 nativeMessageSendEvent::SendFundingCreated {ref node_id, ref msg, } => {
1028 let mut node_id_nonref = (*node_id).clone();
1029 let mut msg_nonref = (*msg).clone();
1030 MessageSendEvent::SendFundingCreated {
1031 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1032 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1035 nativeMessageSendEvent::SendFundingSigned {ref node_id, ref msg, } => {
1036 let mut node_id_nonref = (*node_id).clone();
1037 let mut msg_nonref = (*msg).clone();
1038 MessageSendEvent::SendFundingSigned {
1039 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1040 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1043 nativeMessageSendEvent::SendFundingLocked {ref node_id, ref msg, } => {
1044 let mut node_id_nonref = (*node_id).clone();
1045 let mut msg_nonref = (*msg).clone();
1046 MessageSendEvent::SendFundingLocked {
1047 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1048 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1051 nativeMessageSendEvent::SendAnnouncementSignatures {ref node_id, ref msg, } => {
1052 let mut node_id_nonref = (*node_id).clone();
1053 let mut msg_nonref = (*msg).clone();
1054 MessageSendEvent::SendAnnouncementSignatures {
1055 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1056 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1059 nativeMessageSendEvent::UpdateHTLCs {ref node_id, ref updates, } => {
1060 let mut node_id_nonref = (*node_id).clone();
1061 let mut updates_nonref = (*updates).clone();
1062 MessageSendEvent::UpdateHTLCs {
1063 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1064 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates_nonref), is_owned: true },
1067 nativeMessageSendEvent::SendRevokeAndACK {ref node_id, ref msg, } => {
1068 let mut node_id_nonref = (*node_id).clone();
1069 let mut msg_nonref = (*msg).clone();
1070 MessageSendEvent::SendRevokeAndACK {
1071 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1072 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1075 nativeMessageSendEvent::SendClosingSigned {ref node_id, ref msg, } => {
1076 let mut node_id_nonref = (*node_id).clone();
1077 let mut msg_nonref = (*msg).clone();
1078 MessageSendEvent::SendClosingSigned {
1079 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1080 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1083 nativeMessageSendEvent::SendShutdown {ref node_id, ref msg, } => {
1084 let mut node_id_nonref = (*node_id).clone();
1085 let mut msg_nonref = (*msg).clone();
1086 MessageSendEvent::SendShutdown {
1087 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1088 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1091 nativeMessageSendEvent::SendChannelReestablish {ref node_id, ref msg, } => {
1092 let mut node_id_nonref = (*node_id).clone();
1093 let mut msg_nonref = (*msg).clone();
1094 MessageSendEvent::SendChannelReestablish {
1095 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1096 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1099 nativeMessageSendEvent::BroadcastChannelAnnouncement {ref msg, ref update_msg, } => {
1100 let mut msg_nonref = (*msg).clone();
1101 let mut update_msg_nonref = (*update_msg).clone();
1102 MessageSendEvent::BroadcastChannelAnnouncement {
1103 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1104 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg_nonref), is_owned: true },
1107 nativeMessageSendEvent::BroadcastNodeAnnouncement {ref msg, } => {
1108 let mut msg_nonref = (*msg).clone();
1109 MessageSendEvent::BroadcastNodeAnnouncement {
1110 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1113 nativeMessageSendEvent::BroadcastChannelUpdate {ref msg, } => {
1114 let mut msg_nonref = (*msg).clone();
1115 MessageSendEvent::BroadcastChannelUpdate {
1116 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1119 nativeMessageSendEvent::SendChannelUpdate {ref node_id, ref msg, } => {
1120 let mut node_id_nonref = (*node_id).clone();
1121 let mut msg_nonref = (*msg).clone();
1122 MessageSendEvent::SendChannelUpdate {
1123 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1124 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1127 nativeMessageSendEvent::HandleError {ref node_id, ref action, } => {
1128 let mut node_id_nonref = (*node_id).clone();
1129 let mut action_nonref = (*action).clone();
1130 MessageSendEvent::HandleError {
1131 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1132 action: crate::lightning::ln::msgs::ErrorAction::native_into(action_nonref),
1135 nativeMessageSendEvent::PaymentFailureNetworkUpdate {ref update, } => {
1136 let mut update_nonref = (*update).clone();
1137 MessageSendEvent::PaymentFailureNetworkUpdate {
1138 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update_nonref),
1141 nativeMessageSendEvent::SendChannelRangeQuery {ref node_id, ref msg, } => {
1142 let mut node_id_nonref = (*node_id).clone();
1143 let mut msg_nonref = (*msg).clone();
1144 MessageSendEvent::SendChannelRangeQuery {
1145 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1146 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1149 nativeMessageSendEvent::SendShortIdsQuery {ref node_id, ref msg, } => {
1150 let mut node_id_nonref = (*node_id).clone();
1151 let mut msg_nonref = (*msg).clone();
1152 MessageSendEvent::SendShortIdsQuery {
1153 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1154 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1157 nativeMessageSendEvent::SendReplyChannelRange {ref node_id, ref msg, } => {
1158 let mut node_id_nonref = (*node_id).clone();
1159 let mut msg_nonref = (*msg).clone();
1160 MessageSendEvent::SendReplyChannelRange {
1161 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1162 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
1168 pub(crate) fn native_into(native: nativeMessageSendEvent) -> Self {
1170 nativeMessageSendEvent::SendAcceptChannel {mut node_id, mut msg, } => {
1171 MessageSendEvent::SendAcceptChannel {
1172 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1173 msg: crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1176 nativeMessageSendEvent::SendOpenChannel {mut node_id, mut msg, } => {
1177 MessageSendEvent::SendOpenChannel {
1178 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1179 msg: crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(msg), is_owned: true },
1182 nativeMessageSendEvent::SendFundingCreated {mut node_id, mut msg, } => {
1183 MessageSendEvent::SendFundingCreated {
1184 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1185 msg: crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(msg), is_owned: true },
1188 nativeMessageSendEvent::SendFundingSigned {mut node_id, mut msg, } => {
1189 MessageSendEvent::SendFundingSigned {
1190 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1191 msg: crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1194 nativeMessageSendEvent::SendFundingLocked {mut node_id, mut msg, } => {
1195 MessageSendEvent::SendFundingLocked {
1196 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1197 msg: crate::lightning::ln::msgs::FundingLocked { inner: ObjOps::heap_alloc(msg), is_owned: true },
1200 nativeMessageSendEvent::SendAnnouncementSignatures {mut node_id, mut msg, } => {
1201 MessageSendEvent::SendAnnouncementSignatures {
1202 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1203 msg: crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(msg), is_owned: true },
1206 nativeMessageSendEvent::UpdateHTLCs {mut node_id, mut updates, } => {
1207 MessageSendEvent::UpdateHTLCs {
1208 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1209 updates: crate::lightning::ln::msgs::CommitmentUpdate { inner: ObjOps::heap_alloc(updates), is_owned: true },
1212 nativeMessageSendEvent::SendRevokeAndACK {mut node_id, mut msg, } => {
1213 MessageSendEvent::SendRevokeAndACK {
1214 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1215 msg: crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(msg), is_owned: true },
1218 nativeMessageSendEvent::SendClosingSigned {mut node_id, mut msg, } => {
1219 MessageSendEvent::SendClosingSigned {
1220 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1221 msg: crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(msg), is_owned: true },
1224 nativeMessageSendEvent::SendShutdown {mut node_id, mut msg, } => {
1225 MessageSendEvent::SendShutdown {
1226 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1227 msg: crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(msg), is_owned: true },
1230 nativeMessageSendEvent::SendChannelReestablish {mut node_id, mut msg, } => {
1231 MessageSendEvent::SendChannelReestablish {
1232 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1233 msg: crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(msg), is_owned: true },
1236 nativeMessageSendEvent::BroadcastChannelAnnouncement {mut msg, mut update_msg, } => {
1237 MessageSendEvent::BroadcastChannelAnnouncement {
1238 msg: crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1239 update_msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(update_msg), is_owned: true },
1242 nativeMessageSendEvent::BroadcastNodeAnnouncement {mut msg, } => {
1243 MessageSendEvent::BroadcastNodeAnnouncement {
1244 msg: crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(msg), is_owned: true },
1247 nativeMessageSendEvent::BroadcastChannelUpdate {mut msg, } => {
1248 MessageSendEvent::BroadcastChannelUpdate {
1249 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1252 nativeMessageSendEvent::SendChannelUpdate {mut node_id, mut msg, } => {
1253 MessageSendEvent::SendChannelUpdate {
1254 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1255 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
1258 nativeMessageSendEvent::HandleError {mut node_id, mut action, } => {
1259 MessageSendEvent::HandleError {
1260 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1261 action: crate::lightning::ln::msgs::ErrorAction::native_into(action),
1264 nativeMessageSendEvent::PaymentFailureNetworkUpdate {mut update, } => {
1265 MessageSendEvent::PaymentFailureNetworkUpdate {
1266 update: crate::lightning::ln::msgs::HTLCFailChannelUpdate::native_into(update),
1269 nativeMessageSendEvent::SendChannelRangeQuery {mut node_id, mut msg, } => {
1270 MessageSendEvent::SendChannelRangeQuery {
1271 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1272 msg: crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1275 nativeMessageSendEvent::SendShortIdsQuery {mut node_id, mut msg, } => {
1276 MessageSendEvent::SendShortIdsQuery {
1277 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1278 msg: crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true },
1281 nativeMessageSendEvent::SendReplyChannelRange {mut node_id, mut msg, } => {
1282 MessageSendEvent::SendReplyChannelRange {
1283 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1284 msg: crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true },
1290 /// Frees any resources used by the MessageSendEvent
1292 pub extern "C" fn MessageSendEvent_free(this_ptr: MessageSendEvent) { }
1293 /// Creates a copy of the MessageSendEvent
1295 pub extern "C" fn MessageSendEvent_clone(orig: &MessageSendEvent) -> MessageSendEvent {
1299 /// Utility method to constructs a new SendAcceptChannel-variant MessageSendEvent
1300 pub extern "C" fn MessageSendEvent_send_accept_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AcceptChannel) -> MessageSendEvent {
1301 MessageSendEvent::SendAcceptChannel {
1307 /// Utility method to constructs a new SendOpenChannel-variant MessageSendEvent
1308 pub extern "C" fn MessageSendEvent_send_open_channel(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::OpenChannel) -> MessageSendEvent {
1309 MessageSendEvent::SendOpenChannel {
1315 /// Utility method to constructs a new SendFundingCreated-variant MessageSendEvent
1316 pub extern "C" fn MessageSendEvent_send_funding_created(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingCreated) -> MessageSendEvent {
1317 MessageSendEvent::SendFundingCreated {
1323 /// Utility method to constructs a new SendFundingSigned-variant MessageSendEvent
1324 pub extern "C" fn MessageSendEvent_send_funding_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingSigned) -> MessageSendEvent {
1325 MessageSendEvent::SendFundingSigned {
1331 /// Utility method to constructs a new SendFundingLocked-variant MessageSendEvent
1332 pub extern "C" fn MessageSendEvent_send_funding_locked(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::FundingLocked) -> MessageSendEvent {
1333 MessageSendEvent::SendFundingLocked {
1339 /// Utility method to constructs a new SendAnnouncementSignatures-variant MessageSendEvent
1340 pub extern "C" fn MessageSendEvent_send_announcement_signatures(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::AnnouncementSignatures) -> MessageSendEvent {
1341 MessageSendEvent::SendAnnouncementSignatures {
1347 /// Utility method to constructs a new UpdateHTLCs-variant MessageSendEvent
1348 pub extern "C" fn MessageSendEvent_update_htlcs(node_id: crate::c_types::PublicKey, updates: crate::lightning::ln::msgs::CommitmentUpdate) -> MessageSendEvent {
1349 MessageSendEvent::UpdateHTLCs {
1355 /// Utility method to constructs a new SendRevokeAndACK-variant MessageSendEvent
1356 pub extern "C" fn MessageSendEvent_send_revoke_and_ack(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::RevokeAndACK) -> MessageSendEvent {
1357 MessageSendEvent::SendRevokeAndACK {
1363 /// Utility method to constructs a new SendClosingSigned-variant MessageSendEvent
1364 pub extern "C" fn MessageSendEvent_send_closing_signed(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ClosingSigned) -> MessageSendEvent {
1365 MessageSendEvent::SendClosingSigned {
1371 /// Utility method to constructs a new SendShutdown-variant MessageSendEvent
1372 pub extern "C" fn MessageSendEvent_send_shutdown(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::Shutdown) -> MessageSendEvent {
1373 MessageSendEvent::SendShutdown {
1379 /// Utility method to constructs a new SendChannelReestablish-variant MessageSendEvent
1380 pub extern "C" fn MessageSendEvent_send_channel_reestablish(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelReestablish) -> MessageSendEvent {
1381 MessageSendEvent::SendChannelReestablish {
1387 /// Utility method to constructs a new BroadcastChannelAnnouncement-variant MessageSendEvent
1388 pub extern "C" fn MessageSendEvent_broadcast_channel_announcement(msg: crate::lightning::ln::msgs::ChannelAnnouncement, update_msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1389 MessageSendEvent::BroadcastChannelAnnouncement {
1395 /// Utility method to constructs a new BroadcastNodeAnnouncement-variant MessageSendEvent
1396 pub extern "C" fn MessageSendEvent_broadcast_node_announcement(msg: crate::lightning::ln::msgs::NodeAnnouncement) -> MessageSendEvent {
1397 MessageSendEvent::BroadcastNodeAnnouncement {
1402 /// Utility method to constructs a new BroadcastChannelUpdate-variant MessageSendEvent
1403 pub extern "C" fn MessageSendEvent_broadcast_channel_update(msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1404 MessageSendEvent::BroadcastChannelUpdate {
1409 /// Utility method to constructs a new SendChannelUpdate-variant MessageSendEvent
1410 pub extern "C" fn MessageSendEvent_send_channel_update(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ChannelUpdate) -> MessageSendEvent {
1411 MessageSendEvent::SendChannelUpdate {
1417 /// Utility method to constructs a new HandleError-variant MessageSendEvent
1418 pub extern "C" fn MessageSendEvent_handle_error(node_id: crate::c_types::PublicKey, action: crate::lightning::ln::msgs::ErrorAction) -> MessageSendEvent {
1419 MessageSendEvent::HandleError {
1425 /// Utility method to constructs a new PaymentFailureNetworkUpdate-variant MessageSendEvent
1426 pub extern "C" fn MessageSendEvent_payment_failure_network_update(update: crate::lightning::ln::msgs::HTLCFailChannelUpdate) -> MessageSendEvent {
1427 MessageSendEvent::PaymentFailureNetworkUpdate {
1432 /// Utility method to constructs a new SendChannelRangeQuery-variant MessageSendEvent
1433 pub extern "C" fn MessageSendEvent_send_channel_range_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> MessageSendEvent {
1434 MessageSendEvent::SendChannelRangeQuery {
1440 /// Utility method to constructs a new SendShortIdsQuery-variant MessageSendEvent
1441 pub extern "C" fn MessageSendEvent_send_short_ids_query(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> MessageSendEvent {
1442 MessageSendEvent::SendShortIdsQuery {
1448 /// Utility method to constructs a new SendReplyChannelRange-variant MessageSendEvent
1449 pub extern "C" fn MessageSendEvent_send_reply_channel_range(node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyChannelRange) -> MessageSendEvent {
1450 MessageSendEvent::SendReplyChannelRange {
1455 /// A trait indicating an object may generate message send events
1457 pub struct MessageSendEventsProvider {
1458 /// An opaque pointer which is passed to your function implementations as an argument.
1459 /// This has no meaning in the LDK, and can be NULL or any other value.
1460 pub this_arg: *mut c_void,
1461 /// Gets the list of pending events which were generated by previous actions, clearing the list
1464 pub get_and_clear_pending_msg_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ,
1465 /// Frees any resources associated with this object given its this_arg pointer.
1466 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1467 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1469 unsafe impl Send for MessageSendEventsProvider {}
1470 unsafe impl Sync for MessageSendEventsProvider {}
1472 pub(crate) extern "C" fn MessageSendEventsProvider_clone_fields(orig: &MessageSendEventsProvider) -> MessageSendEventsProvider {
1473 MessageSendEventsProvider {
1474 this_arg: orig.this_arg,
1475 get_and_clear_pending_msg_events: Clone::clone(&orig.get_and_clear_pending_msg_events),
1476 free: Clone::clone(&orig.free),
1480 use lightning::util::events::MessageSendEventsProvider as rustMessageSendEventsProvider;
1481 impl rustMessageSendEventsProvider for MessageSendEventsProvider {
1482 fn get_and_clear_pending_msg_events(&self) -> Vec<lightning::util::events::MessageSendEvent> {
1483 let mut ret = (self.get_and_clear_pending_msg_events)(self.this_arg);
1484 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
1489 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1490 // directly as a Deref trait in higher-level structs:
1491 impl std::ops::Deref for MessageSendEventsProvider {
1493 fn deref(&self) -> &Self {
1497 /// Calls the free function if one is set
1499 pub extern "C" fn MessageSendEventsProvider_free(this_ptr: MessageSendEventsProvider) { }
1500 impl Drop for MessageSendEventsProvider {
1501 fn drop(&mut self) {
1502 if let Some(f) = self.free {
1507 /// A trait indicating an object may generate events.
1509 /// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
1513 /// See [`process_pending_events`] for requirements around event processing.
1515 /// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
1516 /// event since the last invocation. The handler must either act upon the event immediately
1517 /// or preserve it for later handling.
1519 /// Note, handlers may call back into the provider and thus deadlocking must be avoided. Be sure to
1520 /// consult the provider's documentation on the implication of processing events and how a handler
1521 /// may safely use the provider (e.g., see [`ChannelManager::process_pending_events`] and
1522 /// [`ChainMonitor::process_pending_events`]).
1524 /// (C-not implementable) As there is likely no reason for a user to implement this trait on their
1527 /// [`process_pending_events`]: Self::process_pending_events
1528 /// [`handle_event`]: EventHandler::handle_event
1529 /// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
1530 /// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
1532 pub struct EventsProvider {
1533 /// An opaque pointer which is passed to your function implementations as an argument.
1534 /// This has no meaning in the LDK, and can be NULL or any other value.
1535 pub this_arg: *mut c_void,
1536 /// Processes any events generated since the last call using the given event handler.
1538 /// Subsequent calls must only process new events. However, handlers must be capable of handling
1539 /// duplicate events across process restarts. This may occur if the provider was recovered from
1540 /// an old state (i.e., it hadn't been successfully persisted after processing pending events).
1541 pub process_pending_events: extern "C" fn (this_arg: *const c_void, handler: crate::lightning::util::events::EventHandler),
1542 /// Frees any resources associated with this object given its this_arg pointer.
1543 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1544 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1546 unsafe impl Send for EventsProvider {}
1547 unsafe impl Sync for EventsProvider {}
1549 pub(crate) extern "C" fn EventsProvider_clone_fields(orig: &EventsProvider) -> EventsProvider {
1551 this_arg: orig.this_arg,
1552 process_pending_events: Clone::clone(&orig.process_pending_events),
1553 free: Clone::clone(&orig.free),
1557 use lightning::util::events::EventsProvider as rustEventsProvider;
1558 /// Calls the free function if one is set
1560 pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
1561 impl Drop for EventsProvider {
1562 fn drop(&mut self) {
1563 if let Some(f) = self.free {
1568 /// A trait implemented for objects handling events from [`EventsProvider`].
1570 pub struct EventHandler {
1571 /// An opaque pointer which is passed to your function implementations as an argument.
1572 /// This has no meaning in the LDK, and can be NULL or any other value.
1573 pub this_arg: *mut c_void,
1574 /// Handles the given [`Event`].
1576 /// See [`EventsProvider`] for details that must be considered when implementing this method.
1577 pub handle_event: extern "C" fn (this_arg: *const c_void, event: crate::lightning::util::events::Event),
1578 /// Frees any resources associated with this object given its this_arg pointer.
1579 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1580 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1582 unsafe impl Send for EventHandler {}
1583 unsafe impl Sync for EventHandler {}
1585 pub(crate) extern "C" fn EventHandler_clone_fields(orig: &EventHandler) -> EventHandler {
1587 this_arg: orig.this_arg,
1588 handle_event: Clone::clone(&orig.handle_event),
1589 free: Clone::clone(&orig.free),
1593 use lightning::util::events::EventHandler as rustEventHandler;
1594 impl rustEventHandler for EventHandler {
1595 fn handle_event(&self, mut event: lightning::util::events::Event) {
1596 (self.handle_event)(self.this_arg, crate::lightning::util::events::Event::native_into(event))
1600 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1601 // directly as a Deref trait in higher-level structs:
1602 impl std::ops::Deref for EventHandler {
1604 fn deref(&self) -> &Self {
1608 /// Calls the free function if one is set
1610 pub extern "C" fn EventHandler_free(this_ptr: EventHandler) { }
1611 impl Drop for EventHandler {
1612 fn drop(&mut self) {
1613 if let Some(f) = self.free {