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