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.
38 pub struct ChannelMonitorUpdate {
39 /// A pointer to the opaque Rust object.
41 /// Nearly everywhere, inner must be non-null, however in places where
42 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
43 pub inner: *mut nativeChannelMonitorUpdate,
44 /// Indicates that this is the only struct which contains the same pointer.
46 /// Rust functions which take ownership of an object provided via an argument require
47 /// this to be true and invalidate the object pointed to by inner.
51 impl Drop for ChannelMonitorUpdate {
53 if self.is_owned && !<*mut nativeChannelMonitorUpdate>::is_null(self.inner) {
54 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
58 /// Frees any resources used by the ChannelMonitorUpdate, if is_owned is set and inner is non-NULL.
60 pub extern "C" fn ChannelMonitorUpdate_free(this_obj: ChannelMonitorUpdate) { }
62 /// Used only if an object of this type is returned as a trait impl by a method
63 pub(crate) extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
64 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate); }
67 impl ChannelMonitorUpdate {
68 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitorUpdate {
69 unsafe { &*ObjOps::untweak_ptr(self.inner) }
71 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitorUpdate {
72 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
74 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
75 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitorUpdate {
76 assert!(self.is_owned);
77 let ret = ObjOps::untweak_ptr(self.inner);
78 self.inner = core::ptr::null_mut();
82 /// The sequence number of this update. Updates *must* be replayed in-order according to this
83 /// sequence number (and updates may panic if they are not). The update_id values are strictly
84 /// increasing and increase by one for each new update, with one exception specified below.
86 /// This sequence number is also used to track up to which points updates which returned
87 /// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given
88 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
90 /// The only instance where update_id values are not strictly increasing is the case where we
91 /// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
92 /// its docs for more details.
94 pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 {
95 let mut inner_val = &mut this_ptr.get_native_mut_ref().update_id;
98 /// The sequence number of this update. Updates *must* be replayed in-order according to this
99 /// sequence number (and updates may panic if they are not). The update_id values are strictly
100 /// increasing and increase by one for each new update, with one exception specified below.
102 /// This sequence number is also used to track up to which points updates which returned
103 /// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given
104 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
106 /// The only instance where update_id values are not strictly increasing is the case where we
107 /// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
108 /// its docs for more details.
110 pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) {
111 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_id = val;
113 impl Clone for ChannelMonitorUpdate {
114 fn clone(&self) -> Self {
116 inner: if <*mut nativeChannelMonitorUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
117 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
123 /// Used only if an object of this type is returned as a trait impl by a method
124 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
125 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void
128 /// Creates a copy of the ChannelMonitorUpdate
129 pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
133 /// (1) a channel has been force closed and
134 /// (2) we receive a preimage from a forward link that allows us to spend an HTLC output on
135 /// this channel's (the backward link's) broadcasted commitment transaction
136 /// then we allow the `ChannelManager` to send a `ChannelMonitorUpdate` with this update ID,
137 /// with the update providing said payment preimage. No other update types are allowed after
141 pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
143 /// Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read
144 pub extern "C" fn ChannelMonitorUpdate_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
145 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
148 pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
149 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) })
152 /// Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write
153 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ {
154 let res: Result<lightning::chain::channelmonitor::ChannelMonitorUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
155 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() };
158 /// An event to be processed by the ChannelManager.
162 pub enum MonitorEvent {
163 /// A monitor event containing an HTLCUpdate.
164 HTLCEvent(crate::lightning::chain::channelmonitor::HTLCUpdate),
165 /// A monitor event that the Channel's commitment transaction was confirmed.
166 CommitmentTxConfirmed(crate::lightning::chain::transaction::OutPoint),
167 /// Indicates a [`ChannelMonitor`] update has completed. See
168 /// [`ChannelMonitorUpdateErr::TemporaryFailure`] for more information on how this is used.
170 /// [`ChannelMonitorUpdateErr::TemporaryFailure`]: super::ChannelMonitorUpdateErr::TemporaryFailure
172 /// The funding outpoint of the [`ChannelMonitor`] that was updated
173 funding_txo: crate::lightning::chain::transaction::OutPoint,
174 /// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
175 /// [`ChannelMonitor::get_latest_update_id`].
177 /// Note that this should only be set to a given update's ID if all previous updates for the
178 /// same [`ChannelMonitor`] have been applied and persisted.
179 monitor_update_id: u64,
181 /// Indicates a [`ChannelMonitor`] update has failed. See
182 /// [`ChannelMonitorUpdateErr::PermanentFailure`] for more information on how this is used.
184 /// [`ChannelMonitorUpdateErr::PermanentFailure`]: super::ChannelMonitorUpdateErr::PermanentFailure
185 UpdateFailed(crate::lightning::chain::transaction::OutPoint),
187 use lightning::chain::channelmonitor::MonitorEvent as nativeMonitorEvent;
190 pub(crate) fn to_native(&self) -> nativeMonitorEvent {
192 MonitorEvent::HTLCEvent (ref a, ) => {
193 let mut a_nonref = (*a).clone();
194 nativeMonitorEvent::HTLCEvent (
195 *unsafe { Box::from_raw(a_nonref.take_inner()) },
198 MonitorEvent::CommitmentTxConfirmed (ref a, ) => {
199 let mut a_nonref = (*a).clone();
200 nativeMonitorEvent::CommitmentTxConfirmed (
201 *unsafe { Box::from_raw(a_nonref.take_inner()) },
204 MonitorEvent::UpdateCompleted {ref funding_txo, ref monitor_update_id, } => {
205 let mut funding_txo_nonref = (*funding_txo).clone();
206 let mut monitor_update_id_nonref = (*monitor_update_id).clone();
207 nativeMonitorEvent::UpdateCompleted {
208 funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
209 monitor_update_id: monitor_update_id_nonref,
212 MonitorEvent::UpdateFailed (ref a, ) => {
213 let mut a_nonref = (*a).clone();
214 nativeMonitorEvent::UpdateFailed (
215 *unsafe { Box::from_raw(a_nonref.take_inner()) },
221 pub(crate) fn into_native(self) -> nativeMonitorEvent {
223 MonitorEvent::HTLCEvent (mut a, ) => {
224 nativeMonitorEvent::HTLCEvent (
225 *unsafe { Box::from_raw(a.take_inner()) },
228 MonitorEvent::CommitmentTxConfirmed (mut a, ) => {
229 nativeMonitorEvent::CommitmentTxConfirmed (
230 *unsafe { Box::from_raw(a.take_inner()) },
233 MonitorEvent::UpdateCompleted {mut funding_txo, mut monitor_update_id, } => {
234 nativeMonitorEvent::UpdateCompleted {
235 funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
236 monitor_update_id: monitor_update_id,
239 MonitorEvent::UpdateFailed (mut a, ) => {
240 nativeMonitorEvent::UpdateFailed (
241 *unsafe { Box::from_raw(a.take_inner()) },
247 pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self {
249 nativeMonitorEvent::HTLCEvent (ref a, ) => {
250 let mut a_nonref = (*a).clone();
251 MonitorEvent::HTLCEvent (
252 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
255 nativeMonitorEvent::CommitmentTxConfirmed (ref a, ) => {
256 let mut a_nonref = (*a).clone();
257 MonitorEvent::CommitmentTxConfirmed (
258 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
261 nativeMonitorEvent::UpdateCompleted {ref funding_txo, ref monitor_update_id, } => {
262 let mut funding_txo_nonref = (*funding_txo).clone();
263 let mut monitor_update_id_nonref = (*monitor_update_id).clone();
264 MonitorEvent::UpdateCompleted {
265 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
266 monitor_update_id: monitor_update_id_nonref,
269 nativeMonitorEvent::UpdateFailed (ref a, ) => {
270 let mut a_nonref = (*a).clone();
271 MonitorEvent::UpdateFailed (
272 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
278 pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
280 nativeMonitorEvent::HTLCEvent (mut a, ) => {
281 MonitorEvent::HTLCEvent (
282 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true },
285 nativeMonitorEvent::CommitmentTxConfirmed (mut a, ) => {
286 MonitorEvent::CommitmentTxConfirmed (
287 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
290 nativeMonitorEvent::UpdateCompleted {mut funding_txo, mut monitor_update_id, } => {
291 MonitorEvent::UpdateCompleted {
292 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true },
293 monitor_update_id: monitor_update_id,
296 nativeMonitorEvent::UpdateFailed (mut a, ) => {
297 MonitorEvent::UpdateFailed (
298 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
304 /// Frees any resources used by the MonitorEvent
306 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
307 /// Creates a copy of the MonitorEvent
309 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
313 /// Utility method to constructs a new HTLCEvent-variant MonitorEvent
314 pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent {
315 MonitorEvent::HTLCEvent(a, )
318 /// Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
319 pub extern "C" fn MonitorEvent_commitment_tx_confirmed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
320 MonitorEvent::CommitmentTxConfirmed(a, )
323 /// Utility method to constructs a new UpdateCompleted-variant MonitorEvent
324 pub extern "C" fn MonitorEvent_update_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, monitor_update_id: u64) -> MonitorEvent {
325 MonitorEvent::UpdateCompleted {
331 /// Utility method to constructs a new UpdateFailed-variant MonitorEvent
332 pub extern "C" fn MonitorEvent_update_failed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
333 MonitorEvent::UpdateFailed(a, )
336 /// Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
337 pub extern "C" fn MonitorEvent_write(obj: &crate::lightning::chain::channelmonitor::MonitorEvent) -> crate::c_types::derived::CVec_u8Z {
338 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
341 /// Read a MonitorEvent from a byte array, created by MonitorEvent_write
342 pub extern "C" fn MonitorEvent_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_MonitorEventZDecodeErrorZ {
343 let res: Result<Option<lightning::chain::channelmonitor::MonitorEvent>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
344 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() };
348 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
349 pub(crate) type nativeHTLCUpdate = nativeHTLCUpdateImport;
351 /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
352 /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
353 /// preimage claim backward will lead to loss of funds.
356 pub struct HTLCUpdate {
357 /// A pointer to the opaque Rust object.
359 /// Nearly everywhere, inner must be non-null, however in places where
360 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
361 pub inner: *mut nativeHTLCUpdate,
362 /// Indicates that this is the only struct which contains the same pointer.
364 /// Rust functions which take ownership of an object provided via an argument require
365 /// this to be true and invalidate the object pointed to by inner.
369 impl Drop for HTLCUpdate {
371 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
372 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
376 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
378 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
380 /// Used only if an object of this type is returned as a trait impl by a method
381 pub(crate) extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
382 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCUpdate); }
386 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCUpdate {
387 unsafe { &*ObjOps::untweak_ptr(self.inner) }
389 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCUpdate {
390 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
392 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
393 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
394 assert!(self.is_owned);
395 let ret = ObjOps::untweak_ptr(self.inner);
396 self.inner = core::ptr::null_mut();
400 impl Clone for HTLCUpdate {
401 fn clone(&self) -> Self {
403 inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
404 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
410 /// Used only if an object of this type is returned as a trait impl by a method
411 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
412 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void
415 /// Creates a copy of the HTLCUpdate
416 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
420 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
421 pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
422 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
425 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
426 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
429 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
430 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
431 let res: Result<lightning::chain::channelmonitor::HTLCUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
432 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() };
435 /// Number of blocks we wait on seeing a HTLC output being solved before we fail corresponding
436 /// inbound HTLCs. This prevents us from failing backwards and then getting a reorg resulting in us
439 /// Note that this is a library-wide security assumption. If a reorg deeper than this number of
440 /// blocks occurs, counterparties may be able to steal funds or claims made by and balances exposed
441 /// by a [`ChannelMonitor`] may be incorrect.
444 pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
445 /// Details about the balance(s) available for spending once the channel appears on chain.
447 /// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
453 /// The channel is not yet closed (or the commitment or closing transaction has not yet
454 /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
455 /// force-closed now.
456 ClaimableOnChannelClose {
457 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
458 /// required to do so.
459 claimable_amount_satoshis: u64,
461 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
462 /// we consider it spendable.
463 ClaimableAwaitingConfirmations {
464 /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
465 /// were spent in broadcasting the transaction.
466 claimable_amount_satoshis: u64,
467 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
469 confirmation_height: u32,
471 /// The channel has been closed, and the given balance should be ours but awaiting spending
472 /// transaction confirmation. If the spending transaction does not confirm in time, it is
473 /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
475 /// Once the spending transaction confirms, before it has reached enough confirmations to be
476 /// considered safe from chain reorganizations, the balance will instead be provided via
477 /// [`Balance::ClaimableAwaitingConfirmations`].
478 ContentiousClaimable {
479 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
480 /// required to do so.
481 claimable_amount_satoshis: u64,
482 /// The height at which the counterparty may be able to claim the balance if we have not
486 /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
487 /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
488 /// likely to be claimed by our counterparty before we do.
489 MaybeClaimableHTLCAwaitingTimeout {
490 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
491 /// required to do so.
492 claimable_amount_satoshis: u64,
493 /// The height at which we will be able to claim the balance if our counterparty has not
495 claimable_height: u32,
498 use lightning::chain::channelmonitor::Balance as nativeBalance;
501 pub(crate) fn to_native(&self) -> nativeBalance {
503 Balance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
504 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
505 nativeBalance::ClaimableOnChannelClose {
506 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
509 Balance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
510 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
511 let mut confirmation_height_nonref = (*confirmation_height).clone();
512 nativeBalance::ClaimableAwaitingConfirmations {
513 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
514 confirmation_height: confirmation_height_nonref,
517 Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
518 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
519 let mut timeout_height_nonref = (*timeout_height).clone();
520 nativeBalance::ContentiousClaimable {
521 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
522 timeout_height: timeout_height_nonref,
525 Balance::MaybeClaimableHTLCAwaitingTimeout {ref claimable_amount_satoshis, ref claimable_height, } => {
526 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
527 let mut claimable_height_nonref = (*claimable_height).clone();
528 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {
529 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
530 claimable_height: claimable_height_nonref,
536 pub(crate) fn into_native(self) -> nativeBalance {
538 Balance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
539 nativeBalance::ClaimableOnChannelClose {
540 claimable_amount_satoshis: claimable_amount_satoshis,
543 Balance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
544 nativeBalance::ClaimableAwaitingConfirmations {
545 claimable_amount_satoshis: claimable_amount_satoshis,
546 confirmation_height: confirmation_height,
549 Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
550 nativeBalance::ContentiousClaimable {
551 claimable_amount_satoshis: claimable_amount_satoshis,
552 timeout_height: timeout_height,
555 Balance::MaybeClaimableHTLCAwaitingTimeout {mut claimable_amount_satoshis, mut claimable_height, } => {
556 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {
557 claimable_amount_satoshis: claimable_amount_satoshis,
558 claimable_height: claimable_height,
564 pub(crate) fn from_native(native: &nativeBalance) -> Self {
566 nativeBalance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
567 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
568 Balance::ClaimableOnChannelClose {
569 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
572 nativeBalance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
573 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
574 let mut confirmation_height_nonref = (*confirmation_height).clone();
575 Balance::ClaimableAwaitingConfirmations {
576 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
577 confirmation_height: confirmation_height_nonref,
580 nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
581 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
582 let mut timeout_height_nonref = (*timeout_height).clone();
583 Balance::ContentiousClaimable {
584 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
585 timeout_height: timeout_height_nonref,
588 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {ref claimable_amount_satoshis, ref claimable_height, } => {
589 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
590 let mut claimable_height_nonref = (*claimable_height).clone();
591 Balance::MaybeClaimableHTLCAwaitingTimeout {
592 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
593 claimable_height: claimable_height_nonref,
599 pub(crate) fn native_into(native: nativeBalance) -> Self {
601 nativeBalance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
602 Balance::ClaimableOnChannelClose {
603 claimable_amount_satoshis: claimable_amount_satoshis,
606 nativeBalance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
607 Balance::ClaimableAwaitingConfirmations {
608 claimable_amount_satoshis: claimable_amount_satoshis,
609 confirmation_height: confirmation_height,
612 nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
613 Balance::ContentiousClaimable {
614 claimable_amount_satoshis: claimable_amount_satoshis,
615 timeout_height: timeout_height,
618 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {mut claimable_amount_satoshis, mut claimable_height, } => {
619 Balance::MaybeClaimableHTLCAwaitingTimeout {
620 claimable_amount_satoshis: claimable_amount_satoshis,
621 claimable_height: claimable_height,
627 /// Frees any resources used by the Balance
629 pub extern "C" fn Balance_free(this_ptr: Balance) { }
630 /// Creates a copy of the Balance
632 pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
636 /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
637 pub extern "C" fn Balance_claimable_on_channel_close(claimable_amount_satoshis: u64) -> Balance {
638 Balance::ClaimableOnChannelClose {
639 claimable_amount_satoshis,
643 /// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
644 pub extern "C" fn Balance_claimable_awaiting_confirmations(claimable_amount_satoshis: u64, confirmation_height: u32) -> Balance {
645 Balance::ClaimableAwaitingConfirmations {
646 claimable_amount_satoshis,
651 /// Utility method to constructs a new ContentiousClaimable-variant Balance
652 pub extern "C" fn Balance_contentious_claimable(claimable_amount_satoshis: u64, timeout_height: u32) -> Balance {
653 Balance::ContentiousClaimable {
654 claimable_amount_satoshis,
659 /// Utility method to constructs a new MaybeClaimableHTLCAwaitingTimeout-variant Balance
660 pub extern "C" fn Balance_maybe_claimable_htlcawaiting_timeout(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
661 Balance::MaybeClaimableHTLCAwaitingTimeout {
662 claimable_amount_satoshis,
666 /// Checks if two Balances contain equal inner contents.
667 /// This ignores pointers and is_owned flags and looks at the values in fields.
669 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
670 if &a.to_native() == &b.to_native() { true } else { false }
673 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
674 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::chain::keysinterface::Sign>;
676 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
677 /// on-chain transactions to ensure no loss of funds occurs.
679 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
680 /// information and are actively monitoring the chain.
682 /// Pending Events or updated HTLCs which have not yet been read out by
683 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
684 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
685 /// gotten are fully handled before re-serializing the new state.
687 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
688 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
689 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
690 /// returned block hash and the the current chain and then reconnecting blocks to get to the
691 /// best chain) upon deserializing the object!
694 pub struct ChannelMonitor {
695 /// A pointer to the opaque Rust object.
697 /// Nearly everywhere, inner must be non-null, however in places where
698 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
699 pub inner: *mut nativeChannelMonitor,
700 /// Indicates that this is the only struct which contains the same pointer.
702 /// Rust functions which take ownership of an object provided via an argument require
703 /// this to be true and invalidate the object pointed to by inner.
707 impl Drop for ChannelMonitor {
709 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
710 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
714 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
716 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
718 /// Used only if an object of this type is returned as a trait impl by a method
719 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
720 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitor); }
723 impl ChannelMonitor {
724 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
725 unsafe { &*ObjOps::untweak_ptr(self.inner) }
727 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
728 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
730 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
731 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
732 assert!(self.is_owned);
733 let ret = ObjOps::untweak_ptr(self.inner);
734 self.inner = core::ptr::null_mut();
739 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
740 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
741 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
744 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
745 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
747 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
750 /// panics if the given update is not the next update by update_id.
753 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, fee_estimator: &crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NoneNoneZ {
754 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
755 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() };
759 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
763 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
764 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
768 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
771 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
772 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
773 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();
777 /// Gets a list of txids, with their output scripts (in the order they appear in the
778 /// transaction), which we must learn about spends of via block_connected().
781 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 {
782 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
783 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 }); };
787 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
788 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
789 /// have been registered.
791 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter) {
792 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter)
795 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
796 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
799 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
800 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
801 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
805 /// Gets the list of pending events which were generated by previous actions, clearing the list
808 /// This is called by ChainMonitor::get_and_clear_pending_events() and is equivalent to
809 /// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do
810 /// no internal locking in ChannelMonitors.
813 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
814 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_events();
815 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::Event::native_into(item) }); };
819 /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
820 /// the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of
821 /// fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows
822 /// a higher revocation secret than the holder commitment number we are aware of. Broadcasting these
823 /// transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to
824 /// broadcast them if counterparty don't close channel with his higher commitment transaction after a
825 /// substantial amount of time (a month or even a year) to get back funds. Best may be to contact
826 /// out-of-band the other node operator to coordinate with him if option is available to you.
827 /// In any-case, choice is up to the user.
830 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 {
831 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger);
832 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); };
836 /// Processes transactions in a newly connected block, which may result in any of the following:
837 /// - update the monitor's state against resolved HTLCs
838 /// - punish the counterparty in the case of seeing a revoked commitment transaction
839 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
840 /// - detect settled outputs for later spending
841 /// - schedule and bump any in-flight claims
843 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
844 /// [`get_outputs_to_watch`].
846 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
849 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 {
850 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 }); };
851 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);
852 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 }); };
856 /// Determines if the disconnected block contained any transactions of interest and updates
859 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) {
860 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
863 /// Processes transactions confirmed in a block with the given header and height, returning new
864 /// outputs to watch. See [`block_connected`] for details.
866 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
867 /// blocks. See [`chain::Confirm`] for calling expectations.
869 /// [`block_connected`]: Self::block_connected
872 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 {
873 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 }); };
874 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);
875 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 }); };
879 /// Processes a transaction that was reorganized out of the chain.
881 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
882 /// than blocks. See [`chain::Confirm`] for calling expectations.
884 /// [`block_disconnected`]: Self::block_disconnected
886 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) {
887 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
890 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
891 /// [`block_connected`] for details.
893 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
894 /// blocks. See [`chain::Confirm`] for calling expectations.
896 /// [`block_connected`]: Self::block_connected
899 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 {
900 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);
901 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 }); };
905 /// Returns the set of txids that should be monitored for re-organization out of the chain.
908 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_TxidZ {
909 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
910 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
914 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
915 /// [`chain::Confirm`] interfaces.
918 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
919 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
920 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
923 /// Gets the balances in this channel which are either claimable by us if we were to
924 /// force-close the channel now or which are claimable on-chain (possibly awaiting
927 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
928 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
929 /// balance, or until our counterparty has claimed the balance and accrued several
930 /// confirmations on the claim transaction.
932 /// Note that the balances available when you or your counterparty have broadcasted revoked
933 /// state(s) may not be fully captured here.
935 /// See [`Balance`] for additional details on the types of claimable balances which
936 /// may be returned here and their meanings.
939 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
940 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
941 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
946 /// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
947 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 {
949 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);
950 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() };