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 unsafe { let _ = 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 /// ChannelMonitorUpdateErr::TemporaryFailure 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 pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 {
100 let mut inner_val = &mut this_ptr.get_native_mut_ref().update_id;
103 /// The sequence number of this update. Updates *must* be replayed in-order according to this
104 /// sequence number (and updates may panic if they are not). The update_id values are strictly
105 /// increasing and increase by one for each new update, with one exception specified below.
107 /// This sequence number is also used to track up to which points updates which returned
108 /// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given
109 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
111 /// The only instance where update_id values are not strictly increasing is the case where we
112 /// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
113 /// its docs for more details.
115 pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) {
116 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_id = val;
118 impl Clone for ChannelMonitorUpdate {
119 fn clone(&self) -> Self {
121 inner: if <*mut nativeChannelMonitorUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
122 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
128 /// Used only if an object of this type is returned as a trait impl by a method
129 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
130 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void
133 /// Creates a copy of the ChannelMonitorUpdate
134 pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
138 /// (1) a channel has been force closed and
139 /// (2) we receive a preimage from a forward link that allows us to spend an HTLC output on
140 /// this channel's (the backward link's) broadcasted commitment transaction
141 /// then we allow the `ChannelManager` to send a `ChannelMonitorUpdate` with this update ID,
142 /// with the update providing said payment preimage. No other update types are allowed after
146 pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
148 /// Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read
149 pub extern "C" fn ChannelMonitorUpdate_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
150 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
153 pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
154 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) })
157 /// Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write
158 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ {
159 let res: Result<lightning::chain::channelmonitor::ChannelMonitorUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
160 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
163 /// An event to be processed by the ChannelManager.
167 pub enum MonitorEvent {
168 /// A monitor event containing an HTLCUpdate.
170 crate::lightning::chain::channelmonitor::HTLCUpdate),
171 /// A monitor event that the Channel's commitment transaction was confirmed.
172 CommitmentTxConfirmed(
173 crate::lightning::chain::transaction::OutPoint),
174 /// Indicates a [`ChannelMonitor`] update has completed. See
175 /// [`ChannelMonitorUpdateErr::TemporaryFailure`] for more information on how this is used.
177 /// [`ChannelMonitorUpdateErr::TemporaryFailure`]: super::ChannelMonitorUpdateErr::TemporaryFailure
179 /// The funding outpoint of the [`ChannelMonitor`] that was updated
180 funding_txo: crate::lightning::chain::transaction::OutPoint,
181 /// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
182 /// [`ChannelMonitor::get_latest_update_id`].
184 /// Note that this should only be set to a given update's ID if all previous updates for the
185 /// same [`ChannelMonitor`] have been applied and persisted.
186 monitor_update_id: u64,
188 /// Indicates a [`ChannelMonitor`] update has failed. See
189 /// [`ChannelMonitorUpdateErr::PermanentFailure`] for more information on how this is used.
191 /// [`ChannelMonitorUpdateErr::PermanentFailure`]: super::ChannelMonitorUpdateErr::PermanentFailure
193 crate::lightning::chain::transaction::OutPoint),
195 use lightning::chain::channelmonitor::MonitorEvent as MonitorEventImport;
196 pub(crate) type nativeMonitorEvent = MonitorEventImport;
200 pub(crate) fn to_native(&self) -> nativeMonitorEvent {
202 MonitorEvent::HTLCEvent (ref a, ) => {
203 let mut a_nonref = (*a).clone();
204 nativeMonitorEvent::HTLCEvent (
205 *unsafe { Box::from_raw(a_nonref.take_inner()) },
208 MonitorEvent::CommitmentTxConfirmed (ref a, ) => {
209 let mut a_nonref = (*a).clone();
210 nativeMonitorEvent::CommitmentTxConfirmed (
211 *unsafe { Box::from_raw(a_nonref.take_inner()) },
214 MonitorEvent::UpdateCompleted {ref funding_txo, ref monitor_update_id, } => {
215 let mut funding_txo_nonref = (*funding_txo).clone();
216 let mut monitor_update_id_nonref = (*monitor_update_id).clone();
217 nativeMonitorEvent::UpdateCompleted {
218 funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
219 monitor_update_id: monitor_update_id_nonref,
222 MonitorEvent::UpdateFailed (ref a, ) => {
223 let mut a_nonref = (*a).clone();
224 nativeMonitorEvent::UpdateFailed (
225 *unsafe { Box::from_raw(a_nonref.take_inner()) },
231 pub(crate) fn into_native(self) -> nativeMonitorEvent {
233 MonitorEvent::HTLCEvent (mut a, ) => {
234 nativeMonitorEvent::HTLCEvent (
235 *unsafe { Box::from_raw(a.take_inner()) },
238 MonitorEvent::CommitmentTxConfirmed (mut a, ) => {
239 nativeMonitorEvent::CommitmentTxConfirmed (
240 *unsafe { Box::from_raw(a.take_inner()) },
243 MonitorEvent::UpdateCompleted {mut funding_txo, mut monitor_update_id, } => {
244 nativeMonitorEvent::UpdateCompleted {
245 funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
246 monitor_update_id: monitor_update_id,
249 MonitorEvent::UpdateFailed (mut a, ) => {
250 nativeMonitorEvent::UpdateFailed (
251 *unsafe { Box::from_raw(a.take_inner()) },
257 pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self {
259 nativeMonitorEvent::HTLCEvent (ref a, ) => {
260 let mut a_nonref = (*a).clone();
261 MonitorEvent::HTLCEvent (
262 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
265 nativeMonitorEvent::CommitmentTxConfirmed (ref a, ) => {
266 let mut a_nonref = (*a).clone();
267 MonitorEvent::CommitmentTxConfirmed (
268 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
271 nativeMonitorEvent::UpdateCompleted {ref funding_txo, ref monitor_update_id, } => {
272 let mut funding_txo_nonref = (*funding_txo).clone();
273 let mut monitor_update_id_nonref = (*monitor_update_id).clone();
274 MonitorEvent::UpdateCompleted {
275 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
276 monitor_update_id: monitor_update_id_nonref,
279 nativeMonitorEvent::UpdateFailed (ref a, ) => {
280 let mut a_nonref = (*a).clone();
281 MonitorEvent::UpdateFailed (
282 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
288 pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
290 nativeMonitorEvent::HTLCEvent (mut a, ) => {
291 MonitorEvent::HTLCEvent (
292 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true },
295 nativeMonitorEvent::CommitmentTxConfirmed (mut a, ) => {
296 MonitorEvent::CommitmentTxConfirmed (
297 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
300 nativeMonitorEvent::UpdateCompleted {mut funding_txo, mut monitor_update_id, } => {
301 MonitorEvent::UpdateCompleted {
302 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true },
303 monitor_update_id: monitor_update_id,
306 nativeMonitorEvent::UpdateFailed (mut a, ) => {
307 MonitorEvent::UpdateFailed (
308 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
314 /// Frees any resources used by the MonitorEvent
316 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
317 /// Creates a copy of the MonitorEvent
319 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
323 /// Utility method to constructs a new HTLCEvent-variant MonitorEvent
324 pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent {
325 MonitorEvent::HTLCEvent(a, )
328 /// Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
329 pub extern "C" fn MonitorEvent_commitment_tx_confirmed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
330 MonitorEvent::CommitmentTxConfirmed(a, )
333 /// Utility method to constructs a new UpdateCompleted-variant MonitorEvent
334 pub extern "C" fn MonitorEvent_update_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, monitor_update_id: u64) -> MonitorEvent {
335 MonitorEvent::UpdateCompleted {
341 /// Utility method to constructs a new UpdateFailed-variant MonitorEvent
342 pub extern "C" fn MonitorEvent_update_failed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
343 MonitorEvent::UpdateFailed(a, )
346 /// Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
347 pub extern "C" fn MonitorEvent_write(obj: &crate::lightning::chain::channelmonitor::MonitorEvent) -> crate::c_types::derived::CVec_u8Z {
348 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
351 /// Read a MonitorEvent from a byte array, created by MonitorEvent_write
352 pub extern "C" fn MonitorEvent_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_MonitorEventZDecodeErrorZ {
353 let res: Result<Option<lightning::chain::channelmonitor::MonitorEvent>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
354 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
358 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
359 pub(crate) type nativeHTLCUpdate = nativeHTLCUpdateImport;
361 /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
362 /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
363 /// preimage claim backward will lead to loss of funds.
366 pub struct HTLCUpdate {
367 /// A pointer to the opaque Rust object.
369 /// Nearly everywhere, inner must be non-null, however in places where
370 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
371 pub inner: *mut nativeHTLCUpdate,
372 /// Indicates that this is the only struct which contains the same pointer.
374 /// Rust functions which take ownership of an object provided via an argument require
375 /// this to be true and invalidate the object pointed to by inner.
379 impl Drop for HTLCUpdate {
381 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
382 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
386 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
388 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
390 /// Used only if an object of this type is returned as a trait impl by a method
391 pub(crate) extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
392 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCUpdate); }
396 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCUpdate {
397 unsafe { &*ObjOps::untweak_ptr(self.inner) }
399 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCUpdate {
400 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
402 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
403 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
404 assert!(self.is_owned);
405 let ret = ObjOps::untweak_ptr(self.inner);
406 self.inner = core::ptr::null_mut();
410 impl Clone for HTLCUpdate {
411 fn clone(&self) -> Self {
413 inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
414 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
420 /// Used only if an object of this type is returned as a trait impl by a method
421 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
422 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void
425 /// Creates a copy of the HTLCUpdate
426 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
430 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
431 pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
432 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
435 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
436 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
439 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
440 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
441 let res: Result<lightning::chain::channelmonitor::HTLCUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
442 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
445 /// Number of blocks we wait on seeing a HTLC output being solved before we fail corresponding
446 /// inbound HTLCs. This prevents us from failing backwards and then getting a reorg resulting in us
449 /// Note that this is a library-wide security assumption. If a reorg deeper than this number of
450 /// blocks occurs, counterparties may be able to steal funds or claims made by and balances exposed
451 /// by a [`ChannelMonitor`] may be incorrect.
454 pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
455 /// Details about the balance(s) available for spending once the channel appears on chain.
457 /// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
463 /// The channel is not yet closed (or the commitment or closing transaction has not yet
464 /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
465 /// force-closed now.
466 ClaimableOnChannelClose {
467 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
468 /// required to do so.
469 claimable_amount_satoshis: u64,
471 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
472 /// we consider it spendable.
473 ClaimableAwaitingConfirmations {
474 /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
475 /// were spent in broadcasting the transaction.
476 claimable_amount_satoshis: u64,
477 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
479 confirmation_height: u32,
481 /// The channel has been closed, and the given balance should be ours but awaiting spending
482 /// transaction confirmation. If the spending transaction does not confirm in time, it is
483 /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
485 /// Once the spending transaction confirms, before it has reached enough confirmations to be
486 /// considered safe from chain reorganizations, the balance will instead be provided via
487 /// [`Balance::ClaimableAwaitingConfirmations`].
488 ContentiousClaimable {
489 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
490 /// required to do so.
491 claimable_amount_satoshis: u64,
492 /// The height at which the counterparty may be able to claim the balance if we have not
496 /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
497 /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
498 /// likely to be claimed by our counterparty before we do.
499 MaybeTimeoutClaimableHTLC {
500 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
501 /// which will be required to do so.
502 claimable_amount_satoshis: u64,
503 /// The height at which we will be able to claim the balance if our counterparty has not
505 claimable_height: u32,
507 /// HTLCs which we received from our counterparty which are claimable with a preimage which we
508 /// do not currently have. This will only be claimable if we receive the preimage from the node
509 /// to which we forwarded this HTLC before the timeout.
510 MaybePreimageClaimableHTLC {
511 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
512 /// which will be required to do so.
513 claimable_amount_satoshis: u64,
514 /// The height at which our counterparty will be able to claim the balance if we have not
515 /// yet received the preimage and claimed it ourselves.
518 /// The channel has been closed, and our counterparty broadcasted a revoked commitment
521 /// Thus, we're able to claim all outputs in the commitment transaction, one of which has the
522 /// following amount.
523 CounterpartyRevokedOutputClaimable {
524 /// The amount, in satoshis, of the output which we can claim.
526 /// Note that for outputs from HTLC balances this may be excluding some on-chain fees that
527 /// were already spent.
528 claimable_amount_satoshis: u64,
531 use lightning::chain::channelmonitor::Balance as BalanceImport;
532 pub(crate) type nativeBalance = BalanceImport;
536 pub(crate) fn to_native(&self) -> nativeBalance {
538 Balance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
539 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
540 nativeBalance::ClaimableOnChannelClose {
541 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
544 Balance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
545 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
546 let mut confirmation_height_nonref = (*confirmation_height).clone();
547 nativeBalance::ClaimableAwaitingConfirmations {
548 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
549 confirmation_height: confirmation_height_nonref,
552 Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
553 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
554 let mut timeout_height_nonref = (*timeout_height).clone();
555 nativeBalance::ContentiousClaimable {
556 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
557 timeout_height: timeout_height_nonref,
560 Balance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
561 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
562 let mut claimable_height_nonref = (*claimable_height).clone();
563 nativeBalance::MaybeTimeoutClaimableHTLC {
564 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
565 claimable_height: claimable_height_nonref,
568 Balance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
569 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
570 let mut expiry_height_nonref = (*expiry_height).clone();
571 nativeBalance::MaybePreimageClaimableHTLC {
572 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
573 expiry_height: expiry_height_nonref,
576 Balance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
577 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
578 nativeBalance::CounterpartyRevokedOutputClaimable {
579 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
585 pub(crate) fn into_native(self) -> nativeBalance {
587 Balance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
588 nativeBalance::ClaimableOnChannelClose {
589 claimable_amount_satoshis: claimable_amount_satoshis,
592 Balance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
593 nativeBalance::ClaimableAwaitingConfirmations {
594 claimable_amount_satoshis: claimable_amount_satoshis,
595 confirmation_height: confirmation_height,
598 Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
599 nativeBalance::ContentiousClaimable {
600 claimable_amount_satoshis: claimable_amount_satoshis,
601 timeout_height: timeout_height,
604 Balance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
605 nativeBalance::MaybeTimeoutClaimableHTLC {
606 claimable_amount_satoshis: claimable_amount_satoshis,
607 claimable_height: claimable_height,
610 Balance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
611 nativeBalance::MaybePreimageClaimableHTLC {
612 claimable_amount_satoshis: claimable_amount_satoshis,
613 expiry_height: expiry_height,
616 Balance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
617 nativeBalance::CounterpartyRevokedOutputClaimable {
618 claimable_amount_satoshis: claimable_amount_satoshis,
624 pub(crate) fn from_native(native: &nativeBalance) -> Self {
626 nativeBalance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
627 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
628 Balance::ClaimableOnChannelClose {
629 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
632 nativeBalance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
633 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
634 let mut confirmation_height_nonref = (*confirmation_height).clone();
635 Balance::ClaimableAwaitingConfirmations {
636 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
637 confirmation_height: confirmation_height_nonref,
640 nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
641 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
642 let mut timeout_height_nonref = (*timeout_height).clone();
643 Balance::ContentiousClaimable {
644 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
645 timeout_height: timeout_height_nonref,
648 nativeBalance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
649 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
650 let mut claimable_height_nonref = (*claimable_height).clone();
651 Balance::MaybeTimeoutClaimableHTLC {
652 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
653 claimable_height: claimable_height_nonref,
656 nativeBalance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
657 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
658 let mut expiry_height_nonref = (*expiry_height).clone();
659 Balance::MaybePreimageClaimableHTLC {
660 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
661 expiry_height: expiry_height_nonref,
664 nativeBalance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
665 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
666 Balance::CounterpartyRevokedOutputClaimable {
667 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
673 pub(crate) fn native_into(native: nativeBalance) -> Self {
675 nativeBalance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
676 Balance::ClaimableOnChannelClose {
677 claimable_amount_satoshis: claimable_amount_satoshis,
680 nativeBalance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
681 Balance::ClaimableAwaitingConfirmations {
682 claimable_amount_satoshis: claimable_amount_satoshis,
683 confirmation_height: confirmation_height,
686 nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
687 Balance::ContentiousClaimable {
688 claimable_amount_satoshis: claimable_amount_satoshis,
689 timeout_height: timeout_height,
692 nativeBalance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
693 Balance::MaybeTimeoutClaimableHTLC {
694 claimable_amount_satoshis: claimable_amount_satoshis,
695 claimable_height: claimable_height,
698 nativeBalance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
699 Balance::MaybePreimageClaimableHTLC {
700 claimable_amount_satoshis: claimable_amount_satoshis,
701 expiry_height: expiry_height,
704 nativeBalance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
705 Balance::CounterpartyRevokedOutputClaimable {
706 claimable_amount_satoshis: claimable_amount_satoshis,
712 /// Frees any resources used by the Balance
714 pub extern "C" fn Balance_free(this_ptr: Balance) { }
715 /// Creates a copy of the Balance
717 pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
721 /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
722 pub extern "C" fn Balance_claimable_on_channel_close(claimable_amount_satoshis: u64) -> Balance {
723 Balance::ClaimableOnChannelClose {
724 claimable_amount_satoshis,
728 /// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
729 pub extern "C" fn Balance_claimable_awaiting_confirmations(claimable_amount_satoshis: u64, confirmation_height: u32) -> Balance {
730 Balance::ClaimableAwaitingConfirmations {
731 claimable_amount_satoshis,
736 /// Utility method to constructs a new ContentiousClaimable-variant Balance
737 pub extern "C" fn Balance_contentious_claimable(claimable_amount_satoshis: u64, timeout_height: u32) -> Balance {
738 Balance::ContentiousClaimable {
739 claimable_amount_satoshis,
744 /// Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
745 pub extern "C" fn Balance_maybe_timeout_claimable_htlc(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
746 Balance::MaybeTimeoutClaimableHTLC {
747 claimable_amount_satoshis,
752 /// Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
753 pub extern "C" fn Balance_maybe_preimage_claimable_htlc(claimable_amount_satoshis: u64, expiry_height: u32) -> Balance {
754 Balance::MaybePreimageClaimableHTLC {
755 claimable_amount_satoshis,
760 /// Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
761 pub extern "C" fn Balance_counterparty_revoked_output_claimable(claimable_amount_satoshis: u64) -> Balance {
762 Balance::CounterpartyRevokedOutputClaimable {
763 claimable_amount_satoshis,
766 /// Checks if two Balances contain equal inner contents.
767 /// This ignores pointers and is_owned flags and looks at the values in fields.
769 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
770 if &a.to_native() == &b.to_native() { true } else { false }
773 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
774 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::chain::keysinterface::Sign>;
776 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
777 /// on-chain transactions to ensure no loss of funds occurs.
779 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
780 /// information and are actively monitoring the chain.
782 /// Pending Events or updated HTLCs which have not yet been read out by
783 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
784 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
785 /// gotten are fully handled before re-serializing the new state.
787 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
788 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
789 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
790 /// returned block hash and the the current chain and then reconnecting blocks to get to the
791 /// best chain) upon deserializing the object!
794 pub struct ChannelMonitor {
795 /// A pointer to the opaque Rust object.
797 /// Nearly everywhere, inner must be non-null, however in places where
798 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
799 pub inner: *mut nativeChannelMonitor,
800 /// Indicates that this is the only struct which contains the same pointer.
802 /// Rust functions which take ownership of an object provided via an argument require
803 /// this to be true and invalidate the object pointed to by inner.
807 impl Drop for ChannelMonitor {
809 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
810 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
814 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
816 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
818 /// Used only if an object of this type is returned as a trait impl by a method
819 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
820 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitor); }
823 impl ChannelMonitor {
824 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
825 unsafe { &*ObjOps::untweak_ptr(self.inner) }
827 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
828 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
830 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
831 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
832 assert!(self.is_owned);
833 let ret = ObjOps::untweak_ptr(self.inner);
834 self.inner = core::ptr::null_mut();
839 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
840 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
841 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
844 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
845 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
847 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
850 /// panics if the given update is not the next update by update_id.
853 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 {
854 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
855 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() };
859 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
863 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
864 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
868 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
871 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
872 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
873 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();
877 /// Gets a list of txids, with their output scripts (in the order they appear in the
878 /// transaction), which we must learn about spends of via block_connected().
881 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 {
882 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
883 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 }); };
887 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
888 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
889 /// have been registered.
891 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter) {
892 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter)
895 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
896 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
899 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
900 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
901 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
905 /// Gets the list of pending events which were generated by previous actions, clearing the list
908 /// This is called by ChainMonitor::get_and_clear_pending_events() and is equivalent to
909 /// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do
910 /// no internal locking in ChannelMonitors.
913 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
914 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_events();
915 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::Event::native_into(item) }); };
919 /// Gets the `node_id` of the counterparty for this channel.
921 /// Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
924 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
927 pub extern "C" fn ChannelMonitor_get_counterparty_node_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::PublicKey {
928 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_counterparty_node_id();
929 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
933 /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
934 /// the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of
935 /// fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows
936 /// a higher revocation secret than the holder commitment number we are aware of. Broadcasting these
937 /// transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to
938 /// broadcast them if counterparty don't close channel with his higher commitment transaction after a
939 /// substantial amount of time (a month or even a year) to get back funds. Best may be to contact
940 /// out-of-band the other node operator to coordinate with him if option is available to you.
941 /// In any-case, choice is up to the user.
944 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 {
945 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger);
946 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); };
950 /// Processes transactions in a newly connected block, which may result in any of the following:
951 /// - update the monitor's state against resolved HTLCs
952 /// - punish the counterparty in the case of seeing a revoked commitment transaction
953 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
954 /// - detect settled outputs for later spending
955 /// - schedule and bump any in-flight claims
957 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
958 /// [`get_outputs_to_watch`].
960 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
963 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 {
964 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 }); };
965 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);
966 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 }); };
970 /// Determines if the disconnected block contained any transactions of interest and updates
973 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) {
974 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
977 /// Processes transactions confirmed in a block with the given header and height, returning new
978 /// outputs to watch. See [`block_connected`] for details.
980 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
981 /// blocks. See [`chain::Confirm`] for calling expectations.
983 /// [`block_connected`]: Self::block_connected
986 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 {
987 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 }); };
988 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);
989 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 }); };
993 /// Processes a transaction that was reorganized out of the chain.
995 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
996 /// than blocks. See [`chain::Confirm`] for calling expectations.
998 /// [`block_disconnected`]: Self::block_disconnected
1000 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) {
1001 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
1004 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
1005 /// [`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_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 {
1014 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);
1015 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 }); };
1019 /// Returns the set of txids that should be monitored for re-organization out of the chain.
1022 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_TxidZ {
1023 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
1024 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
1028 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1029 /// [`chain::Confirm`] interfaces.
1032 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
1033 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1034 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1037 /// Gets the balances in this channel which are either claimable by us if we were to
1038 /// force-close the channel now or which are claimable on-chain (possibly awaiting
1041 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
1042 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
1043 /// balance, or until our counterparty has claimed the balance and accrued several
1044 /// confirmations on the claim transaction.
1046 /// Note that for `ChannelMonitors` which track a channel which went on-chain with versions of
1047 /// LDK prior to 0.0.111, balances may not be fully captured if our counterparty broadcasted
1048 /// a revoked state.
1050 /// See [`Balance`] for additional details on the types of claimable balances which
1051 /// may be returned here and their meanings.
1054 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
1055 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
1056 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
1061 /// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
1062 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 {
1064 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);
1065 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };