Drop the now-unused usizeslice bindings struct
[rust-lightning] / lightning-c-bindings / src / ln / channelmonitor.rs
1 //! The logic to monitor for on-chain transactions and create the relevant claim responses lives
2 //! here.
3 //!
4 //! ChannelMonitor objects are generated by ChannelManager in response to relevant
5 //! messages/actions, and MUST be persisted to disk (and, preferably, remotely) before progress can
6 //! be made in responding to certain messages, see ManyChannelMonitor for more.
7 //!
8 //! Note that ChannelMonitors are an important part of the lightning trust model and a copy of the
9 //! latest ChannelMonitor must always be actively monitoring for chain updates (and no out-of-date
10 //! ChannelMonitors should do so). Thus, if you're building rust-lightning into an HSM or other
11 //! security-domain-separated system design, you should consider having multiple paths for
12 //! ChannelMonitors to get out of the HSM and onto monitoring devices.
13
14 use std::ffi::c_void;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17
18
19 use lightning::ln::channelmonitor::ChannelMonitorUpdate as nativeChannelMonitorUpdateImport;
20 type nativeChannelMonitorUpdate = nativeChannelMonitorUpdateImport;
21
22 /// An update generated by the underlying Channel itself which contains some new information the
23 /// ChannelMonitor should be made aware of.
24 #[must_use]
25 #[repr(C)]
26 pub struct ChannelMonitorUpdate {
27         /// Nearly everyhwere, inner must be non-null, however in places where
28         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
29         pub inner: *mut nativeChannelMonitorUpdate,
30         pub is_owned: bool,
31 }
32
33 impl Drop for ChannelMonitorUpdate {
34         fn drop(&mut self) {
35                 if self.is_owned && !self.inner.is_null() {
36                         let _ = unsafe { Box::from_raw(self.inner) };
37                 }
38         }
39 }
40 #[no_mangle]
41 pub extern "C" fn ChannelMonitorUpdate_free(this_ptr: ChannelMonitorUpdate) { }
42 #[allow(unused)]
43 /// Used only if an object of this type is returned as a trait impl by a method
44 extern "C" fn ChannelMonitorUpdate_free_void(this_ptr: *mut c_void) {
45         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitorUpdate); }
46 }
47 #[allow(unused)]
48 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
49 impl ChannelMonitorUpdate {
50         pub(crate) fn take_ptr(mut self) -> *mut nativeChannelMonitorUpdate {
51                 assert!(self.is_owned);
52                 let ret = self.inner;
53                 self.inner = std::ptr::null_mut();
54                 ret
55         }
56 }
57 impl Clone for ChannelMonitorUpdate {
58         fn clone(&self) -> Self {
59                 Self {
60                         inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
61                         is_owned: true,
62                 }
63         }
64 }
65 #[allow(unused)]
66 /// Used only if an object of this type is returned as a trait impl by a method
67 pub(crate) extern "C" fn ChannelMonitorUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
68         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelMonitorUpdate)).clone() })) as *mut c_void
69 }
70 /// The sequence number of this update. Updates *must* be replayed in-order according to this
71 /// sequence number (and updates may panic if they are not). The update_id values are strictly
72 /// increasing and increase by one for each new update.
73 ///
74 /// This sequence number is also used to track up to which points updates which returned
75 /// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given
76 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
77 #[no_mangle]
78 pub extern "C" fn ChannelMonitorUpdate_get_update_id(this_ptr: &ChannelMonitorUpdate) -> u64 {
79         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.update_id;
80         (*inner_val)
81 }
82 /// The sequence number of this update. Updates *must* be replayed in-order according to this
83 /// sequence number (and updates may panic if they are not). The update_id values are strictly
84 /// increasing and increase by one for each new update.
85 ///
86 /// This sequence number is also used to track up to which points updates which returned
87 /// ChannelMonitorUpdateErr::TemporaryFailure have been applied to all copies of a given
88 /// ChannelMonitor when ChannelManager::channel_monitor_updated is called.
89 #[no_mangle]
90 pub extern "C" fn ChannelMonitorUpdate_set_update_id(this_ptr: &mut ChannelMonitorUpdate, mut val: u64) {
91         unsafe { &mut *this_ptr.inner }.update_id = val;
92 }
93 #[no_mangle]
94 pub extern "C" fn ChannelMonitorUpdate_write(obj: *const ChannelMonitorUpdate) -> crate::c_types::derived::CVec_u8Z {
95         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
96 }
97 #[no_mangle]
98 pub extern "C" fn ChannelMonitorUpdate_read(ser: crate::c_types::u8slice) -> ChannelMonitorUpdate {
99         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
100                 ChannelMonitorUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true }
101         } else {
102                 ChannelMonitorUpdate { inner: std::ptr::null_mut(), is_owned: true }
103         }
104 }
105 /// An error enum representing a failure to persist a channel monitor update.
106 #[must_use]
107 #[derive(Clone)]
108 #[repr(C)]
109 pub enum ChannelMonitorUpdateErr {
110         /// Used to indicate a temporary failure (eg connection to a watchtower or remote backup of
111         /// our state failed, but is expected to succeed at some point in the future).
112         ///
113         /// Such a failure will \"freeze\" a channel, preventing us from revoking old states or
114         /// submitting new commitment transactions to the counterparty. Once the update(s) which failed
115         /// have been successfully applied, ChannelManager::channel_monitor_updated can be used to
116         /// restore the channel to an operational state.
117         ///
118         /// Note that a given ChannelManager will *never* re-generate a given ChannelMonitorUpdate. If
119         /// you return a TemporaryFailure you must ensure that it is written to disk safely before
120         /// writing out the latest ChannelManager state.
121         ///
122         /// Even when a channel has been \"frozen\" updates to the ChannelMonitor can continue to occur
123         /// (eg if an inbound HTLC which we forwarded was claimed upstream resulting in us attempting
124         /// to claim it on this channel) and those updates must be applied wherever they can be. At
125         /// least one such updated ChannelMonitor must be persisted otherwise PermanentFailure should
126         /// be returned to get things on-chain ASAP using only the in-memory copy. Obviously updates to
127         /// the channel which would invalidate previous ChannelMonitors are not made when a channel has
128         /// been \"frozen\".
129         ///
130         /// Note that even if updates made after TemporaryFailure succeed you must still call
131         /// channel_monitor_updated to ensure you have the latest monitor and re-enable normal channel
132         /// operation.
133         ///
134         /// Note that the update being processed here will not be replayed for you when you call
135         /// ChannelManager::channel_monitor_updated, so you must store the update itself along
136         /// with the persisted ChannelMonitor on your own local disk prior to returning a
137         /// TemporaryFailure. You may, of course, employ a journaling approach, storing only the
138         /// ChannelMonitorUpdate on disk without updating the monitor itself, replaying the journal at
139         /// reload-time.
140         ///
141         /// For deployments where a copy of ChannelMonitors and other local state are backed up in a
142         /// remote location (with local copies persisted immediately), it is anticipated that all
143         /// updates will return TemporaryFailure until the remote copies could be updated.
144         TemporaryFailure,
145         /// Used to indicate no further channel monitor updates will be allowed (eg we've moved on to a
146         /// different watchtower and cannot update with all watchtowers that were previously informed
147         /// of this channel).
148         ///
149         /// At reception of this error, ChannelManager will force-close the channel and return at
150         /// least a final ChannelMonitorUpdate::ChannelForceClosed which must be delivered to at
151         /// least one ChannelMonitor copy. Revocation secret MUST NOT be released and offchain channel
152         /// update must be rejected.
153         ///
154         /// This failure may also signal a failure to update the local persisted copy of one of
155         /// the channel monitor instance.
156         ///
157         /// Note that even when you fail a holder commitment transaction update, you must store the
158         /// update to ensure you can claim from it in case of a duplicate copy of this ChannelMonitor
159         /// broadcasts it (e.g distributed channel-monitor deployment)
160         PermanentFailure,
161 }
162 use lightning::ln::channelmonitor::ChannelMonitorUpdateErr as nativeChannelMonitorUpdateErr;
163 impl ChannelMonitorUpdateErr {
164         #[allow(unused)]
165         pub(crate) fn to_native(&self) -> nativeChannelMonitorUpdateErr {
166                 match self {
167                         ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure,
168                         ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure,
169                 }
170         }
171         #[allow(unused)]
172         pub(crate) fn into_native(self) -> nativeChannelMonitorUpdateErr {
173                 match self {
174                         ChannelMonitorUpdateErr::TemporaryFailure => nativeChannelMonitorUpdateErr::TemporaryFailure,
175                         ChannelMonitorUpdateErr::PermanentFailure => nativeChannelMonitorUpdateErr::PermanentFailure,
176                 }
177         }
178         #[allow(unused)]
179         pub(crate) fn from_native(native: &nativeChannelMonitorUpdateErr) -> Self {
180                 match native {
181                         nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure,
182                         nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure,
183                 }
184         }
185         #[allow(unused)]
186         pub(crate) fn native_into(native: nativeChannelMonitorUpdateErr) -> Self {
187                 match native {
188                         nativeChannelMonitorUpdateErr::TemporaryFailure => ChannelMonitorUpdateErr::TemporaryFailure,
189                         nativeChannelMonitorUpdateErr::PermanentFailure => ChannelMonitorUpdateErr::PermanentFailure,
190                 }
191         }
192 }
193
194 use lightning::ln::channelmonitor::MonitorUpdateError as nativeMonitorUpdateErrorImport;
195 type nativeMonitorUpdateError = nativeMonitorUpdateErrorImport;
196
197 /// General Err type for ChannelMonitor actions. Generally, this implies that the data provided is
198 /// inconsistent with the ChannelMonitor being called. eg for ChannelMonitor::update_monitor this
199 /// means you tried to update a monitor for a different channel or the ChannelMonitorUpdate was
200 /// corrupted.
201 /// Contains a human-readable error message.
202 #[must_use]
203 #[repr(C)]
204 pub struct MonitorUpdateError {
205         /// Nearly everyhwere, inner must be non-null, however in places where
206         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
207         pub inner: *mut nativeMonitorUpdateError,
208         pub is_owned: bool,
209 }
210
211 impl Drop for MonitorUpdateError {
212         fn drop(&mut self) {
213                 if self.is_owned && !self.inner.is_null() {
214                         let _ = unsafe { Box::from_raw(self.inner) };
215                 }
216         }
217 }
218 #[no_mangle]
219 pub extern "C" fn MonitorUpdateError_free(this_ptr: MonitorUpdateError) { }
220 #[allow(unused)]
221 /// Used only if an object of this type is returned as a trait impl by a method
222 extern "C" fn MonitorUpdateError_free_void(this_ptr: *mut c_void) {
223         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMonitorUpdateError); }
224 }
225 #[allow(unused)]
226 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
227 impl MonitorUpdateError {
228         pub(crate) fn take_ptr(mut self) -> *mut nativeMonitorUpdateError {
229                 assert!(self.is_owned);
230                 let ret = self.inner;
231                 self.inner = std::ptr::null_mut();
232                 ret
233         }
234 }
235
236 use lightning::ln::channelmonitor::MonitorEvent as nativeMonitorEventImport;
237 type nativeMonitorEvent = nativeMonitorEventImport;
238
239 /// An event to be processed by the ChannelManager.
240 #[must_use]
241 #[repr(C)]
242 pub struct MonitorEvent {
243         /// Nearly everyhwere, inner must be non-null, however in places where
244         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
245         pub inner: *mut nativeMonitorEvent,
246         pub is_owned: bool,
247 }
248
249 impl Drop for MonitorEvent {
250         fn drop(&mut self) {
251                 if self.is_owned && !self.inner.is_null() {
252                         let _ = unsafe { Box::from_raw(self.inner) };
253                 }
254         }
255 }
256 #[no_mangle]
257 pub extern "C" fn MonitorEvent_free(this_ptr: MonitorEvent) { }
258 #[allow(unused)]
259 /// Used only if an object of this type is returned as a trait impl by a method
260 extern "C" fn MonitorEvent_free_void(this_ptr: *mut c_void) {
261         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMonitorEvent); }
262 }
263 #[allow(unused)]
264 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
265 impl MonitorEvent {
266         pub(crate) fn take_ptr(mut self) -> *mut nativeMonitorEvent {
267                 assert!(self.is_owned);
268                 let ret = self.inner;
269                 self.inner = std::ptr::null_mut();
270                 ret
271         }
272 }
273
274 use lightning::ln::channelmonitor::HTLCUpdate as nativeHTLCUpdateImport;
275 type nativeHTLCUpdate = nativeHTLCUpdateImport;
276
277 /// Simple structure send back by ManyChannelMonitor in case of HTLC detected onchain from a
278 /// forward channel and from which info are needed to update HTLC in a backward channel.
279 #[must_use]
280 #[repr(C)]
281 pub struct HTLCUpdate {
282         /// Nearly everyhwere, inner must be non-null, however in places where
283         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
284         pub inner: *mut nativeHTLCUpdate,
285         pub is_owned: bool,
286 }
287
288 impl Drop for HTLCUpdate {
289         fn drop(&mut self) {
290                 if self.is_owned && !self.inner.is_null() {
291                         let _ = unsafe { Box::from_raw(self.inner) };
292                 }
293         }
294 }
295 #[no_mangle]
296 pub extern "C" fn HTLCUpdate_free(this_ptr: HTLCUpdate) { }
297 #[allow(unused)]
298 /// Used only if an object of this type is returned as a trait impl by a method
299 extern "C" fn HTLCUpdate_free_void(this_ptr: *mut c_void) {
300         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCUpdate); }
301 }
302 #[allow(unused)]
303 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
304 impl HTLCUpdate {
305         pub(crate) fn take_ptr(mut self) -> *mut nativeHTLCUpdate {
306                 assert!(self.is_owned);
307                 let ret = self.inner;
308                 self.inner = std::ptr::null_mut();
309                 ret
310         }
311 }
312 impl Clone for HTLCUpdate {
313         fn clone(&self) -> Self {
314                 Self {
315                         inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
316                         is_owned: true,
317                 }
318         }
319 }
320 #[allow(unused)]
321 /// Used only if an object of this type is returned as a trait impl by a method
322 pub(crate) extern "C" fn HTLCUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void {
323         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCUpdate)).clone() })) as *mut c_void
324 }
325 #[no_mangle]
326 pub extern "C" fn HTLCUpdate_write(obj: *const HTLCUpdate) -> crate::c_types::derived::CVec_u8Z {
327         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
328 }
329 #[no_mangle]
330 pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> HTLCUpdate {
331         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
332                 HTLCUpdate { inner: Box::into_raw(Box::new(res)), is_owned: true }
333         } else {
334                 HTLCUpdate { inner: std::ptr::null_mut(), is_owned: true }
335         }
336 }
337
338 use lightning::ln::channelmonitor::ChannelMonitor as nativeChannelMonitorImport;
339 type nativeChannelMonitor = nativeChannelMonitorImport<crate::chain::keysinterface::ChannelKeys>;
340
341 /// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
342 /// on-chain transactions to ensure no loss of funds occurs.
343 ///
344 /// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
345 /// information and are actively monitoring the chain.
346 ///
347 /// Pending Events or updated HTLCs which have not yet been read out by
348 /// get_and_clear_pending_monitor_events or get_and_clear_pending_events are serialized to disk and
349 /// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
350 /// gotten are fully handled before re-serializing the new state.
351 #[must_use]
352 #[repr(C)]
353 pub struct ChannelMonitor {
354         /// Nearly everyhwere, inner must be non-null, however in places where
355         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
356         pub inner: *mut nativeChannelMonitor,
357         pub is_owned: bool,
358 }
359
360 impl Drop for ChannelMonitor {
361         fn drop(&mut self) {
362                 if self.is_owned && !self.inner.is_null() {
363                         let _ = unsafe { Box::from_raw(self.inner) };
364                 }
365         }
366 }
367 #[no_mangle]
368 pub extern "C" fn ChannelMonitor_free(this_ptr: ChannelMonitor) { }
369 #[allow(unused)]
370 /// Used only if an object of this type is returned as a trait impl by a method
371 extern "C" fn ChannelMonitor_free_void(this_ptr: *mut c_void) {
372         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelMonitor); }
373 }
374 #[allow(unused)]
375 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
376 impl ChannelMonitor {
377         pub(crate) fn take_ptr(mut self) -> *mut nativeChannelMonitor {
378                 assert!(self.is_owned);
379                 let ret = self.inner;
380                 self.inner = std::ptr::null_mut();
381                 ret
382         }
383 }
384 /// Simple trait indicating ability to track a set of ChannelMonitors and multiplex events between
385 /// them. Generally should be implemented by keeping a local SimpleManyChannelMonitor and passing
386 /// events to it, while also taking any add/update_monitor events and passing them to some remote
387 /// server(s).
388 ///
389 /// In general, you must always have at least one local copy in memory, which must never fail to
390 /// update (as it is responsible for broadcasting the latest state in case the channel is closed),
391 /// and then persist it to various on-disk locations. If, for some reason, the in-memory copy fails
392 /// to update (eg out-of-memory or some other condition), you must immediately shut down without
393 /// taking any further action such as writing the current state to disk. This should likely be
394 /// accomplished via panic!() or abort().
395 ///
396 /// Note that any updates to a channel's monitor *must* be applied to each instance of the
397 /// channel's monitor everywhere (including remote watchtowers) *before* this function returns. If
398 /// an update occurs and a remote watchtower is left with old state, it may broadcast transactions
399 /// which we have revoked, allowing our counterparty to claim all funds in the channel!
400 ///
401 /// User needs to notify implementors of ManyChannelMonitor when a new block is connected or
402 /// disconnected using their `block_connected` and `block_disconnected` methods. However, rather
403 /// than calling these methods directly, the user should register implementors as listeners to the
404 /// BlockNotifier and call the BlockNotifier's `block_(dis)connected` methods, which will notify
405 /// all registered listeners in one go.
406 #[repr(C)]
407 pub struct ManyChannelMonitor {
408         pub this_arg: *mut c_void,
409         /// Adds a monitor for the given `funding_txo`.
410         ///
411         /// Implementer must also ensure that the funding_txo txid *and* outpoint are registered with
412         /// any relevant ChainWatchInterfaces such that the provided monitor receives block_connected
413         /// callbacks with the funding transaction, or any spends of it.
414         ///
415         /// Further, the implementer must also ensure that each output returned in
416         /// monitor.get_outputs_to_watch() is registered to ensure that the provided monitor learns about
417         /// any spends of any of the outputs.
418         ///
419         /// Any spends of outputs which should have been registered which aren't passed to
420         /// ChannelMonitors via block_connected may result in FUNDS LOSS.
421         #[must_use]
422         pub add_monitor: extern "C" fn (this_arg: *const c_void, funding_txo: crate::chain::transaction::OutPoint, monitor: crate::ln::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ,
423         /// Updates a monitor for the given `funding_txo`.
424         ///
425         /// Implementer must also ensure that the funding_txo txid *and* outpoint are registered with
426         /// any relevant ChainWatchInterfaces such that the provided monitor receives block_connected
427         /// callbacks with the funding transaction, or any spends of it.
428         ///
429         /// Further, the implementer must also ensure that each output returned in
430         /// monitor.get_watch_outputs() is registered to ensure that the provided monitor learns about
431         /// any spends of any of the outputs.
432         ///
433         /// Any spends of outputs which should have been registered which aren't passed to
434         /// ChannelMonitors via block_connected may result in FUNDS LOSS.
435         ///
436         /// In case of distributed watchtowers deployment, even if an Err is return, the new version
437         /// must be written to disk, as state may have been stored but rejected due to a block forcing
438         /// a commitment broadcast. This storage is used to claim outputs of rejected state confirmed
439         /// onchain by another watchtower, lagging behind on block processing.
440         #[must_use]
441         pub update_monitor: extern "C" fn (this_arg: *const c_void, funding_txo: crate::chain::transaction::OutPoint, monitor: crate::ln::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ,
442         /// Used by ChannelManager to get list of HTLC resolved onchain and which needed to be updated
443         /// with success or failure.
444         ///
445         /// You should probably just call through to
446         /// ChannelMonitor::get_and_clear_pending_monitor_events() for each ChannelMonitor and return
447         /// the full list.
448         #[must_use]
449         pub get_and_clear_pending_monitor_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MonitorEventZ,
450         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
451 }
452 unsafe impl Send for ManyChannelMonitor {}
453 unsafe impl Sync for ManyChannelMonitor {}
454
455 use lightning::ln::channelmonitor::ManyChannelMonitor as rustManyChannelMonitor;
456 impl rustManyChannelMonitor for ManyChannelMonitor {
457         type Keys = crate::chain::keysinterface::ChannelKeys;
458         fn add_monitor(&self, funding_txo: lightning::chain::transaction::OutPoint, monitor: lightning::ln::channelmonitor::ChannelMonitor<Self::Keys>) -> Result<(), lightning::ln::channelmonitor::ChannelMonitorUpdateErr> {
459                 let mut ret = (self.add_monitor)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, crate::ln::channelmonitor::ChannelMonitor { inner: Box::into_raw(Box::new(monitor)), is_owned: true });
460                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { (*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).into_native() })};
461                 local_ret
462         }
463         fn update_monitor(&self, funding_txo: lightning::chain::transaction::OutPoint, monitor: lightning::ln::channelmonitor::ChannelMonitorUpdate) -> Result<(), lightning::ln::channelmonitor::ChannelMonitorUpdateErr> {
464                 let mut ret = (self.update_monitor)(self.this_arg, crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, crate::ln::channelmonitor::ChannelMonitorUpdate { inner: Box::into_raw(Box::new(monitor)), is_owned: true });
465                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(ret.contents.result.take_ptr()) })*/ }), false => Err( { (*unsafe { Box::from_raw(ret.contents.err.take_ptr()) }).into_native() })};
466                 local_ret
467         }
468         fn get_and_clear_pending_monitor_events(&self) -> Vec<lightning::ln::channelmonitor::MonitorEvent> {
469                 let mut ret = (self.get_and_clear_pending_monitor_events)(self.this_arg);
470                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { *unsafe { Box::from_raw(item.take_ptr()) } }); };
471                 local_ret
472         }
473 }
474
475 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
476 // directly as a Deref trait in higher-level structs:
477 impl std::ops::Deref for ManyChannelMonitor {
478         type Target = Self;
479         fn deref(&self) -> &Self {
480                 self
481         }
482 }
483 /// Calls the free function if one is set
484 #[no_mangle]
485 pub extern "C" fn ManyChannelMonitor_free(this_ptr: ManyChannelMonitor) { }
486 impl Drop for ManyChannelMonitor {
487         fn drop(&mut self) {
488                 if let Some(f) = self.free {
489                         f(self.this_arg);
490                 }
491         }
492 }
493 /// Updates a ChannelMonitor on the basis of some new information provided by the Channel
494 /// itself.
495 ///
496 /// panics if the given update is not the next update by update_id.
497 #[must_use]
498 #[no_mangle]
499 pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &mut ChannelMonitor, mut updates: crate::ln::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::chain::chaininterface::BroadcasterInterface, logger: &crate::util::logger::Logger) -> crate::c_types::derived::CResult_NoneMonitorUpdateErrorZ {
500         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.update_monitor(*unsafe { Box::from_raw(updates.take_ptr()) }, broadcaster, logger);
501         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::channelmonitor::MonitorUpdateError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
502         local_ret
503 }
504
505 /// Gets the update_id from the latest ChannelMonitorUpdate which was applied to this
506 /// ChannelMonitor.
507 #[must_use]
508 #[no_mangle]
509 pub extern "C" fn ChannelMonitor_get_latest_update_id(this_arg: &ChannelMonitor) -> u64 {
510         let mut ret = unsafe { &*this_arg.inner }.get_latest_update_id();
511         ret
512 }
513
514 /// Gets the funding transaction outpoint of the channel this ChannelMonitor is monitoring for.
515 #[must_use]
516 #[no_mangle]
517 pub extern "C" fn ChannelMonitor_get_funding_txo(this_arg: &ChannelMonitor) -> crate::c_types::derived::C2Tuple_OutPointScriptZ {
518         let mut ret = unsafe { &*this_arg.inner }.get_funding_txo();
519         let (ref orig_ret_0, ref orig_ret_1) = ret; let mut local_ret = (crate::chain::transaction::OutPoint { inner: unsafe { ( (&(*orig_ret_0) as *const _) as *mut _) }, is_owned: false }, orig_ret_1.clone().into_bytes().into()).into();
520         local_ret
521 }
522
523 /// Get the list of HTLCs who's status has been updated on chain. This should be called by
524 /// ChannelManager via ManyChannelMonitor::get_and_clear_pending_monitor_events().
525 #[must_use]
526 #[no_mangle]
527 pub extern "C" fn ChannelMonitor_get_and_clear_pending_monitor_events(this_arg: &mut ChannelMonitor) -> crate::c_types::derived::CVec_MonitorEventZ {
528         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.get_and_clear_pending_monitor_events();
529         let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::ln::channelmonitor::MonitorEvent { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
530         local_ret.into()
531 }
532
533 /// Gets the list of pending events which were generated by previous actions, clearing the list
534 /// in the process.
535 ///
536 /// This is called by ManyChannelMonitor::get_and_clear_pending_events() and is equivalent to
537 /// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do
538 /// no internal locking in ChannelMonitors.
539 #[must_use]
540 #[no_mangle]
541 pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &mut ChannelMonitor) -> crate::c_types::derived::CVec_EventZ {
542         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.get_and_clear_pending_events();
543         let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::util::events::Event::native_into(item) }); };
544         local_ret.into()
545 }
546
547 /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
548 /// the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of
549 /// fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows
550 /// a higher revocation secret than the holder commitment number we are aware of. Broadcasting these
551 /// transactions are UNSAFE, as they allow counterparty side to punish you. Nevertheless you may want to
552 /// broadcast them if counterparty don't close channel with his higher commitment transaction after a
553 /// substantial amount of time (a month or even a year) to get back funds. Best may be to contact
554 /// out-of-band the other node operator to coordinate with him if option is available to you.
555 /// In any-case, choice is up to the user.
556 #[must_use]
557 #[no_mangle]
558 pub extern "C" fn ChannelMonitor_get_latest_holder_commitment_txn(this_arg: &mut ChannelMonitor, logger: &crate::util::logger::Logger) -> crate::c_types::derived::CVec_TransactionZ {
559         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChannelMonitor)) }.get_latest_holder_commitment_txn(logger);
560         let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { let mut local_ret_0 = ::bitcoin::consensus::encode::serialize(&item); local_ret_0.into() }); };
561         local_ret.into()
562 }
563