c15e5bb5568483a32f07bc8c0362070e5db42955
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / channelmonitor.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! The logic to monitor for on-chain transactions and create the relevant claim responses lives
10 //! here.
11 //!
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.
15 //!
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.
21
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};
30
31
32 use lightning::chain::channelmonitor::ChannelMonitorUpdate as nativeChannelMonitorUpdateImport;
33 pub(crate) type nativeChannelMonitorUpdate = nativeChannelMonitorUpdateImport;
34
35 /// An update generated by the underlying channel itself which contains some new information the
36 /// [`ChannelMonitor`] should be made aware of.
37 ///
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.
42 #[must_use]
43 #[repr(C)]
44 pub struct ChannelMonitorUpdate {
45         /// A pointer to the opaque Rust object.
46
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.
51
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.
54         pub is_owned: bool,
55 }
56
57 impl Drop for ChannelMonitorUpdate {
58         fn drop(&mut self) {
59                 if self.is_owned && !<*mut nativeChannelMonitorUpdate>::is_null(self.inner) {
60                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
61                 }
62         }
63 }
64 /// Frees any resources used by the ChannelMonitorUpdate, if is_owned is set and inner is non-NULL.
65 #[no_mangle]
66 pub extern "C" fn ChannelMonitorUpdate_free(this_obj: ChannelMonitorUpdate) { }
67 #[allow(unused)]
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) };
71 }
72 #[allow(unused)]
73 impl ChannelMonitorUpdate {
74         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitorUpdate {
75                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
76         }
77         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitorUpdate {
78                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
79         }
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();
85                 ret
86         }
87 }
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.
91 ///
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.
95 ///
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.
101 ///
102 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
103 #[no_mangle]
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;
106         *inner_val
107 }
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.
111 ///
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.
115 ///
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.
121 ///
122 /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
123 #[no_mangle]
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;
126 }
127 impl Clone for ChannelMonitorUpdate {
128         fn clone(&self) -> Self {
129                 Self {
130                         inner: if <*mut nativeChannelMonitorUpdate>::is_null(self.inner) { core::ptr::null_mut() } else {
131                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
132                         is_owned: true,
133                 }
134         }
135 }
136 #[allow(unused)]
137 /// Used only if an object of this type is returned as a trait impl by a method
138 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
139         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void
140 }
141 #[no_mangle]
142 /// Creates a copy of the ChannelMonitorUpdate
143 pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
144         orig.clone()
145 }
146 /// Checks if two ChannelMonitorUpdates contain equal inner contents.
147 /// This ignores pointers and is_owned flags and looks at the values in fields.
148 /// Two objects with NULL inner values will be considered "equal" here.
149 #[no_mangle]
150 pub extern "C" fn ChannelMonitorUpdate_eq(a: &ChannelMonitorUpdate, b: &ChannelMonitorUpdate) -> bool {
151         if a.inner == b.inner { return true; }
152         if a.inner.is_null() || b.inner.is_null() { return false; }
153         if a.get_native_ref() == b.get_native_ref() { true } else { false }
154 }
155 /// The update ID used for a [`ChannelMonitorUpdate`] that is either:
156 ///
157 ///\t(1) attempting to force close the channel by broadcasting our latest commitment transaction or
158 ///\t(2) providing a preimage (after the channel has been force closed) from a forward link that
159 ///\t\tallows us to spend an HTLC output on this channel's (the backward link's) broadcasted
160 ///\t\tcommitment transaction.
161 ///
162 /// No other [`ChannelMonitorUpdate`]s are allowed after force-close.
163
164 #[no_mangle]
165 pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
166 #[no_mangle]
167 /// Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read
168 pub extern "C" fn ChannelMonitorUpdate_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
169         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
170 }
171 #[no_mangle]
172 pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
173         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) })
174 }
175 #[no_mangle]
176 /// Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write
177 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ {
178         let res: Result<lightning::chain::channelmonitor::ChannelMonitorUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
179         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() };
180         local_res
181 }
182 /// An event to be processed by the ChannelManager.
183 #[derive(Clone)]
184 #[must_use]
185 #[repr(C)]
186 pub enum MonitorEvent {
187         /// A monitor event containing an HTLCUpdate.
188         HTLCEvent(
189                 crate::lightning::chain::channelmonitor::HTLCUpdate),
190         /// A monitor event that the Channel's commitment transaction was confirmed.
191         HolderForceClosed(
192                 crate::lightning::chain::transaction::OutPoint),
193         /// Indicates a [`ChannelMonitor`] update has completed. See
194         /// [`ChannelMonitorUpdateStatus::InProgress`] for more information on how this is used.
195         ///
196         /// [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
197         Completed {
198                 /// The funding outpoint of the [`ChannelMonitor`] that was updated
199                 funding_txo: crate::lightning::chain::transaction::OutPoint,
200                 /// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
201                 /// [`ChannelMonitor::get_latest_update_id`].
202                 ///
203                 /// Note that this should only be set to a given update's ID if all previous updates for the
204                 /// same [`ChannelMonitor`] have been applied and persisted.
205                 monitor_update_id: u64,
206         },
207 }
208 use lightning::chain::channelmonitor::MonitorEvent as MonitorEventImport;
209 pub(crate) type nativeMonitorEvent = MonitorEventImport;
210
211 impl MonitorEvent {
212         #[allow(unused)]
213         pub(crate) fn to_native(&self) -> nativeMonitorEvent {
214                 match self {
215                         MonitorEvent::HTLCEvent (ref a, ) => {
216                                 let mut a_nonref = Clone::clone(a);
217                                 nativeMonitorEvent::HTLCEvent (
218                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
219                                 )
220                         },
221                         MonitorEvent::HolderForceClosed (ref a, ) => {
222                                 let mut a_nonref = Clone::clone(a);
223                                 nativeMonitorEvent::HolderForceClosed (
224                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
225                                 )
226                         },
227                         MonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
228                                 let mut funding_txo_nonref = Clone::clone(funding_txo);
229                                 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
230                                 nativeMonitorEvent::Completed {
231                                         funding_txo: *unsafe { Box::from_raw(funding_txo_nonref.take_inner()) },
232                                         monitor_update_id: monitor_update_id_nonref,
233                                 }
234                         },
235                 }
236         }
237         #[allow(unused)]
238         pub(crate) fn into_native(self) -> nativeMonitorEvent {
239                 match self {
240                         MonitorEvent::HTLCEvent (mut a, ) => {
241                                 nativeMonitorEvent::HTLCEvent (
242                                         *unsafe { Box::from_raw(a.take_inner()) },
243                                 )
244                         },
245                         MonitorEvent::HolderForceClosed (mut a, ) => {
246                                 nativeMonitorEvent::HolderForceClosed (
247                                         *unsafe { Box::from_raw(a.take_inner()) },
248                                 )
249                         },
250                         MonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => {
251                                 nativeMonitorEvent::Completed {
252                                         funding_txo: *unsafe { Box::from_raw(funding_txo.take_inner()) },
253                                         monitor_update_id: monitor_update_id,
254                                 }
255                         },
256                 }
257         }
258         #[allow(unused)]
259         pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self {
260                 match native {
261                         nativeMonitorEvent::HTLCEvent (ref a, ) => {
262                                 let mut a_nonref = Clone::clone(a);
263                                 MonitorEvent::HTLCEvent (
264                                         crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
265                                 )
266                         },
267                         nativeMonitorEvent::HolderForceClosed (ref a, ) => {
268                                 let mut a_nonref = Clone::clone(a);
269                                 MonitorEvent::HolderForceClosed (
270                                         crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
271                                 )
272                         },
273                         nativeMonitorEvent::Completed {ref funding_txo, ref monitor_update_id, } => {
274                                 let mut funding_txo_nonref = Clone::clone(funding_txo);
275                                 let mut monitor_update_id_nonref = Clone::clone(monitor_update_id);
276                                 MonitorEvent::Completed {
277                                         funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo_nonref), is_owned: true },
278                                         monitor_update_id: monitor_update_id_nonref,
279                                 }
280                         },
281                 }
282         }
283         #[allow(unused)]
284         pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
285                 match native {
286                         nativeMonitorEvent::HTLCEvent (mut a, ) => {
287                                 MonitorEvent::HTLCEvent (
288                                         crate::lightning::chain::channelmonitor::HTLCUpdate { inner: ObjOps::heap_alloc(a), is_owned: true },
289                                 )
290                         },
291                         nativeMonitorEvent::HolderForceClosed (mut a, ) => {
292                                 MonitorEvent::HolderForceClosed (
293                                         crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(a), is_owned: true },
294                                 )
295                         },
296                         nativeMonitorEvent::Completed {mut funding_txo, mut monitor_update_id, } => {
297                                 MonitorEvent::Completed {
298                                         funding_txo: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true },
299                                         monitor_update_id: monitor_update_id,
300                                 }
301                         },
302                 }
303         }
304 }
305 /// Frees any resources used by the MonitorEvent
306 #[no_mangle]
307 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
308 /// Creates a copy of the MonitorEvent
309 #[no_mangle]
310 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
311         orig.clone()
312 }
313 #[no_mangle]
314 /// Utility method to constructs a new HTLCEvent-variant MonitorEvent
315 pub extern "C" fn MonitorEvent_htlcevent(a: crate::lightning::chain::channelmonitor::HTLCUpdate) -> MonitorEvent {
316         MonitorEvent::HTLCEvent(a, )
317 }
318 #[no_mangle]
319 /// Utility method to constructs a new HolderForceClosed-variant MonitorEvent
320 pub extern "C" fn MonitorEvent_holder_force_closed(a: crate::lightning::chain::transaction::OutPoint) -> MonitorEvent {
321         MonitorEvent::HolderForceClosed(a, )
322 }
323 #[no_mangle]
324 /// Utility method to constructs a new Completed-variant MonitorEvent
325 pub extern "C" fn MonitorEvent_completed(funding_txo: crate::lightning::chain::transaction::OutPoint, monitor_update_id: u64) -> MonitorEvent {
326         MonitorEvent::Completed {
327                 funding_txo,
328                 monitor_update_id,
329         }
330 }
331 /// Checks if two MonitorEvents contain equal inner contents.
332 /// This ignores pointers and is_owned flags and looks at the values in fields.
333 #[no_mangle]
334 pub extern "C" fn MonitorEvent_eq(a: &MonitorEvent, b: &MonitorEvent) -> bool {
335         if &a.to_native() == &b.to_native() { true } else { false }
336 }
337 #[no_mangle]
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())
341 }
342 #[no_mangle]
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::native_into(e) }).into() };
347         local_res
348 }
349
350 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
351 pub(crate) type nativeHTLCUpdate = nativeHTLCUpdateImport;
352
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.
356 #[must_use]
357 #[repr(C)]
358 pub struct HTLCUpdate {
359         /// A pointer to the opaque Rust object.
360
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.
365
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.
368         pub is_owned: bool,
369 }
370
371 impl Drop for HTLCUpdate {
372         fn drop(&mut self) {
373                 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
374                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
375                 }
376         }
377 }
378 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
379 #[no_mangle]
380 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
381 #[allow(unused)]
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         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCUpdate) };
385 }
386 #[allow(unused)]
387 impl HTLCUpdate {
388         pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCUpdate {
389                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
390         }
391         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCUpdate {
392                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
393         }
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();
399                 ret
400         }
401 }
402 impl Clone for HTLCUpdate {
403         fn clone(&self) -> Self {
404                 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()) },
407                         is_owned: true,
408                 }
409         }
410 }
411 #[allow(unused)]
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
415 }
416 #[no_mangle]
417 /// Creates a copy of the HTLCUpdate
418 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
419         orig.clone()
420 }
421 /// Checks if two HTLCUpdates contain equal inner contents.
422 /// This ignores pointers and is_owned flags and looks at the values in fields.
423 /// Two objects with NULL inner values will be considered "equal" here.
424 #[no_mangle]
425 pub extern "C" fn HTLCUpdate_eq(a: &HTLCUpdate, b: &HTLCUpdate) -> bool {
426         if a.inner == b.inner { return true; }
427         if a.inner.is_null() || b.inner.is_null() { return false; }
428         if a.get_native_ref() == b.get_native_ref() { true } else { false }
429 }
430 #[no_mangle]
431 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
432 pub extern "C" fn HTLCUpdate_write(obj: &crate::lightning::chain::channelmonitor::HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
433         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
434 }
435 #[no_mangle]
436 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
437         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
438 }
439 #[no_mangle]
440 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
441 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
442         let res: Result<lightning::chain::channelmonitor::HTLCUpdate, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
443         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() };
444         local_res
445 }
446 /// Number of blocks we wait on seeing a HTLC output being solved before we fail corresponding
447 /// inbound HTLCs. This prevents us from failing backwards and then getting a reorg resulting in us
448 /// losing money.
449 ///
450 /// Note that this is a library-wide security assumption. If a reorg deeper than this number of
451 /// blocks occurs, counterparties may be able to steal funds or claims made by and balances exposed
452 /// by a  [`ChannelMonitor`] may be incorrect.
453
454 #[no_mangle]
455 pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
456 /// Details about the balance(s) available for spending once the channel appears on chain.
457 ///
458 /// See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
459 /// be provided.
460 #[derive(Clone)]
461 #[must_use]
462 #[repr(C)]
463 pub enum Balance {
464         /// The channel is not yet closed (or the commitment or closing transaction has not yet
465         /// appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
466         /// force-closed now.
467         ClaimableOnChannelClose {
468                 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
469                 /// required to do so.
470                 amount_satoshis: u64,
471         },
472         /// The channel has been closed, and the given balance is ours but awaiting confirmations until
473         /// we consider it spendable.
474         ClaimableAwaitingConfirmations {
475                 /// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
476                 /// were spent in broadcasting the transaction.
477                 amount_satoshis: u64,
478                 /// The height at which an [`Event::SpendableOutputs`] event will be generated for this
479                 /// amount.
480                 confirmation_height: u32,
481         },
482         /// The channel has been closed, and the given balance should be ours but awaiting spending
483         /// transaction confirmation. If the spending transaction does not confirm in time, it is
484         /// possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
485         ///
486         /// Once the spending transaction confirms, before it has reached enough confirmations to be
487         /// considered safe from chain reorganizations, the balance will instead be provided via
488         /// [`Balance::ClaimableAwaitingConfirmations`].
489         ContentiousClaimable {
490                 /// The amount available to claim, in satoshis, excluding the on-chain fees which will be
491                 /// required to do so.
492                 amount_satoshis: u64,
493                 /// The height at which the counterparty may be able to claim the balance if we have not
494                 /// done so.
495                 timeout_height: u32,
496                 /// The payment hash that locks this HTLC.
497                 payment_hash: crate::c_types::ThirtyTwoBytes,
498                 /// The preimage that can be used to claim this HTLC.
499                 payment_preimage: crate::c_types::ThirtyTwoBytes,
500         },
501         /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
502         /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
503         /// likely to be claimed by our counterparty before we do.
504         MaybeTimeoutClaimableHTLC {
505                 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
506                 /// which will be required to do so.
507                 amount_satoshis: u64,
508                 /// The height at which we will be able to claim the balance if our counterparty has not
509                 /// done so.
510                 claimable_height: u32,
511                 /// The payment hash whose preimage our counterparty needs to claim this HTLC.
512                 payment_hash: crate::c_types::ThirtyTwoBytes,
513         },
514         /// HTLCs which we received from our counterparty which are claimable with a preimage which we
515         /// do not currently have. This will only be claimable if we receive the preimage from the node
516         /// to which we forwarded this HTLC before the timeout.
517         MaybePreimageClaimableHTLC {
518                 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
519                 /// which will be required to do so.
520                 amount_satoshis: u64,
521                 /// The height at which our counterparty will be able to claim the balance if we have not
522                 /// yet received the preimage and claimed it ourselves.
523                 expiry_height: u32,
524                 /// The payment hash whose preimage we need to claim this HTLC.
525                 payment_hash: crate::c_types::ThirtyTwoBytes,
526         },
527         /// The channel has been closed, and our counterparty broadcasted a revoked commitment
528         /// transaction.
529         ///
530         /// Thus, we're able to claim all outputs in the commitment transaction, one of which has the
531         /// following amount.
532         CounterpartyRevokedOutputClaimable {
533                 /// The amount, in satoshis, of the output which we can claim.
534                 ///
535                 /// Note that for outputs from HTLC balances this may be excluding some on-chain fees that
536                 /// were already spent.
537                 amount_satoshis: u64,
538         },
539 }
540 use lightning::chain::channelmonitor::Balance as BalanceImport;
541 pub(crate) type nativeBalance = BalanceImport;
542
543 impl Balance {
544         #[allow(unused)]
545         pub(crate) fn to_native(&self) -> nativeBalance {
546                 match self {
547                         Balance::ClaimableOnChannelClose {ref amount_satoshis, } => {
548                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
549                                 nativeBalance::ClaimableOnChannelClose {
550                                         amount_satoshis: amount_satoshis_nonref,
551                                 }
552                         },
553                         Balance::ClaimableAwaitingConfirmations {ref amount_satoshis, ref confirmation_height, } => {
554                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
555                                 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
556                                 nativeBalance::ClaimableAwaitingConfirmations {
557                                         amount_satoshis: amount_satoshis_nonref,
558                                         confirmation_height: confirmation_height_nonref,
559                                 }
560                         },
561                         Balance::ContentiousClaimable {ref amount_satoshis, ref timeout_height, ref payment_hash, ref payment_preimage, } => {
562                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
563                                 let mut timeout_height_nonref = Clone::clone(timeout_height);
564                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
565                                 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
566                                 nativeBalance::ContentiousClaimable {
567                                         amount_satoshis: amount_satoshis_nonref,
568                                         timeout_height: timeout_height_nonref,
569                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
570                                         payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data),
571                                 }
572                         },
573                         Balance::MaybeTimeoutClaimableHTLC {ref amount_satoshis, ref claimable_height, ref payment_hash, } => {
574                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
575                                 let mut claimable_height_nonref = Clone::clone(claimable_height);
576                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
577                                 nativeBalance::MaybeTimeoutClaimableHTLC {
578                                         amount_satoshis: amount_satoshis_nonref,
579                                         claimable_height: claimable_height_nonref,
580                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
581                                 }
582                         },
583                         Balance::MaybePreimageClaimableHTLC {ref amount_satoshis, ref expiry_height, ref payment_hash, } => {
584                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
585                                 let mut expiry_height_nonref = Clone::clone(expiry_height);
586                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
587                                 nativeBalance::MaybePreimageClaimableHTLC {
588                                         amount_satoshis: amount_satoshis_nonref,
589                                         expiry_height: expiry_height_nonref,
590                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data),
591                                 }
592                         },
593                         Balance::CounterpartyRevokedOutputClaimable {ref amount_satoshis, } => {
594                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
595                                 nativeBalance::CounterpartyRevokedOutputClaimable {
596                                         amount_satoshis: amount_satoshis_nonref,
597                                 }
598                         },
599                 }
600         }
601         #[allow(unused)]
602         pub(crate) fn into_native(self) -> nativeBalance {
603                 match self {
604                         Balance::ClaimableOnChannelClose {mut amount_satoshis, } => {
605                                 nativeBalance::ClaimableOnChannelClose {
606                                         amount_satoshis: amount_satoshis,
607                                 }
608                         },
609                         Balance::ClaimableAwaitingConfirmations {mut amount_satoshis, mut confirmation_height, } => {
610                                 nativeBalance::ClaimableAwaitingConfirmations {
611                                         amount_satoshis: amount_satoshis,
612                                         confirmation_height: confirmation_height,
613                                 }
614                         },
615                         Balance::ContentiousClaimable {mut amount_satoshis, mut timeout_height, mut payment_hash, mut payment_preimage, } => {
616                                 nativeBalance::ContentiousClaimable {
617                                         amount_satoshis: amount_satoshis,
618                                         timeout_height: timeout_height,
619                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
620                                         payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage.data),
621                                 }
622                         },
623                         Balance::MaybeTimeoutClaimableHTLC {mut amount_satoshis, mut claimable_height, mut payment_hash, } => {
624                                 nativeBalance::MaybeTimeoutClaimableHTLC {
625                                         amount_satoshis: amount_satoshis,
626                                         claimable_height: claimable_height,
627                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
628                                 }
629                         },
630                         Balance::MaybePreimageClaimableHTLC {mut amount_satoshis, mut expiry_height, mut payment_hash, } => {
631                                 nativeBalance::MaybePreimageClaimableHTLC {
632                                         amount_satoshis: amount_satoshis,
633                                         expiry_height: expiry_height,
634                                         payment_hash: ::lightning::ln::PaymentHash(payment_hash.data),
635                                 }
636                         },
637                         Balance::CounterpartyRevokedOutputClaimable {mut amount_satoshis, } => {
638                                 nativeBalance::CounterpartyRevokedOutputClaimable {
639                                         amount_satoshis: amount_satoshis,
640                                 }
641                         },
642                 }
643         }
644         #[allow(unused)]
645         pub(crate) fn from_native(native: &nativeBalance) -> Self {
646                 match native {
647                         nativeBalance::ClaimableOnChannelClose {ref amount_satoshis, } => {
648                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
649                                 Balance::ClaimableOnChannelClose {
650                                         amount_satoshis: amount_satoshis_nonref,
651                                 }
652                         },
653                         nativeBalance::ClaimableAwaitingConfirmations {ref amount_satoshis, ref confirmation_height, } => {
654                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
655                                 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
656                                 Balance::ClaimableAwaitingConfirmations {
657                                         amount_satoshis: amount_satoshis_nonref,
658                                         confirmation_height: confirmation_height_nonref,
659                                 }
660                         },
661                         nativeBalance::ContentiousClaimable {ref amount_satoshis, ref timeout_height, ref payment_hash, ref payment_preimage, } => {
662                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
663                                 let mut timeout_height_nonref = Clone::clone(timeout_height);
664                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
665                                 let mut payment_preimage_nonref = Clone::clone(payment_preimage);
666                                 Balance::ContentiousClaimable {
667                                         amount_satoshis: amount_satoshis_nonref,
668                                         timeout_height: timeout_height_nonref,
669                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
670                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage_nonref.0 },
671                                 }
672                         },
673                         nativeBalance::MaybeTimeoutClaimableHTLC {ref amount_satoshis, ref claimable_height, ref payment_hash, } => {
674                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
675                                 let mut claimable_height_nonref = Clone::clone(claimable_height);
676                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
677                                 Balance::MaybeTimeoutClaimableHTLC {
678                                         amount_satoshis: amount_satoshis_nonref,
679                                         claimable_height: claimable_height_nonref,
680                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
681                                 }
682                         },
683                         nativeBalance::MaybePreimageClaimableHTLC {ref amount_satoshis, ref expiry_height, ref payment_hash, } => {
684                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
685                                 let mut expiry_height_nonref = Clone::clone(expiry_height);
686                                 let mut payment_hash_nonref = Clone::clone(payment_hash);
687                                 Balance::MaybePreimageClaimableHTLC {
688                                         amount_satoshis: amount_satoshis_nonref,
689                                         expiry_height: expiry_height_nonref,
690                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
691                                 }
692                         },
693                         nativeBalance::CounterpartyRevokedOutputClaimable {ref amount_satoshis, } => {
694                                 let mut amount_satoshis_nonref = Clone::clone(amount_satoshis);
695                                 Balance::CounterpartyRevokedOutputClaimable {
696                                         amount_satoshis: amount_satoshis_nonref,
697                                 }
698                         },
699                 }
700         }
701         #[allow(unused)]
702         pub(crate) fn native_into(native: nativeBalance) -> Self {
703                 match native {
704                         nativeBalance::ClaimableOnChannelClose {mut amount_satoshis, } => {
705                                 Balance::ClaimableOnChannelClose {
706                                         amount_satoshis: amount_satoshis,
707                                 }
708                         },
709                         nativeBalance::ClaimableAwaitingConfirmations {mut amount_satoshis, mut confirmation_height, } => {
710                                 Balance::ClaimableAwaitingConfirmations {
711                                         amount_satoshis: amount_satoshis,
712                                         confirmation_height: confirmation_height,
713                                 }
714                         },
715                         nativeBalance::ContentiousClaimable {mut amount_satoshis, mut timeout_height, mut payment_hash, mut payment_preimage, } => {
716                                 Balance::ContentiousClaimable {
717                                         amount_satoshis: amount_satoshis,
718                                         timeout_height: timeout_height,
719                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
720                                         payment_preimage: crate::c_types::ThirtyTwoBytes { data: payment_preimage.0 },
721                                 }
722                         },
723                         nativeBalance::MaybeTimeoutClaimableHTLC {mut amount_satoshis, mut claimable_height, mut payment_hash, } => {
724                                 Balance::MaybeTimeoutClaimableHTLC {
725                                         amount_satoshis: amount_satoshis,
726                                         claimable_height: claimable_height,
727                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
728                                 }
729                         },
730                         nativeBalance::MaybePreimageClaimableHTLC {mut amount_satoshis, mut expiry_height, mut payment_hash, } => {
731                                 Balance::MaybePreimageClaimableHTLC {
732                                         amount_satoshis: amount_satoshis,
733                                         expiry_height: expiry_height,
734                                         payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
735                                 }
736                         },
737                         nativeBalance::CounterpartyRevokedOutputClaimable {mut amount_satoshis, } => {
738                                 Balance::CounterpartyRevokedOutputClaimable {
739                                         amount_satoshis: amount_satoshis,
740                                 }
741                         },
742                 }
743         }
744 }
745 /// Frees any resources used by the Balance
746 #[no_mangle]
747 pub extern "C" fn Balance_free(this_ptr: Balance) { }
748 /// Creates a copy of the Balance
749 #[no_mangle]
750 pub extern "C" fn Balance_clone(orig: &Balance) -> Balance {
751         orig.clone()
752 }
753 #[no_mangle]
754 /// Utility method to constructs a new ClaimableOnChannelClose-variant Balance
755 pub extern "C" fn Balance_claimable_on_channel_close(amount_satoshis: u64) -> Balance {
756         Balance::ClaimableOnChannelClose {
757                 amount_satoshis,
758         }
759 }
760 #[no_mangle]
761 /// Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
762 pub extern "C" fn Balance_claimable_awaiting_confirmations(amount_satoshis: u64, confirmation_height: u32) -> Balance {
763         Balance::ClaimableAwaitingConfirmations {
764                 amount_satoshis,
765                 confirmation_height,
766         }
767 }
768 #[no_mangle]
769 /// Utility method to constructs a new ContentiousClaimable-variant Balance
770 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 {
771         Balance::ContentiousClaimable {
772                 amount_satoshis,
773                 timeout_height,
774                 payment_hash,
775                 payment_preimage,
776         }
777 }
778 #[no_mangle]
779 /// Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
780 pub extern "C" fn Balance_maybe_timeout_claimable_htlc(amount_satoshis: u64, claimable_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes) -> Balance {
781         Balance::MaybeTimeoutClaimableHTLC {
782                 amount_satoshis,
783                 claimable_height,
784                 payment_hash,
785         }
786 }
787 #[no_mangle]
788 /// Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
789 pub extern "C" fn Balance_maybe_preimage_claimable_htlc(amount_satoshis: u64, expiry_height: u32, payment_hash: crate::c_types::ThirtyTwoBytes) -> Balance {
790         Balance::MaybePreimageClaimableHTLC {
791                 amount_satoshis,
792                 expiry_height,
793                 payment_hash,
794         }
795 }
796 #[no_mangle]
797 /// Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
798 pub extern "C" fn Balance_counterparty_revoked_output_claimable(amount_satoshis: u64) -> Balance {
799         Balance::CounterpartyRevokedOutputClaimable {
800                 amount_satoshis,
801         }
802 }
803 /// Checks if two Balances contain equal inner contents.
804 /// This ignores pointers and is_owned flags and looks at the values in fields.
805 #[no_mangle]
806 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
807         if &a.to_native() == &b.to_native() { true } else { false }
808 }
809 /// The amount claimable, in satoshis. This excludes balances that we are unsure if we are able
810 /// to claim, this is because we are waiting for a preimage or for a timeout to expire. For more
811 /// information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and
812 /// [`Balance::MaybePreimageClaimableHTLC`].
813 ///
814 /// On-chain fees required to claim the balance are not included in this amount.
815 #[must_use]
816 #[no_mangle]
817 pub extern "C" fn Balance_claimable_amount_satoshis(this_arg: &crate::lightning::chain::channelmonitor::Balance) -> u64 {
818         let mut ret = this_arg.to_native().claimable_amount_satoshis();
819         ret
820 }
821
822
823 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
824 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::sign::WriteableEcdsaChannelSigner>;
825
826 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
827 /// on-chain transactions to ensure no loss of funds occurs.
828 ///
829 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
830 /// information and are actively monitoring the chain.
831 ///
832 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
833 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
834 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
835 /// returned block hash and the the current chain and then reconnecting blocks to get to the
836 /// best chain) upon deserializing the object!
837 #[must_use]
838 #[repr(C)]
839 pub struct ChannelMonitor {
840         /// A pointer to the opaque Rust object.
841
842         /// Nearly everywhere, inner must be non-null, however in places where
843         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
844         pub inner: *mut nativeChannelMonitor,
845         /// Indicates that this is the only struct which contains the same pointer.
846
847         /// Rust functions which take ownership of an object provided via an argument require
848         /// this to be true and invalidate the object pointed to by inner.
849         pub is_owned: bool,
850 }
851
852 impl Drop for ChannelMonitor {
853         fn drop(&mut self) {
854                 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
855                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
856                 }
857         }
858 }
859 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
860 #[no_mangle]
861 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
862 #[allow(unused)]
863 /// Used only if an object of this type is returned as a trait impl by a method
864 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
865         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitor) };
866 }
867 #[allow(unused)]
868 impl ChannelMonitor {
869         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
870                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
871         }
872         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
873                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
874         }
875         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
876         pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
877                 assert!(self.is_owned);
878                 let ret = ObjOps::untweak_ptr(self.inner);
879                 self.inner = core::ptr::null_mut();
880                 ret
881         }
882 }
883 impl Clone for ChannelMonitor {
884         fn clone(&self) -> Self {
885                 Self {
886                         inner: if <*mut nativeChannelMonitor>::is_null(self.inner) { core::ptr::null_mut() } else {
887                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
888                         is_owned: true,
889                 }
890         }
891 }
892 #[allow(unused)]
893 /// Used only if an object of this type is returned as a trait impl by a method
894 pub(crate) extern "C" fn ChannelMonitor_clone_void(this_ptr: *const c_void) -> *mut c_void {
895         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitor)).clone() })) as *mut c_void
896 }
897 #[no_mangle]
898 /// Creates a copy of the ChannelMonitor
899 pub extern "C" fn ChannelMonitor_clone(orig: &ChannelMonitor) -> ChannelMonitor {
900         orig.clone()
901 }
902 #[no_mangle]
903 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
904 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
905         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
906 }
907 #[no_mangle]
908 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
909         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
910 }
911 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
912 /// itself.
913 ///
914 /// panics if the given update is not the next update by update_id.
915 #[must_use]
916 #[no_mangle]
917 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 {
918         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
919         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() };
920         local_ret
921 }
922
923 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
924 /// ChannelMonitor.
925 #[must_use]
926 #[no_mangle]
927 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
928         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
929         ret
930 }
931
932 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
933 #[must_use]
934 #[no_mangle]
935 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointCVec_u8ZZ {
936         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
937         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();
938         local_ret
939 }
940
941 /// Gets a list of txids, with their output scripts (in the order they appear in the
942 /// transaction), which we must learn about spends of via block_connected().
943 #[must_use]
944 #[no_mangle]
945 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 {
946         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
947         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 }); };
948         local_ret.into()
949 }
950
951 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
952 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
953 /// have been registered.
954 #[no_mangle]
955 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter) {
956         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter)
957 }
958
959 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
960 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
961 #[must_use]
962 #[no_mangle]
963 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
964         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
965         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
966         local_ret.into()
967 }
968
969 /// Processes [`SpendableOutputs`] events produced from each [`ChannelMonitor`] upon maturity.
970 ///
971 /// For channels featuring anchor outputs, this method will also process [`BumpTransaction`]
972 /// events produced from each [`ChannelMonitor`] while there is a balance to claim onchain
973 /// within each channel. As the confirmation of a commitment transaction may be critical to the
974 /// safety of funds, we recommend invoking this every 30 seconds, or lower if running in an
975 /// environment with spotty connections, like on mobile.
976 ///
977 /// An [`EventHandler`] may safely call back to the provider, though this shouldn't be needed in
978 /// order to handle these events.
979 ///
980 /// [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
981 /// [`BumpTransaction`]: crate::events::Event::BumpTransaction
982 #[no_mangle]
983 pub extern "C" fn ChannelMonitor_process_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, handler: &crate::lightning::events::EventHandler) {
984         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.process_pending_events(handler)
985 }
986
987 /// Gets the counterparty's initial commitment transaction. The returned commitment
988 /// transaction is unsigned. This is intended to be called during the initial persistence of
989 /// the monitor (inside an implementation of [`Persist::persist_new_channel`]), to allow for
990 /// watchtowers in the persistence pipeline to have enough data to form justice transactions.
991 ///
992 /// This is similar to [`Self::counterparty_commitment_txs_from_update`], except
993 /// that for the initial commitment transaction, we don't have a corresponding update.
994 ///
995 /// This will only return `Some` for channel monitors that have been created after upgrading
996 /// to LDK 0.0.117+.
997 ///
998 /// [`Persist::persist_new_channel`]: crate::chain::chainmonitor::Persist::persist_new_channel
999 ///
1000 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1001 #[must_use]
1002 #[no_mangle]
1003 pub extern "C" fn ChannelMonitor_initial_counterparty_commitment_tx(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::ln::chan_utils::CommitmentTransaction {
1004         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.initial_counterparty_commitment_tx();
1005         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 };
1006         local_ret
1007 }
1008
1009 /// Gets all of the counterparty commitment transactions provided by the given update. This
1010 /// may be empty if the update doesn't include any new counterparty commitments. Returned
1011 /// commitment transactions are unsigned.
1012 ///
1013 /// This is provided so that watchtower clients in the persistence pipeline are able to build
1014 /// justice transactions for each counterparty commitment upon each update. It's intended to be
1015 /// used within an implementation of [`Persist::update_persisted_channel`], which is provided
1016 /// with a monitor and an update. Once revoked, signing a justice transaction can be done using
1017 /// [`Self::sign_to_local_justice_tx`].
1018 ///
1019 /// It is expected that a watchtower client may use this method to retrieve the latest counterparty
1020 /// commitment transaction(s), and then hold the necessary data until a later update in which
1021 /// the monitor has been updated with the corresponding revocation data, at which point the
1022 /// monitor can sign the justice transaction.
1023 ///
1024 /// This will only return a non-empty list for monitor updates that have been created after
1025 /// upgrading to LDK 0.0.117+. Note that no restriction lies on the monitors themselves, which
1026 /// may have been created prior to upgrading.
1027 ///
1028 /// [`Persist::update_persisted_channel`]: crate::chain::chainmonitor::Persist::update_persisted_channel
1029 #[must_use]
1030 #[no_mangle]
1031 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 {
1032         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_commitment_txs_from_update(update.get_native_ref());
1033         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 } }); };
1034         local_ret.into()
1035 }
1036
1037 /// Wrapper around [`EcdsaChannelSigner::sign_justice_revoked_output`] to make
1038 /// signing the justice transaction easier for implementors of
1039 /// [`chain::chainmonitor::Persist`]. On success this method returns the provided transaction
1040 /// signing the input at `input_idx`. This method will only produce a valid signature for
1041 /// a transaction spending the `to_local` output of a commitment transaction, i.e. this cannot
1042 /// be used for revoked HTLC outputs.
1043 ///
1044 /// `Value` is the value of the output being spent by the input at `input_idx`, committed
1045 /// in the BIP 143 signature.
1046 ///
1047 /// This method will only succeed if this monitor has received the revocation secret for the
1048 /// provided `commitment_number`. If a commitment number is provided that does not correspond
1049 /// to the commitment transaction being revoked, this will return a signed transaction, but
1050 /// the signature will not be valid.
1051 ///
1052 /// [`EcdsaChannelSigner::sign_justice_revoked_output`]: crate::sign::EcdsaChannelSigner::sign_justice_revoked_output
1053 /// [`Persist`]: crate::chain::chainmonitor::Persist
1054 #[must_use]
1055 #[no_mangle]
1056 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 {
1057         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_to_local_justice_tx(justice_tx.into_bitcoin(), input_idx, value, commitment_number);
1058         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() };
1059         local_ret
1060 }
1061
1062 /// Gets the `node_id` of the counterparty for this channel.
1063 ///
1064 /// Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
1065 /// otherwise.
1066 ///
1067 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1068 #[must_use]
1069 #[no_mangle]
1070 pub extern "C" fn ChannelMonitor_get_counterparty_node_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::PublicKey {
1071         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_counterparty_node_id();
1072         let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else {  { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
1073         local_ret
1074 }
1075
1076 /// Used by [`ChannelManager`] deserialization to broadcast the latest holder state if its copy
1077 /// of the channel state was out-of-date.
1078 ///
1079 /// You may also use this to broadcast the latest local commitment transaction, either because
1080 /// a monitor update failed or because we've fallen behind (i.e. we've received proof that our
1081 /// counterparty side knows a revocation secret we gave them that they shouldn't know).
1082 ///
1083 /// Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty
1084 /// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
1085 /// close channel with their commitment transaction after a substantial amount of time. Best
1086 /// may be to contact the other node operator out-of-band to coordinate other options available
1087 /// to you.
1088 ///
1089 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1090 #[must_use]
1091 #[no_mangle]
1092 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 {
1093         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger);
1094         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); };
1095         local_ret.into()
1096 }
1097
1098 /// Processes transactions in a newly connected block, which may result in any of the following:
1099 /// - update the monitor's state against resolved HTLCs
1100 /// - punish the counterparty in the case of seeing a revoked commitment transaction
1101 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
1102 /// - detect settled outputs for later spending
1103 /// - schedule and bump any in-flight claims
1104 ///
1105 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
1106 /// [`get_outputs_to_watch`].
1107 ///
1108 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
1109 #[must_use]
1110 #[no_mangle]
1111 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 {
1112         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 }); };
1113         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);
1114         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 }); };
1115         local_ret.into()
1116 }
1117
1118 /// Determines if the disconnected block contained any transactions of interest and updates
1119 /// appropriately.
1120 #[no_mangle]
1121 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) {
1122         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
1123 }
1124
1125 /// Processes transactions confirmed in a block with the given header and height, returning new
1126 /// outputs to watch. See [`block_connected`] for details.
1127 ///
1128 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1129 /// blocks. See [`chain::Confirm`] for calling expectations.
1130 ///
1131 /// [`block_connected`]: Self::block_connected
1132 #[must_use]
1133 #[no_mangle]
1134 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 {
1135         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 }); };
1136         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);
1137         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 }); };
1138         local_ret.into()
1139 }
1140
1141 /// Processes a transaction that was reorganized out of the chain.
1142 ///
1143 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
1144 /// than blocks. See [`chain::Confirm`] for calling expectations.
1145 ///
1146 /// [`block_disconnected`]: Self::block_disconnected
1147 #[no_mangle]
1148 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) {
1149         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
1150 }
1151
1152 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
1153 /// [`block_connected`] for details.
1154 ///
1155 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1156 /// blocks. See [`chain::Confirm`] for calling expectations.
1157 ///
1158 /// [`block_connected`]: Self::block_connected
1159 #[must_use]
1160 #[no_mangle]
1161 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 {
1162         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);
1163         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 }); };
1164         local_ret.into()
1165 }
1166
1167 /// Returns the set of txids that should be monitored for re-organization out of the chain.
1168 #[must_use]
1169 #[no_mangle]
1170 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_ThirtyTwoBytesCOption_ThirtyTwoBytesZZZ {
1171         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
1172         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 = if orig_ret_0_1.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_1.unwrap().into_inner() } }) }; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.into_inner() }, local_orig_ret_0_1).into(); local_ret_0 }); };
1173         local_ret.into()
1174 }
1175
1176 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1177 /// [`chain::Confirm`] interfaces.
1178 #[must_use]
1179 #[no_mangle]
1180 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
1181         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1182         crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1183 }
1184
1185 /// Triggers rebroadcasts/fee-bumps of pending claims from a force-closed channel. This is
1186 /// crucial in preventing certain classes of pinning attacks, detecting substantial mempool
1187 /// feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend
1188 /// invoking this every 30 seconds, or lower if running in an environment with spotty
1189 /// connections, like on mobile.
1190 #[no_mangle]
1191 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, mut logger: crate::lightning::util::logger::Logger) {
1192         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.rebroadcast_pending_claims(broadcaster, fee_estimator, logger)
1193 }
1194
1195 /// Returns the descriptors for relevant outputs (i.e., those that we can spend) within the
1196 /// transaction if they exist and the transaction has at least [`ANTI_REORG_DELAY`]
1197 /// confirmations. For [`SpendableOutputDescriptor::DelayedPaymentOutput`] descriptors to be
1198 /// returned, the transaction must have at least `max(ANTI_REORG_DELAY, to_self_delay)`
1199 /// confirmations.
1200 ///
1201 /// Descriptors returned by this method are primarily exposed via [`Event::SpendableOutputs`]
1202 /// once they are no longer under reorg risk. This method serves as a way to retrieve these
1203 /// descriptors at a later time, either for historical purposes, or to replay any
1204 /// missed/unhandled descriptors. For the purpose of gathering historical records, if the
1205 /// channel close has fully resolved (i.e., [`ChannelMonitor::get_claimable_balances`] returns
1206 /// an empty set), you can retrieve all spendable outputs by providing all descendant spending
1207 /// transactions starting from the channel's funding transaction and going down three levels.
1208 ///
1209 /// `tx` is a transaction we'll scan the outputs of. Any transaction can be provided. If any
1210 /// outputs which can be spent by us are found, at least one descriptor is returned.
1211 ///
1212 /// `confirmation_height` must be the height of the block in which `tx` was included in.
1213 #[must_use]
1214 #[no_mangle]
1215 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 {
1216         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_spendable_outputs(&tx.into_bitcoin(), confirmation_height);
1217         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::sign::SpendableOutputDescriptor::native_into(item) }); };
1218         local_ret.into()
1219 }
1220
1221 /// Gets the balances in this channel which are either claimable by us if we were to
1222 /// force-close the channel now or which are claimable on-chain (possibly awaiting
1223 /// confirmation).
1224 ///
1225 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
1226 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
1227 /// balance, or until our counterparty has claimed the balance and accrued several
1228 /// confirmations on the claim transaction.
1229 ///
1230 /// Note that for `ChannelMonitors` which track a channel which went on-chain with versions of
1231 /// LDK prior to 0.0.111, not all or excess balances may be included.
1232 ///
1233 /// See [`Balance`] for additional details on the types of claimable balances which
1234 /// may be returned here and their meanings.
1235 #[must_use]
1236 #[no_mangle]
1237 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
1238         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
1239         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
1240         local_ret.into()
1241 }
1242
1243 #[no_mangle]
1244 /// Read a C2Tuple_ThirtyTwoBytesChannelMonitorZ from a byte array, created by C2Tuple_ThirtyTwoBytesChannelMonitorZ_write
1245 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 {
1246         let arg_a_conv = arg_a;
1247         let arg_b_conv = arg_b;
1248         let arg_conv = (arg_a_conv, arg_b_conv);
1249         let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::sign::WriteableEcdsaChannelSigner>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1250         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::native_into(e) }).into() };
1251         local_res
1252 }