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