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