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