Merge pull request #16 from afilini/cleanup
[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::ffi::c_void;
23 use bitcoin::hashes::Hash;
24 use crate::c_types::*;
25
26
27 use lightning::chain::channelmonitor::ChannelMonitorUpdate as nativeChannelMonitorUpdateImport;
28 type nativeChannelMonitorUpdate = nativeChannelMonitorUpdateImport;
29
30 /// An update generated by the underlying Channel itself which contains some new information the
31 /// ChannelMonitor should be made aware of.
32 #[must_use]
33 #[repr(C)]
34 pub struct ChannelMonitorUpdate {
35         /// A pointer to the opaque Rust object.
36
37         /// Nearly everywhere, inner must be non-null, however in places where
38         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
39         pub inner: *mut nativeChannelMonitorUpdate,
40         /// Indicates that this is the only struct which contains the same pointer.
41
42         /// Rust functions which take ownership of an object provided via an argument require
43         /// this to be true and invalidate the object pointed to by inner.
44         pub is_owned: bool,
45 }
46
47 impl Drop for ChannelMonitorUpdate {
48         fn drop(&mut self) {
49                 if self.is_owned && !<*mut nativeChannelMonitorUpdate>::is_null(self.inner) {
50                         let _ = unsafe { Box::from_raw(self.inner) };
51                 }
52         }
53 }
54 /// Frees any resources used by the ChannelMonitorUpdate, if is_owned is set and inner is non-NULL.
55 #[no_mangle]
56 pub extern "C" fn ChannelMonitorUpdate_free(this_obj: ChannelMonitorUpdate) { }
57 #[allow(unused)]
58 /// Used only if an object of this type is returned as a trait impl by a method
59 extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
60         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate); }
61 }
62 #[allow(unused)]
63 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
64 impl ChannelMonitorUpdate {
65         pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitorUpdate {
66                 assert!(self.is_owned);
67                 let ret = self.inner;
68                 self.inner = std::ptr::null_mut();
69                 ret
70         }
71 }
72 /// The sequence number of this update. Updates *must* be replayed in-order according to this
73 /// sequence number (and updates may panic if they are not). The update_id values are strictly
74 /// increasing and increase by one for each new update, with one exception specified below.
75 ///
76 /// This sequence number is also used to track up to which points updates which returned
77 /// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given
78 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
79 ///
80 /// The only instance where update_id values are not strictly increasing is the case where we
81 /// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
82 /// its docs for more details.
83 #[no_mangle]
84 pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 {
85         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.update_id;
86         (*inner_val)
87 }
88 /// The sequence number of this update. Updates *must* be replayed in-order according to this
89 /// sequence number (and updates may panic if they are not). The update_id values are strictly
90 /// increasing and increase by one for each new update, with one exception specified below.
91 ///
92 /// This sequence number is also used to track up to which points updates which returned
93 /// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given
94 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
95 ///
96 /// The only instance where update_id values are not strictly increasing is the case where we
97 /// allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
98 /// its docs for more details.
99 #[no_mangle]
100 pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) {
101         unsafe { &mut *this_ptr.inner }.update_id = val;
102 }
103 impl Clone for ChannelMonitorUpdate {
104         fn clone(&self) -> Self {
105                 Self {
106                         inner: if <*mut nativeChannelMonitorUpdate>::is_null(self.inner) { std::ptr::null_mut() } else {
107                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
108                         is_owned: true,
109                 }
110         }
111 }
112 #[allow(unused)]
113 /// Used only if an object of this type is returned as a trait impl by a method
114 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
115         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void
116 }
117 #[no_mangle]
118 /// Creates a copy of the ChannelMonitorUpdate
119 pub extern "C" fn ChannelMonitorUpdate_clone(orig: &ChannelMonitorUpdate) -> ChannelMonitorUpdate {
120         orig.clone()
121 }
122 /// If:
123 ///    (1) a channel has been force closed and
124 ///    (2) we receive a preimage from a forward link that allows us to spend an HTLC output on
125 ///        this channel's (the backward link's) broadcasted commitment transaction
126 /// then we allow the `ChannelManager` to send a `ChannelMonitorUpdate` with this update ID,
127 /// with the update providing said payment preimage. No other update types are allowed after
128 /// force-close.
129
130 #[no_mangle]
131 pub static CLOSED_CHANNEL_UPDATE_ID: u64 = lightning::chain::channelmonitor::CLOSED_CHANNEL_UPDATE_ID;
132 #[no_mangle]
133 /// Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read
134 pub extern "C" fn ChannelMonitorUpdate_write(obj: &ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
135         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
136 }
137 #[no_mangle]
138 pub(crate) extern "C" fn ChannelMonitorUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
139         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitorUpdate) })
140 }
141 #[no_mangle]
142 /// Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write
143 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelMonitorUpdateDecodeErrorZ {
144         let res = crate::c_types::deserialize_obj(ser);
145         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
146         local_res
147 }
148 /// An error enum representing a failure to persist a channel monitor update.
149 #[must_use]
150 #[derive(Clone)]
151 #[repr(C)]
152 pub enum ChannelMonitorUpdateErr {
153         /// Used to indicate a temporary failure (eg connection to a watchtower or remote backup of
154         /// our state failed, but is expected to succeed at some point in the future).
155         ///
156         /// Such a failure will \"freeze\" a channel, preventing us from revoking old states or
157         /// submitting new commitment transactions to the counterparty. Once the update(s) which failed
158         /// have been successfully applied, ChannelManager::channel_monitor_updated can be used to
159         /// restore the channel to an operational state.
160         ///
161         /// Note that a given ChannelManager will *never* re-generate a given ChannelMonitorUpdate. If
162         /// you return a TemporaryFailure you must ensure that it is written to disk safely before
163         /// writing out the latest ChannelManager state.
164         ///
165         /// Even when a channel has been \"frozen\" updates to the ChannelMonitor can continue to occur
166         /// (eg if an inbound HTLC which we forwarded was claimed upstream resulting in us attempting
167         /// to claim it on this channel) and those updates must be applied wherever they can be. At
168         /// least one such updated ChannelMonitor must be persisted otherwise PermanentFailure should
169         /// be returned to get things on-chain ASAP using only the in-memory copy. Obviously updates to
170         /// the channel which would invalidate previous ChannelMonitors are not made when a channel has
171         /// been \"frozen\".
172         ///
173         /// Note that even if updates made after TemporaryFailure succeed you must still call
174         /// channel_monitor_updated to ensure you have the latest monitor and re-enable normal channel
175         /// operation.
176         ///
177         /// Note that the update being processed here will not be replayed for you when you call
178         /// ChannelManager::channel_monitor_updated, so you must store the update itself along
179         /// with the persisted ChannelMonitor on your own local disk prior to returning a
180         /// TemporaryFailure. You may, of course, employ a journaling approach, storing only the
181         /// ChannelMonitorUpdate on disk without updating the monitor itself, replaying the journal at
182         /// reload-time.
183         ///
184         /// For deployments where a copy of ChannelMonitors and other local state are backed up in a
185         /// remote location (with local copies persisted immediately), it is anticipated that all
186         /// updates will return TemporaryFailure until the remote copies could be updated.
187         TemporaryFailure,
188         /// Used to indicate no further channel monitor updates will be allowed (eg we've moved on to a
189         /// different watchtower and cannot update with all watchtowers that were previously informed
190         /// of this channel).
191         ///
192         /// At reception of this error, ChannelManager will force-close the channel and return at
193         /// least a final ChannelMonitorUpdate::ChannelForceClosed which must be delivered to at
194         /// least one ChannelMonitor copy. Revocation secret MUST NOT be released and offchain channel
195         /// update must be rejected.
196         ///
197         /// This failure may also signal a failure to update the local persisted copy of one of
198         /// the channel monitor instance.
199         ///
200         /// Note that even when you fail a holder commitment transaction update, you must store the
201         /// update to ensure you can claim from it in case of a duplicate copy of this ChannelMonitor
202         /// broadcasts it (e.g distributed channel-monitor deployment)
203         ///
204         /// In case of distributed watchtowers deployment, the new version must be written to disk, as
205         /// state may have been stored but rejected due to a block forcing a commitment broadcast. This
206         /// storage is used to claim outputs of rejected state confirmed onchain by another watchtower,
207         /// lagging behind on block processing.
208         PermanentFailure,
209 }
210 use lightning::chain::channelmonitor::ChannelMonitorUpdateErr as nativeChannelMonitorUpdateErr;
211 impl ChannelMonitorUpdateErr {
212         #[allow(unused)]
213         pub(crate) fn to_native(&self) -> nativeChannelMonitorUpdateErr {
214                 match self {
215                         ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure,
216                         ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure,
217                 }
218         }
219         #[allow(unused)]
220         pub(crate) fn into_native(self) -> nativeChannelMonitorUpdateErr {
221                 match self {
222                         ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure,
223                         ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure,
224                 }
225         }
226         #[allow(unused)]
227         pub(crate) fn from_native(native: &nativeChannelMonitorUpdateErr) -> Self {
228                 match native {
229                         nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure,
230                         nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure,
231                 }
232         }
233         #[allow(unused)]
234         pub(crate) fn native_into(native: nativeChannelMonitorUpdateErr) -> Self {
235                 match native {
236                         nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure,
237                         nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure,
238                 }
239         }
240 }
241 /// Creates a copy of the ChannelMonitorUpdateErr
242 #[no_mangle]
243 pub extern "C" fn ChannelMonitorUpdateErr_clone(orig: &ChannelMonitorUpdateErr) -> ChannelMonitorUpdateErr {
244         orig.clone()
245 }
246
247 use lightning::chain::channelmonitor::MonitorUpdateError as nativeMonitorUpdateErrorImport;
248 type nativeMonitorUpdateError = nativeMonitorUpdateErrorImport;
249
250 /// General Err type for ChannelMonitor actions. Generally, this implies that the data provided is
251 /// inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::update_monitor this
252 /// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was
253 /// corrupted.
254 /// Contains a developer-readable error message.
255 #[must_use]
256 #[repr(C)]
257 pub struct MonitorUpdateError {
258         /// A pointer to the opaque Rust object.
259
260         /// Nearly everywhere, inner must be non-null, however in places where
261         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
262         pub inner: *mut nativeMonitorUpdateError,
263         /// Indicates that this is the only struct which contains the same pointer.
264
265         /// Rust functions which take ownership of an object provided via an argument require
266         /// this to be true and invalidate the object pointed to by inner.
267         pub is_owned: bool,
268 }
269
270 impl Drop for MonitorUpdateError {
271         fn drop(&mut self) {
272                 if self.is_owned && !<*mut nativeMonitorUpdateError>::is_null(self.inner) {
273                         let _ = unsafe { Box::from_raw(self.inner) };
274                 }
275         }
276 }
277 /// Frees any resources used by the MonitorUpdateError, if is_owned is set and inner is non-NULL.
278 #[no_mangle]
279 pub extern "C" fn MonitorUpdateError_free(this_obj: MonitorUpdateError) { }
280 #[allow(unused)]
281 /// Used only if an object of this type is returned as a trait impl by a method
282 extern "C" fn MonitorUpdateError_free_void(this_ptr: *mut c_void) {
283         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMonitorUpdateError); }
284 }
285 #[allow(unused)]
286 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
287 impl MonitorUpdateError {
288         pub(crate) fn take_inner(mut self) -> *mut nativeMonitorUpdateError {
289                 assert!(self.is_owned);
290                 let ret = self.inner;
291                 self.inner = std::ptr::null_mut();
292                 ret
293         }
294 }
295 impl Clone for MonitorUpdateError {
296         fn clone(&self) -> Self {
297                 Self {
298                         inner: if <*mut nativeMonitorUpdateError>::is_null(self.inner) { std::ptr::null_mut() } else {
299                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
300                         is_owned: true,
301                 }
302         }
303 }
304 #[allow(unused)]
305 /// Used only if an object of this type is returned as a trait impl by a method
306 pub(crate) extern "C" fn MonitorUpdateError_clone_void(this_ptr: *const c_void) -> *mut c_void {
307         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMonitorUpdateError)).clone() })) as *mut c_void
308 }
309 #[no_mangle]
310 /// Creates a copy of the MonitorUpdateError
311 pub extern "C" fn MonitorUpdateError_clone(orig: &MonitorUpdateError) -> MonitorUpdateError {
312         orig.clone()
313 }
314 /// An event to be processed by the ChannelManager.
315 #[must_use]
316 #[derive(Clone)]
317 #[repr(C)]
318 pub enum MonitorEvent {
319         /// A monitor event containing an HTLCUpdate.
320         HTLCEvent(crate::lightning::chain::channelmonitor::HTLCUpdate),
321         /// A monitor event that the Channel's commitment transaction was broadcasted.
322         CommitmentTxBroadcasted(crate::lightning::chain::transaction::OutPoint),
323 }
324 use lightning::chain::channelmonitor::MonitorEvent as nativeMonitorEvent;
325 impl MonitorEvent {
326         #[allow(unused)]
327         pub(crate) fn to_native(&self) -> nativeMonitorEvent {
328                 match self {
329                         MonitorEvent::HTLCEvent (ref a, ) => {
330                                 let mut a_nonref = (*a).clone();
331                                 nativeMonitorEvent::HTLCEvent (
332                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
333                                 )
334                         },
335                         MonitorEvent::CommitmentTxBroadcasted (ref a, ) => {
336                                 let mut a_nonref = (*a).clone();
337                                 nativeMonitorEvent::CommitmentTxBroadcasted (
338                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
339                                 )
340                         },
341                 }
342         }
343         #[allow(unused)]
344         pub(crate) fn into_native(self) -> nativeMonitorEvent {
345                 match self {
346                         MonitorEvent::HTLCEvent (mut a, ) => {
347                                 nativeMonitorEvent::HTLCEvent (
348                                         *unsafe { Box::from_raw(a.take_inner()) },
349                                 )
350                         },
351                         MonitorEvent::CommitmentTxBroadcasted (mut a, ) => {
352                                 nativeMonitorEvent::CommitmentTxBroadcasted (
353                                         *unsafe { Box::from_raw(a.take_inner()) },
354                                 )
355                         },
356                 }
357         }
358         #[allow(unused)]
359         pub(crate) fn from_native(native: &nativeMonitorEvent) -> Self {
360                 match native {
361                         nativeMonitorEvent::HTLCEvent (ref a, ) => {
362                                 let mut a_nonref = (*a).clone();
363                                 MonitorEvent::HTLCEvent (
364                                         crate::lightning::chain::channelmonitor::HTLCUpdate { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
365                                 )
366                         },
367                         nativeMonitorEvent::CommitmentTxBroadcasted (ref a, ) => {
368                                 let mut a_nonref = (*a).clone();
369                                 MonitorEvent::CommitmentTxBroadcasted (
370                                         crate::lightning::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(a_nonref)), is_owned: true },
371                                 )
372                         },
373                 }
374         }
375         #[allow(unused)]
376         pub(crate) fn native_into(native: nativeMonitorEvent) -> Self {
377                 match native {
378                         nativeMonitorEvent::HTLCEvent (mut a, ) => {
379                                 MonitorEvent::HTLCEvent (
380                                         crate::lightning::chain::channelmonitor::HTLCUpdate { inner: Box::into_raw(Box::new(a)), is_owned: true },
381                                 )
382                         },
383                         nativeMonitorEvent::CommitmentTxBroadcasted (mut a, ) => {
384                                 MonitorEvent::CommitmentTxBroadcasted (
385                                         crate::lightning::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(a)), is_owned: true },
386                                 )
387                         },
388                 }
389         }
390 }
391 /// Frees any resources used by the MonitorEvent
392 #[no_mangle]
393 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
394 /// Creates a copy of the MonitorEvent
395 #[no_mangle]
396 pub extern "C" fn MonitorEvent_clone(orig: &MonitorEvent) -> MonitorEvent {
397         orig.clone()
398 }
399
400 use lightning::chain::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
401 type nativeHTLCUpdate = nativeHTLCUpdateImport;
402
403 /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
404 /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
405 /// preimage claim backward will lead to loss of funds.
406 #[must_use]
407 #[repr(C)]
408 pub struct HTLCUpdate {
409         /// A pointer to the opaque Rust object.
410
411         /// Nearly everywhere, inner must be non-null, however in places where
412         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
413         pub inner: *mut nativeHTLCUpdate,
414         /// Indicates that this is the only struct which contains the same pointer.
415
416         /// Rust functions which take ownership of an object provided via an argument require
417         /// this to be true and invalidate the object pointed to by inner.
418         pub is_owned: bool,
419 }
420
421 impl Drop for HTLCUpdate {
422         fn drop(&mut self) {
423                 if self.is_owned && !<*mut nativeHTLCUpdate>::is_null(self.inner) {
424                         let _ = unsafe { Box::from_raw(self.inner) };
425                 }
426         }
427 }
428 /// Frees any resources used by the HTLCUpdate, if is_owned is set and inner is non-NULL.
429 #[no_mangle]
430 pub extern "C" fn HTLCUpdate_free(this_obj: HTLCUpdate) { }
431 #[allow(unused)]
432 /// Used only if an object of this type is returned as a trait impl by a method
433 extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
434         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCUpdate); }
435 }
436 #[allow(unused)]
437 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
438 impl HTLCUpdate {
439         pub(crate) fn take_inner(mut self) -> *mut nativeHTLCUpdate {
440                 assert!(self.is_owned);
441                 let ret = self.inner;
442                 self.inner = std::ptr::null_mut();
443                 ret
444         }
445 }
446 impl Clone for HTLCUpdate {
447         fn clone(&self) -> Self {
448                 Self {
449                         inner: if <*mut nativeHTLCUpdate>::is_null(self.inner) { std::ptr::null_mut() } else {
450                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
451                         is_owned: true,
452                 }
453         }
454 }
455 #[allow(unused)]
456 /// Used only if an object of this type is returned as a trait impl by a method
457 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
458         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void
459 }
460 #[no_mangle]
461 /// Creates a copy of the HTLCUpdate
462 pub extern "C" fn HTLCUpdate_clone(orig: &HTLCUpdate) -> HTLCUpdate {
463         orig.clone()
464 }
465 #[no_mangle]
466 /// Serialize the HTLCUpdate object into a byte array which can be read by HTLCUpdate_read
467 pub extern "C" fn HTLCUpdate_write(obj: &HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
468         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
469 }
470 #[no_mangle]
471 pub(crate) extern "C" fn HTLCUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
472         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCUpdate) })
473 }
474 #[no_mangle]
475 /// Read a HTLCUpdate from a byte array, created by HTLCUpdate_write
476 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCUpdateDecodeErrorZ {
477         let res = crate::c_types::deserialize_obj(ser);
478         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::channelmonitor::HTLCUpdate { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
479         local_res
480 }
481
482 use lightning::chain::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
483 type nativeChannelMonitor = nativeChannelMonitorImport<crate::lightning::chain::keysinterface::Sign>;
484
485 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
486 /// on-chain transactions to ensure no loss of funds occurs.
487 ///
488 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
489 /// information and are actively monitoring the chain.
490 ///
491 /// Pending Events or updated HTLCs which have not yet been read out by
492 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
493 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
494 /// gotten are fully handled before re-serializing the new state.
495 ///
496 /// Note that the deserializer is only implemented for (BlockHash, ChannelMonitor), which
497 /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
498 /// the \"reorg path\" (ie disconnecting blocks until you find a common ancestor from both the
499 /// returned block hash and the the current chain and then reconnecting blocks to get to the
500 /// best chain) upon deserializing the object!
501 #[must_use]
502 #[repr(C)]
503 pub struct ChannelMonitor {
504         /// A pointer to the opaque Rust object.
505
506         /// Nearly everywhere, inner must be non-null, however in places where
507         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
508         pub inner: *mut nativeChannelMonitor,
509         /// Indicates that this is the only struct which contains the same pointer.
510
511         /// Rust functions which take ownership of an object provided via an argument require
512         /// this to be true and invalidate the object pointed to by inner.
513         pub is_owned: bool,
514 }
515
516 impl Drop for ChannelMonitor {
517         fn drop(&mut self) {
518                 if self.is_owned && !<*mut nativeChannelMonitor>::is_null(self.inner) {
519                         let _ = unsafe { Box::from_raw(self.inner) };
520                 }
521         }
522 }
523 /// Frees any resources used by the ChannelMonitor, if is_owned is set and inner is non-NULL.
524 #[no_mangle]
525 pub extern "C" fn ChannelMonitor_free(this_obj: ChannelMonitor) { }
526 #[allow(unused)]
527 /// Used only if an object of this type is returned as a trait impl by a method
528 extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
529         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitor); }
530 }
531 #[allow(unused)]
532 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
533 impl ChannelMonitor {
534         pub(crate) fn take_inner(mut self) -> *mut nativeChannelMonitor {
535                 assert!(self.is_owned);
536                 let ret = self.inner;
537                 self.inner = std::ptr::null_mut();
538                 ret
539         }
540 }
541 #[no_mangle]
542 /// Serialize the ChannelMonitor object into a byte array which can be read by ChannelMonitor_read
543 pub extern "C" fn ChannelMonitor_write(obj: &ChannelMonitor) -> crate::c_types::derived::CVec_u8Z {
544         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
545 }
546 #[no_mangle]
547 pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
548         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelMonitor) })
549 }
550 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
551 /// itself.
552 ///
553 /// panics if the given update is not the next update by update_id.
554 #[must_use]
555 #[no_mangle]
556 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 {
557         let mut ret = unsafe { &*this_arg.inner }.update_monitor(unsafe { &*updates.inner }, broadcaster, fee_estimator, logger);
558         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::chain::channelmonitor::MonitorUpdateError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
559         local_ret
560 }
561
562 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
563 /// ChannelMonitor.
564 #[must_use]
565 #[no_mangle]
566 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &ChannelMonitor) -> u64 {
567         let mut ret = unsafe { &*this_arg.inner }.get_latest_update_id();
568         ret
569 }
570
571 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
572 #[must_use]
573 #[no_mangle]
574 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
575         let mut ret = unsafe { &*this_arg.inner }.get_funding_txo();
576         let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (crate::lightning::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(orig_ret_0)), is_owned: true }, orig_ret_1.into_bytes().into()).into();
577         local_ret
578 }
579
580 /// Gets a list of txids, with their output scripts (in the order they appear in the
581 /// transaction), which we must learn about spends of via block_connected().
582 #[must_use]
583 #[no_mangle]
584 pub extern "C" fn ChannelMonitor_get_outputs_to_watch(this_arg: &ChannelMonitor) -> crate::c_types::derived::CVec_C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZZ {
585         let mut ret = unsafe { &*this_arg.inner }.get_outputs_to_watch();
586         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 }); };
587         local_ret.into()
588 }
589
590 /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
591 /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
592 /// have been registered.
593 #[no_mangle]
594 pub extern "C" fn ChannelMonitor_load_outputs_to_watch(this_arg: &ChannelMonitor, filter: &crate::lightning::chain::Filter) {
595         unsafe { &*this_arg.inner }.load_outputs_to_watch(filter)
596 }
597
598 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
599 /// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
600 #[must_use]
601 #[no_mangle]
602 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
603         let mut ret = unsafe { &*this_arg.inner }.get_and_clear_pending_monitor_events();
604         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
605         local_ret.into()
606 }
607
608 /// Gets the list of pending events which were generated by previous actions, clearing the list
609 /// in the process.
610 ///
611 /// This is called by ChainMonitor::get_and_clear_pending_events() and is equivalent to
612 /// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do
613 /// no internal locking in ChannelMonitors.
614 #[must_use]
615 #[no_mangle]
616 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
617         let mut ret = unsafe { &*this_arg.inner }.get_and_clear_pending_events();
618         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::Event::native_into(item) }); };
619         local_ret.into()
620 }
621
622 /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
623 /// the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of
624 /// fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows
625 /// a higher revocation secret than the holder commitment number we are aware of. Broadcasting these
626 /// transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to
627 /// broadcast them if counterparty don't close channel with his higher commitment transaction after a
628 /// substantial amount of time (a month or even a year) to get back funds. Best may be to contact
629 /// out-of-band the other node operator to coordinate with him if option is available to you.
630 /// In any-case, choice is up to the user.
631 #[must_use]
632 #[no_mangle]
633 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 {
634         let mut ret = unsafe { &*this_arg.inner }.get_latest_holder_commitment_txn(logger);
635         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let mut local_ret_0 = ::bitcoin::consensus::encode::serialize(&item); crate::c_types::Transaction::from_vec(local_ret_0) }); };
636         local_ret.into()
637 }
638
639 /// Processes transactions in a newly connected block, which may result in any of the following:
640 /// - update the monitor's state against resolved HTLCs
641 /// - punish the counterparty in the case of seeing a revoked commitment transaction
642 /// - force close the channel and claim/timeout incoming/outgoing HTLCs if near expiration
643 /// - detect settled outputs for later spending
644 /// - schedule and bump any in-flight claims
645 ///
646 /// Returns any new outputs to watch from `txdata`; after called, these are also included in
647 /// [`get_outputs_to_watch`].
648 ///
649 /// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
650 #[must_use]
651 #[no_mangle]
652 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 {
653         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 }); };
654         let mut ret = unsafe { &*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);
655         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 }); };
656         local_ret.into()
657 }
658
659 /// Determines if the disconnected block contained any transactions of interest and updates
660 /// appropriately.
661 #[no_mangle]
662 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) {
663         unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger)
664 }
665
666 /// Processes transactions confirmed in a block with the given header and height, returning new
667 /// outputs to watch. See [`block_connected`] for details.
668 ///
669 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
670 /// blocks. May be called before or after [`update_best_block`] for transactions in the
671 /// corresponding block. See [`update_best_block`] for further calling expectations. 
672 ///
673 /// [`block_connected`]: Self::block_connected
674 /// [`update_best_block`]: Self::update_best_block
675 #[must_use]
676 #[no_mangle]
677 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 {
678         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 }); };
679         let mut ret = unsafe { &*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);
680         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 }); };
681         local_ret.into()
682 }
683
684 /// Processes a transaction that was reorganized out of the chain.
685 ///
686 /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
687 /// than blocks. May be called before or after [`update_best_block`] for transactions in the
688 /// corresponding block. See [`update_best_block`] for further calling expectations.
689 ///
690 /// [`block_disconnected`]: Self::block_disconnected
691 /// [`update_best_block`]: Self::update_best_block
692 #[no_mangle]
693 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) {
694         unsafe { &*this_arg.inner }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), broadcaster, fee_estimator, logger)
695 }
696
697 /// Updates the monitor with the current best chain tip, returning new outputs to watch. See
698 /// [`block_connected`] for details.
699 ///
700 /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
701 /// blocks. May be called before or after [`transactions_confirmed`] for the corresponding
702 /// block.
703 ///
704 /// Must be called after new blocks become available for the most recent block. Intermediary
705 /// blocks, however, may be safely skipped. In the event of a chain re-organization, this only
706 /// needs to be called for the most recent block assuming `transaction_unconfirmed` is called
707 /// for any affected transactions.
708 ///
709 /// [`block_connected`]: Self::block_connected
710 /// [`transactions_confirmed`]: Self::transactions_confirmed
711 /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
712 #[must_use]
713 #[no_mangle]
714 pub extern "C" fn ChannelMonitor_update_best_block(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 {
715         let mut ret = unsafe { &*this_arg.inner }.update_best_block(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, broadcaster, fee_estimator, logger);
716         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 }); };
717         local_ret.into()
718 }
719
720 /// Returns the set of txids that should be monitored for re-organization out of the chain.
721 #[must_use]
722 #[no_mangle]
723 pub extern "C" fn ChannelMonitor_get_relevant_txids(this_arg: &ChannelMonitor) -> crate::c_types::derived::CVec_TxidZ {
724         let mut ret = unsafe { &*this_arg.inner }.get_relevant_txids();
725         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
726         local_ret.into()
727 }
728
729 /// `Persist` defines behavior for persisting channel monitors: this could mean
730 /// writing once to disk, and/or uploading to one or more backup services.
731 ///
732 /// Note that for every new monitor, you **must** persist the new `ChannelMonitor`
733 /// to disk/backups. And, on every update, you **must** persist either the
734 /// `ChannelMonitorUpdate` or the updated monitor itself. Otherwise, there is risk
735 /// of situations such as revoking a transaction, then crashing before this
736 /// revocation can be persisted, then unintentionally broadcasting a revoked
737 /// transaction and losing money. This is a risk because previous channel states
738 /// are toxic, so it's important that whatever channel state is persisted is
739 /// kept up-to-date.
740 #[repr(C)]
741 pub struct Persist {
742         /// An opaque pointer which is passed to your function implementations as an argument.
743         /// This has no meaning in the LDK, and can be NULL or any other value.
744         pub this_arg: *mut c_void,
745         /// Persist a new channel's data. The data can be stored any way you want, but
746         /// the identifier provided by Rust-Lightning is the channel's outpoint (and
747         /// it is up to you to maintain a correct mapping between the outpoint and the
748         /// stored channel data). Note that you **must** persist every new monitor to
749         /// disk. See the `Persist` trait documentation for more details.
750         ///
751         /// See [`ChannelMonitor::write`] for writing out a `ChannelMonitor`,
752         /// and [`ChannelMonitorUpdateErr`] for requirements when returning errors.
753         #[must_use]
754         pub persist_new_channel: extern "C" fn (this_arg: *const c_void, id: crate::lightning::chain::transaction::OutPoint, data: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ,
755         /// Update one channel's data. The provided `ChannelMonitor` has already
756         /// applied the given update.
757         ///
758         /// Note that on every update, you **must** persist either the
759         /// `ChannelMonitorUpdate` or the updated monitor itself to disk/backups. See
760         /// the `Persist` trait documentation for more details.
761         ///
762         /// If an implementer chooses to persist the updates only, they need to make
763         /// sure that all the updates are applied to the `ChannelMonitors` *before*
764         /// the set of channel monitors is given to the `ChannelManager`
765         /// deserialization routine. See [`ChannelMonitor::update_monitor`] for
766         /// applying a monitor update to a monitor. If full `ChannelMonitors` are
767         /// persisted, then there is no need to persist individual updates.
768         ///
769         /// Note that there could be a performance tradeoff between persisting complete
770         /// channel monitors on every update vs. persisting only updates and applying
771         /// them in batches. The size of each monitor grows `O(number of state updates)`
772         /// whereas updates are small and `O(1)`.
773         ///
774         /// See [`ChannelMonitor::write`] for writing out a `ChannelMonitor`,
775         /// [`ChannelMonitorUpdate::write`] for writing out an update, and
776         /// [`ChannelMonitorUpdateErr`] for requirements when returning errors.
777         #[must_use]
778         pub update_persisted_channel: extern "C" fn (this_arg: *const c_void, id: crate::lightning::chain::transaction::OutPoint, update: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, data: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ,
779         /// Frees any resources associated with this object given its this_arg pointer.
780         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
781         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
782 }
783 unsafe impl Send for Persist {}
784 unsafe impl Sync for Persist {}
785
786 use lightning::chain::channelmonitor::Persist as rustPersist;
787 impl rustPersist<crate::lightning::chain::keysinterface::Sign> for Persist {
788         fn persist_new_channel(&self, id: lightning::chain::transaction::OutPoint, data: &lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::Sign>) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> {
789                 let mut ret = (self.persist_new_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(id)), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { (data as *const _) as *mut _ }, is_owned: false });
790                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
791                 local_ret
792         }
793         fn update_persisted_channel(&self, id: lightning::chain::transaction::OutPoint, update: &lightning::chain::channelmonitor::ChannelMonitorUpdate, data: &lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::Sign>) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> {
794                 let mut ret = (self.update_persisted_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(id)), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: unsafe { (update as *const _) as *mut _ }, is_owned: false }, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { (data as *const _) as *mut _ }, is_owned: false });
795                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
796                 local_ret
797         }
798 }
799
800 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
801 // directly as a Deref trait in higher-level structs:
802 impl std::ops::Deref for Persist {
803         type Target = Self;
804         fn deref(&self) -> &Self {
805                 self
806         }
807 }
808 /// Calls the free function if one is set
809 #[no_mangle]
810 pub extern "C" fn Persist_free(this_ptr: Persist) { }
811 impl Drop for Persist {
812         fn drop(&mut self) {
813                 if let Some(f) = self.free {
814                         f(self.this_arg);
815                 }
816         }
817 }
818 #[no_mangle]
819 /// Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
820 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 {
821         let arg_conv = arg;
822         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);
823         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: Box::into_raw(Box::new(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: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
824         local_res
825 }