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 //! The logic to monitor for on-chain transactions and create the relevant claim responses lives
12 //! ChannelMonitor objects are generated by ChannelManager in response to relevant
13 //! messages/actions, and MUST be persisted to disk (and, preferably, remotely) before progress can
14 //! be made in responding to certain messages, see [`chain::Watch`] for more.
16 //! Note that ChannelMonitors are an important part of the lightning trust model and a copy of the
17 //! latest ChannelMonitor must always be actively monitoring for chain updates (and no out-of-date
18 //! ChannelMonitors should do so). Thus, if you're building rust-lightning into an HSM or other
19 //! security-domain-separated system design, you should consider having multiple paths for
20 //! ChannelMonitors to get out of the HSM and onto monitoring devices.
22 use alloc::str::FromStr;
23 use core::ffi::c_void;
24 use core::convert::Infallible;
25 use bitcoin::hashes::Hash;
26 use crate::c_types::*;
27 #[cfg(feature="no-std")]
28 use alloc::{vec::Vec, boxed::Box};
31 use lightning::chain::channelmonitor::ChannelMonitorUpdate as nativeChannelMonitorUpdateImport;
32 pub(crate) type nativeChannelMonitorUpdate = nativeChannelMonitorUpdateImport;
34 /// An update generated by the underlying channel itself which contains some new information the
35 /// [`ChannelMonitor`] should be made aware of.
37 /// Because this represents only a small number of updates to the underlying state, it is generally
38 /// much smaller than a full [`ChannelMonitor`]. However, for large single commitment transaction
39 /// updates (e.g. ones during which there are hundreds of HTLCs pending on the commitment
40 /// transaction), a single update may reach upwards of 1 MiB in serialized size.
43 pub struct ChannelMonitorUpdate {
44 /// A pointer to the opaque Rust object.
46 /// Nearly everywhere, inner must be non-null, however in places where
47 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
48 pub inner: *mut nativeChannelMonitorUpdate,
49 /// Indicates that this is the only struct which contains the same pointer.
51 /// Rust functions which take ownership of an object provided via an argument require
52 /// this to be true and invalidate the object pointed to by inner.
56 impl Drop for ChannelMonitorUpdate {
58 if self.is_owned && !<*mut nativeChannelMonitorUpdate>::is_null(self.inner) {
59 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
63 /// Frees any resources used by the ChannelMonitorUpdate, if is_owned is set and inner is non-NULL.
65 pub extern "C" fn ChannelMonitorUpdate_free(this_obj: ChannelMonitorUpdate) { }
67 /// Used only if an object of this type is returned as a trait impl by a method
68 pub(crate) extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
69 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate) };
72 impl ChannelMonitorUpdate {
73 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitorUpdate {
74 unsafe { &*ObjOps::untweak_ptr(self.inner) }
76 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitorUpdate {
77 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
79 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
80 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitorUpdate {
81 assert!(self.is_owned);
82 let ret = ObjOps::untweak_ptr(self.inner);
83 self.inner = core::ptr::null_mut();
87 /// The sequence number of this update. Updates *must* be replayed in-order according to this
88 /// sequence number (and updates may panic if they are not). The update_id values are strictly
89 /// increasing and increase by one for each new update, with one exception specified below.
91 /// This sequence number is also used to track up to which points updates which returned
92 /// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
93 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
95 /// The only instance where update_id values are not strictly increasing is the case where we
96 /// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
97 /// its docs for more details.
99 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
101 pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 {
102 let mut inner_val = &mut this_ptr.get_native_mut_ref().update_id;
105 /// The sequence number of this update. Updates *must* be replayed in-order according to this
106 /// sequence number (and updates may panic if they are not). The update_id values are strictly
107 /// increasing and increase by one for each new update, with one exception specified below.
109 /// This sequence number is also used to track up to which points updates which returned
110 /// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
111 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
113 /// The only instance where update_id values are not strictly increasing is the case where we
114 /// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
115 /// its docs for more details.
117 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
119 pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) {
120 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_id = val;
122 impl Clone for ChannelMonitorUpdate {
123 fn clone(&self) -> Self {
125 inner: if <*mut nativeChannelMonitorUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
126 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
132 /// Used only if an object of this type is returned as a trait impl by a method
133 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
134 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void
137 /// Creates a copy of the ChannelMonitorUpdate
138 pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
142 /// (1) a channel has been force closed and
143 /// (2) we receive a preimage from a forward link that allows us to spend an HTLC output on
144 /// this channel's (the backward link's) broadcasted commitment transaction
145 /// then we allow the `ChannelManager` to send a `ChannelMonitorUpdate` with this update ID,
146 /// with the update providing said payment preimage. No other update types are allowed after
150 pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
152 /// Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read
153 pub extern "C" fn ChannelMonitorUpdate_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
154 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
157 pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
158 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) })
161 /// Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write
162 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ {
163 let res: Result<lightning::chain::channelmonitor::ChannelMonitorUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
164 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
167 /// An event to be processed by the ChannelManager.
171 pub enum MonitorEvent {
172 /// A monitor event containing an HTLCUpdate.
174 crate::lightning::chain::channelmonitor::HTLCUpdate),
175 /// A monitor event that the Channel's commitment transaction was confirmed.
176 CommitmentTxConfirmed(
177 crate::lightning::chain::transaction::OutPoint),
178 /// Indicates a [`ChannelMonitor`] update has completed. See
179 /// [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
181 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
183 /// The funding outpoint of the [`ChannelMonitor`] that was updated
184 funding_txo: crate::lightning::chain::transaction::OutPoint,
185 /// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
186 /// [`ChannelMonitor::get_latest_update_id`].
188 /// Note that this should only be set to a given update's ID if all previous updates for the
189 /// same [`ChannelMonitor`] have been applied and persisted.
190 monitor_update_id: u64,
192 /// Indicates a [`ChannelMonitor`] update has failed. See
193 /// [`ChannelMonitorUpdateStatus::PermanentFailure`] for more information on how this is used.
195 /// [`ChannelMonitorUpdateStatus::PermanentFailure`]: super::ChannelMonitorUpdateStatus::PermanentFailure
197 crate::lightning::chain::transaction::OutPoint),
199 use lightning::chain::channelmonitor::MonitorEvent as MonitorEventImport;
200 pub(crate) type nativeMonitorEvent = MonitorEventImport;
204 pub(crate) fn to_native(&self) -> nativeMonitorEvent {
206 MonitorEvent::HTLCEvent (ref a, ) => {
207 let mut a_nonref = Clone::clone(a);
208 nativeMonitorEvent::HTLCEvent (
209 *unsafe { Box::from_raw(a_nonref.take_inner()) },
212 MonitorEvent::CommitmentTxConfirmed (ref a, ) => {
213 let mut a_nonref = Clone::clone(a);
214 nativeMonitorEvent::CommitmentTxConfirmed (
215 *unsafe { Box::from_raw(a_nonref.take_inner()) },
218 MonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
219 let mut funding_txo_nonref = Clone::clone(funding_txo);
220 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
221 nativeMonitorEvent::Completed {
222 funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
223 monitor_update_id: monitor_update_id_nonref,
226 MonitorEvent::UpdateFailed (ref a, ) => {
227 let mut a_nonref = Clone::clone(a);
228 nativeMonitorEvent::UpdateFailed (
229 *unsafe { Box::from_raw(a_nonref.take_inner()) },
235 pub(crate) fn into_native(self) -> nativeMonitorEvent {
237 MonitorEvent::HTLCEvent (mut a, ) => {
238 nativeMonitorEvent::HTLCEvent (
239 *unsafe { Box::from_raw(a.take_inner()) },
242 MonitorEvent::CommitmentTxConfirmed (mut a, ) => {
243 nativeMonitorEvent::CommitmentTxConfirmed (
244 *unsafe { Box::from_raw(a.take_inner()) },
247 MonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => {
248 nativeMonitorEvent::Completed {
249 funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
250 monitor_update_id: monitor_update_id,
253 MonitorEvent::UpdateFailed (mut a, ) => {
254 nativeMonitorEvent::UpdateFailed (
255 *unsafe { Box::from_raw(a.take_inner()) },
261 pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self {
263 nativeMonitorEvent::HTLCEvent (ref a, ) => {
264 let mut a_nonref = Clone::clone(a);
265 MonitorEvent::HTLCEvent (
266 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
269 nativeMonitorEvent::CommitmentTxConfirmed (ref a, ) => {
270 let mut a_nonref = Clone::clone(a);
271 MonitorEvent::CommitmentTxConfirmed (
272 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
275 nativeMonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
276 let mut funding_txo_nonref = Clone::clone(funding_txo);
277 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
278 MonitorEvent::Completed {
279 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
280 monitor_update_id: monitor_update_id_nonref,
283 nativeMonitorEvent::UpdateFailed (ref a, ) => {
284 let mut a_nonref = Clone::clone(a);
285 MonitorEvent::UpdateFailed (
286 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
292 pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
294 nativeMonitorEvent::HTLCEvent (mut a, ) => {
295 MonitorEvent::HTLCEvent (
296 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true },
299 nativeMonitorEvent::CommitmentTxConfirmed (mut a, ) => {
300 MonitorEvent::CommitmentTxConfirmed (
301 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
304 nativeMonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => {
305 MonitorEvent::Completed {
306 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true },
307 monitor_update_id: monitor_update_id,
310 nativeMonitorEvent::UpdateFailed (mut a, ) => {
311 MonitorEvent::UpdateFailed (
312 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
318 /// Frees any resources used by the MonitorEvent
320 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
321 /// Creates a copy of the MonitorEvent
323 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
327 /// Utility method to constructs a new HTLCEvent-variant MonitorEvent
328 pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent {
329 MonitorEvent::HTLCEvent(a, )
332 /// Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
333 pub extern "C" fn MonitorEvent_commitment_tx_confirmed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
334 MonitorEvent::CommitmentTxConfirmed(a, )
337 /// Utility method to constructs a new Completed-variant MonitorEvent
338 pub extern "C" fn MonitorEvent_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, monitor_update_id: u64) -> MonitorEvent {
339 MonitorEvent::Completed {
345 /// Utility method to constructs a new UpdateFailed-variant MonitorEvent
346 pub extern "C" fn MonitorEvent_update_failed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
347 MonitorEvent::UpdateFailed(a, )
349 /// Checks if two MonitorEvents contain equal inner contents.
350 /// This ignores pointers and is_owned flags and looks at the values in fields.
352 pub extern "C" fn MonitorEvent_eq(a: &MonitorEvent, b: &MonitorEvent) -> bool {
353 if &a.to_native() == &b.to_native() { true } else { false }
356 /// Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
357 pub extern "C" fn MonitorEvent_write(obj: &crate::lightning::chain::channelmonitor::MonitorEvent) -> crate::c_types::derived::CVec_u8Z {
358 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
361 /// Read a MonitorEvent from a byte array, created by MonitorEvent_write
362 pub extern "C" fn MonitorEvent_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_MonitorEventZDecodeErrorZ {
363 let res: Result<Option<lightning::chain::channelmonitor::MonitorEvent>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
364 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_MonitorEventZ::None } else { crate::c_types::derived::COption_MonitorEventZ::Some( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
368 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
369 pub(crate) type nativeHTLCUpdate = nativeHTLCUpdateImport;
371 /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
372 /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
373 /// preimage claim backward will lead to loss of funds.
376 pub struct HTLCUpdate {
377 /// A pointer to the opaque Rust object.
379 /// Nearly everywhere, inner must be non-null, however in places where
380 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
381 pub inner: *mut nativeHTLCUpdate,
382 /// Indicates that this is the only struct which contains the same pointer.
384 /// Rust functions which take ownership of an object provided via an argument require
385 /// this to be true and invalidate the object pointed to by inner.
389 impl Drop for HTLCUpdate {
391 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
392 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
396 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
398 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
400 /// Used only if an object of this type is returned as a trait impl by a method
401 pub(crate) extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
402 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCUpdate) };
406 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCUpdate {
407 unsafe { &*ObjOps::untweak_ptr(self.inner) }
409 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCUpdate {
410 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
412 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
413 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
414 assert!(self.is_owned);
415 let ret = ObjOps::untweak_ptr(self.inner);
416 self.inner = core::ptr::null_mut();
420 impl Clone for HTLCUpdate {
421 fn clone(&self) -> Self {
423 inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
424 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
430 /// Used only if an object of this type is returned as a trait impl by a method
431 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
432 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void
435 /// Creates a copy of the HTLCUpdate
436 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
439 /// Checks if two HTLCUpdates contain equal inner contents.
440 /// This ignores pointers and is_owned flags and looks at the values in fields.
441 /// Two objects with NULL inner values will be considered "equal" here.
443 pub extern "C" fn HTLCUpdate_eq(a: &HTLCUpdate, b: &HTLCUpdate) -> bool {
444 if a.inner == b.inner { return true; }
445 if a.inner.is_null() || b.inner.is_null() { return false; }
446 if a.get_native_ref() == b.get_native_ref() { true } else { false }
449 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
450 pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
451 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
454 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
455 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
458 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
459 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
460 let res: Result<lightning::chain::channelmonitor::HTLCUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
461 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
464 /// Number of blocks we wait on seeing a HTLC output being solved before we fail corresponding
465 /// inbound HTLCs. This prevents us from failing backwards and then getting a reorg resulting in us
468 /// Note that this is a library-wide security assumption. If a reorg deeper than this number of
469 /// blocks occurs, counterparties may be able to steal funds or claims made by and balances exposed
470 /// by a [`ChannelMonitor`] may be incorrect.
473 pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
474 /// Details about the balance(s) available for spending once the channel appears on chain.
476 /// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
482 /// The channel is not yet closed (or the commitment or closing transaction has not yet
483 /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
484 /// force-closed now.
485 ClaimableOnChannelClose {
486 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
487 /// required to do so.
488 claimable_amount_satoshis: u64,
490 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
491 /// we consider it spendable.
492 ClaimableAwaitingConfirmations {
493 /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
494 /// were spent in broadcasting the transaction.
495 claimable_amount_satoshis: u64,
496 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
498 confirmation_height: u32,
500 /// The channel has been closed, and the given balance should be ours but awaiting spending
501 /// transaction confirmation. If the spending transaction does not confirm in time, it is
502 /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
504 /// Once the spending transaction confirms, before it has reached enough confirmations to be
505 /// considered safe from chain reorganizations, the balance will instead be provided via
506 /// [`Balance::ClaimableAwaitingConfirmations`].
507 ContentiousClaimable {
508 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
509 /// required to do so.
510 claimable_amount_satoshis: u64,
511 /// The height at which the counterparty may be able to claim the balance if we have not
515 /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
516 /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
517 /// likely to be claimed by our counterparty before we do.
518 MaybeTimeoutClaimableHTLC {
519 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
520 /// which will be required to do so.
521 claimable_amount_satoshis: u64,
522 /// The height at which we will be able to claim the balance if our counterparty has not
524 claimable_height: u32,
526 /// HTLCs which we received from our counterparty which are claimable with a preimage which we
527 /// do not currently have. This will only be claimable if we receive the preimage from the node
528 /// to which we forwarded this HTLC before the timeout.
529 MaybePreimageClaimableHTLC {
530 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
531 /// which will be required to do so.
532 claimable_amount_satoshis: u64,
533 /// The height at which our counterparty will be able to claim the balance if we have not
534 /// yet received the preimage and claimed it ourselves.
537 /// The channel has been closed, and our counterparty broadcasted a revoked commitment
540 /// Thus, we're able to claim all outputs in the commitment transaction, one of which has the
541 /// following amount.
542 CounterpartyRevokedOutputClaimable {
543 /// The amount, in satoshis, of the output which we can claim.
545 /// Note that for outputs from HTLC balances this may be excluding some on-chain fees that
546 /// were already spent.
547 claimable_amount_satoshis: u64,
550 use lightning::chain::channelmonitor::Balance as BalanceImport;
551 pub(crate) type nativeBalance = BalanceImport;
555 pub(crate) fn to_native(&self) -> nativeBalance {
557 Balance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
558 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
559 nativeBalance::ClaimableOnChannelClose {
560 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
563 Balance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
564 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
565 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
566 nativeBalance::ClaimableAwaitingConfirmations {
567 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
568 confirmation_height: confirmation_height_nonref,
571 Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
572 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
573 let mut timeout_height_nonref = Clone::clone(timeout_height);
574 nativeBalance::ContentiousClaimable {
575 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
576 timeout_height: timeout_height_nonref,
579 Balance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
580 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
581 let mut claimable_height_nonref = Clone::clone(claimable_height);
582 nativeBalance::MaybeTimeoutClaimableHTLC {
583 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
584 claimable_height: claimable_height_nonref,
587 Balance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
588 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
589 let mut expiry_height_nonref = Clone::clone(expiry_height);
590 nativeBalance::MaybePreimageClaimableHTLC {
591 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
592 expiry_height: expiry_height_nonref,
595 Balance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
596 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
597 nativeBalance::CounterpartyRevokedOutputClaimable {
598 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
604 pub(crate) fn into_native(self) -> nativeBalance {
606 Balance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
607 nativeBalance::ClaimableOnChannelClose {
608 claimable_amount_satoshis: claimable_amount_satoshis,
611 Balance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
612 nativeBalance::ClaimableAwaitingConfirmations {
613 claimable_amount_satoshis: claimable_amount_satoshis,
614 confirmation_height: confirmation_height,
617 Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
618 nativeBalance::ContentiousClaimable {
619 claimable_amount_satoshis: claimable_amount_satoshis,
620 timeout_height: timeout_height,
623 Balance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
624 nativeBalance::MaybeTimeoutClaimableHTLC {
625 claimable_amount_satoshis: claimable_amount_satoshis,
626 claimable_height: claimable_height,
629 Balance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
630 nativeBalance::MaybePreimageClaimableHTLC {
631 claimable_amount_satoshis: claimable_amount_satoshis,
632 expiry_height: expiry_height,
635 Balance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
636 nativeBalance::CounterpartyRevokedOutputClaimable {
637 claimable_amount_satoshis: claimable_amount_satoshis,
643 pub(crate) fn from_native(native: &nativeBalance) -> Self {
645 nativeBalance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
646 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
647 Balance::ClaimableOnChannelClose {
648 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
651 nativeBalance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
652 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
653 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
654 Balance::ClaimableAwaitingConfirmations {
655 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
656 confirmation_height: confirmation_height_nonref,
659 nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
660 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
661 let mut timeout_height_nonref = Clone::clone(timeout_height);
662 Balance::ContentiousClaimable {
663 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
664 timeout_height: timeout_height_nonref,
667 nativeBalance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
668 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
669 let mut claimable_height_nonref = Clone::clone(claimable_height);
670 Balance::MaybeTimeoutClaimableHTLC {
671 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
672 claimable_height: claimable_height_nonref,
675 nativeBalance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
676 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
677 let mut expiry_height_nonref = Clone::clone(expiry_height);
678 Balance::MaybePreimageClaimableHTLC {
679 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
680 expiry_height: expiry_height_nonref,
683 nativeBalance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
684 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
685 Balance::CounterpartyRevokedOutputClaimable {
686 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
692 pub(crate) fn native_into(native: nativeBalance) -> Self {
694 nativeBalance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
695 Balance::ClaimableOnChannelClose {
696 claimable_amount_satoshis: claimable_amount_satoshis,
699 nativeBalance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
700 Balance::ClaimableAwaitingConfirmations {
701 claimable_amount_satoshis: claimable_amount_satoshis,
702 confirmation_height: confirmation_height,
705 nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
706 Balance::ContentiousClaimable {
707 claimable_amount_satoshis: claimable_amount_satoshis,
708 timeout_height: timeout_height,
711 nativeBalance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
712 Balance::MaybeTimeoutClaimableHTLC {
713 claimable_amount_satoshis: claimable_amount_satoshis,
714 claimable_height: claimable_height,
717 nativeBalance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
718 Balance::MaybePreimageClaimableHTLC {
719 claimable_amount_satoshis: claimable_amount_satoshis,
720 expiry_height: expiry_height,
723 nativeBalance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
724 Balance::CounterpartyRevokedOutputClaimable {
725 claimable_amount_satoshis: claimable_amount_satoshis,
731 /// Frees any resources used by the Balance
733 pub extern "C" fn Balance_free(this_ptr: Balance) { }
734 /// Creates a copy of the Balance
736 pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
740 /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
741 pub extern "C" fn Balance_claimable_on_channel_close(claimable_amount_satoshis: u64) -> Balance {
742 Balance::ClaimableOnChannelClose {
743 claimable_amount_satoshis,
747 /// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
748 pub extern "C" fn Balance_claimable_awaiting_confirmations(claimable_amount_satoshis: u64, confirmation_height: u32) -> Balance {
749 Balance::ClaimableAwaitingConfirmations {
750 claimable_amount_satoshis,
755 /// Utility method to constructs a new ContentiousClaimable-variant Balance
756 pub extern "C" fn Balance_contentious_claimable(claimable_amount_satoshis: u64, timeout_height: u32) -> Balance {
757 Balance::ContentiousClaimable {
758 claimable_amount_satoshis,
763 /// Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
764 pub extern "C" fn Balance_maybe_timeout_claimable_htlc(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
765 Balance::MaybeTimeoutClaimableHTLC {
766 claimable_amount_satoshis,
771 /// Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
772 pub extern "C" fn Balance_maybe_preimage_claimable_htlc(claimable_amount_satoshis: u64, expiry_height: u32) -> Balance {
773 Balance::MaybePreimageClaimableHTLC {
774 claimable_amount_satoshis,
779 /// Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
780 pub extern "C" fn Balance_counterparty_revoked_output_claimable(claimable_amount_satoshis: u64) -> Balance {
781 Balance::CounterpartyRevokedOutputClaimable {
782 claimable_amount_satoshis,
785 /// Checks if two Balances contain equal inner contents.
786 /// This ignores pointers and is_owned flags and looks at the values in fields.
788 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
789 if &a.to_native() == &b.to_native() { true } else { false }
792 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
793 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::chain::keysinterface::Sign>;
795 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
796 /// on-chain transactions to ensure no loss of funds occurs.
798 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
799 /// information and are actively monitoring the chain.
801 /// Pending Events or updated HTLCs which have not yet been read out by
802 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
803 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
804 /// gotten are fully handled before re-serializing the new state.
806 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
807 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
808 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
809 /// returned block hash and the the current chain and then reconnecting blocks to get to the
810 /// best chain) upon deserializing the object!
813 pub struct ChannelMonitor {
814 /// A pointer to the opaque Rust object.
816 /// Nearly everywhere, inner must be non-null, however in places where
817 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
818 pub inner: *mut nativeChannelMonitor,
819 /// Indicates that this is the only struct which contains the same pointer.
821 /// Rust functions which take ownership of an object provided via an argument require
822 /// this to be true and invalidate the object pointed to by inner.
826 impl Drop for ChannelMonitor {
828 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
829 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
833 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
835 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
837 /// Used only if an object of this type is returned as a trait impl by a method
838 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
839 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitor) };
842 impl ChannelMonitor {
843 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
844 unsafe { &*ObjOps::untweak_ptr(self.inner) }
846 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
847 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
849 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
850 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
851 assert!(self.is_owned);
852 let ret = ObjOps::untweak_ptr(self.inner);
853 self.inner = core::ptr::null_mut();
858 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
859 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
860 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
863 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
864 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
866 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
869 /// panics if the given update is not the next update by update_id.
872 pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, updates: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NoneNoneZ {
873 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
874 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
878 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
882 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
883 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
887 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
890 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
891 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
892 let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(orig_ret_0), is_owned: true }, orig_ret_1.into_bytes().into()).into();
896 /// Gets a list of txids, with their output scripts (in the order they appear in the
897 /// transaction), which we must learn about spends of via block_connected().
900 pub extern "C" fn ChannelMonitor_get_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZZ {
901 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
902 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, orig_orig_ret_0_1_0_1.into_bytes().into()).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
906 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
907 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
908 /// have been registered.
910 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter) {
911 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter)
914 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
915 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
918 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
919 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
920 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
924 /// Gets the list of pending events which were generated by previous actions, clearing the list
927 /// This is called by the [`EventsProvider::process_pending_events`] implementation for
928 /// [`ChainMonitor`].
930 /// [`EventsProvider::process_pending_events`]: crate::util::events::EventsProvider::process_pending_events
931 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
934 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
935 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_events();
936 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::Event::native_into(item) }); };
940 /// Gets the `node_id` of the counterparty for this channel.
942 /// Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
945 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
948 pub extern "C" fn ChannelMonitor_get_counterparty_node_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::PublicKey {
949 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_counterparty_node_id();
950 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
954 /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
955 /// the Channel was out-of-date.
957 /// You may also use this to broadcast the latest local commitment transaction, either because
958 /// a monitor update failed with [`ChannelMonitorUpdateStatus::PermanentFailure`] or because we've
959 /// fallen behind (i.e. we've received proof that our counterparty side knows a revocation
960 /// secret we gave them that they shouldn't know).
962 /// Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty
963 /// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
964 /// close channel with their commitment transaction after a substantial amount of time. Best
965 /// may be to contact the other node operator out-of-band to coordinate other options available
966 /// to you. In any-case, the choice is up to you.
968 /// [`ChannelMonitorUpdateStatus::PermanentFailure`]: super::ChannelMonitorUpdateStatus::PermanentFailure
971 pub extern "C" fn ChannelMonitor_get_latest_holder_commitment_txn(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionZ {
972 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger);
973 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); };
977 /// Processes transactions in a newly connected block, which may result in any of the following:
978 /// - update the monitor's state against resolved HTLCs
979 /// - punish the counterparty in the case of seeing a revoked commitment transaction
980 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
981 /// - detect settled outputs for later spending
982 /// - schedule and bump any in-flight claims
984 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
985 /// [`get_outputs_to_watch`].
987 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
990 pub extern "C" fn ChannelMonitor_block_connected(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
991 let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); };
992 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height, broadcaster, fee_estimator, logger);
993 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
997 /// Determines if the disconnected block contained any transactions of interest and updates
1000 pub extern "C" fn ChannelMonitor_block_disconnected(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) {
1001 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
1004 /// Processes transactions confirmed in a block with the given header and height, returning new
1005 /// outputs to watch. See [`block_connected`] for details.
1007 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1008 /// blocks. See [`chain::Confirm`] for calling expectations.
1010 /// [`block_connected`]: Self::block_connected
1013 pub extern "C" fn ChannelMonitor_transactions_confirmed(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
1014 let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); };
1015 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transactions_confirmed(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height, broadcaster, fee_estimator, logger);
1016 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1020 /// Processes a transaction that was reorganized out of the chain.
1022 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
1023 /// than blocks. See [`chain::Confirm`] for calling expectations.
1025 /// [`block_disconnected`]: Self::block_disconnected
1027 pub extern "C" fn ChannelMonitor_transaction_unconfirmed(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, txid: *const [u8; 32], mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) {
1028 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
1031 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
1032 /// [`block_connected`] for details.
1034 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1035 /// blocks. See [`chain::Confirm`] for calling expectations.
1037 /// [`block_connected`]: Self::block_connected
1040 pub extern "C" fn ChannelMonitor_best_block_updated(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, header: *const [u8; 80], mut height: u32, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
1041 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.best_block_updated(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger);
1042 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { let (mut orig_orig_ret_0_1_0_0, mut orig_orig_ret_0_1_0_1) = item; let mut local_orig_ret_0_1_0 = (orig_orig_ret_0_1_0_0, crate::c_types::TxOut::from_rust(orig_orig_ret_0_1_0_1)).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1046 /// Returns the set of txids that should be monitored for re-organization out of the chain.
1049 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_TxidBlockHashZZ {
1050 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
1051 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = if orig_ret_0_1.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (orig_ret_0_1.unwrap()).into_inner() } } }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1).into(); local_ret_0 }); };
1055 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1056 /// [`chain::Confirm`] interfaces.
1059 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
1060 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1061 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1064 /// Gets the balances in this channel which are either claimable by us if we were to
1065 /// force-close the channel now or which are claimable on-chain (possibly awaiting
1068 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
1069 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
1070 /// balance, or until our counterparty has claimed the balance and accrued several
1071 /// confirmations on the claim transaction.
1073 /// Note that for `ChannelMonitors` which track a channel which went on-chain with versions of
1074 /// LDK prior to 0.0.111, balances may not be fully captured if our counterparty broadcasted
1075 /// a revoked state.
1077 /// See [`Balance`] for additional details on the types of claimable balances which
1078 /// may be returned here and their meanings.
1081 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
1082 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
1083 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
1088 /// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
1089 pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_read(ser: crate::c_types::u8slice, arg: &crate::lightning::chain::keysinterface::KeysInterface) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ {
1091 let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::Sign>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1092 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_res_0_0, mut orig_res_0_1) = o; let mut local_res_0 = (crate::c_types::ThirtyTwoBytes { data: orig_res_0_0.into_inner() }, crate::lightning::chain::channelmonitor::ChannelMonitor { inner: ObjOps::heap_alloc(orig_res_0_1), is_owned: true }).into(); local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };