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