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