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