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 alloc::string::String;
24 use core::ffi::c_void;
25 use core::convert::Infallible;
26 use bitcoin::hashes::Hash;
27 use crate::c_types::*;
28 #[cfg(feature="no-std")]
29 use alloc::{vec::Vec, boxed::Box};
32 use lightning::chain::channelmonitor::ChannelMonitorUpdate as nativeChannelMonitorUpdateImport;
33 pub(crate) type nativeChannelMonitorUpdate = nativeChannelMonitorUpdateImport;
35 /// An update generated by the underlying channel itself which contains some new information the
36 /// [`ChannelMonitor`] should be made aware of.
38 /// Because this represents only a small number of updates to the underlying state, it is generally
39 /// much smaller than a full [`ChannelMonitor`]. However, for large single commitment transaction
40 /// updates (e.g. ones during which there are hundreds of HTLCs pending on the commitment
41 /// transaction), a single update may reach upwards of 1 MiB in serialized size.
44 pub struct ChannelMonitorUpdate {
45 /// A pointer to the opaque Rust object.
47 /// Nearly everywhere, inner must be non-null, however in places where
48 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
49 pub inner: *mut nativeChannelMonitorUpdate,
50 /// Indicates that this is the only struct which contains the same pointer.
52 /// Rust functions which take ownership of an object provided via an argument require
53 /// this to be true and invalidate the object pointed to by inner.
57 impl Drop for ChannelMonitorUpdate {
59 if self.is_owned && !<*mut nativeChannelMonitorUpdate>::is_null(self.inner) {
60 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
64 /// Frees any resources used by the ChannelMonitorUpdate, if is_owned is set and inner is non-NULL.
66 pub extern "C" fn ChannelMonitorUpdate_free(this_obj: ChannelMonitorUpdate) { }
68 /// Used only if an object of this type is returned as a trait impl by a method
69 pub(crate) extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
70 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate) };
73 impl ChannelMonitorUpdate {
74 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitorUpdate {
75 unsafe { &*ObjOps::untweak_ptr(self.inner) }
77 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitorUpdate {
78 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
80 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
81 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitorUpdate {
82 assert!(self.is_owned);
83 let ret = ObjOps::untweak_ptr(self.inner);
84 self.inner = core::ptr::null_mut();
88 /// The sequence number of this update. Updates *must* be replayed in-order according to this
89 /// sequence number (and updates may panic if they are not). The update_id values are strictly
90 /// increasing and increase by one for each new update, with two exceptions specified below.
92 /// This sequence number is also used to track up to which points updates which returned
93 /// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
94 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
96 /// The only instances we allow where update_id values are not strictly increasing have a
97 /// special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that
98 /// will force close the channel by broadcasting the latest commitment transaction or
99 /// special post-force-close updates, like providing preimages necessary to claim outputs on the
100 /// broadcast commitment transaction. See its docs for more details.
102 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
104 pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 {
105 let mut inner_val = &mut this_ptr.get_native_mut_ref().update_id;
108 /// The sequence number of this update. Updates *must* be replayed in-order according to this
109 /// sequence number (and updates may panic if they are not). The update_id values are strictly
110 /// increasing and increase by one for each new update, with two exceptions specified below.
112 /// This sequence number is also used to track up to which points updates which returned
113 /// [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
114 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
116 /// The only instances we allow where update_id values are not strictly increasing have a
117 /// special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that
118 /// will force close the channel by broadcasting the latest commitment transaction or
119 /// special post-force-close updates, like providing preimages necessary to claim outputs on the
120 /// broadcast commitment transaction. See its docs for more details.
122 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
124 pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) {
125 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_id = val;
127 /// The channel ID associated with these updates.
129 /// Will be `None` for `ChannelMonitorUpdate`s constructed on LDK versions prior to 0.0.121 and
130 /// always `Some` otherwise.
132 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
134 pub extern "C" fn ChannelMonitorUpdate_get_channel_id(this_ptr: &ChannelMonitorUpdate) -> crate::lightning::ln::types::ChannelId {
135 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id;
136 let mut local_inner_val = crate::lightning::ln::types::ChannelId { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::types::ChannelId<>) as *mut _ }, is_owned: false };
139 /// The channel ID associated with these updates.
141 /// Will be `None` for `ChannelMonitorUpdate`s constructed on LDK versions prior to 0.0.121 and
142 /// always `Some` otherwise.
144 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
146 pub extern "C" fn ChannelMonitorUpdate_set_channel_id(this_ptr: &mut ChannelMonitorUpdate, mut val: crate::lightning::ln::types::ChannelId) {
147 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
148 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = local_val;
150 impl Clone for ChannelMonitorUpdate {
151 fn clone(&self) -> Self {
153 inner: if <*mut nativeChannelMonitorUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
154 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
160 /// Used only if an object of this type is returned as a trait impl by a method
161 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
162 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelMonitorUpdate)).clone() })) as *mut c_void
165 /// Creates a copy of the ChannelMonitorUpdate
166 pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
169 /// Get a string which allows debug introspection of a ChannelMonitorUpdate object
170 pub extern "C" fn ChannelMonitorUpdate_debug_str_void(o: *const c_void) -> Str {
171 alloc::format!("{:?}", unsafe { o as *const crate::lightning::chain::channelmonitor::ChannelMonitorUpdate }).into()}
172 /// Checks if two ChannelMonitorUpdates contain equal inner contents.
173 /// This ignores pointers and is_owned flags and looks at the values in fields.
174 /// Two objects with NULL inner values will be considered "equal" here.
176 pub extern "C" fn ChannelMonitorUpdate_eq(a: &ChannelMonitorUpdate, b: &ChannelMonitorUpdate) -> bool {
177 if a.inner == b.inner { return true; }
178 if a.inner.is_null() || b.inner.is_null() { return false; }
179 if a.get_native_ref() == b.get_native_ref() { true } else { false }
181 /// The update ID used for a [`ChannelMonitorUpdate`] that is either:
183 ///\t(1) attempting to force close the channel by broadcasting our latest commitment transaction or
184 ///\t(2) providing a preimage (after the channel has been force closed) from a forward link that
185 ///\t\tallows us to spend an HTLC output on this channel's (the backward link's) broadcasted
186 ///\t\tcommitment transaction.
188 /// No other [`ChannelMonitorUpdate`]s are allowed after force-close.
191 pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
193 /// Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read
194 pub extern "C" fn ChannelMonitorUpdate_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
195 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
198 pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
199 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) })
202 /// Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write
203 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ {
204 let res: Result<lightning::chain::channelmonitor::ChannelMonitorUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
205 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
208 /// An event to be processed by the ChannelManager.
212 pub enum MonitorEvent {
213 /// A monitor event containing an HTLCUpdate.
215 crate::lightning::chain::channelmonitor::HTLCUpdate),
216 /// Indicates we broadcasted the channel's latest commitment transaction and thus closed the
217 /// channel. Holds information about the channel and why it was closed.
218 HolderForceClosedWithInfo {
219 /// The reason the channel was closed.
220 reason: crate::lightning::events::ClosureReason,
221 /// The funding outpoint of the channel.
222 outpoint: crate::lightning::chain::transaction::OutPoint,
223 /// The channel ID of the channel.
224 channel_id: crate::lightning::ln::types::ChannelId,
226 /// Indicates we broadcasted the channel's latest commitment transaction and thus closed the
229 crate::lightning::chain::transaction::OutPoint),
230 /// Indicates a [`ChannelMonitor`] update has completed. See
231 /// [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
233 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
235 /// The funding outpoint of the [`ChannelMonitor`] that was updated
236 funding_txo: crate::lightning::chain::transaction::OutPoint,
237 /// The channel ID of the channel associated with the [`ChannelMonitor`]
238 channel_id: crate::lightning::ln::types::ChannelId,
239 /// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
240 /// [`ChannelMonitor::get_latest_update_id`].
242 /// Note that this should only be set to a given update's ID if all previous updates for the
243 /// same [`ChannelMonitor`] have been applied and persisted.
244 monitor_update_id: u64,
247 use lightning::chain::channelmonitor::MonitorEvent as MonitorEventImport;
248 pub(crate) type nativeMonitorEvent = MonitorEventImport;
252 pub(crate) fn to_native(&self) -> nativeMonitorEvent {
254 MonitorEvent::HTLCEvent (ref a, ) => {
255 let mut a_nonref = Clone::clone(a);
256 nativeMonitorEvent::HTLCEvent (
257 *unsafe { Box::from_raw(a_nonref.take_inner()) },
260 MonitorEvent::HolderForceClosedWithInfo {ref reason, ref outpoint, ref channel_id, } => {
261 let mut reason_nonref = Clone::clone(reason);
262 let mut outpoint_nonref = Clone::clone(outpoint);
263 let mut channel_id_nonref = Clone::clone(channel_id);
264 nativeMonitorEvent::HolderForceClosedWithInfo {
265 reason: reason_nonref.into_native(),
266 outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
267 channel_id: *unsafe { Box::from_raw(channel_id_nonref.take_inner()) },
270 MonitorEvent::HolderForceClosed (ref a, ) => {
271 let mut a_nonref = Clone::clone(a);
272 nativeMonitorEvent::HolderForceClosed (
273 *unsafe { Box::from_raw(a_nonref.take_inner()) },
276 MonitorEvent::Completed {ref funding_txo, ref channel_id, ref monitor_update_id, } => {
277 let mut funding_txo_nonref = Clone::clone(funding_txo);
278 let mut channel_id_nonref = Clone::clone(channel_id);
279 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
280 nativeMonitorEvent::Completed {
281 funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
282 channel_id: *unsafe { Box::from_raw(channel_id_nonref.take_inner()) },
283 monitor_update_id: monitor_update_id_nonref,
289 pub(crate) fn into_native(self) -> nativeMonitorEvent {
291 MonitorEvent::HTLCEvent (mut a, ) => {
292 nativeMonitorEvent::HTLCEvent (
293 *unsafe { Box::from_raw(a.take_inner()) },
296 MonitorEvent::HolderForceClosedWithInfo {mut reason, mut outpoint, mut channel_id, } => {
297 nativeMonitorEvent::HolderForceClosedWithInfo {
298 reason: reason.into_native(),
299 outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
300 channel_id: *unsafe { Box::from_raw(channel_id.take_inner()) },
303 MonitorEvent::HolderForceClosed (mut a, ) => {
304 nativeMonitorEvent::HolderForceClosed (
305 *unsafe { Box::from_raw(a.take_inner()) },
308 MonitorEvent::Completed {mut funding_txo, mut channel_id, mut monitor_update_id, } => {
309 nativeMonitorEvent::Completed {
310 funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
311 channel_id: *unsafe { Box::from_raw(channel_id.take_inner()) },
312 monitor_update_id: monitor_update_id,
318 pub(crate) fn from_native(native: &MonitorEventImport) -> Self {
319 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeMonitorEvent) };
321 nativeMonitorEvent::HTLCEvent (ref a, ) => {
322 let mut a_nonref = Clone::clone(a);
323 MonitorEvent::HTLCEvent (
324 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
327 nativeMonitorEvent::HolderForceClosedWithInfo {ref reason, ref outpoint, ref channel_id, } => {
328 let mut reason_nonref = Clone::clone(reason);
329 let mut outpoint_nonref = Clone::clone(outpoint);
330 let mut channel_id_nonref = Clone::clone(channel_id);
331 MonitorEvent::HolderForceClosedWithInfo {
332 reason: crate::lightning::events::ClosureReason::native_into(reason_nonref),
333 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true },
334 channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id_nonref), is_owned: true },
337 nativeMonitorEvent::HolderForceClosed (ref a, ) => {
338 let mut a_nonref = Clone::clone(a);
339 MonitorEvent::HolderForceClosed (
340 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
343 nativeMonitorEvent::Completed {ref funding_txo, ref channel_id, ref monitor_update_id, } => {
344 let mut funding_txo_nonref = Clone::clone(funding_txo);
345 let mut channel_id_nonref = Clone::clone(channel_id);
346 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
347 MonitorEvent::Completed {
348 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
349 channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id_nonref), is_owned: true },
350 monitor_update_id: monitor_update_id_nonref,
356 pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
358 nativeMonitorEvent::HTLCEvent (mut a, ) => {
359 MonitorEvent::HTLCEvent (
360 crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true },
363 nativeMonitorEvent::HolderForceClosedWithInfo {mut reason, mut outpoint, mut channel_id, } => {
364 MonitorEvent::HolderForceClosedWithInfo {
365 reason: crate::lightning::events::ClosureReason::native_into(reason),
366 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true },
367 channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id), is_owned: true },
370 nativeMonitorEvent::HolderForceClosed (mut a, ) => {
371 MonitorEvent::HolderForceClosed (
372 crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
375 nativeMonitorEvent::Completed {mut funding_txo, mut channel_id, mut monitor_update_id, } => {
376 MonitorEvent::Completed {
377 funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true },
378 channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id), is_owned: true },
379 monitor_update_id: monitor_update_id,
385 /// Frees any resources used by the MonitorEvent
387 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
388 /// Creates a copy of the MonitorEvent
390 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
394 /// Used only if an object of this type is returned as a trait impl by a method
395 pub(crate) extern "C" fn MonitorEvent_clone_void(this_ptr: *const c_void) -> *mut c_void {
396 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const MonitorEvent)).clone() })) as *mut c_void
399 /// Used only if an object of this type is returned as a trait impl by a method
400 pub(crate) extern "C" fn MonitorEvent_free_void(this_ptr: *mut c_void) {
401 let _ = unsafe { Box::from_raw(this_ptr as *mut MonitorEvent) };
404 /// Utility method to constructs a new HTLCEvent-variant MonitorEvent
405 pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent {
406 MonitorEvent::HTLCEvent(a, )
409 /// Utility method to constructs a new HolderForceClosedWithInfo-variant MonitorEvent
410 pub extern "C" fn MonitorEvent_holder_force_closed_with_info(reason: crate::lightning::events::ClosureReason, outpoint: crate::lightning::chain::transaction::OutPoint, channel_id: crate::lightning::ln::types::ChannelId) -> MonitorEvent {
411 MonitorEvent::HolderForceClosedWithInfo {
418 /// Utility method to constructs a new HolderForceClosed-variant MonitorEvent
419 pub extern "C" fn MonitorEvent_holder_force_closed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
420 MonitorEvent::HolderForceClosed(a, )
423 /// Utility method to constructs a new Completed-variant MonitorEvent
424 pub extern "C" fn MonitorEvent_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, channel_id: crate::lightning::ln::types::ChannelId, monitor_update_id: u64) -> MonitorEvent {
425 MonitorEvent::Completed {
431 /// Checks if two MonitorEvents contain equal inner contents.
432 /// This ignores pointers and is_owned flags and looks at the values in fields.
434 pub extern "C" fn MonitorEvent_eq(a: &MonitorEvent, b: &MonitorEvent) -> bool {
435 if &a.to_native() == &b.to_native() { true } else { false }
438 /// Serialize the MonitorEvent object into a byte array which can be read by MonitorEvent_read
439 pub extern "C" fn MonitorEvent_write(obj: &crate::lightning::chain::channelmonitor::MonitorEvent) -> crate::c_types::derived::CVec_u8Z {
440 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
443 pub(crate) extern "C" fn MonitorEvent_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
444 MonitorEvent_write(unsafe { &*(obj as *const MonitorEvent) })
447 /// Read a MonitorEvent from a byte array, created by MonitorEvent_write
448 pub extern "C" fn MonitorEvent_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_MonitorEventZDecodeErrorZ {
449 let res: Result<Option<lightning::chain::channelmonitor::MonitorEvent>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
450 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_MonitorEventZ::None } else { crate::c_types::derived::COption_MonitorEventZ::Some( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
454 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
455 pub(crate) type nativeHTLCUpdate = nativeHTLCUpdateImport;
457 /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
458 /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
459 /// preimage claim backward will lead to loss of funds.
462 pub struct HTLCUpdate {
463 /// A pointer to the opaque Rust object.
465 /// Nearly everywhere, inner must be non-null, however in places where
466 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
467 pub inner: *mut nativeHTLCUpdate,
468 /// Indicates that this is the only struct which contains the same pointer.
470 /// Rust functions which take ownership of an object provided via an argument require
471 /// this to be true and invalidate the object pointed to by inner.
475 impl Drop for HTLCUpdate {
477 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
478 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
482 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
484 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
486 /// Used only if an object of this type is returned as a trait impl by a method
487 pub(crate) extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
488 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCUpdate) };
492 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCUpdate {
493 unsafe { &*ObjOps::untweak_ptr(self.inner) }
495 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCUpdate {
496 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
498 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
499 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
500 assert!(self.is_owned);
501 let ret = ObjOps::untweak_ptr(self.inner);
502 self.inner = core::ptr::null_mut();
506 impl Clone for HTLCUpdate {
507 fn clone(&self) -> Self {
509 inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
510 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
516 /// Used only if an object of this type is returned as a trait impl by a method
517 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
518 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHTLCUpdate)).clone() })) as *mut c_void
521 /// Creates a copy of the HTLCUpdate
522 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
525 /// Checks if two HTLCUpdates contain equal inner contents.
526 /// This ignores pointers and is_owned flags and looks at the values in fields.
527 /// Two objects with NULL inner values will be considered "equal" here.
529 pub extern "C" fn HTLCUpdate_eq(a: &HTLCUpdate, b: &HTLCUpdate) -> bool {
530 if a.inner == b.inner { return true; }
531 if a.inner.is_null() || b.inner.is_null() { return false; }
532 if a.get_native_ref() == b.get_native_ref() { true } else { false }
535 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
536 pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
537 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
540 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
541 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
544 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
545 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
546 let res: Result<lightning::chain::channelmonitor::HTLCUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
547 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
550 /// Number of blocks we wait on seeing a HTLC output being solved before we fail corresponding
551 /// inbound HTLCs. This prevents us from failing backwards and then getting a reorg resulting in us
554 /// Note that this is a library-wide security assumption. If a reorg deeper than this number of
555 /// blocks occurs, counterparties may be able to steal funds or claims made by and balances exposed
556 /// by a [`ChannelMonitor`] may be incorrect.
559 pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
560 /// Details about the balance(s) available for spending once the channel appears on chain.
562 /// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
568 /// The channel is not yet closed (or the commitment or closing transaction has not yet
569 /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
570 /// force-closed now.
571 ClaimableOnChannelClose {
572 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
573 /// required to do so.
574 amount_satoshis: u64,
576 /// The channel has been closed, and the given balance is ours but awaiting confirmations until
577 /// we consider it spendable.
578 ClaimableAwaitingConfirmations {
579 /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
580 /// were spent in broadcasting the transaction.
581 amount_satoshis: u64,
582 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
584 confirmation_height: u32,
586 /// The channel has been closed, and the given balance should be ours but awaiting spending
587 /// transaction confirmation. If the spending transaction does not confirm in time, it is
588 /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
590 /// Once the spending transaction confirms, before it has reached enough confirmations to be
591 /// considered safe from chain reorganizations, the balance will instead be provided via
592 /// [`Balance::ClaimableAwaitingConfirmations`].
593 ContentiousClaimable {
594 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
595 /// required to do so.
596 amount_satoshis: u64,
597 /// The height at which the counterparty may be able to claim the balance if we have not
600 /// The payment hash that locks this HTLC.
601 payment_hash: crate::c_types::ThirtyTwoBytes,
602 /// The preimage that can be used to claim this HTLC.
603 payment_preimage: crate::c_types::ThirtyTwoBytes,
605 /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
606 /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
607 /// likely to be claimed by our counterparty before we do.
608 MaybeTimeoutClaimableHTLC {
609 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
610 /// which will be required to do so.
611 amount_satoshis: u64,
612 /// The height at which we will be able to claim the balance if our counterparty has not
614 claimable_height: u32,
615 /// The payment hash whose preimage our counterparty needs to claim this HTLC.
616 payment_hash: crate::c_types::ThirtyTwoBytes,
618 /// HTLCs which we received from our counterparty which are claimable with a preimage which we
619 /// do not currently have. This will only be claimable if we receive the preimage from the node
620 /// to which we forwarded this HTLC before the timeout.
621 MaybePreimageClaimableHTLC {
622 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
623 /// which will be required to do so.
624 amount_satoshis: u64,
625 /// The height at which our counterparty will be able to claim the balance if we have not
626 /// yet received the preimage and claimed it ourselves.
628 /// The payment hash whose preimage we need to claim this HTLC.
629 payment_hash: crate::c_types::ThirtyTwoBytes,
631 /// The channel has been closed, and our counterparty broadcasted a revoked commitment
634 /// Thus, we're able to claim all outputs in the commitment transaction, one of which has the
635 /// following amount.
636 CounterpartyRevokedOutputClaimable {
637 /// The amount, in satoshis, of the output which we can claim.
639 /// Note that for outputs from HTLC balances this may be excluding some on-chain fees that
640 /// were already spent.
641 amount_satoshis: u64,
644 use lightning::chain::channelmonitor::Balance as BalanceImport;
645 pub(crate) type nativeBalance = BalanceImport;
649 pub(crate) fn to_native(&self) -> nativeBalance {
651 Balance::ClaimableOnChannelClose {ref amount_satoshis, } => {
652 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
653 nativeBalance::ClaimableOnChannelClose {
654 amount_satoshis: amount_satoshis_nonref,
657 Balance::ClaimableAwaitingConfirmations {ref amount_satoshis, ref confirmation_height, } => {
658 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
659 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
660 nativeBalance::ClaimableAwaitingConfirmations {
661 amount_satoshis: amount_satoshis_nonref,
662 confirmation_height: confirmation_height_nonref,
665 Balance::ContentiousClaimable {ref amount_satoshis, ref timeout_height, ref payment_hash, ref payment_preimage, } => {
666 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
667 let mut timeout_height_nonref = Clone::clone(timeout_height);
668 let mut payment_hash_nonref = Clone::clone(payment_hash);
669 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
670 nativeBalance::ContentiousClaimable {
671 amount_satoshis: amount_satoshis_nonref,
672 timeout_height: timeout_height_nonref,
673 payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_nonref.data),
674 payment_preimage: ::lightning::ln::types::PaymentPreimage(payment_preimage_nonref.data),
677 Balance::MaybeTimeoutClaimableHTLC {ref amount_satoshis, ref claimable_height, ref payment_hash, } => {
678 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
679 let mut claimable_height_nonref = Clone::clone(claimable_height);
680 let mut payment_hash_nonref = Clone::clone(payment_hash);
681 nativeBalance::MaybeTimeoutClaimableHTLC {
682 amount_satoshis: amount_satoshis_nonref,
683 claimable_height: claimable_height_nonref,
684 payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_nonref.data),
687 Balance::MaybePreimageClaimableHTLC {ref amount_satoshis, ref expiry_height, ref payment_hash, } => {
688 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
689 let mut expiry_height_nonref = Clone::clone(expiry_height);
690 let mut payment_hash_nonref = Clone::clone(payment_hash);
691 nativeBalance::MaybePreimageClaimableHTLC {
692 amount_satoshis: amount_satoshis_nonref,
693 expiry_height: expiry_height_nonref,
694 payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_nonref.data),
697 Balance::CounterpartyRevokedOutputClaimable {ref amount_satoshis, } => {
698 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
699 nativeBalance::CounterpartyRevokedOutputClaimable {
700 amount_satoshis: amount_satoshis_nonref,
706 pub(crate) fn into_native(self) -> nativeBalance {
708 Balance::ClaimableOnChannelClose {mut amount_satoshis, } => {
709 nativeBalance::ClaimableOnChannelClose {
710 amount_satoshis: amount_satoshis,
713 Balance::ClaimableAwaitingConfirmations {mut amount_satoshis, mut confirmation_height, } => {
714 nativeBalance::ClaimableAwaitingConfirmations {
715 amount_satoshis: amount_satoshis,
716 confirmation_height: confirmation_height,
719 Balance::ContentiousClaimable {mut amount_satoshis, mut timeout_height, mut payment_hash, mut payment_preimage, } => {
720 nativeBalance::ContentiousClaimable {
721 amount_satoshis: amount_satoshis,
722 timeout_height: timeout_height,
723 payment_hash: ::lightning::ln::types::PaymentHash(payment_hash.data),
724 payment_preimage: ::lightning::ln::types::PaymentPreimage(payment_preimage.data),
727 Balance::MaybeTimeoutClaimableHTLC {mut amount_satoshis, mut claimable_height, mut payment_hash, } => {
728 nativeBalance::MaybeTimeoutClaimableHTLC {
729 amount_satoshis: amount_satoshis,
730 claimable_height: claimable_height,
731 payment_hash: ::lightning::ln::types::PaymentHash(payment_hash.data),
734 Balance::MaybePreimageClaimableHTLC {mut amount_satoshis, mut expiry_height, mut payment_hash, } => {
735 nativeBalance::MaybePreimageClaimableHTLC {
736 amount_satoshis: amount_satoshis,
737 expiry_height: expiry_height,
738 payment_hash: ::lightning::ln::types::PaymentHash(payment_hash.data),
741 Balance::CounterpartyRevokedOutputClaimable {mut amount_satoshis, } => {
742 nativeBalance::CounterpartyRevokedOutputClaimable {
743 amount_satoshis: amount_satoshis,
749 pub(crate) fn from_native(native: &BalanceImport) -> Self {
750 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBalance) };
752 nativeBalance::ClaimableOnChannelClose {ref amount_satoshis, } => {
753 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
754 Balance::ClaimableOnChannelClose {
755 amount_satoshis: amount_satoshis_nonref,
758 nativeBalance::ClaimableAwaitingConfirmations {ref amount_satoshis, ref confirmation_height, } => {
759 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
760 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
761 Balance::ClaimableAwaitingConfirmations {
762 amount_satoshis: amount_satoshis_nonref,
763 confirmation_height: confirmation_height_nonref,
766 nativeBalance::ContentiousClaimable {ref amount_satoshis, ref timeout_height, ref payment_hash, ref payment_preimage, } => {
767 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
768 let mut timeout_height_nonref = Clone::clone(timeout_height);
769 let mut payment_hash_nonref = Clone::clone(payment_hash);
770 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
771 Balance::ContentiousClaimable {
772 amount_satoshis: amount_satoshis_nonref,
773 timeout_height: timeout_height_nonref,
774 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
775 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
778 nativeBalance::MaybeTimeoutClaimableHTLC {ref amount_satoshis, ref claimable_height, ref payment_hash, } => {
779 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
780 let mut claimable_height_nonref = Clone::clone(claimable_height);
781 let mut payment_hash_nonref = Clone::clone(payment_hash);
782 Balance::MaybeTimeoutClaimableHTLC {
783 amount_satoshis: amount_satoshis_nonref,
784 claimable_height: claimable_height_nonref,
785 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
788 nativeBalance::MaybePreimageClaimableHTLC {ref amount_satoshis, ref expiry_height, ref payment_hash, } => {
789 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
790 let mut expiry_height_nonref = Clone::clone(expiry_height);
791 let mut payment_hash_nonref = Clone::clone(payment_hash);
792 Balance::MaybePreimageClaimableHTLC {
793 amount_satoshis: amount_satoshis_nonref,
794 expiry_height: expiry_height_nonref,
795 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
798 nativeBalance::CounterpartyRevokedOutputClaimable {ref amount_satoshis, } => {
799 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
800 Balance::CounterpartyRevokedOutputClaimable {
801 amount_satoshis: amount_satoshis_nonref,
807 pub(crate) fn native_into(native: nativeBalance) -> Self {
809 nativeBalance::ClaimableOnChannelClose {mut amount_satoshis, } => {
810 Balance::ClaimableOnChannelClose {
811 amount_satoshis: amount_satoshis,
814 nativeBalance::ClaimableAwaitingConfirmations {mut amount_satoshis, mut confirmation_height, } => {
815 Balance::ClaimableAwaitingConfirmations {
816 amount_satoshis: amount_satoshis,
817 confirmation_height: confirmation_height,
820 nativeBalance::ContentiousClaimable {mut amount_satoshis, mut timeout_height, mut payment_hash, mut payment_preimage, } => {
821 Balance::ContentiousClaimable {
822 amount_satoshis: amount_satoshis,
823 timeout_height: timeout_height,
824 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
825 payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
828 nativeBalance::MaybeTimeoutClaimableHTLC {mut amount_satoshis, mut claimable_height, mut payment_hash, } => {
829 Balance::MaybeTimeoutClaimableHTLC {
830 amount_satoshis: amount_satoshis,
831 claimable_height: claimable_height,
832 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
835 nativeBalance::MaybePreimageClaimableHTLC {mut amount_satoshis, mut expiry_height, mut payment_hash, } => {
836 Balance::MaybePreimageClaimableHTLC {
837 amount_satoshis: amount_satoshis,
838 expiry_height: expiry_height,
839 payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
842 nativeBalance::CounterpartyRevokedOutputClaimable {mut amount_satoshis, } => {
843 Balance::CounterpartyRevokedOutputClaimable {
844 amount_satoshis: amount_satoshis,
850 /// Frees any resources used by the Balance
852 pub extern "C" fn Balance_free(this_ptr: Balance) { }
853 /// Creates a copy of the Balance
855 pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
859 /// Used only if an object of this type is returned as a trait impl by a method
860 pub(crate) extern "C" fn Balance_clone_void(this_ptr: *const c_void) -> *mut c_void {
861 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Balance)).clone() })) as *mut c_void
864 /// Used only if an object of this type is returned as a trait impl by a method
865 pub(crate) extern "C" fn Balance_free_void(this_ptr: *mut c_void) {
866 let _ = unsafe { Box::from_raw(this_ptr as *mut Balance) };
869 /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
870 pub extern "C" fn Balance_claimable_on_channel_close(amount_satoshis: u64) -> Balance {
871 Balance::ClaimableOnChannelClose {
876 /// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
877 pub extern "C" fn Balance_claimable_awaiting_confirmations(amount_satoshis: u64, confirmation_height: u32) -> Balance {
878 Balance::ClaimableAwaitingConfirmations {
884 /// Utility method to constructs a new ContentiousClaimable-variant Balance
885 pub extern "C" fn Balance_contentious_claimable(amount_satoshis: u64, timeout_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes, payment_preimage: crate::c_types::ThirtyTwoBytes) -> Balance {
886 Balance::ContentiousClaimable {
894 /// Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
895 pub extern "C" fn Balance_maybe_timeout_claimable_htlc(amount_satoshis: u64, claimable_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes) -> Balance {
896 Balance::MaybeTimeoutClaimableHTLC {
903 /// Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
904 pub extern "C" fn Balance_maybe_preimage_claimable_htlc(amount_satoshis: u64, expiry_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes) -> Balance {
905 Balance::MaybePreimageClaimableHTLC {
912 /// Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
913 pub extern "C" fn Balance_counterparty_revoked_output_claimable(amount_satoshis: u64) -> Balance {
914 Balance::CounterpartyRevokedOutputClaimable {
918 /// Get a string which allows debug introspection of a Balance object
919 pub extern "C" fn Balance_debug_str_void(o: *const c_void) -> Str {
920 alloc::format!("{:?}", unsafe { o as *const crate::lightning::chain::channelmonitor::Balance }).into()}
921 /// Checks if two Balances contain equal inner contents.
922 /// This ignores pointers and is_owned flags and looks at the values in fields.
924 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
925 if &a.to_native() == &b.to_native() { true } else { false }
927 /// The amount claimable, in satoshis. This excludes balances that we are unsure if we are able
928 /// to claim, this is because we are waiting for a preimage or for a timeout to expire. For more
929 /// information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and
930 /// [`Balance::MaybePreimageClaimableHTLC`].
932 /// On-chain fees required to claim the balance are not included in this amount.
935 pub extern "C" fn Balance_claimable_amount_satoshis(this_arg: &crate::lightning::chain::channelmonitor::Balance) -> u64 {
936 let mut ret = this_arg.to_native().claimable_amount_satoshis();
941 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
942 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner, >;
944 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
945 /// on-chain transactions to ensure no loss of funds occurs.
947 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
948 /// information and are actively monitoring the chain.
950 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
951 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
952 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
953 /// returned block hash and the the current chain and then reconnecting blocks to get to the
954 /// best chain) upon deserializing the object!
957 pub struct ChannelMonitor {
958 /// A pointer to the opaque Rust object.
960 /// Nearly everywhere, inner must be non-null, however in places where
961 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
962 pub inner: *mut nativeChannelMonitor,
963 /// Indicates that this is the only struct which contains the same pointer.
965 /// Rust functions which take ownership of an object provided via an argument require
966 /// this to be true and invalidate the object pointed to by inner.
970 impl Drop for ChannelMonitor {
972 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
973 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
977 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
979 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
981 /// Used only if an object of this type is returned as a trait impl by a method
982 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
983 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitor) };
986 impl ChannelMonitor {
987 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
988 unsafe { &*ObjOps::untweak_ptr(self.inner) }
990 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
991 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
993 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
994 pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
995 assert!(self.is_owned);
996 let ret = ObjOps::untweak_ptr(self.inner);
997 self.inner = core::ptr::null_mut();
1001 impl Clone for ChannelMonitor {
1002 fn clone(&self) -> Self {
1004 inner: if <*mut nativeChannelMonitor>::is_null(self.inner) { core::ptr::null_mut() } else {
1005 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1011 /// Used only if an object of this type is returned as a trait impl by a method
1012 pub(crate) extern "C" fn ChannelMonitor_clone_void(this_ptr: *const c_void) -> *mut c_void {
1013 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelMonitor)).clone() })) as *mut c_void
1016 /// Creates a copy of the ChannelMonitor
1017 pub extern "C" fn ChannelMonitor_clone(orig: &ChannelMonitor) -> ChannelMonitor {
1021 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
1022 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
1023 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1026 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1027 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
1029 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
1032 /// panics if the given update is not the next update by update_id.
1035 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 {
1036 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
1037 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() };
1041 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
1045 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
1046 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
1050 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
1053 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointCVec_u8ZZ {
1054 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
1055 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.to_bytes().into()).into();
1059 /// Gets the channel_id of the channel this ChannelMonitor is monitoring for.
1062 pub extern "C" fn ChannelMonitor_channel_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::ln::types::ChannelId {
1063 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_id();
1064 crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(ret), is_owned: true }
1067 /// Gets a list of txids, with their output scripts (in the order they appear in the
1068 /// transaction), which we must learn about spends of via block_connected().
1071 pub extern "C" fn ChannelMonitor_get_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_ThirtyTwoBytesCVec_C2Tuple_u32CVec_u8ZZZZZ {
1072 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
1073 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.to_bytes().into()).into(); local_orig_ret_0_1_0 }); }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: *orig_ret_0_0.as_ref() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1077 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
1078 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
1079 /// have been registered.
1081 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter, logger: &crate::lightning::util::logger::Logger) {
1082 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter, logger)
1085 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
1086 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
1089 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
1090 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
1091 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
1095 /// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
1097 /// For channels featuring anchor outputs, this method will also process [`BumpTransaction`]
1098 /// events produced from each [`ChannelMonitor`] while there is a balance to claim onchain
1099 /// within each channel. As the confirmation of a commitment transaction may be critical to the
1100 /// safety of funds, we recommend invoking this every 30 seconds, or lower if running in an
1101 /// environment with spotty connections, like on mobile.
1103 /// An [`EventHandler`] may safely call back to the provider, though this shouldn't be needed in
1104 /// order to handle these events.
1106 /// [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
1107 /// [`BumpTransaction`]: crate::events::Event::BumpTransaction
1109 pub extern "C" fn ChannelMonitor_process_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, handler: &crate::lightning::events::EventHandler) {
1110 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_events(handler)
1113 /// Gets the counterparty's initial commitment transaction. The returned commitment
1114 /// transaction is unsigned. This is intended to be called during the initial persistence of
1115 /// the monitor (inside an implementation of [`Persist::persist_new_channel`]), to allow for
1116 /// watchtowers in the persistence pipeline to have enough data to form justice transactions.
1118 /// This is similar to [`Self::counterparty_commitment_txs_from_update`], except
1119 /// that for the initial commitment transaction, we don't have a corresponding update.
1121 /// This will only return `Some` for channel monitors that have been created after upgrading
1122 /// to LDK 0.0.117+.
1124 /// [`Persist::persist_new_channel`]: crate::chain::chainmonitor::Persist::persist_new_channel
1126 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1129 pub extern "C" fn ChannelMonitor_initial_counterparty_commitment_tx(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::ln::chan_utils::CommitmentTransaction {
1130 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.initial_counterparty_commitment_tx();
1131 let mut local_ret = crate::lightning::ln::chan_utils::CommitmentTransaction { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
1135 /// Gets all of the counterparty commitment transactions provided by the given update. This
1136 /// may be empty if the update doesn't include any new counterparty commitments. Returned
1137 /// commitment transactions are unsigned.
1139 /// This is provided so that watchtower clients in the persistence pipeline are able to build
1140 /// justice transactions for each counterparty commitment upon each update. It's intended to be
1141 /// used within an implementation of [`Persist::update_persisted_channel`], which is provided
1142 /// with a monitor and an update. Once revoked, signing a justice transaction can be done using
1143 /// [`Self::sign_to_local_justice_tx`].
1145 /// It is expected that a watchtower client may use this method to retrieve the latest counterparty
1146 /// commitment transaction(s), and then hold the necessary data until a later update in which
1147 /// the monitor has been updated with the corresponding revocation data, at which point the
1148 /// monitor can sign the justice transaction.
1150 /// This will only return a non-empty list for monitor updates that have been created after
1151 /// upgrading to LDK 0.0.117+. Note that no restriction lies on the monitors themselves, which
1152 /// may have been created prior to upgrading.
1154 /// [`Persist::update_persisted_channel`]: crate::chain::chainmonitor::Persist::update_persisted_channel
1157 pub extern "C" fn ChannelMonitor_counterparty_commitment_txs_from_update(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, update: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_CommitmentTransactionZ {
1158 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_commitment_txs_from_update(update.get_native_ref());
1159 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::chan_utils::CommitmentTransaction { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1163 /// Wrapper around [`EcdsaChannelSigner::sign_justice_revoked_output`] to make
1164 /// signing the justice transaction easier for implementors of
1165 /// [`chain::chainmonitor::Persist`]. On success this method returns the provided transaction
1166 /// signing the input at `input_idx`. This method will only produce a valid signature for
1167 /// a transaction spending the `to_local` output of a commitment transaction, i.e. this cannot
1168 /// be used for revoked HTLC outputs.
1170 /// `Value` is the value of the output being spent by the input at `input_idx`, committed
1171 /// in the BIP 143 signature.
1173 /// This method will only succeed if this monitor has received the revocation secret for the
1174 /// provided `commitment_number`. If a commitment number is provided that does not correspond
1175 /// to the commitment transaction being revoked, this will return a signed transaction, but
1176 /// the signature will not be valid.
1178 /// [`EcdsaChannelSigner::sign_justice_revoked_output`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_justice_revoked_output
1179 /// [`Persist`]: crate::chain::chainmonitor::Persist
1182 pub extern "C" fn ChannelMonitor_sign_to_local_justice_tx(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, mut justice_tx: crate::c_types::Transaction, mut input_idx: usize, mut value: u64, mut commitment_number: u64) -> crate::c_types::derived::CResult_TransactionNoneZ {
1183 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_to_local_justice_tx(justice_tx.into_bitcoin(), input_idx, value, commitment_number);
1184 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Transaction::from_bitcoin(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1188 /// Gets the `node_id` of the counterparty for this channel.
1190 /// Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
1193 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1196 pub extern "C" fn ChannelMonitor_get_counterparty_node_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::PublicKey {
1197 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_counterparty_node_id();
1198 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1202 /// You may use this to broadcast the latest local commitment transaction, either because
1203 /// a monitor update failed or because we've fallen behind (i.e. we've received proof that our
1204 /// counterparty side knows a revocation secret we gave them that they shouldn't know).
1206 /// Broadcasting these transactions in this manner is UNSAFE, as they allow counterparty
1207 /// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
1208 /// close channel with their commitment transaction after a substantial amount of time. Best
1209 /// may be to contact the other node operator out-of-band to coordinate other options available
1212 pub extern "C" fn ChannelMonitor_broadcast_latest_holder_commitment_txn(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, broadcaster: &crate::lightning::chain::chaininterface::BroadcasterInterface, fee_estimator: &crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) {
1213 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcast_latest_holder_commitment_txn(broadcaster, fee_estimator, logger)
1216 /// Processes transactions in a newly connected block, which may result in any of the following:
1217 /// - update the monitor's state against resolved HTLCs
1218 /// - punish the counterparty in the case of seeing a revoked commitment transaction
1219 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
1220 /// - detect settled outputs for later spending
1221 /// - schedule and bump any in-flight claims
1223 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
1224 /// [`get_outputs_to_watch`].
1226 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
1229 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, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
1230 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 }); };
1231 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);
1232 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.as_ref() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1236 /// Determines if the disconnected block contained any transactions of interest and updates
1239 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, logger: &crate::lightning::util::logger::Logger) {
1240 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
1243 /// Processes transactions confirmed in a block with the given header and height, returning new
1244 /// outputs to watch. See [`block_connected`] for details.
1246 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1247 /// blocks. See [`chain::Confirm`] for calling expectations.
1249 /// [`block_connected`]: Self::block_connected
1252 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, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
1253 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 }); };
1254 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);
1255 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.as_ref() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1259 /// Processes a transaction that was reorganized out of the chain.
1261 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
1262 /// than blocks. See [`chain::Confirm`] for calling expectations.
1264 /// [`block_disconnected`]: Self::block_disconnected
1266 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, logger: &crate::lightning::util::logger::Logger) {
1267 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
1270 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
1271 /// [`block_connected`] for details.
1273 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1274 /// blocks. See [`chain::Confirm`] for calling expectations.
1276 /// [`block_connected`]: Self::block_connected
1279 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, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionOutputsZ {
1280 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);
1281 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.as_ref() }, local_orig_ret_0_1.into()).into(); local_ret_0 }); };
1285 /// Returns the set of txids that should be monitored for re-organization out of the chain.
1288 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C3Tuple_ThirtyTwoBytesu32COption_ThirtyTwoBytesZZZ {
1289 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
1290 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, mut orig_ret_0_2) = item; let mut local_orig_ret_0_2 = if orig_ret_0_2.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some( { crate::c_types::ThirtyTwoBytes { data: *orig_ret_0_2.unwrap().as_ref() } }) }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: *orig_ret_0_0.as_ref() }, orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); };
1294 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1295 /// [`chain::Confirm`] interfaces.
1298 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
1299 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1300 crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1303 /// Triggers rebroadcasts/fee-bumps of pending claims from a force-closed channel. This is
1304 /// crucial in preventing certain classes of pinning attacks, detecting substantial mempool
1305 /// feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend
1306 /// invoking this every 30 seconds, or lower if running in an environment with spotty
1307 /// connections, like on mobile.
1309 pub extern "C" fn ChannelMonitor_rebroadcast_pending_claims(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) {
1310 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.rebroadcast_pending_claims(broadcaster, fee_estimator, logger)
1313 /// Triggers rebroadcasts of pending claims from a force-closed channel after a transaction
1314 /// signature generation failure.
1316 pub extern "C" fn ChannelMonitor_signer_unblocked(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) {
1317 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signer_unblocked(broadcaster, fee_estimator, logger)
1320 /// Returns the descriptors for relevant outputs (i.e., those that we can spend) within the
1321 /// transaction if they exist and the transaction has at least [`ANTI_REORG_DELAY`]
1322 /// confirmations. For [`SpendableOutputDescriptor::DelayedPaymentOutput`] descriptors to be
1323 /// returned, the transaction must have at least `max(ANTI_REORG_DELAY, to_self_delay)`
1326 /// Descriptors returned by this method are primarily exposed via [`Event::SpendableOutputs`]
1327 /// once they are no longer under reorg risk. This method serves as a way to retrieve these
1328 /// descriptors at a later time, either for historical purposes, or to replay any
1329 /// missed/unhandled descriptors. For the purpose of gathering historical records, if the
1330 /// channel close has fully resolved (i.e., [`ChannelMonitor::get_claimable_balances`] returns
1331 /// an empty set), you can retrieve all spendable outputs by providing all descendant spending
1332 /// transactions starting from the channel's funding transaction and going down three levels.
1334 /// `tx` is a transaction we'll scan the outputs of. Any transaction can be provided. If any
1335 /// outputs which can be spent by us are found, at least one descriptor is returned.
1337 /// `confirmation_height` must be the height of the block in which `tx` was included in.
1340 pub extern "C" fn ChannelMonitor_get_spendable_outputs(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, mut tx: crate::c_types::Transaction, mut confirmation_height: u32) -> crate::c_types::derived::CVec_SpendableOutputDescriptorZ {
1341 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_spendable_outputs(&tx.into_bitcoin(), confirmation_height);
1342 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::sign::SpendableOutputDescriptor::native_into(item) }); };
1346 /// Checks if the monitor is fully resolved. Resolved monitor is one that has claimed all of
1347 /// its outputs and balances (i.e. [`Self::get_claimable_balances`] returns an empty set).
1349 /// This function returns true only if [`Self::get_claimable_balances`] has been empty for at least
1350 /// 4032 blocks as an additional protection against any bugs resulting in spuriously empty balance sets.
1353 pub extern "C" fn ChannelMonitor_is_fully_resolved(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, logger: &crate::lightning::util::logger::Logger) -> bool {
1354 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_fully_resolved(logger);
1358 /// Gets the balances in this channel which are either claimable by us if we were to
1359 /// force-close the channel now or which are claimable on-chain (possibly awaiting
1362 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
1363 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
1364 /// balance, or until our counterparty has claimed the balance and accrued several
1365 /// confirmations on the claim transaction.
1367 /// Note that for `ChannelMonitors` which track a channel which went on-chain with versions of
1368 /// LDK prior to 0.0.111, not all or excess balances may be included.
1370 /// See [`Balance`] for additional details on the types of claimable balances which
1371 /// may be returned here and their meanings.
1374 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
1375 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
1376 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
1381 /// Read a C2Tuple_ThirtyTwoBytesChannelMonitorZ from a byte array, created by C2Tuple_ThirtyTwoBytesChannelMonitorZ_write
1382 pub extern "C" fn C2Tuple_ThirtyTwoBytesChannelMonitorZ_read(ser: crate::c_types::u8slice, arg_a: &crate::lightning::sign::EntropySource, arg_b: &crate::lightning::sign::SignerProvider) -> crate::c_types::derived::CResult_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ {
1383 let arg_a_conv = arg_a;
1384 let arg_b_conv = arg_b;
1385 let arg_conv = (arg_a_conv, arg_b_conv);
1386 let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1387 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.as_ref() }, crate::lightning::chain::channelmonitor::ChannelMonitor { inner: ObjOps::heap_alloc(orig_res_0_1), is_owned: true }).into(); local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };