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 MonitorEventImport;
188 pub(crate) type nativeMonitorEvent = MonitorEventImport;
192 pub(crate) fn to_native(&self) -> nativeMonitorEvent {
194 MonitorEvent::HTLCEvent (ref a, ) => {
195 let mut a_nonref = (*a).clone();
196 nativeMonitorEvent::HTLCEvent (
197 *unsafe { Box::from_raw(a_nonref.take_inner()) },
200 MonitorEvent::CommitmentTxConfirmed (ref a, ) => {
201 let mut a_nonref = (*a).clone();
202 nativeMonitorEvent::CommitmentTxConfirmed (
203 *unsafe { Box::from_raw(a_nonref.take_inner()) },
206 MonitorEvent::UpdateCompleted {ref funding_txo, ref monitor_update_id, } => {
207 let mut funding_txo_nonref = (*funding_txo).clone();
208 let mut monitor_update_id_nonref = (*monitor_update_id).clone();
209 nativeMonitorEvent::UpdateCompleted {
210 funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
211 monitor_update_id: monitor_update_id_nonref,
214 MonitorEvent::UpdateFailed (ref a, ) => {
215 let mut a_nonref = (*a).clone();
216 nativeMonitorEvent::UpdateFailed (
217 *unsafe { Box::from_raw(a_nonref.take_inner()) },
223 pub(crate) fn into_native(self) -> nativeMonitorEvent {
225 MonitorEvent::HTLCEvent (mut a, ) => {
226 nativeMonitorEvent::HTLCEvent (
227 *unsafe { Box::from_raw(a.take_inner()) },
230 MonitorEvent::CommitmentTxConfirmed (mut a, ) => {
231 nativeMonitorEvent::CommitmentTxConfirmed (
232 *unsafe { Box::from_raw(a.take_inner()) },
235 MonitorEvent::UpdateCompleted {mut funding_txo, mut monitor_update_id, } => {
236 nativeMonitorEvent::UpdateCompleted {
237 funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
238 monitor_update_id: monitor_update_id,
241 MonitorEvent::UpdateFailed (mut a, ) => {
242 nativeMonitorEvent::UpdateFailed (
243 *unsafe { Box::from_raw(a.take_inner()) },
249 pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self {
251 nativeMonitorEvent::HTLCEvent (ref a, ) => {
252 let mut a_nonref = (*a).clone();
253 MonitorEvent::HTLCEvent (
254 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
257 nativeMonitorEvent::CommitmentTxConfirmed (ref a, ) => {
258 let mut a_nonref = (*a).clone();
259 MonitorEvent::CommitmentTxConfirmed (
260 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
263 nativeMonitorEvent::UpdateCompleted {ref funding_txo, ref monitor_update_id, } => {
264 let mut funding_txo_nonref = (*funding_txo).clone();
265 let mut monitor_update_id_nonref = (*monitor_update_id).clone();
266 MonitorEvent::UpdateCompleted {
267 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
268 monitor_update_id: monitor_update_id_nonref,
271 nativeMonitorEvent::UpdateFailed (ref a, ) => {
272 let mut a_nonref = (*a).clone();
273 MonitorEvent::UpdateFailed (
274 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
280 pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
282 nativeMonitorEvent::HTLCEvent (mut a, ) => {
283 MonitorEvent::HTLCEvent (
284 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true },
287 nativeMonitorEvent::CommitmentTxConfirmed (mut a, ) => {
288 MonitorEvent::CommitmentTxConfirmed (
289 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
292 nativeMonitorEvent::UpdateCompleted {mut funding_txo, mut monitor_update_id, } => {
293 MonitorEvent::UpdateCompleted {
294 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true },
295 monitor_update_id: monitor_update_id,
298 nativeMonitorEvent::UpdateFailed (mut a, ) => {
299 MonitorEvent::UpdateFailed (
300 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
306 /// Frees any resources used by the MonitorEvent
308 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
309 /// Creates a copy of the MonitorEvent
311 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
315 /// Utility method to constructs a new HTLCEvent-variant MonitorEvent
316 pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent {
317 MonitorEvent::HTLCEvent(a, )
320 /// Utility method to constructs a new CommitmentTxConfirmed-variant MonitorEvent
321 pub extern "C" fn MonitorEvent_commitment_tx_confirmed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
322 MonitorEvent::CommitmentTxConfirmed(a, )
325 /// Utility method to constructs a new UpdateCompleted-variant MonitorEvent
326 pub extern "C" fn MonitorEvent_update_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, monitor_update_id: u64) -> MonitorEvent {
327 MonitorEvent::UpdateCompleted {
333 /// Utility method to constructs a new UpdateFailed-variant MonitorEvent
334 pub extern "C" fn MonitorEvent_update_failed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
335 MonitorEvent::UpdateFailed(a, )
338 /// Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
339 pub extern "C" fn MonitorEvent_write(obj: &crate::lightning::chain::channelmonitor::MonitorEvent) -> crate::c_types::derived::CVec_u8Z {
340 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
343 /// Read a MonitorEvent from a byte array, created by MonitorEvent_write
344 pub extern "C" fn MonitorEvent_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_MonitorEventZDecodeErrorZ {
345 let res: Result<Option<lightning::chain::channelmonitor::MonitorEvent>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
346 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() };
350 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
351 pub(crate) type nativeHTLCUpdate = nativeHTLCUpdateImport;
353 /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
354 /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
355 /// preimage claim backward will lead to loss of funds.
358 pub struct HTLCUpdate {
359 /// A pointer to the opaque Rust object.
361 /// Nearly everywhere, inner must be non-null, however in places where
362 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
363 pub inner: *mut nativeHTLCUpdate,
364 /// Indicates that this is the only struct which contains the same pointer.
366 /// Rust functions which take ownership of an object provided via an argument require
367 /// this to be true and invalidate the object pointed to by inner.
371 impl Drop for HTLCUpdate {
373 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
374 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
378 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
380 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
382 /// Used only if an object of this type is returned as a trait impl by a method
383 pub(crate) extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
384 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCUpdate); }
388 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCUpdate {
389 unsafe { &*ObjOps::untweak_ptr(self.inner) }
391 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCUpdate {
392 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
394 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
395 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
396 assert!(self.is_owned);
397 let ret = ObjOps::untweak_ptr(self.inner);
398 self.inner = core::ptr::null_mut();
402 impl Clone for HTLCUpdate {
403 fn clone(&self) -> Self {
405 inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
406 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
412 /// Used only if an object of this type is returned as a trait impl by a method
413 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
414 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void
417 /// Creates a copy of the HTLCUpdate
418 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
422 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
423 pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
424 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
427 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
428 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
431 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
432 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
433 let res: Result<lightning::chain::channelmonitor::HTLCUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
434 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() };
437 /// Number of blocks we wait on seeing a HTLC output being solved before we fail corresponding
438 /// inbound HTLCs. This prevents us from failing backwards and then getting a reorg resulting in us
441 /// Note that this is a library-wide security assumption. If a reorg deeper than this number of
442 /// blocks occurs, counterparties may be able to steal funds or claims made by and balances exposed
443 /// by a [`ChannelMonitor`] may be incorrect.
446 pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
447 /// Details about the balance(s) available for spending once the channel appears on chain.
449 /// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
455 /// The channel is not yet closed (or the commitment or closing transaction has not yet
456 /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
457 /// force-closed now.
458 ClaimableOnChannelClose {
459 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
460 /// required to do so.
461 claimable_amount_satoshis: u64,
463 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
464 /// we consider it spendable.
465 ClaimableAwaitingConfirmations {
466 /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
467 /// were spent in broadcasting the transaction.
468 claimable_amount_satoshis: u64,
469 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
471 confirmation_height: u32,
473 /// The channel has been closed, and the given balance should be ours but awaiting spending
474 /// transaction confirmation. If the spending transaction does not confirm in time, it is
475 /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
477 /// Once the spending transaction confirms, before it has reached enough confirmations to be
478 /// considered safe from chain reorganizations, the balance will instead be provided via
479 /// [`Balance::ClaimableAwaitingConfirmations`].
480 ContentiousClaimable {
481 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
482 /// required to do so.
483 claimable_amount_satoshis: u64,
484 /// The height at which the counterparty may be able to claim the balance if we have not
488 /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
489 /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
490 /// likely to be claimed by our counterparty before we do.
491 MaybeClaimableHTLCAwaitingTimeout {
492 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
493 /// required to do so.
494 claimable_amount_satoshis: u64,
495 /// The height at which we will be able to claim the balance if our counterparty has not
497 claimable_height: u32,
500 use lightning::chain::channelmonitor::Balance as BalanceImport;
501 pub(crate) type nativeBalance = BalanceImport;
505 pub(crate) fn to_native(&self) -> nativeBalance {
507 Balance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
508 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
509 nativeBalance::ClaimableOnChannelClose {
510 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
513 Balance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
514 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
515 let mut confirmation_height_nonref = (*confirmation_height).clone();
516 nativeBalance::ClaimableAwaitingConfirmations {
517 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
518 confirmation_height: confirmation_height_nonref,
521 Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
522 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
523 let mut timeout_height_nonref = (*timeout_height).clone();
524 nativeBalance::ContentiousClaimable {
525 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
526 timeout_height: timeout_height_nonref,
529 Balance::MaybeClaimableHTLCAwaitingTimeout {ref claimable_amount_satoshis, ref claimable_height, } => {
530 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
531 let mut claimable_height_nonref = (*claimable_height).clone();
532 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {
533 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
534 claimable_height: claimable_height_nonref,
540 pub(crate) fn into_native(self) -> nativeBalance {
542 Balance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
543 nativeBalance::ClaimableOnChannelClose {
544 claimable_amount_satoshis: claimable_amount_satoshis,
547 Balance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
548 nativeBalance::ClaimableAwaitingConfirmations {
549 claimable_amount_satoshis: claimable_amount_satoshis,
550 confirmation_height: confirmation_height,
553 Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
554 nativeBalance::ContentiousClaimable {
555 claimable_amount_satoshis: claimable_amount_satoshis,
556 timeout_height: timeout_height,
559 Balance::MaybeClaimableHTLCAwaitingTimeout {mut claimable_amount_satoshis, mut claimable_height, } => {
560 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {
561 claimable_amount_satoshis: claimable_amount_satoshis,
562 claimable_height: claimable_height,
568 pub(crate) fn from_native(native: &nativeBalance) -> Self {
570 nativeBalance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
571 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
572 Balance::ClaimableOnChannelClose {
573 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
576 nativeBalance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
577 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
578 let mut confirmation_height_nonref = (*confirmation_height).clone();
579 Balance::ClaimableAwaitingConfirmations {
580 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
581 confirmation_height: confirmation_height_nonref,
584 nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
585 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
586 let mut timeout_height_nonref = (*timeout_height).clone();
587 Balance::ContentiousClaimable {
588 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
589 timeout_height: timeout_height_nonref,
592 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {ref claimable_amount_satoshis, ref claimable_height, } => {
593 let mut claimable_amount_satoshis_nonref = (*claimable_amount_satoshis).clone();
594 let mut claimable_height_nonref = (*claimable_height).clone();
595 Balance::MaybeClaimableHTLCAwaitingTimeout {
596 claimable_amount_satoshis: claimable_amount_satoshis_nonref,
597 claimable_height: claimable_height_nonref,
603 pub(crate) fn native_into(native: nativeBalance) -> Self {
605 nativeBalance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
606 Balance::ClaimableOnChannelClose {
607 claimable_amount_satoshis: claimable_amount_satoshis,
610 nativeBalance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
611 Balance::ClaimableAwaitingConfirmations {
612 claimable_amount_satoshis: claimable_amount_satoshis,
613 confirmation_height: confirmation_height,
616 nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
617 Balance::ContentiousClaimable {
618 claimable_amount_satoshis: claimable_amount_satoshis,
619 timeout_height: timeout_height,
622 nativeBalance::MaybeClaimableHTLCAwaitingTimeout {mut claimable_amount_satoshis, mut claimable_height, } => {
623 Balance::MaybeClaimableHTLCAwaitingTimeout {
624 claimable_amount_satoshis: claimable_amount_satoshis,
625 claimable_height: claimable_height,
631 /// Frees any resources used by the Balance
633 pub extern "C" fn Balance_free(this_ptr: Balance) { }
634 /// Creates a copy of the Balance
636 pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
640 /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
641 pub extern "C" fn Balance_claimable_on_channel_close(claimable_amount_satoshis: u64) -> Balance {
642 Balance::ClaimableOnChannelClose {
643 claimable_amount_satoshis,
647 /// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
648 pub extern "C" fn Balance_claimable_awaiting_confirmations(claimable_amount_satoshis: u64, confirmation_height: u32) -> Balance {
649 Balance::ClaimableAwaitingConfirmations {
650 claimable_amount_satoshis,
655 /// Utility method to constructs a new ContentiousClaimable-variant Balance
656 pub extern "C" fn Balance_contentious_claimable(claimable_amount_satoshis: u64, timeout_height: u32) -> Balance {
657 Balance::ContentiousClaimable {
658 claimable_amount_satoshis,
663 /// Utility method to constructs a new MaybeClaimableHTLCAwaitingTimeout-variant Balance
664 pub extern "C" fn Balance_maybe_claimable_htlcawaiting_timeout(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
665 Balance::MaybeClaimableHTLCAwaitingTimeout {
666 claimable_amount_satoshis,
670 /// Checks if two Balances contain equal inner contents.
671 /// This ignores pointers and is_owned flags and looks at the values in fields.
673 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
674 if &a.to_native() == &b.to_native() { true } else { false }
677 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
678 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::chain::keysinterface::Sign>;
680 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
681 /// on-chain transactions to ensure no loss of funds occurs.
683 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
684 /// information and are actively monitoring the chain.
686 /// Pending Events or updated HTLCs which have not yet been read out by
687 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
688 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
689 /// gotten are fully handled before re-serializing the new state.
691 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
692 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
693 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
694 /// returned block hash and the the current chain and then reconnecting blocks to get to the
695 /// best chain) upon deserializing the object!
698 pub struct ChannelMonitor {
699 /// A pointer to the opaque Rust object.
701 /// Nearly everywhere, inner must be non-null, however in places where
702 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
703 pub inner: *mut nativeChannelMonitor,
704 /// Indicates that this is the only struct which contains the same pointer.
706 /// Rust functions which take ownership of an object provided via an argument require
707 /// this to be true and invalidate the object pointed to by inner.
711 impl Drop for ChannelMonitor {
713 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
714 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
718 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
720 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
722 /// Used only if an object of this type is returned as a trait impl by a method
723 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
724 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitor); }
727 impl ChannelMonitor {
728 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
729 unsafe { &*ObjOps::untweak_ptr(self.inner) }
731 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
732 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
734 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
735 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
736 assert!(self.is_owned);
737 let ret = ObjOps::untweak_ptr(self.inner);
738 self.inner = core::ptr::null_mut();
743 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
744 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
745 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
748 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
749 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
751 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
754 /// panics if the given update is not the next update by update_id.
757 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 {
758 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
759 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() };
763 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
767 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
768 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
772 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
775 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
776 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
777 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();
781 /// Gets a list of txids, with their output scripts (in the order they appear in the
782 /// transaction), which we must learn about spends of via block_connected().
785 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 {
786 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
787 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 }); };
791 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
792 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
793 /// have been registered.
795 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter) {
796 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter)
799 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
800 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
803 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
804 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
805 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
809 /// Gets the list of pending events which were generated by previous actions, clearing the list
812 /// This is called by ChainMonitor::get_and_clear_pending_events() and is equivalent to
813 /// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do
814 /// no internal locking in ChannelMonitors.
817 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
818 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_events();
819 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::Event::native_into(item) }); };
823 /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
824 /// the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of
825 /// fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows
826 /// a higher revocation secret than the holder commitment number we are aware of. Broadcasting these
827 /// transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to
828 /// broadcast them if counterparty don't close channel with his higher commitment transaction after a
829 /// substantial amount of time (a month or even a year) to get back funds. Best may be to contact
830 /// out-of-band the other node operator to coordinate with him if option is available to you.
831 /// In any-case, choice is up to the user.
834 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 {
835 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger);
836 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); };
840 /// Processes transactions in a newly connected block, which may result in any of the following:
841 /// - update the monitor's state against resolved HTLCs
842 /// - punish the counterparty in the case of seeing a revoked commitment transaction
843 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
844 /// - detect settled outputs for later spending
845 /// - schedule and bump any in-flight claims
847 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
848 /// [`get_outputs_to_watch`].
850 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
853 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 {
854 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 }); };
855 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);
856 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 }); };
860 /// Determines if the disconnected block contained any transactions of interest and updates
863 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) {
864 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
867 /// Processes transactions confirmed in a block with the given header and height, returning new
868 /// outputs to watch. See [`block_connected`] for details.
870 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
871 /// blocks. See [`chain::Confirm`] for calling expectations.
873 /// [`block_connected`]: Self::block_connected
876 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 {
877 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 }); };
878 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);
879 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 }); };
883 /// Processes a transaction that was reorganized out of the chain.
885 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
886 /// than blocks. See [`chain::Confirm`] for calling expectations.
888 /// [`block_disconnected`]: Self::block_disconnected
890 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) {
891 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
894 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
895 /// [`block_connected`] for details.
897 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
898 /// blocks. See [`chain::Confirm`] for calling expectations.
900 /// [`block_connected`]: Self::block_connected
903 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 {
904 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);
905 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 }); };
909 /// Returns the set of txids that should be monitored for re-organization out of the chain.
912 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_TxidZ {
913 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
914 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
918 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
919 /// [`chain::Confirm`] interfaces.
922 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
923 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
924 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
927 /// Gets the balances in this channel which are either claimable by us if we were to
928 /// force-close the channel now or which are claimable on-chain (possibly awaiting
931 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
932 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
933 /// balance, or until our counterparty has claimed the balance and accrued several
934 /// confirmations on the claim transaction.
936 /// Note that the balances available when you or your counterparty have broadcasted revoked
937 /// state(s) may not be fully captured here.
939 /// See [`Balance`] for additional details on the types of claimable balances which
940 /// may be returned here and their meanings.
943 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
944 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
945 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
950 /// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
951 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 {
953 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);
954 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() };