Update auto-generated bindings for LDK 0.0.115
[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         },
529         /// HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
530         /// fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
531         /// likely to be claimed by our counterparty before we do.
532         MaybeTimeoutClaimableHTLC {
533                 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
534                 /// which will be required to do so.
535                 claimable_amount_satoshis: u64,
536                 /// The height at which we will be able to claim the balance if our counterparty has not
537                 /// done so.
538                 claimable_height: u32,
539         },
540         /// HTLCs which we received from our counterparty which are claimable with a preimage which we
541         /// do not currently have. This will only be claimable if we receive the preimage from the node
542         /// to which we forwarded this HTLC before the timeout.
543         MaybePreimageClaimableHTLC {
544                 /// The amount potentially available to claim, in satoshis, excluding the on-chain fees
545                 /// which will be required to do so.
546                 claimable_amount_satoshis: u64,
547                 /// The height at which our counterparty will be able to claim the balance if we have not
548                 /// yet received the preimage and claimed it ourselves.
549                 expiry_height: u32,
550         },
551         /// The channel has been closed, and our counterparty broadcasted a revoked commitment
552         /// transaction.
553         ///
554         /// Thus, we're able to claim all outputs in the commitment transaction, one of which has the
555         /// following amount.
556         CounterpartyRevokedOutputClaimable {
557                 /// The amount, in satoshis, of the output which we can claim.
558                 ///
559                 /// Note that for outputs from HTLC balances this may be excluding some on-chain fees that
560                 /// were already spent.
561                 claimable_amount_satoshis: u64,
562         },
563 }
564 use lightning::chain::channelmonitor::Balance as BalanceImport;
565 pub(crate) type nativeBalance = BalanceImport;
566
567 impl Balance {
568         #[allow(unused)]
569         pub(crate) fn to_native(&self) -> nativeBalance {
570                 match self {
571                         Balance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
572                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
573                                 nativeBalance::ClaimableOnChannelClose {
574                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
575                                 }
576                         },
577                         Balance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
578                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
579                                 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
580                                 nativeBalance::ClaimableAwaitingConfirmations {
581                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
582                                         confirmation_height: confirmation_height_nonref,
583                                 }
584                         },
585                         Balance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
586                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
587                                 let mut timeout_height_nonref = Clone::clone(timeout_height);
588                                 nativeBalance::ContentiousClaimable {
589                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
590                                         timeout_height: timeout_height_nonref,
591                                 }
592                         },
593                         Balance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
594                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
595                                 let mut claimable_height_nonref = Clone::clone(claimable_height);
596                                 nativeBalance::MaybeTimeoutClaimableHTLC {
597                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
598                                         claimable_height: claimable_height_nonref,
599                                 }
600                         },
601                         Balance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
602                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
603                                 let mut expiry_height_nonref = Clone::clone(expiry_height);
604                                 nativeBalance::MaybePreimageClaimableHTLC {
605                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
606                                         expiry_height: expiry_height_nonref,
607                                 }
608                         },
609                         Balance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
610                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
611                                 nativeBalance::CounterpartyRevokedOutputClaimable {
612                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
613                                 }
614                         },
615                 }
616         }
617         #[allow(unused)]
618         pub(crate) fn into_native(self) -> nativeBalance {
619                 match self {
620                         Balance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
621                                 nativeBalance::ClaimableOnChannelClose {
622                                         claimable_amount_satoshis: claimable_amount_satoshis,
623                                 }
624                         },
625                         Balance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
626                                 nativeBalance::ClaimableAwaitingConfirmations {
627                                         claimable_amount_satoshis: claimable_amount_satoshis,
628                                         confirmation_height: confirmation_height,
629                                 }
630                         },
631                         Balance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
632                                 nativeBalance::ContentiousClaimable {
633                                         claimable_amount_satoshis: claimable_amount_satoshis,
634                                         timeout_height: timeout_height,
635                                 }
636                         },
637                         Balance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
638                                 nativeBalance::MaybeTimeoutClaimableHTLC {
639                                         claimable_amount_satoshis: claimable_amount_satoshis,
640                                         claimable_height: claimable_height,
641                                 }
642                         },
643                         Balance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
644                                 nativeBalance::MaybePreimageClaimableHTLC {
645                                         claimable_amount_satoshis: claimable_amount_satoshis,
646                                         expiry_height: expiry_height,
647                                 }
648                         },
649                         Balance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
650                                 nativeBalance::CounterpartyRevokedOutputClaimable {
651                                         claimable_amount_satoshis: claimable_amount_satoshis,
652                                 }
653                         },
654                 }
655         }
656         #[allow(unused)]
657         pub(crate) fn from_native(native: &nativeBalance) -> Self {
658                 match native {
659                         nativeBalance::ClaimableOnChannelClose {ref claimable_amount_satoshis, } => {
660                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
661                                 Balance::ClaimableOnChannelClose {
662                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
663                                 }
664                         },
665                         nativeBalance::ClaimableAwaitingConfirmations {ref claimable_amount_satoshis, ref confirmation_height, } => {
666                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
667                                 let mut confirmation_height_nonref = Clone::clone(confirmation_height);
668                                 Balance::ClaimableAwaitingConfirmations {
669                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
670                                         confirmation_height: confirmation_height_nonref,
671                                 }
672                         },
673                         nativeBalance::ContentiousClaimable {ref claimable_amount_satoshis, ref timeout_height, } => {
674                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
675                                 let mut timeout_height_nonref = Clone::clone(timeout_height);
676                                 Balance::ContentiousClaimable {
677                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
678                                         timeout_height: timeout_height_nonref,
679                                 }
680                         },
681                         nativeBalance::MaybeTimeoutClaimableHTLC {ref claimable_amount_satoshis, ref claimable_height, } => {
682                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
683                                 let mut claimable_height_nonref = Clone::clone(claimable_height);
684                                 Balance::MaybeTimeoutClaimableHTLC {
685                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
686                                         claimable_height: claimable_height_nonref,
687                                 }
688                         },
689                         nativeBalance::MaybePreimageClaimableHTLC {ref claimable_amount_satoshis, ref expiry_height, } => {
690                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
691                                 let mut expiry_height_nonref = Clone::clone(expiry_height);
692                                 Balance::MaybePreimageClaimableHTLC {
693                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
694                                         expiry_height: expiry_height_nonref,
695                                 }
696                         },
697                         nativeBalance::CounterpartyRevokedOutputClaimable {ref claimable_amount_satoshis, } => {
698                                 let mut claimable_amount_satoshis_nonref = Clone::clone(claimable_amount_satoshis);
699                                 Balance::CounterpartyRevokedOutputClaimable {
700                                         claimable_amount_satoshis: claimable_amount_satoshis_nonref,
701                                 }
702                         },
703                 }
704         }
705         #[allow(unused)]
706         pub(crate) fn native_into(native: nativeBalance) -> Self {
707                 match native {
708                         nativeBalance::ClaimableOnChannelClose {mut claimable_amount_satoshis, } => {
709                                 Balance::ClaimableOnChannelClose {
710                                         claimable_amount_satoshis: claimable_amount_satoshis,
711                                 }
712                         },
713                         nativeBalance::ClaimableAwaitingConfirmations {mut claimable_amount_satoshis, mut confirmation_height, } => {
714                                 Balance::ClaimableAwaitingConfirmations {
715                                         claimable_amount_satoshis: claimable_amount_satoshis,
716                                         confirmation_height: confirmation_height,
717                                 }
718                         },
719                         nativeBalance::ContentiousClaimable {mut claimable_amount_satoshis, mut timeout_height, } => {
720                                 Balance::ContentiousClaimable {
721                                         claimable_amount_satoshis: claimable_amount_satoshis,
722                                         timeout_height: timeout_height,
723                                 }
724                         },
725                         nativeBalance::MaybeTimeoutClaimableHTLC {mut claimable_amount_satoshis, mut claimable_height, } => {
726                                 Balance::MaybeTimeoutClaimableHTLC {
727                                         claimable_amount_satoshis: claimable_amount_satoshis,
728                                         claimable_height: claimable_height,
729                                 }
730                         },
731                         nativeBalance::MaybePreimageClaimableHTLC {mut claimable_amount_satoshis, mut expiry_height, } => {
732                                 Balance::MaybePreimageClaimableHTLC {
733                                         claimable_amount_satoshis: claimable_amount_satoshis,
734                                         expiry_height: expiry_height,
735                                 }
736                         },
737                         nativeBalance::CounterpartyRevokedOutputClaimable {mut claimable_amount_satoshis, } => {
738                                 Balance::CounterpartyRevokedOutputClaimable {
739                                         claimable_amount_satoshis: claimable_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(claimable_amount_satoshis: u64) -> Balance {
756         Balance::ClaimableOnChannelClose {
757                 claimable_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(claimable_amount_satoshis: u64, confirmation_height: u32) -> Balance {
763         Balance::ClaimableAwaitingConfirmations {
764                 claimable_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(claimable_amount_satoshis: u64, timeout_height: u32) -> Balance {
771         Balance::ContentiousClaimable {
772                 claimable_amount_satoshis,
773                 timeout_height,
774         }
775 }
776 #[no_mangle]
777 /// Utility method to constructs a new MaybeTimeoutClaimableHTLC-variant Balance
778 pub extern "C" fn Balance_maybe_timeout_claimable_htlc(claimable_amount_satoshis: u64, claimable_height: u32) -> Balance {
779         Balance::MaybeTimeoutClaimableHTLC {
780                 claimable_amount_satoshis,
781                 claimable_height,
782         }
783 }
784 #[no_mangle]
785 /// Utility method to constructs a new MaybePreimageClaimableHTLC-variant Balance
786 pub extern "C" fn Balance_maybe_preimage_claimable_htlc(claimable_amount_satoshis: u64, expiry_height: u32) -> Balance {
787         Balance::MaybePreimageClaimableHTLC {
788                 claimable_amount_satoshis,
789                 expiry_height,
790         }
791 }
792 #[no_mangle]
793 /// Utility method to constructs a new CounterpartyRevokedOutputClaimable-variant Balance
794 pub extern "C" fn Balance_counterparty_revoked_output_claimable(claimable_amount_satoshis: u64) -> Balance {
795         Balance::CounterpartyRevokedOutputClaimable {
796                 claimable_amount_satoshis,
797         }
798 }
799 /// Checks if two Balances contain equal inner contents.
800 /// This ignores pointers and is_owned flags and looks at the values in fields.
801 #[no_mangle]
802 pub extern "C" fn Balance_eq(a: &Balance, b: &Balance) -> bool {
803         if &a.to_native() == &b.to_native() { true } else { false }
804 }
805
806 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
807 pub(crate) type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner>;
808
809 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
810 /// on-chain transactions to ensure no loss of funds occurs.
811 ///
812 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
813 /// information and are actively monitoring the chain.
814 ///
815 /// Pending Events or updated HTLCs which have not yet been read out by
816 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
817 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
818 /// gotten are fully handled before re-serializing the new state.
819 ///
820 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
821 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
822 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
823 /// returned block hash and the the current chain and then reconnecting blocks to get to the
824 /// best chain) upon deserializing the object!
825 #[must_use]
826 #[repr(C)]
827 pub struct ChannelMonitor {
828         /// A pointer to the opaque Rust object.
829
830         /// Nearly everywhere, inner must be non-null, however in places where
831         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
832         pub inner: *mut nativeChannelMonitor,
833         /// Indicates that this is the only struct which contains the same pointer.
834
835         /// Rust functions which take ownership of an object provided via an argument require
836         /// this to be true and invalidate the object pointed to by inner.
837         pub is_owned: bool,
838 }
839
840 impl Drop for ChannelMonitor {
841         fn drop(&mut self) {
842                 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
843                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
844                 }
845         }
846 }
847 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
848 #[no_mangle]
849 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
850 #[allow(unused)]
851 /// Used only if an object of this type is returned as a trait impl by a method
852 pub(crate) extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
853         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelMonitor) };
854 }
855 #[allow(unused)]
856 impl ChannelMonitor {
857         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelMonitor {
858                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
859         }
860         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelMonitor {
861                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
862         }
863         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
864         pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
865                 assert!(self.is_owned);
866                 let ret = ObjOps::untweak_ptr(self.inner);
867                 self.inner = core::ptr::null_mut();
868                 ret
869         }
870 }
871 #[no_mangle]
872 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
873 pub extern "C" fn ChannelMonitor_write(obj: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
874         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
875 }
876 #[no_mangle]
877 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
878         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
879 }
880 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
881 /// itself.
882 ///
883 /// panics if the given update is not the next update by update_id.
884 #[must_use]
885 #[no_mangle]
886 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 {
887         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger);
888         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() };
889         local_ret
890 }
891
892 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
893 /// ChannelMonitor.
894 #[must_use]
895 #[no_mangle]
896 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> u64 {
897         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_update_id();
898         ret
899 }
900
901 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
902 #[must_use]
903 #[no_mangle]
904 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
905         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_funding_txo();
906         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();
907         local_ret
908 }
909
910 /// Gets a list of txids, with their output scripts (in the order they appear in the
911 /// transaction), which we must learn about spends of via block_connected().
912 #[must_use]
913 #[no_mangle]
914 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 {
915         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_outputs_to_watch();
916         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 }); };
917         local_ret.into()
918 }
919
920 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
921 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
922 /// have been registered.
923 #[no_mangle]
924 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, filter: &crate::lightning::chain::Filter) {
925         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.load_outputs_to_watch(filter)
926 }
927
928 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
929 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
930 #[must_use]
931 #[no_mangle]
932 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
933         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_monitor_events();
934         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
935         local_ret.into()
936 }
937
938 /// Gets the list of pending events which were generated by previous actions, clearing the list
939 /// in the process.
940 ///
941 /// This is called by the [`EventsProvider::process_pending_events`] implementation for
942 /// [`ChainMonitor`].
943 ///
944 /// [`EventsProvider::process_pending_events`]: crate::events::EventsProvider::process_pending_events
945 /// [`ChainMonitor`]: crate::chain::chainmonitor::ChainMonitor
946 #[must_use]
947 #[no_mangle]
948 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
949         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_and_clear_pending_events();
950         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::Event::native_into(item) }); };
951         local_ret.into()
952 }
953
954 /// Gets the `node_id` of the counterparty for this channel.
955 ///
956 /// Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
957 /// otherwise.
958 ///
959 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
960 #[must_use]
961 #[no_mangle]
962 pub extern "C" fn ChannelMonitor_get_counterparty_node_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::PublicKey {
963         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_counterparty_node_id();
964         let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else {  { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
965         local_ret
966 }
967
968 /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
969 /// the Channel was out-of-date.
970 ///
971 /// You may also use this to broadcast the latest local commitment transaction, either because
972 /// a monitor update failed with [`ChannelMonitorUpdateStatus::PermanentFailure`] or because we've
973 /// fallen behind (i.e. we've received proof that our counterparty side knows a revocation
974 /// secret we gave them that they shouldn't know).
975 ///
976 /// Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty
977 /// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
978 /// close channel with their commitment transaction after a substantial amount of time. Best
979 /// may be to contact the other node operator out-of-band to coordinate other options available
980 /// to you. In any-case, the choice is up to you.
981 ///
982 /// [`ChannelMonitorUpdateStatus::PermanentFailure`]: super::ChannelMonitorUpdateStatus::PermanentFailure
983 #[must_use]
984 #[no_mangle]
985 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 {
986         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_latest_holder_commitment_txn(logger);
987         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::Transaction::from_bitcoin(&item) }); };
988         local_ret.into()
989 }
990
991 /// Processes transactions in a newly connected block, which may result in any of the following:
992 /// - update the monitor's state against resolved HTLCs
993 /// - punish the counterparty in the case of seeing a revoked commitment transaction
994 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
995 /// - detect settled outputs for later spending
996 /// - schedule and bump any in-flight claims
997 ///
998 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
999 /// [`get_outputs_to_watch`].
1000 ///
1001 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
1002 #[must_use]
1003 #[no_mangle]
1004 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 {
1005         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 }); };
1006         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);
1007         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 }); };
1008         local_ret.into()
1009 }
1010
1011 /// Determines if the disconnected block contained any transactions of interest and updates
1012 /// appropriately.
1013 #[no_mangle]
1014 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) {
1015         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
1016 }
1017
1018 /// Processes transactions confirmed in a block with the given header and height, returning new
1019 /// outputs to watch. See [`block_connected`] for details.
1020 ///
1021 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1022 /// blocks. See [`chain::Confirm`] for calling expectations.
1023 ///
1024 /// [`block_connected`]: Self::block_connected
1025 #[must_use]
1026 #[no_mangle]
1027 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 {
1028         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 }); };
1029         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);
1030         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 }); };
1031         local_ret.into()
1032 }
1033
1034 /// Processes a transaction that was reorganized out of the chain.
1035 ///
1036 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
1037 /// than blocks. See [`chain::Confirm`] for calling expectations.
1038 ///
1039 /// [`block_disconnected`]: Self::block_disconnected
1040 #[no_mangle]
1041 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) {
1042         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
1043 }
1044
1045 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
1046 /// [`block_connected`] for details.
1047 ///
1048 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
1049 /// blocks. See [`chain::Confirm`] for calling expectations.
1050 ///
1051 /// [`block_connected`]: Self::block_connected
1052 #[must_use]
1053 #[no_mangle]
1054 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 {
1055         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);
1056         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 }); };
1057         local_ret.into()
1058 }
1059
1060 /// Returns the set of txids that should be monitored for re-organization out of the chain.
1061 #[must_use]
1062 #[no_mangle]
1063 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_TxidBlockHashZZ {
1064         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_relevant_txids();
1065         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::ThirtyTwoBytes::null() } else {  { 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 }); };
1066         local_ret.into()
1067 }
1068
1069 /// Gets the latest best block which was connected either via the [`chain::Listen`] or
1070 /// [`chain::Confirm`] interfaces.
1071 #[must_use]
1072 #[no_mangle]
1073 pub extern "C" fn ChannelMonitor_current_best_block(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::lightning::chain::BestBlock {
1074         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.current_best_block();
1075         crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
1076 }
1077
1078 /// Triggers rebroadcasts/fee-bumps of pending claims from a force-closed channel. This is
1079 /// crucial in preventing certain classes of pinning attacks, detecting substantial mempool
1080 /// feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend
1081 /// invoking this every 30 seconds, or lower if running in an environment with spotty
1082 /// connections, like on mobile.
1083 #[no_mangle]
1084 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) {
1085         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.rebroadcast_pending_claims(broadcaster, fee_estimator, logger)
1086 }
1087
1088 /// Gets the balances in this channel which are either claimable by us if we were to
1089 /// force-close the channel now or which are claimable on-chain (possibly awaiting
1090 /// confirmation).
1091 ///
1092 /// Any balances in the channel which are available on-chain (excluding on-chain fees) are
1093 /// included here until an [`Event::SpendableOutputs`] event has been generated for the
1094 /// balance, or until our counterparty has claimed the balance and accrued several
1095 /// confirmations on the claim transaction.
1096 ///
1097 /// Note that for `ChannelMonitors` which track a channel which went on-chain with versions of
1098 /// LDK prior to 0.0.111, balances may not be fully captured if our counterparty broadcasted
1099 /// a revoked state.
1100 ///
1101 /// See [`Balance`] for additional details on the types of claimable balances which
1102 /// may be returned here and their meanings.
1103 #[must_use]
1104 #[no_mangle]
1105 pub extern "C" fn ChannelMonitor_get_claimable_balances(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CVec_BalanceZ {
1106         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances();
1107         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
1108         local_ret.into()
1109 }
1110
1111 #[no_mangle]
1112 /// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
1113 pub extern "C" fn C2Tuple_BlockHashChannelMonitorZ_read(ser: crate::c_types::u8slice, arg_a: &crate::lightning::chain::keysinterface::EntropySource, arg_b: &crate::lightning::chain::keysinterface::SignerProvider) -> crate::c_types::derived::CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ {
1114         let arg_a_conv = arg_a;
1115         let arg_b_conv = arg_b;
1116         let arg_conv = (arg_a_conv, arg_b_conv);
1117         let res: Result<(bitcoin::hash_types::BlockHash, lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner>), lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1118         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() };
1119         local_res
1120 }