1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! Logic to connect off-chain channel management with on-chain transaction monitoring.
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.
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.
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.
25 use std::str::FromStr;
27 use core::convert::Infallible;
28 use bitcoin::hashes::Hash;
29 use crate::c_types::*;
32 use lightning::chain::chainmonitor::MonitorUpdateId as nativeMonitorUpdateIdImport;
33 pub(crate) type nativeMonitorUpdateId = nativeMonitorUpdateIdImport;
35 /// An opaque identifier describing a specific [`Persist`] method call.
38 pub struct MonitorUpdateId {
39 /// A pointer to the opaque Rust object.
41 /// Nearly everywhere, inner must be non-null, however in places where
42 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
43 pub inner: *mut nativeMonitorUpdateId,
44 /// Indicates that this is the only struct which contains the same pointer.
46 /// Rust functions which take ownership of an object provided via an argument require
47 /// this to be true and invalidate the object pointed to by inner.
51 impl Drop for MonitorUpdateId {
53 if self.is_owned && !<*mut nativeMonitorUpdateId>::is_null(self.inner) {
54 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
58 /// Frees any resources used by the MonitorUpdateId, if is_owned is set and inner is non-NULL.
60 pub extern "C" fn MonitorUpdateId_free(this_obj: MonitorUpdateId) { }
62 /// Used only if an object of this type is returned as a trait impl by a method
63 pub(crate) extern "C" fn MonitorUpdateId_free_void(this_ptr: *mut c_void) {
64 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMonitorUpdateId); }
67 impl MonitorUpdateId {
68 pub(crate) fn get_native_ref(&self) -> &'static nativeMonitorUpdateId {
69 unsafe { &*ObjOps::untweak_ptr(self.inner) }
71 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMonitorUpdateId {
72 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
74 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
75 pub(crate) fn take_inner(mut self) -> *mut nativeMonitorUpdateId {
76 assert!(self.is_owned);
77 let ret = ObjOps::untweak_ptr(self.inner);
78 self.inner = std::ptr::null_mut();
82 impl Clone for MonitorUpdateId {
83 fn clone(&self) -> Self {
85 inner: if <*mut nativeMonitorUpdateId>::is_null(self.inner) { std::ptr::null_mut() } else {
86 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
92 /// Used only if an object of this type is returned as a trait impl by a method
93 pub(crate) extern "C" fn MonitorUpdateId_clone_void(this_ptr: *const c_void) -> *mut c_void {
94 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMonitorUpdateId)).clone() })) as *mut c_void
97 /// Creates a copy of the MonitorUpdateId
98 pub extern "C" fn MonitorUpdateId_clone(orig: &MonitorUpdateId) -> MonitorUpdateId {
101 /// Checks if two MonitorUpdateIds contain equal inner contents.
103 pub extern "C" fn MonitorUpdateId_hash(o: &MonitorUpdateId) -> u64 {
104 if o.inner.is_null() { return 0; }
105 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
107 let mut hasher = core::hash::SipHasher::new();
108 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
109 std::hash::Hasher::finish(&hasher)
111 /// Checks if two MonitorUpdateIds contain equal inner contents.
112 /// This ignores pointers and is_owned flags and looks at the values in fields.
113 /// Two objects with NULL inner values will be considered "equal" here.
115 pub extern "C" fn MonitorUpdateId_eq(a: &MonitorUpdateId, b: &MonitorUpdateId) -> bool {
116 if a.inner == b.inner { return true; }
117 if a.inner.is_null() || b.inner.is_null() { return false; }
118 if a.get_native_ref() == b.get_native_ref() { true } else { false }
120 /// `Persist` defines behavior for persisting channel monitors: this could mean
121 /// writing once to disk, and/or uploading to one or more backup services.
123 /// Each method can return three possible values:
124 /// * If persistence (including any relevant `fsync()` calls) happens immediately, the
125 /// implementation should return `Ok(())`, indicating normal channel operation should continue.
126 /// * If persistence happens asynchronously, implementations should first ensure the
127 /// [`ChannelMonitor`] or [`ChannelMonitorUpdate`] are written durably to disk, and then return
128 /// `Err(ChannelMonitorUpdateErr::TemporaryFailure)` while the update continues in the
129 /// background. Once the update completes, [`ChainMonitor::channel_monitor_updated`] should be
130 /// called with the corresponding [`MonitorUpdateId`].
132 /// Note that unlike the direct [`chain::Watch`] interface,
133 /// [`ChainMonitor::channel_monitor_updated`] must be called once for *each* update which occurs.
135 /// * If persistence fails for some reason, implementations should return
136 /// `Err(ChannelMonitorUpdateErr::PermanentFailure)`, in which case the channel will likely be
137 /// closed without broadcasting the latest state. See
138 /// [`ChannelMonitorUpdateErr::PermanentFailure`] for more details.
141 /// An opaque pointer which is passed to your function implementations as an argument.
142 /// This has no meaning in the LDK, and can be NULL or any other value.
143 pub this_arg: *mut c_void,
144 /// Persist a new channel's data in response to a [`chain::Watch::watch_channel`] call. This is
145 /// called by [`ChannelManager`] for new channels, or may be called directly, e.g. on startup.
147 /// The data can be stored any way you want, but the identifier provided by LDK is the
148 /// channel's outpoint (and it is up to you to maintain a correct mapping between the outpoint
149 /// and the stored channel data). Note that you **must** persist every new monitor to disk.
151 /// The `update_id` is used to identify this call to [`ChainMonitor::channel_monitor_updated`],
152 /// if you return [`ChannelMonitorUpdateErr::TemporaryFailure`].
154 /// See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`
155 /// and [`ChannelMonitorUpdateErr`] for requirements when returning errors.
157 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
158 /// [`Writeable::write`]: crate::util::ser::Writeable::write
160 pub persist_new_channel: extern "C" fn (this_arg: *const c_void, channel_id: crate::lightning::chain::transaction::OutPoint, data: &crate::lightning::chain::channelmonitor::ChannelMonitor, update_id: crate::lightning::chain::chainmonitor::MonitorUpdateId) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ,
161 /// Update one channel's data. The provided [`ChannelMonitor`] has already applied the given
164 /// Note that on every update, you **must** persist either the [`ChannelMonitorUpdate`] or the
165 /// updated monitor itself to disk/backups. See the [`Persist`] trait documentation for more
168 /// During blockchain synchronization operations, this may be called with no
169 /// [`ChannelMonitorUpdate`], in which case the full [`ChannelMonitor`] needs to be persisted.
170 /// Note that after the full [`ChannelMonitor`] is persisted any previous
171 /// [`ChannelMonitorUpdate`]s which were persisted should be discarded - they can no longer be
172 /// applied to the persisted [`ChannelMonitor`] as they were already applied.
174 /// If an implementer chooses to persist the updates only, they need to make
175 /// sure that all the updates are applied to the `ChannelMonitors` *before*
176 /// the set of channel monitors is given to the `ChannelManager`
177 /// deserialization routine. See [`ChannelMonitor::update_monitor`] for
178 /// applying a monitor update to a monitor. If full `ChannelMonitors` are
179 /// persisted, then there is no need to persist individual updates.
181 /// Note that there could be a performance tradeoff between persisting complete
182 /// channel monitors on every update vs. persisting only updates and applying
183 /// them in batches. The size of each monitor grows `O(number of state updates)`
184 /// whereas updates are small and `O(1)`.
186 /// The `update_id` is used to identify this call to [`ChainMonitor::channel_monitor_updated`],
187 /// if you return [`ChannelMonitorUpdateErr::TemporaryFailure`].
189 /// See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`,
190 /// [`Writeable::write`] on [`ChannelMonitorUpdate`] for writing out an update, and
191 /// [`ChannelMonitorUpdateErr`] for requirements when returning errors.
193 /// [`Writeable::write`]: crate::util::ser::Writeable::write
195 /// Note that update (or a relevant inner pointer) may be NULL or all-0s to represent None
197 pub update_persisted_channel: extern "C" fn (this_arg: *const c_void, channel_id: crate::lightning::chain::transaction::OutPoint, update: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, data: &crate::lightning::chain::channelmonitor::ChannelMonitor, update_id: crate::lightning::chain::chainmonitor::MonitorUpdateId) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ,
198 /// Frees any resources associated with this object given its this_arg pointer.
199 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
200 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
202 unsafe impl Send for Persist {}
203 unsafe impl Sync for Persist {}
205 pub(crate) extern "C" fn Persist_clone_fields(orig: &Persist) -> Persist {
207 this_arg: orig.this_arg,
208 persist_new_channel: Clone::clone(&orig.persist_new_channel),
209 update_persisted_channel: Clone::clone(&orig.update_persisted_channel),
210 free: Clone::clone(&orig.free),
214 use lightning::chain::chainmonitor::Persist as rustPersist;
215 impl rustPersist<crate::lightning::chain::keysinterface::Sign> for Persist {
216 fn persist_new_channel(&self, mut channel_id: lightning::chain::transaction::OutPoint, mut data: &lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::Sign>, mut update_id: lightning::chain::chainmonitor::MonitorUpdateId) -> Result<(), lightning::chain::ChannelMonitorUpdateErr> {
217 let mut ret = (self.persist_new_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(channel_id), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((data as *const lightning::chain::channelmonitor::ChannelMonitor<_, >) as *mut _) }, is_owned: false }, crate::lightning::chain::chainmonitor::MonitorUpdateId { inner: ObjOps::heap_alloc(update_id), is_owned: true });
218 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() })};
221 fn update_persisted_channel(&self, mut channel_id: lightning::chain::transaction::OutPoint, mut update: &Option<lightning::chain::channelmonitor::ChannelMonitorUpdate>, mut data: &lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::chain::keysinterface::Sign>, mut update_id: lightning::chain::chainmonitor::MonitorUpdateId) -> Result<(), lightning::chain::ChannelMonitorUpdateErr> {
222 let mut local_update = &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: unsafe { (if update.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (update.as_ref().unwrap()) }) } as *const lightning::chain::channelmonitor::ChannelMonitorUpdate<>) as *mut _ }, is_owned: false };
223 let mut ret = (self.update_persisted_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(channel_id), is_owned: true }, local_update, &crate::lightning::chain::channelmonitor::ChannelMonitor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((data as *const lightning::chain::channelmonitor::ChannelMonitor<_, >) as *mut _) }, is_owned: false }, crate::lightning::chain::chainmonitor::MonitorUpdateId { inner: ObjOps::heap_alloc(update_id), is_owned: true });
224 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() })};
229 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
230 // directly as a Deref trait in higher-level structs:
231 impl std::ops::Deref for Persist {
233 fn deref(&self) -> &Self {
237 /// Calls the free function if one is set
239 pub extern "C" fn Persist_free(this_ptr: Persist) { }
240 impl Drop for Persist {
242 if let Some(f) = self.free {
248 use lightning::chain::chainmonitor::LockedChannelMonitor as nativeLockedChannelMonitorImport;
249 pub(crate) type nativeLockedChannelMonitor = nativeLockedChannelMonitorImport<'static, crate::lightning::chain::keysinterface::Sign>;
251 /// A read-only reference to a current ChannelMonitor.
253 /// Note that this holds a mutex in [`ChainMonitor`] and may block other events until it is
257 pub struct LockedChannelMonitor {
258 /// A pointer to the opaque Rust object.
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 nativeLockedChannelMonitor,
263 /// Indicates that this is the only struct which contains the same pointer.
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.
270 impl Drop for LockedChannelMonitor {
272 if self.is_owned && !<*mut nativeLockedChannelMonitor>::is_null(self.inner) {
273 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
277 /// Frees any resources used by the LockedChannelMonitor, if is_owned is set and inner is non-NULL.
279 pub extern "C" fn LockedChannelMonitor_free(this_obj: LockedChannelMonitor) { }
281 /// Used only if an object of this type is returned as a trait impl by a method
282 pub(crate) extern "C" fn LockedChannelMonitor_free_void(this_ptr: *mut c_void) {
283 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedChannelMonitor); }
286 impl LockedChannelMonitor {
287 pub(crate) fn get_native_ref(&self) -> &'static nativeLockedChannelMonitor {
288 unsafe { &*ObjOps::untweak_ptr(self.inner) }
290 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeLockedChannelMonitor {
291 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
293 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
294 pub(crate) fn take_inner(mut self) -> *mut nativeLockedChannelMonitor {
295 assert!(self.is_owned);
296 let ret = ObjOps::untweak_ptr(self.inner);
297 self.inner = std::ptr::null_mut();
302 use lightning::chain::chainmonitor::ChainMonitor as nativeChainMonitorImport;
303 pub(crate) 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>;
305 /// An implementation of [`chain::Watch`] for monitoring channels.
307 /// Connected and disconnected blocks must be provided to `ChainMonitor` as documented by
308 /// [`chain::Watch`]. May be used in conjunction with [`ChannelManager`] to monitor channels locally
309 /// or used independently to monitor channels remotely. See the [module-level documentation] for
312 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
313 /// [module-level documentation]: crate::chain::chainmonitor
316 pub struct ChainMonitor {
317 /// A pointer to the opaque Rust object.
319 /// Nearly everywhere, inner must be non-null, however in places where
320 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
321 pub inner: *mut nativeChainMonitor,
322 /// Indicates that this is the only struct which contains the same pointer.
324 /// Rust functions which take ownership of an object provided via an argument require
325 /// this to be true and invalidate the object pointed to by inner.
329 impl Drop for ChainMonitor {
331 if self.is_owned && !<*mut nativeChainMonitor>::is_null(self.inner) {
332 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
336 /// Frees any resources used by the ChainMonitor, if is_owned is set and inner is non-NULL.
338 pub extern "C" fn ChainMonitor_free(this_obj: ChainMonitor) { }
340 /// Used only if an object of this type is returned as a trait impl by a method
341 pub(crate) extern "C" fn ChainMonitor_free_void(this_ptr: *mut c_void) {
342 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainMonitor); }
346 pub(crate) fn get_native_ref(&self) -> &'static nativeChainMonitor {
347 unsafe { &*ObjOps::untweak_ptr(self.inner) }
349 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainMonitor {
350 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
352 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
353 pub(crate) fn take_inner(mut self) -> *mut nativeChainMonitor {
354 assert!(self.is_owned);
355 let ret = ObjOps::untweak_ptr(self.inner);
356 self.inner = std::ptr::null_mut();
360 /// Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
362 /// When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
363 /// will call back to it indicating transactions and outputs of interest. This allows clients to
364 /// pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
365 /// always need to fetch full blocks absent another means for determining which blocks contain
366 /// transactions relevant to the watched channels.
369 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 {
370 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() }) } };
371 let mut ret = lightning::chain::chainmonitor::ChainMonitor::new(local_chain_source, broadcaster, logger, feeest, persister);
372 ChainMonitor { inner: ObjOps::heap_alloc(ret), is_owned: true }
375 /// Gets the balances in the contained [`ChannelMonitor`]s which are claimable on-chain or
376 /// claims which are awaiting confirmation.
378 /// Includes the balances from each [`ChannelMonitor`] *except* those included in
379 /// `ignored_channels`, allowing you to filter out balances from channels which are still open
380 /// (and whose balance should likely be pulled from the [`ChannelDetails`]).
382 /// See [`ChannelMonitor::get_claimable_balances`] for more details on the exact criteria for
383 /// inclusion in the return value.
386 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 {
387 let mut local_ignored_channels = Vec::new(); for mut item in ignored_channels.as_slice().iter() { local_ignored_channels.push( { item.get_native_ref() }); };
388 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances(&local_ignored_channels[..]);
389 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
393 /// Gets the [`LockedChannelMonitor`] for a given funding outpoint, returning an `Err` if no
394 /// such [`ChannelMonitor`] is currently being monitored for.
396 /// Note that the result holds a mutex over our monitor set, and should not be held
400 pub extern "C" fn ChainMonitor_get_monitor(this_arg: &ChainMonitor, mut funding_txo: crate::lightning::chain::transaction::OutPoint) -> crate::c_types::derived::CResult_LockedChannelMonitorNoneZ {
401 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_monitor(*unsafe { Box::from_raw(funding_txo.take_inner()) });
402 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() };
406 /// Lists the funding outpoint of each [`ChannelMonitor`] being monitored.
408 /// Note that [`ChannelMonitor`]s are not removed when a channel is closed as they are always
409 /// monitoring for on-chain state resolutions.
412 pub extern "C" fn ChainMonitor_list_monitors(this_arg: &ChainMonitor) -> crate::c_types::derived::CVec_OutPointZ {
413 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_monitors();
414 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 } }); };
418 /// Indicates the persistence of a [`ChannelMonitor`] has completed after
419 /// [`ChannelMonitorUpdateErr::TemporaryFailure`] was returned from an update operation.
421 /// Thus, the anticipated use is, at a high level:
422 /// 1) This [`ChainMonitor`] calls [`Persist::update_persisted_channel`] which stores the
423 /// update to disk and begins updating any remote (e.g. watchtower/backup) copies,
424 /// returning [`ChannelMonitorUpdateErr::TemporaryFailure`],
425 /// 2) once all remote copies are updated, you call this function with the
426 /// `completed_update_id` that completed, and once all pending updates have completed the
427 /// channel will be re-enabled.
429 /// Returns an [`APIError::APIMisuseError`] if `funding_txo` does not match any currently
430 /// registered [`ChannelMonitor`]s.
433 pub extern "C" fn ChainMonitor_channel_monitor_updated(this_arg: &ChainMonitor, mut funding_txo: crate::lightning::chain::transaction::OutPoint, mut completed_update_id: crate::lightning::chain::chainmonitor::MonitorUpdateId) -> crate::c_types::derived::CResult_NoneAPIErrorZ {
434 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_monitor_updated(*unsafe { Box::from_raw(funding_txo.take_inner()) }, *unsafe { Box::from_raw(completed_update_id.take_inner()) });
435 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::util::errors::APIError::native_into(e) }).into() };
439 impl From<nativeChainMonitor> for crate::lightning::chain::Listen {
440 fn from(obj: nativeChainMonitor) -> Self {
441 let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
442 let mut ret = ChainMonitor_as_Listen(&rust_obj);
443 // 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
444 rust_obj.inner = std::ptr::null_mut();
445 ret.free = Some(ChainMonitor_free_void);
449 /// Constructs a new Listen which calls the relevant methods on this_arg.
450 /// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
452 pub extern "C" fn ChainMonitor_as_Listen(this_arg: &ChainMonitor) -> crate::lightning::chain::Listen {
453 crate::lightning::chain::Listen {
454 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
456 block_connected: ChainMonitor_Listen_block_connected,
457 block_disconnected: ChainMonitor_Listen_block_disconnected,
461 extern "C" fn ChainMonitor_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
462 <nativeChainMonitor as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
464 extern "C" fn ChainMonitor_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
465 <nativeChainMonitor as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
468 impl From<nativeChainMonitor> for crate::lightning::chain::Confirm {
469 fn from(obj: nativeChainMonitor) -> Self {
470 let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
471 let mut ret = ChainMonitor_as_Confirm(&rust_obj);
472 // 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
473 rust_obj.inner = std::ptr::null_mut();
474 ret.free = Some(ChainMonitor_free_void);
478 /// Constructs a new Confirm which calls the relevant methods on this_arg.
479 /// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
481 pub extern "C" fn ChainMonitor_as_Confirm(this_arg: &ChainMonitor) -> crate::lightning::chain::Confirm {
482 crate::lightning::chain::Confirm {
483 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
485 transactions_confirmed: ChainMonitor_Confirm_transactions_confirmed,
486 transaction_unconfirmed: ChainMonitor_Confirm_transaction_unconfirmed,
487 best_block_updated: ChainMonitor_Confirm_best_block_updated,
488 get_relevant_txids: ChainMonitor_Confirm_get_relevant_txids,
492 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) {
493 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 }); };
494 <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)
496 extern "C" fn ChainMonitor_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
497 <nativeChainMonitor as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
499 extern "C" fn ChainMonitor_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
500 <nativeChainMonitor as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
503 extern "C" fn ChainMonitor_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
504 let mut ret = <nativeChainMonitor as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, );
505 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
509 impl From<nativeChainMonitor> for crate::lightning::chain::Watch {
510 fn from(obj: nativeChainMonitor) -> Self {
511 let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
512 let mut ret = ChainMonitor_as_Watch(&rust_obj);
513 // 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
514 rust_obj.inner = std::ptr::null_mut();
515 ret.free = Some(ChainMonitor_free_void);
519 /// Constructs a new Watch which calls the relevant methods on this_arg.
520 /// This copies the `inner` pointer in this_arg and thus the returned Watch must be freed before this_arg is
522 pub extern "C" fn ChainMonitor_as_Watch(this_arg: &ChainMonitor) -> crate::lightning::chain::Watch {
523 crate::lightning::chain::Watch {
524 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
526 watch_channel: ChainMonitor_Watch_watch_channel,
527 update_channel: ChainMonitor_Watch_update_channel,
528 release_pending_monitor_events: ChainMonitor_Watch_release_pending_monitor_events,
533 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 {
534 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()) });
535 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() };
539 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 {
540 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()) });
541 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() };
545 extern "C" fn ChainMonitor_Watch_release_pending_monitor_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MonitorEventZ {
546 let mut ret = <nativeChainMonitor as lightning::chain::Watch<_>>::release_pending_monitor_events(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, );
547 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); };
551 impl From<nativeChainMonitor> for crate::lightning::util::events::EventsProvider {
552 fn from(obj: nativeChainMonitor) -> Self {
553 let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
554 let mut ret = ChainMonitor_as_EventsProvider(&rust_obj);
555 // 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
556 rust_obj.inner = std::ptr::null_mut();
557 ret.free = Some(ChainMonitor_free_void);
561 /// Constructs a new EventsProvider which calls the relevant methods on this_arg.
562 /// This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
564 pub extern "C" fn ChainMonitor_as_EventsProvider(this_arg: &ChainMonitor) -> crate::lightning::util::events::EventsProvider {
565 crate::lightning::util::events::EventsProvider {
566 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
568 process_pending_events: ChainMonitor_EventsProvider_process_pending_events,
572 extern "C" fn ChainMonitor_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
573 <nativeChainMonitor as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, handler)