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