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.
165 crate::lightning::chain::channelmonitor::HTLCUpdate),
166 /// A monitor event that the Channel's commitment transaction was confirmed.
167 CommitmentTxConfirmed(
168 crate::lightning::chain::transaction::OutPoint),
169 /// Indicates a [`ChannelMonitor`] update has completed. See
170 /// [`ChannelMonitorUpdateErr::TemporaryFailure`] for more information on how this is used.
172 /// [`ChannelMonitorUpdateErr::TemporaryFailure`]: super::ChannelMonitorUpdateErr::TemporaryFailure
174 /// The funding outpoint of the [`ChannelMonitor`] that was updated
175 funding_txo: crate::lightning::chain::transaction::OutPoint,
176 /// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
177 /// [`ChannelMonitor::get_latest_update_id`].
179 /// Note that this should only be set to a given update's ID if all previous updates for the
180 /// same [`ChannelMonitor`] have been applied and persisted.
181 monitor_update_id: u64,
183 /// Indicates a [`ChannelMonitor`] update has failed. See
184 /// [`ChannelMonitorUpdateErr::PermanentFailure`] for more information on how this is used.
186 /// [`ChannelMonitorUpdateErr::PermanentFailure`]: super::ChannelMonitorUpdateErr::PermanentFailure
188 crate::lightning::chain::transaction::OutPoint),
190 use lightning::chain::channelmonitor::MonitorEvent as MonitorEventImport;
191 pub(crate) type nativeMonitorEvent = MonitorEventImport;
195 pub(crate) fn to_native(&self) -> nativeMonitorEvent {
197 MonitorEvent::HTLCEvent (ref a, ) => {
198 let mut a_nonref = (*a).clone();
199 nativeMonitorEvent::HTLCEvent (
200 *unsafe { Box::from_raw(a_nonref.take_inner()) },
203 MonitorEvent::CommitmentTxConfirmed (ref a, ) => {
204 let mut a_nonref = (*a).clone();
205 nativeMonitorEvent::CommitmentTxConfirmed (
206 *unsafe { Box::from_raw(a_nonref.take_inner()) },
209 MonitorEvent::UpdateCompleted {ref funding_txo, ref monitor_update_id, } => {
210 let mut funding_txo_nonref = (*funding_txo).clone();
211 let mut monitor_update_id_nonref = (*monitor_update_id).clone();
212 nativeMonitorEvent::UpdateCompleted {
213 funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
214 monitor_update_id: monitor_update_id_nonref,
217 MonitorEvent::UpdateFailed (ref a, ) => {
218 let mut a_nonref = (*a).clone();
219 nativeMonitorEvent::UpdateFailed (
220 *unsafe { Box::from_raw(a_nonref.take_inner()) },
226 pub(crate) fn into_native(self) -> nativeMonitorEvent {
228 MonitorEvent::HTLCEvent (mut a, ) => {
229 nativeMonitorEvent::HTLCEvent (
230 *unsafe { Box::from_raw(a.take_inner()) },
233 MonitorEvent::CommitmentTxConfirmed (mut a, ) => {
234 nativeMonitorEvent::CommitmentTxConfirmed (
235 *unsafe { Box::from_raw(a.take_inner()) },
238 MonitorEvent::UpdateCompleted {mut funding_txo, mut monitor_update_id, } => {
239 nativeMonitorEvent::UpdateCompleted {
240 funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
241 monitor_update_id: monitor_update_id,
244 MonitorEvent::UpdateFailed (mut a, ) => {
245 nativeMonitorEvent::UpdateFailed (
246 *unsafe { Box::from_raw(a.take_inner()) },
252 pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self {
254 nativeMonitorEvent::HTLCEvent (ref a, ) => {
255 let mut a_nonref = (*a).clone();
256 MonitorEvent::HTLCEvent (
257 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
260 nativeMonitorEvent::CommitmentTxConfirmed (ref a, ) => {
261 let mut a_nonref = (*a).clone();
262 MonitorEvent::CommitmentTxConfirmed (
263 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
266 nativeMonitorEvent::UpdateCompleted {ref funding_txo, ref monitor_update_id, } => {
267 let mut funding_txo_nonref = (*funding_txo).clone();
268 let mut monitor_update_id_nonref = (*monitor_update_id).clone();
269 MonitorEvent::UpdateCompleted {
270 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
271 monitor_update_id: monitor_update_id_nonref,
274 nativeMonitorEvent::UpdateFailed (ref a, ) => {
275 let mut a_nonref = (*a).clone();
276 MonitorEvent::UpdateFailed (
277 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
283 pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
285 nativeMonitorEvent::HTLCEvent (mut a, ) => {
286 MonitorEvent::HTLCEvent (
287 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true },
290 nativeMonitorEvent::CommitmentTxConfirmed (mut a, ) => {
291 MonitorEvent::CommitmentTxConfirmed (
292 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
295 nativeMonitorEvent::UpdateCompleted {mut funding_txo, mut monitor_update_id, } => {
296 MonitorEvent::UpdateCompleted {
297 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true },
298 monitor_update_id: monitor_update_id,
301 nativeMonitorEvent::UpdateFailed (mut a, ) => {
302 MonitorEvent::UpdateFailed (
303 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
309 /// Frees any resources used by the MonitorEvent
311 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
312 /// Creates a copy of the MonitorEvent
314 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
318 /// Utility method to constructs a new HTLCEvent-variant MonitorEvent
319 pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent {
320 MonitorEvent::HTLCEvent(a, )
323 /// Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
324 pub extern "C" fn MonitorEvent_commitment_tx_confirmed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
325 MonitorEvent::CommitmentTxConfirmed(a, )
328 /// Utility method to constructs a new UpdateCompleted-variant MonitorEvent
329 pub extern "C" fn MonitorEvent_update_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, monitor_update_id: u64) -> MonitorEvent {
330 MonitorEvent::UpdateCompleted {
336 /// Utility method to constructs a new UpdateFailed-variant MonitorEvent
337 pub extern "C" fn MonitorEvent_update_failed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
338 MonitorEvent::UpdateFailed(a, )
341 /// Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
342 pub extern "C" fn MonitorEvent_write(obj: &crate::lightning::chain::channelmonitor::MonitorEvent) -> crate::c_types::derived::CVec_u8Z {
343 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
346 /// Read a MonitorEvent from a byte array, created by MonitorEvent_write
347 pub extern "C" fn MonitorEvent_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_MonitorEventZDecodeErrorZ {
348 let res: Result<Option<lightning::chain::channelmonitor::MonitorEvent>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
349 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() };
353 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
354 pub(crate) type nativeHTLCUpdate = nativeHTLCUpdateImport;
356 /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
357 /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
358 /// preimage claim backward will lead to loss of funds.
361 pub struct HTLCUpdate {
362 /// A pointer to the opaque Rust object.
364 /// Nearly everywhere, inner must be non-null, however in places where
365 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
366 pub inner: *mut nativeHTLCUpdate,
367 /// Indicates that this is the only struct which contains the same pointer.
369 /// Rust functions which take ownership of an object provided via an argument require
370 /// this to be true and invalidate the object pointed to by inner.
374 impl Drop for HTLCUpdate {
376 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
377 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
381 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
383 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
385 /// Used only if an object of this type is returned as a trait impl by a method
386 pub(crate) extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
387 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCUpdate); }
391 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCUpdate {
392 unsafe { &*ObjOps::untweak_ptr(self.inner) }
394 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCUpdate {
395 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
397 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
398 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
399 assert!(self.is_owned);
400 let ret = ObjOps::untweak_ptr(self.inner);
401 self.inner = core::ptr::null_mut();
405 impl Clone for HTLCUpdate {
406 fn clone(&self) -> Self {
408 inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
409 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
415 /// Used only if an object of this type is returned as a trait impl by a method
416 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
417 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void
420 /// Creates a copy of the HTLCUpdate
421 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
425 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
426 pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
427 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
430 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
431 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
434 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
435 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
436 let res: Result<lightning::chain::channelmonitor::HTLCUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
437 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() };
440 /// Number of blocks we wait on seeing a HTLC output being solved before we fail corresponding
441 /// inbound HTLCs. This prevents us from failing backwards and then getting a reorg resulting in us
444 /// Note that this is a library-wide security assumption. If a reorg deeper than this number of
445 /// blocks occurs, counterparties may be able to steal funds or claims made by and balances exposed
446 /// by a [`ChannelMonitor`] may be incorrect.
449 pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
450 /// Details about the balance(s) available for spending once the channel appears on chain.
452 /// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
458 /// The channel is not yet closed (or the commitment or closing transaction has not yet
459 /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
460 /// force-closed now.
461 ClaimableOnChannelClose {
462 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
463 /// required to do so.
464 claimable_amount_satoshis: u64,
466 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
467 /// we consider it spendable.
468 ClaimableAwaitingConfirmations {
469 /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
470 /// were spent in broadcasting the transaction.
471 claimable_amount_satoshis: u64,
472 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
474 confirmation_height: u32,
476 /// The channel has been closed, and the given balance should be ours but awaiting spending
477 /// transaction confirmation. If the spending transaction does not confirm in time, it is
478 /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
480 /// Once the spending transaction confirms, before it has reached enough confirmations to be
481 /// considered safe from chain reorganizations, the balance will instead be provided via
482 /// [`Balance::ClaimableAwaitingConfirmations`].
483 ContentiousClaimable {
484 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
485 /// required to do so.
486 claimable_amount_satoshis: u64,
487 /// The height at which the counterparty may be able to claim the balance if we have not
491 /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
492 /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
493 /// likely to be claimed by our counterparty before we do.
494 MaybeClaimableHTLCAwaitingTimeout {
495 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
496 /// required to do so.
497 claimable_amount_satoshis: u64,
498 /// The height at which we will be able to claim the balance if our counterparty has not
500 claimable_height: u32,
503 use lightning::chain::channelmonitor::Balance as BalanceImport;
504 pub(crate) type nativeBalance = BalanceImport;
508 pub(crate) fn to_native(&self) -> nativeBalance {
510 Balance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
511 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
512 nativeBalance::ClaimableOnChannelClose {
513 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
516 Balance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
517 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
518 let mut confirmation_height_nonref = (*confirmation_height).clone();
519 nativeBalance::ClaimableAwaitingConfirmations {
520 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
521 confirmation_height: confirmation_height_nonref,
524 Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
525 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
526 let mut timeout_height_nonref = (*timeout_height).clone();
527 nativeBalance::ContentiousClaimable {
528 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
529 timeout_height: timeout_height_nonref,
532 Balance::MaybeClaimableHTLCAwaitingTimeout {ref claimable_amount_satoshis, ref claimable_height, } => {
533 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
534 let mut claimable_height_nonref = (*claimable_height).clone();
535 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {
536 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
537 claimable_height: claimable_height_nonref,
543 pub(crate) fn into_native(self) -> nativeBalance {
545 Balance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
546 nativeBalance::ClaimableOnChannelClose {
547 claimable_amount_satoshis: claimable_amount_satoshis,
550 Balance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
551 nativeBalance::ClaimableAwaitingConfirmations {
552 claimable_amount_satoshis: claimable_amount_satoshis,
553 confirmation_height: confirmation_height,
556 Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
557 nativeBalance::ContentiousClaimable {
558 claimable_amount_satoshis: claimable_amount_satoshis,
559 timeout_height: timeout_height,
562 Balance::MaybeClaimableHTLCAwaitingTimeout {mut claimable_amount_satoshis, mut claimable_height, } => {
563 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {
564 claimable_amount_satoshis: claimable_amount_satoshis,
565 claimable_height: claimable_height,
571 pub(crate) fn from_native(native: &nativeBalance) -> Self {
573 nativeBalance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
574 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
575 Balance::ClaimableOnChannelClose {
576 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
579 nativeBalance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
580 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
581 let mut confirmation_height_nonref = (*confirmation_height).clone();
582 Balance::ClaimableAwaitingConfirmations {
583 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
584 confirmation_height: confirmation_height_nonref,
587 nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
588 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
589 let mut timeout_height_nonref = (*timeout_height).clone();
590 Balance::ContentiousClaimable {
591 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
592 timeout_height: timeout_height_nonref,
595 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {ref claimable_amount_satoshis, ref claimable_height, } => {
596 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
597 let mut claimable_height_nonref = (*claimable_height).clone();
598 Balance::MaybeClaimableHTLCAwaitingTimeout {
599 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
600 claimable_height: claimable_height_nonref,
606 pub(crate) fn native_into(native: nativeBalance) -> Self {
608 nativeBalance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
609 Balance::ClaimableOnChannelClose {
610 claimable_amount_satoshis: claimable_amount_satoshis,
613 nativeBalance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
614 Balance::ClaimableAwaitingConfirmations {
615 claimable_amount_satoshis: claimable_amount_satoshis,
616 confirmation_height: confirmation_height,
619 nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
620 Balance::ContentiousClaimable {
621 claimable_amount_satoshis: claimable_amount_satoshis,
622 timeout_height: timeout_height,
625 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {mut claimable_amount_satoshis, mut claimable_height, } => {
626 Balance::MaybeClaimableHTLCAwaitingTimeout {
627 claimable_amount_satoshis: claimable_amount_satoshis,
628 claimable_height: claimable_height,
634 /// Frees any resources used by the Balance
636 pub extern "C" fn Balance_free(this_ptr: Balance) { }
637 /// Creates a copy of the Balance
639 pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
643 /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
644 pub extern "C" fn Balance_claimable_on_channel_close(claimable_amount_satoshis: u64) -> Balance {
645 Balance::ClaimableOnChannelClose {
646 claimable_amount_satoshis,
650 /// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
651 pub extern "C" fn Balance_claimable_awaiting_confirmations(claimable_amount_satoshis: u64, confirmation_height: u32) -> Balance {
652 Balance::ClaimableAwaitingConfirmations {
653 claimable_amount_satoshis,
658 /// Utility method to constructs a new ContentiousClaimable-variant Balance
659 pub extern "C" fn Balance_contentious_claimable(claimable_amount_satoshis: u64, timeout_height: u32) -> Balance {
660 Balance::ContentiousClaimable {
661 claimable_amount_satoshis,
666 /// Utility method to constructs a new MaybeClaimableHTLCAwaitingTimeout-variant Balance
667 pub extern "C" fn Balance_maybe_claimable_htlcawaiting_timeout(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
668 Balance::MaybeClaimableHTLCAwaitingTimeout {
669 claimable_amount_satoshis,
673 /// Checks if two Balances contain equal inner contents.
674 /// This ignores pointers and is_owned flags and looks at the values in fields.
676 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
677 if &a.to_native() == &b.to_native() { true } else { false }
680 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
681 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::chain::keysinterface::Sign>;
683 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
684 /// on-chain transactions to ensure no loss of funds occurs.
686 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
687 /// information and are actively monitoring the chain.
689 /// Pending Events or updated HTLCs which have not yet been read out by
690 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
691 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
692 /// gotten are fully handled before re-serializing the new state.
694 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
695 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
696 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
697 /// returned block hash and the the current chain and then reconnecting blocks to get to the
698 /// best chain) upon deserializing the object!
701 pub struct ChannelMonitor {
702 /// A pointer to the opaque Rust object.
704 /// Nearly everywhere, inner must be non-null, however in places where
705 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
706 pub inner: *mut nativeChannelMonitor,
707 /// Indicates that this is the only struct which contains the same pointer.
709 /// Rust functions which take ownership of an object provided via an argument require
710 /// this to be true and invalidate the object pointed to by inner.
714 impl Drop for ChannelMonitor {
716 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
717 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
721 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
723 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
725 /// Used only if an object of this type is returned as a trait impl by a method
726 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
727 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitor); }
730 impl ChannelMonitor {
731 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
732 unsafe { &*ObjOps::untweak_ptr(self.inner) }
734 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
735 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
737 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
738 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
739 assert!(self.is_owned);
740 let ret = ObjOps::untweak_ptr(self.inner);
741 self.inner = core::ptr::null_mut();
746 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
747 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
748 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
751 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
752 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
754 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
757 /// panics if the given update is not the next update by update_id.
760 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 {
761 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
762 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() };
766 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
770 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
771 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
775 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
778 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
779 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
780 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();
784 /// Gets a list of txids, with their output scripts (in the order they appear in the
785 /// transaction), which we must learn about spends of via block_connected().
788 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 {
789 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
790 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 }); };
794 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
795 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
796 /// have been registered.
798 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter) {
799 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter)
802 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
803 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
806 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
807 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
808 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
812 /// Gets the list of pending events which were generated by previous actions, clearing the list
815 /// This is called by ChainMonitor::get_and_clear_pending_events() and is equivalent to
816 /// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do
817 /// no internal locking in ChannelMonitors.
820 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
821 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_events();
822 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::Event::native_into(item) }); };
826 /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
827 /// the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of
828 /// fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows
829 /// a higher revocation secret than the holder commitment number we are aware of. Broadcasting these
830 /// transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to
831 /// broadcast them if counterparty don't close channel with his higher commitment transaction after a
832 /// substantial amount of time (a month or even a year) to get back funds. Best may be to contact
833 /// out-of-band the other node operator to coordinate with him if option is available to you.
834 /// In any-case, choice is up to the user.
837 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 {
838 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger);
839 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); };
843 /// Processes transactions in a newly connected block, which may result in any of the following:
844 /// - update the monitor's state against resolved HTLCs
845 /// - punish the counterparty in the case of seeing a revoked commitment transaction
846 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
847 /// - detect settled outputs for later spending
848 /// - schedule and bump any in-flight claims
850 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
851 /// [`get_outputs_to_watch`].
853 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
856 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 {
857 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 }); };
858 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);
859 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 }); };
863 /// Determines if the disconnected block contained any transactions of interest and updates
866 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) {
867 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
870 /// Processes transactions confirmed in a block with the given header and height, returning new
871 /// outputs to watch. See [`block_connected`] for details.
873 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
874 /// blocks. See [`chain::Confirm`] for calling expectations.
876 /// [`block_connected`]: Self::block_connected
879 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 {
880 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 }); };
881 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);
882 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 }); };
886 /// Processes a transaction that was reorganized out of the chain.
888 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
889 /// than blocks. See [`chain::Confirm`] for calling expectations.
891 /// [`block_disconnected`]: Self::block_disconnected
893 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) {
894 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
897 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
898 /// [`block_connected`] for details.
900 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
901 /// blocks. See [`chain::Confirm`] for calling expectations.
903 /// [`block_connected`]: Self::block_connected
906 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 {
907 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);
908 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 }); };
912 /// Returns the set of txids that should be monitored for re-organization out of the chain.
915 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_TxidZ {
916 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
917 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
921 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
922 /// [`chain::Confirm`] interfaces.
925 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
926 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
927 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
930 /// Gets the balances in this channel which are either claimable by us if we were to
931 /// force-close the channel now or which are claimable on-chain (possibly awaiting
934 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
935 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
936 /// balance, or until our counterparty has claimed the balance and accrued several
937 /// confirmations on the claim transaction.
939 /// Note that the balances available when you or your counterparty have broadcasted revoked
940 /// state(s) may not be fully captured here.
942 /// See [`Balance`] for additional details on the types of claimable balances which
943 /// may be returned here and their meanings.
946 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
947 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
948 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
953 /// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
954 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 {
956 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);
957 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() };