5c37216daf5d3e480a30f797ccfe534a731f7e95
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / chainmonitor.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 //! Logic to connect off-chain channel management with on-chain transaction monitoring.
10 //!
11 //! [`ChainMonitor`] is an implementation of [`chain::Watch`] used both to process blocks and to
12 //! update [`ChannelMonitor`]s accordingly. If any on-chain events need further processing, it will
13 //! make those available as [`MonitorEvent`]s to be consumed.
14 //!
15 //! [`ChainMonitor`] is parameterized by an optional chain source, which must implement the
16 //! [`chain::Filter`] trait. This provides a mechanism to signal new relevant outputs back to light
17 //! clients, such that transactions spending those outputs are included in block data.
18 //!
19 //! [`ChainMonitor`] may be used directly to monitor channels locally or as a part of a distributed
20 //! setup to monitor channels remotely. In the latter case, a custom [`chain::Watch`] implementation
21 //! would be responsible for routing each update to a remote server and for retrieving monitor
22 //! events. The remote server would make use of [`ChainMonitor`] for block processing and for
23 //! servicing [`ChannelMonitor`] updates from the client.
24
25 use std::str::FromStr;
26 use std::ffi::c_void;
27 use core::convert::Infallible;
28 use bitcoin::hashes::Hash;
29 use crate::c_types::*;
30
31 /// `Persist` defines behavior for persisting channel monitors: this could mean
32 /// writing once to disk, and/or uploading to one or more backup services.
33 ///
34 /// Note that for every new monitor, you **must** persist the new `ChannelMonitor`
35 /// to disk/backups. And, on every update, you **must** persist either the
36 /// `ChannelMonitorUpdate` or the updated monitor itself. Otherwise, there is risk
37 /// of situations such as revoking a transaction, then crashing before this
38 /// revocation can be persisted, then unintentionally broadcasting a revoked
39 /// transaction and losing money. This is a risk because previous channel states
40 /// are toxic, so it's important that whatever channel state is persisted is
41 /// kept up-to-date.
42 #[repr(C)]
43 pub struct Persist {
44         /// An opaque pointer which is passed to your function implementations as an argument.
45         /// This has no meaning in the LDK, and can be NULL or any other value.
46         pub this_arg: *mut c_void,
47         /// Persist a new channel's data. The data can be stored any way you want, but
48         /// the identifier provided by Rust-Lightning is the channel's outpoint (and
49         /// it is up to you to maintain a correct mapping between the outpoint and the
50         /// stored channel data). Note that you **must** persist every new monitor to
51         /// disk. See the `Persist` trait documentation for more details.
52         ///
53         /// See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`
54         /// and [`ChannelMonitorUpdateErr`] for requirements when returning errors.
55         ///
56         /// [`Writeable::write`]: crate::util::ser::Writeable::write
57         #[must_use]
58         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,
59         /// Update one channel's data. The provided `ChannelMonitor` has already
60         /// applied the given update.
61         ///
62         /// Note that on every update, you **must** persist either the
63         /// `ChannelMonitorUpdate` or the updated monitor itself to disk/backups. See
64         /// the `Persist` trait documentation for more details.
65         ///
66         /// If an implementer chooses to persist the updates only, they need to make
67         /// sure that all the updates are applied to the `ChannelMonitors` *before*
68         /// the set of channel monitors is given to the `ChannelManager`
69         /// deserialization routine. See [`ChannelMonitor::update_monitor`] for
70         /// applying a monitor update to a monitor. If full `ChannelMonitors` are
71         /// persisted, then there is no need to persist individual updates.
72         ///
73         /// Note that there could be a performance tradeoff between persisting complete
74         /// channel monitors on every update vs. persisting only updates and applying
75         /// them in batches. The size of each monitor grows `O(number of state updates)`
76         /// whereas updates are small and `O(1)`.
77         ///
78         /// See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`,
79         /// [`Writeable::write`] on [`ChannelMonitorUpdate`] for writing out an update, and
80         /// [`ChannelMonitorUpdateErr`] for requirements when returning errors.
81         ///
82         /// [`Writeable::write`]: crate::util::ser::Writeable::write
83         #[must_use]
84         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,
85         /// Frees any resources associated with this object given its this_arg pointer.
86         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
87         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
88 }
89 unsafe impl Send for Persist {}
90 unsafe impl Sync for Persist {}
91 #[no_mangle]
92 pub(crate) extern "C" fn Persist_clone_fields(orig: &Persist) -> Persist {
93         Persist {
94                 this_arg: orig.this_arg,
95                 persist_new_channel: Clone::clone(&orig.persist_new_channel),
96                 update_persisted_channel: Clone::clone(&orig.update_persisted_channel),
97                 free: Clone::clone(&orig.free),
98         }
99 }
100
101 use lightning::chain::chainmonitor::Persist as rustPersist;
102 impl rustPersist<crate::lightning::chain::keysinterface::Sign> for Persist {
103         fn persist_new_channel(&self, mut id: lightning::chain::transaction::OutPoint, mut data: &lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::Sign>) -> Result<(), lightning::chain::ChannelMonitorUpdateErr> {
104                 let mut ret = (self.persist_new_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(id), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((data as *const _) as *mut _) }, is_owned: false });
105                 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() })};
106                 local_ret
107         }
108         fn update_persisted_channel(&self, mut id: lightning::chain::transaction::OutPoint, mut update: &lightning::chain::channelmonitor::ChannelMonitorUpdate, mut data: &lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::Sign>) -> Result<(), lightning::chain::ChannelMonitorUpdateErr> {
109                 let mut ret = (self.update_persisted_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(id), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: unsafe { ObjOps::nonnull_ptr_to_inner((update as *const _) as *mut _) }, is_owned: false }, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((data as *const _) as *mut _) }, is_owned: false });
110                 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() })};
111                 local_ret
112         }
113 }
114
115 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
116 // directly as a Deref trait in higher-level structs:
117 impl std::ops::Deref for Persist {
118         type Target = Self;
119         fn deref(&self) -> &Self {
120                 self
121         }
122 }
123 /// Calls the free function if one is set
124 #[no_mangle]
125 pub extern "C" fn Persist_free(this_ptr: Persist) { }
126 impl Drop for Persist {
127         fn drop(&mut self) {
128                 if let Some(f) = self.free {
129                         f(self.this_arg);
130                 }
131         }
132 }
133
134 use lightning::chain::chainmonitor::LockedChannelMonitor as nativeLockedChannelMonitorImport;
135 type nativeLockedChannelMonitor = nativeLockedChannelMonitorImport<'static, crate::lightning::chain::keysinterface::Sign>;
136
137 /// A read-only reference to a current ChannelMonitor.
138 ///
139 /// Note that this holds a mutex in [`ChainMonitor`] and may block other events until it is
140 /// released.
141 #[must_use]
142 #[repr(C)]
143 pub struct LockedChannelMonitor {
144         /// A pointer to the opaque Rust object.
145
146         /// Nearly everywhere, inner must be non-null, however in places where
147         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
148         pub inner: *mut nativeLockedChannelMonitor,
149         /// Indicates that this is the only struct which contains the same pointer.
150
151         /// Rust functions which take ownership of an object provided via an argument require
152         /// this to be true and invalidate the object pointed to by inner.
153         pub is_owned: bool,
154 }
155
156 impl Drop for LockedChannelMonitor {
157         fn drop(&mut self) {
158                 if self.is_owned && !<*mut nativeLockedChannelMonitor>::is_null(self.inner) {
159                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
160                 }
161         }
162 }
163 /// Frees any resources used by the LockedChannelMonitor, if is_owned is set and inner is non-NULL.
164 #[no_mangle]
165 pub extern "C" fn LockedChannelMonitor_free(this_obj: LockedChannelMonitor) { }
166 #[allow(unused)]
167 /// Used only if an object of this type is returned as a trait impl by a method
168 extern "C" fn LockedChannelMonitor_free_void(this_ptr: *mut c_void) {
169         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedChannelMonitor); }
170 }
171 #[allow(unused)]
172 impl LockedChannelMonitor {
173         pub(crate) fn get_native_ref(&self) -> &'static nativeLockedChannelMonitor {
174                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
175         }
176         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeLockedChannelMonitor {
177                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
178         }
179         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
180         pub(crate) fn take_inner(mut self) -> *mut nativeLockedChannelMonitor {
181                 assert!(self.is_owned);
182                 let ret = ObjOps::untweak_ptr(self.inner);
183                 self.inner = std::ptr::null_mut();
184                 ret
185         }
186 }
187
188 use lightning::chain::chainmonitor::ChainMonitor as nativeChainMonitorImport;
189 type nativeChainMonitor = nativeChainMonitorImport<crate::lightning::chain::keysinterface::Sign, crate::lightning::chain::Filter, crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::chain::chaininterface::FeeEstimator, crate::lightning::util::logger::Logger, crate::lightning::chain::chainmonitor::Persist>;
190
191 /// An implementation of [`chain::Watch`] for monitoring channels.
192 ///
193 /// Connected and disconnected blocks must be provided to `ChainMonitor` as documented by
194 /// [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally
195 /// or used independently to monitor channels remotely. See the [module-level documentation] for
196 /// details.
197 ///
198 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
199 /// [module-level documentation]: crate::chain::chainmonitor
200 #[must_use]
201 #[repr(C)]
202 pub struct ChainMonitor {
203         /// A pointer to the opaque Rust object.
204
205         /// Nearly everywhere, 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 nativeChainMonitor,
208         /// Indicates that this is the only struct which contains the same pointer.
209
210         /// Rust functions which take ownership of an object provided via an argument require
211         /// this to be true and invalidate the object pointed to by inner.
212         pub is_owned: bool,
213 }
214
215 impl Drop for ChainMonitor {
216         fn drop(&mut self) {
217                 if self.is_owned && !<*mut nativeChainMonitor>::is_null(self.inner) {
218                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
219                 }
220         }
221 }
222 /// Frees any resources used by the ChainMonitor, if is_owned is set and inner is non-NULL.
223 #[no_mangle]
224 pub extern "C" fn ChainMonitor_free(this_obj: ChainMonitor) { }
225 #[allow(unused)]
226 /// Used only if an object of this type is returned as a trait impl by a method
227 extern "C" fn ChainMonitor_free_void(this_ptr: *mut c_void) {
228         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainMonitor); }
229 }
230 #[allow(unused)]
231 impl ChainMonitor {
232         pub(crate) fn get_native_ref(&self) -> &'static nativeChainMonitor {
233                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
234         }
235         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainMonitor {
236                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
237         }
238         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
239         pub(crate) fn take_inner(mut self) -> *mut nativeChainMonitor {
240                 assert!(self.is_owned);
241                 let ret = ObjOps::untweak_ptr(self.inner);
242                 self.inner = std::ptr::null_mut();
243                 ret
244         }
245 }
246 /// Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
247 ///
248 /// When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
249 /// will call back to it indicating transactions and outputs of interest. This allows clients to
250 /// pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
251 /// always need to fetch full blocks absent another means for determining which blocks contain
252 /// transactions relevant to the watched channels.
253 #[must_use]
254 #[no_mangle]
255 pub extern "C" fn ChainMonitor_new(mut chain_source: crate::c_types::derived::COption_FilterZ, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut logger: crate::lightning::util::logger::Logger, mut feeest: crate::lightning::chain::chaininterface::FeeEstimator, mut persister: crate::lightning::chain::chainmonitor::Persist) -> ChainMonitor {
256         let mut local_chain_source = { /* chain_source*/ let chain_source_opt = chain_source; { } if chain_source_opt.is_none() { None } else { Some({ chain_source_opt.take() }) } };
257         let mut ret = lightning::chain::chainmonitor::ChainMonitor::new(local_chain_source, broadcaster, logger, feeest, persister);
258         ChainMonitor { inner: ObjOps::heap_alloc(ret), is_owned: true }
259 }
260
261 /// Gets the balances in the contained [`ChannelMonitor`]s which are claimable on-chain or
262 /// claims which are awaiting confirmation.
263 ///
264 /// Includes the balances from each [`ChannelMonitor`] *except* those included in
265 /// `ignored_channels`, allowing you to filter out balances from channels which are still open
266 /// (and whose balance should likely be pulled from the [`ChannelDetails`]).
267 ///
268 /// See [`ChannelMonitor::get_claimable_balances`] for more details on the exact criteria for
269 /// inclusion in the return value.
270 #[must_use]
271 #[no_mangle]
272 pub extern "C" fn ChainMonitor_get_claimable_balances(this_arg: &ChainMonitor, mut ignored_channels: crate::c_types::derived::CVec_ChannelDetailsZ) -> crate::c_types::derived::CVec_BalanceZ {
273         let mut local_ignored_channels = Vec::new(); for mut item in ignored_channels.as_slice().iter() { local_ignored_channels.push( { item.get_native_ref() }); };
274         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances(&local_ignored_channels[..]);
275         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
276         local_ret.into()
277 }
278
279 /// Gets the [`LockedChannelMonitor`] for a given funding outpoint, returning an `Err` if no
280 /// such [`ChannelMonitor`] is currently being monitored for.
281 ///
282 /// Note that the result holds a mutex over our monitor set, and should not be held
283 /// indefinitely.
284 #[must_use]
285 #[no_mangle]
286 pub extern "C" fn ChainMonitor_get_monitor(this_arg: &ChainMonitor, mut funding_txo: crate::lightning::chain::transaction::OutPoint) -> crate::c_types::derived::CResult_LockedChannelMonitorNoneZ {
287         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_monitor(*unsafe { Box::from_raw(funding_txo.take_inner()) });
288         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::chainmonitor::LockedChannelMonitor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
289         local_ret
290 }
291
292 /// Lists the funding outpoint of each [`ChannelMonitor`] being monitored.
293 ///
294 /// Note that [`ChannelMonitor`]s are not removed when a channel is closed as they are always
295 /// monitoring for on-chain state resolutions.
296 #[must_use]
297 #[no_mangle]
298 pub extern "C" fn ChainMonitor_list_monitors(this_arg: &ChainMonitor) -> crate::c_types::derived::CVec_OutPointZ {
299         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_monitors();
300         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
301         local_ret.into()
302 }
303
304 impl From<nativeChainMonitor> for crate::lightning::chain::Listen {
305         fn from(obj: nativeChainMonitor) -> Self {
306                 let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
307                 let mut ret = ChainMonitor_as_Listen(&rust_obj);
308                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
309                 rust_obj.inner = std::ptr::null_mut();
310                 ret.free = Some(ChainMonitor_free_void);
311                 ret
312         }
313 }
314 /// Constructs a new Listen which calls the relevant methods on this_arg.
315 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
316 #[no_mangle]
317 pub extern "C" fn ChainMonitor_as_Listen(this_arg: &ChainMonitor) -> crate::lightning::chain::Listen {
318         crate::lightning::chain::Listen {
319                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
320                 free: None,
321                 block_connected: ChainMonitor_Listen_block_connected,
322                 block_disconnected: ChainMonitor_Listen_block_disconnected,
323         }
324 }
325
326 extern "C" fn ChainMonitor_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
327         <nativeChainMonitor as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
328 }
329 extern "C" fn ChainMonitor_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
330         <nativeChainMonitor as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
331 }
332
333 impl From<nativeChainMonitor> for crate::lightning::chain::Confirm {
334         fn from(obj: nativeChainMonitor) -> Self {
335                 let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
336                 let mut ret = ChainMonitor_as_Confirm(&rust_obj);
337                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
338                 rust_obj.inner = std::ptr::null_mut();
339                 ret.free = Some(ChainMonitor_free_void);
340                 ret
341         }
342 }
343 /// Constructs a new Confirm which calls the relevant methods on this_arg.
344 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
345 #[no_mangle]
346 pub extern "C" fn ChainMonitor_as_Confirm(this_arg: &ChainMonitor) -> crate::lightning::chain::Confirm {
347         crate::lightning::chain::Confirm {
348                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
349                 free: None,
350                 transactions_confirmed: ChainMonitor_Confirm_transactions_confirmed,
351                 transaction_unconfirmed: ChainMonitor_Confirm_transaction_unconfirmed,
352                 best_block_updated: ChainMonitor_Confirm_best_block_updated,
353                 get_relevant_txids: ChainMonitor_Confirm_get_relevant_txids,
354         }
355 }
356
357 extern "C" fn ChainMonitor_Confirm_transactions_confirmed(this_arg: *const c_void, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
358         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 }); };
359         <nativeChainMonitor as lightning::chain::Confirm<>>::transactions_confirmed(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
360 }
361 extern "C" fn ChainMonitor_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
362         <nativeChainMonitor as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
363 }
364 extern "C" fn ChainMonitor_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
365         <nativeChainMonitor as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
366 }
367 #[must_use]
368 extern "C" fn ChainMonitor_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
369         let mut ret = <nativeChainMonitor as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, );
370         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
371         local_ret.into()
372 }
373
374 impl From<nativeChainMonitor> for crate::lightning::chain::Watch {
375         fn from(obj: nativeChainMonitor) -> Self {
376                 let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
377                 let mut ret = ChainMonitor_as_Watch(&rust_obj);
378                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
379                 rust_obj.inner = std::ptr::null_mut();
380                 ret.free = Some(ChainMonitor_free_void);
381                 ret
382         }
383 }
384 /// Constructs a new Watch which calls the relevant methods on this_arg.
385 /// This copies the `inner` pointer in this_arg and thus the returned Watch must be freed before this_arg is
386 #[no_mangle]
387 pub extern "C" fn ChainMonitor_as_Watch(this_arg: &ChainMonitor) -> crate::lightning::chain::Watch {
388         crate::lightning::chain::Watch {
389                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
390                 free: None,
391                 watch_channel: ChainMonitor_Watch_watch_channel,
392                 update_channel: ChainMonitor_Watch_update_channel,
393                 release_pending_monitor_events: ChainMonitor_Watch_release_pending_monitor_events,
394         }
395 }
396
397 #[must_use]
398 extern "C" fn ChainMonitor_Watch_watch_channel(this_arg: *const c_void, mut funding_outpoint: crate::lightning::chain::transaction::OutPoint, mut monitor: crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ {
399         let mut ret = <nativeChainMonitor as lightning::chain::Watch<_>>::watch_channel(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, *unsafe { Box::from_raw(funding_outpoint.take_inner()) }, *unsafe { Box::from_raw(monitor.take_inner()) });
400         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::ChannelMonitorUpdateErr::native_into(e) }).into() };
401         local_ret
402 }
403 #[must_use]
404 extern "C" fn ChainMonitor_Watch_update_channel(this_arg: *const c_void, mut funding_txo: crate::lightning::chain::transaction::OutPoint, mut update: crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ {
405         let mut ret = <nativeChainMonitor as lightning::chain::Watch<_>>::update_channel(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, *unsafe { Box::from_raw(funding_txo.take_inner()) }, *unsafe { Box::from_raw(update.take_inner()) });
406         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::ChannelMonitorUpdateErr::native_into(e) }).into() };
407         local_ret
408 }
409 #[must_use]
410 extern "C" fn ChainMonitor_Watch_release_pending_monitor_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MonitorEventZ {
411         let mut ret = <nativeChainMonitor as lightning::chain::Watch<_>>::release_pending_monitor_events(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, );
412         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
413         local_ret.into()
414 }
415
416 impl From<nativeChainMonitor> for crate::lightning::util::events::EventsProvider {
417         fn from(obj: nativeChainMonitor) -> Self {
418                 let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
419                 let mut ret = ChainMonitor_as_EventsProvider(&rust_obj);
420                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
421                 rust_obj.inner = std::ptr::null_mut();
422                 ret.free = Some(ChainMonitor_free_void);
423                 ret
424         }
425 }
426 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
427 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
428 #[no_mangle]
429 pub extern "C" fn ChainMonitor_as_EventsProvider(this_arg: &ChainMonitor) -> crate::lightning::util::events::EventsProvider {
430         crate::lightning::util::events::EventsProvider {
431                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
432                 free: None,
433                 process_pending_events: ChainMonitor_EventsProvider_process_pending_events,
434         }
435 }
436
437 extern "C" fn ChainMonitor_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
438         <nativeChainMonitor as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, handler)
439 }
440