4551b082735afc15f32ed86baa86b703e5e420b0
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / mod.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 //! Structs and traits which allow other parts of rust-lightning to interact with the blockchain.
10
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
19
20 pub mod chaininterface;
21 pub mod chainmonitor;
22 pub mod channelmonitor;
23 pub mod transaction;
24 mod onchaintx {
25
26 use alloc::str::FromStr;
27 use alloc::string::String;
28 use core::ffi::c_void;
29 use core::convert::Infallible;
30 use bitcoin::hashes::Hash;
31 use crate::c_types::*;
32 #[cfg(feature="no-std")]
33 use alloc::{vec::Vec, boxed::Box};
34
35 }
36 mod package {
37
38 use alloc::str::FromStr;
39 use alloc::string::String;
40 use core::ffi::c_void;
41 use core::convert::Infallible;
42 use bitcoin::hashes::Hash;
43 use crate::c_types::*;
44 #[cfg(feature="no-std")]
45 use alloc::{vec::Vec, boxed::Box};
46
47 }
48
49 use lightning::chain::BestBlock as nativeBestBlockImport;
50 pub(crate) type nativeBestBlock = nativeBestBlockImport;
51
52 /// The best known block as identified by its hash and height.
53 #[must_use]
54 #[repr(C)]
55 pub struct BestBlock {
56         /// A pointer to the opaque Rust object.
57
58         /// Nearly everywhere, inner must be non-null, however in places where
59         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
60         pub inner: *mut nativeBestBlock,
61         /// Indicates that this is the only struct which contains the same pointer.
62
63         /// Rust functions which take ownership of an object provided via an argument require
64         /// this to be true and invalidate the object pointed to by inner.
65         pub is_owned: bool,
66 }
67
68 impl Drop for BestBlock {
69         fn drop(&mut self) {
70                 if self.is_owned && !<*mut nativeBestBlock>::is_null(self.inner) {
71                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
72                 }
73         }
74 }
75 /// Frees any resources used by the BestBlock, if is_owned is set and inner is non-NULL.
76 #[no_mangle]
77 pub extern "C" fn BestBlock_free(this_obj: BestBlock) { }
78 #[allow(unused)]
79 /// Used only if an object of this type is returned as a trait impl by a method
80 pub(crate) extern "C" fn BestBlock_free_void(this_ptr: *mut c_void) {
81         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBestBlock) };
82 }
83 #[allow(unused)]
84 impl BestBlock {
85         pub(crate) fn get_native_ref(&self) -> &'static nativeBestBlock {
86                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
87         }
88         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBestBlock {
89                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
90         }
91         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
92         pub(crate) fn take_inner(mut self) -> *mut nativeBestBlock {
93                 assert!(self.is_owned);
94                 let ret = ObjOps::untweak_ptr(self.inner);
95                 self.inner = core::ptr::null_mut();
96                 ret
97         }
98 }
99 impl Clone for BestBlock {
100         fn clone(&self) -> Self {
101                 Self {
102                         inner: if <*mut nativeBestBlock>::is_null(self.inner) { core::ptr::null_mut() } else {
103                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
104                         is_owned: true,
105                 }
106         }
107 }
108 #[allow(unused)]
109 /// Used only if an object of this type is returned as a trait impl by a method
110 pub(crate) extern "C" fn BestBlock_clone_void(this_ptr: *const c_void) -> *mut c_void {
111         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBestBlock)).clone() })) as *mut c_void
112 }
113 #[no_mangle]
114 /// Creates a copy of the BestBlock
115 pub extern "C" fn BestBlock_clone(orig: &BestBlock) -> BestBlock {
116         orig.clone()
117 }
118 /// Checks if two BestBlocks contain equal inner contents.
119 /// This ignores pointers and is_owned flags and looks at the values in fields.
120 /// Two objects with NULL inner values will be considered "equal" here.
121 #[no_mangle]
122 pub extern "C" fn BestBlock_eq(a: &BestBlock, b: &BestBlock) -> bool {
123         if a.inner == b.inner { return true; }
124         if a.inner.is_null() || b.inner.is_null() { return false; }
125         if a.get_native_ref() == b.get_native_ref() { true } else { false }
126 }
127 /// Constructs a `BestBlock` that represents the genesis block at height 0 of the given
128 /// network.
129 #[must_use]
130 #[no_mangle]
131 pub extern "C" fn BestBlock_from_network(mut network: crate::bitcoin::network::Network) -> crate::lightning::chain::BestBlock {
132         let mut ret = lightning::chain::BestBlock::from_network(network.into_bitcoin());
133         crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
134 }
135
136 /// Returns a `BestBlock` as identified by the given block hash and height.
137 #[must_use]
138 #[no_mangle]
139 pub extern "C" fn BestBlock_new(mut block_hash: crate::c_types::ThirtyTwoBytes, mut height: u32) -> crate::lightning::chain::BestBlock {
140         let mut ret = lightning::chain::BestBlock::new(::bitcoin::hash_types::BlockHash::from_slice(&block_hash.data[..]).unwrap(), height);
141         crate::lightning::chain::BestBlock { inner: ObjOps::heap_alloc(ret), is_owned: true }
142 }
143
144 /// Returns the best block hash.
145 #[must_use]
146 #[no_mangle]
147 pub extern "C" fn BestBlock_block_hash(this_arg: &crate::lightning::chain::BestBlock) -> crate::c_types::ThirtyTwoBytes {
148         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.block_hash();
149         crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
150 }
151
152 /// Returns the best block height.
153 #[must_use]
154 #[no_mangle]
155 pub extern "C" fn BestBlock_height(this_arg: &crate::lightning::chain::BestBlock) -> u32 {
156         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.height();
157         ret
158 }
159
160 /// The `Listen` trait is used to notify when blocks have been connected or disconnected from the
161 /// chain.
162 ///
163 /// Useful when needing to replay chain data upon startup or as new chain events occur. Clients
164 /// sourcing chain data using a block-oriented API should prefer this interface over [`Confirm`].
165 /// Such clients fetch the entire header chain whereas clients using [`Confirm`] only fetch headers
166 /// when needed.
167 ///
168 /// By using [`Listen::filtered_block_connected`] this interface supports clients fetching the
169 /// entire header chain and only blocks with matching transaction data using BIP 157 filters or
170 /// other similar filtering.
171 #[repr(C)]
172 pub struct Listen {
173         /// An opaque pointer which is passed to your function implementations as an argument.
174         /// This has no meaning in the LDK, and can be NULL or any other value.
175         pub this_arg: *mut c_void,
176         /// Notifies the listener that a block was added at the given height, with the transaction data
177         /// possibly filtered.
178         pub filtered_block_connected: extern "C" fn (this_arg: *const c_void, header: *const [u8; 80], txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, height: u32),
179         /// Notifies the listener that a block was added at the given height.
180         pub block_connected: extern "C" fn (this_arg: *const c_void, block: crate::c_types::u8slice, height: u32),
181         /// Notifies the listener that a block was removed at the given height.
182         pub block_disconnected: extern "C" fn (this_arg: *const c_void, header: *const [u8; 80], height: u32),
183         /// Frees any resources associated with this object given its this_arg pointer.
184         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
185         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
186 }
187 unsafe impl Send for Listen {}
188 unsafe impl Sync for Listen {}
189 #[allow(unused)]
190 pub(crate) fn Listen_clone_fields(orig: &Listen) -> Listen {
191         Listen {
192                 this_arg: orig.this_arg,
193                 filtered_block_connected: Clone::clone(&orig.filtered_block_connected),
194                 block_connected: Clone::clone(&orig.block_connected),
195                 block_disconnected: Clone::clone(&orig.block_disconnected),
196                 free: Clone::clone(&orig.free),
197         }
198 }
199
200 use lightning::chain::Listen as rustListen;
201 impl rustListen for Listen {
202         fn filtered_block_connected(&self, mut header: &bitcoin::blockdata::block::BlockHeader, mut txdata: &lightning::chain::transaction::TransactionData, mut height: u32) {
203                 let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s };
204                 let mut local_txdata = Vec::new(); for item in txdata.iter() { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item; let mut local_txdata_0 = (orig_txdata_0_0, crate::c_types::Transaction::from_bitcoin(&orig_txdata_0_1)).into(); local_txdata_0 }); };
205                 (self.filtered_block_connected)(self.this_arg, &local_header, local_txdata.into(), height)
206         }
207         fn block_connected(&self, mut block: &bitcoin::blockdata::block::Block, mut height: u32) {
208                 let mut local_block = ::bitcoin::consensus::encode::serialize(block);
209                 (self.block_connected)(self.this_arg, crate::c_types::u8slice::from_slice(&local_block), height)
210         }
211         fn block_disconnected(&self, mut header: &bitcoin::blockdata::block::BlockHeader, mut height: u32) {
212                 let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s };
213                 (self.block_disconnected)(self.this_arg, &local_header, height)
214         }
215 }
216
217 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
218 // directly as a Deref trait in higher-level structs:
219 impl core::ops::Deref for Listen {
220         type Target = Self;
221         fn deref(&self) -> &Self {
222                 self
223         }
224 }
225 impl core::ops::DerefMut for Listen {
226         fn deref_mut(&mut self) -> &mut Self {
227                 self
228         }
229 }
230 /// Calls the free function if one is set
231 #[no_mangle]
232 pub extern "C" fn Listen_free(this_ptr: Listen) { }
233 impl Drop for Listen {
234         fn drop(&mut self) {
235                 if let Some(f) = self.free {
236                         f(self.this_arg);
237                 }
238         }
239 }
240 /// The `Confirm` trait is used to notify LDK when relevant transactions have been confirmed on
241 /// chain or unconfirmed during a chain reorganization.
242 ///
243 /// Clients sourcing chain data using a transaction-oriented API should prefer this interface over
244 /// [`Listen`]. For instance, an Electrum-based transaction sync implementation may implement
245 /// [`Filter`] to subscribe to relevant transactions and unspent outputs it should monitor for
246 /// on-chain activity. Then, it needs to notify LDK via this interface upon observing any changes
247 /// with reference to the confirmation status of the monitored objects.
248 ///
249 /// # Use
250 /// The intended use is as follows:
251 /// - Call [`transactions_confirmed`] to notify LDK whenever any of the registered transactions or
252 ///   outputs are, respectively, confirmed or spent on chain.
253 /// - Call [`transaction_unconfirmed`] to notify LDK whenever any transaction returned by
254 ///   [`get_relevant_txids`] is no longer confirmed in the block with the given block hash.
255 /// - Call [`best_block_updated`] to notify LDK whenever a new chain tip becomes available.
256 ///
257 /// # Order
258 ///
259 /// Clients must call these methods in chain order. Specifically:
260 /// - Transactions which are confirmed in a particular block must be given before transactions
261 ///   confirmed in a later block.
262 /// - Dependent transactions within the same block must be given in topological order, possibly in
263 ///   separate calls.
264 /// - All unconfirmed transactions must be given after the original confirmations and before *any*
265 ///   reconfirmations, i.e., [`transactions_confirmed`] and [`transaction_unconfirmed`] calls should
266 ///   never be interleaved, but always conduced *en bloc*.
267 /// - Any reconfirmed transactions need to be explicitly unconfirmed before they are reconfirmed
268 ///   in regard to the new block.
269 ///
270 /// See individual method documentation for further details.
271 ///
272 /// [`transactions_confirmed`]: Self::transactions_confirmed
273 /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
274 /// [`best_block_updated`]: Self::best_block_updated
275 /// [`get_relevant_txids`]: Self::get_relevant_txids
276 #[repr(C)]
277 pub struct Confirm {
278         /// An opaque pointer which is passed to your function implementations as an argument.
279         /// This has no meaning in the LDK, and can be NULL or any other value.
280         pub this_arg: *mut c_void,
281         /// Notifies LDK of transactions confirmed in a block with a given header and height.
282         ///
283         /// Must be called for any transactions registered by [`Filter::register_tx`] or any
284         /// transactions spending an output registered by [`Filter::register_output`]. Such transactions
285         /// appearing in the same block do not need to be included in the same call; instead, multiple
286         /// calls with additional transactions may be made so long as they are made in [chain order].
287         ///
288         /// May be called before or after [`best_block_updated`] for the corresponding block. However,
289         /// in the event of a chain reorganization, it must not be called with a `header` that is no
290         /// longer in the chain as of the last call to [`best_block_updated`].
291         ///
292         /// [chain order]: Confirm#order
293         /// [`best_block_updated`]: Self::best_block_updated
294         pub transactions_confirmed: extern "C" fn (this_arg: *const c_void, header: *const [u8; 80], txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, height: u32),
295         /// Notifies LDK of a transaction that is no longer confirmed as result of a chain reorganization.
296         ///
297         /// Must be called for any transaction returned by [`get_relevant_txids`] if it has been
298         /// reorganized out of the best chain or if it is no longer confirmed in the block with the
299         /// given block hash. Once called, the given transaction will not be returned
300         /// by [`get_relevant_txids`], unless it has been reconfirmed via [`transactions_confirmed`].
301         ///
302         /// [`get_relevant_txids`]: Self::get_relevant_txids
303         /// [`transactions_confirmed`]: Self::transactions_confirmed
304         pub transaction_unconfirmed: extern "C" fn (this_arg: *const c_void, txid: *const [u8; 32]),
305         /// Notifies LDK of an update to the best header connected at the given height.
306         ///
307         /// Must be called whenever a new chain tip becomes available. May be skipped for intermediary
308         /// blocks.
309         pub best_block_updated: extern "C" fn (this_arg: *const c_void, header: *const [u8; 80], height: u32),
310         /// Returns transactions that must be monitored for reorganization out of the chain along
311         /// with the hash of the block as part of which it had been previously confirmed.
312         ///
313         /// Note that the returned `Option<BlockHash>` might be `None` for channels created with LDK
314         /// 0.0.112 and prior, in which case you need to manually track previous confirmations.
315         ///
316         /// Will include any transactions passed to [`transactions_confirmed`] that have insufficient
317         /// confirmations to be safe from a chain reorganization. Will not include any transactions
318         /// passed to [`transaction_unconfirmed`], unless later reconfirmed.
319         ///
320         /// Must be called to determine the subset of transactions that must be monitored for
321         /// reorganization. Will be idempotent between calls but may change as a result of calls to the
322         /// other interface methods. Thus, this is useful to determine which transactions must be
323         /// given to [`transaction_unconfirmed`].
324         ///
325         /// If any of the returned transactions are confirmed in a block other than the one with the
326         /// given hash, they need to be unconfirmed and reconfirmed via [`transaction_unconfirmed`] and
327         /// [`transactions_confirmed`], respectively.
328         ///
329         /// [`transactions_confirmed`]: Self::transactions_confirmed
330         /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
331         pub get_relevant_txids: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_ThirtyTwoBytesCOption_ThirtyTwoBytesZZZ,
332         /// Frees any resources associated with this object given its this_arg pointer.
333         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
334         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
335 }
336 unsafe impl Send for Confirm {}
337 unsafe impl Sync for Confirm {}
338 #[allow(unused)]
339 pub(crate) fn Confirm_clone_fields(orig: &Confirm) -> Confirm {
340         Confirm {
341                 this_arg: orig.this_arg,
342                 transactions_confirmed: Clone::clone(&orig.transactions_confirmed),
343                 transaction_unconfirmed: Clone::clone(&orig.transaction_unconfirmed),
344                 best_block_updated: Clone::clone(&orig.best_block_updated),
345                 get_relevant_txids: Clone::clone(&orig.get_relevant_txids),
346                 free: Clone::clone(&orig.free),
347         }
348 }
349
350 use lightning::chain::Confirm as rustConfirm;
351 impl rustConfirm for Confirm {
352         fn transactions_confirmed(&self, mut header: &bitcoin::blockdata::block::BlockHeader, mut txdata: &lightning::chain::transaction::TransactionData, mut height: u32) {
353                 let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s };
354                 let mut local_txdata = Vec::new(); for item in txdata.iter() { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item; let mut local_txdata_0 = (orig_txdata_0_0, crate::c_types::Transaction::from_bitcoin(&orig_txdata_0_1)).into(); local_txdata_0 }); };
355                 (self.transactions_confirmed)(self.this_arg, &local_header, local_txdata.into(), height)
356         }
357         fn transaction_unconfirmed(&self, mut txid: &bitcoin::hash_types::Txid) {
358                 (self.transaction_unconfirmed)(self.this_arg, txid.as_inner())
359         }
360         fn best_block_updated(&self, mut header: &bitcoin::blockdata::block::BlockHeader, mut height: u32) {
361                 let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s };
362                 (self.best_block_updated)(self.this_arg, &local_header, height)
363         }
364         fn get_relevant_txids(&self) -> Vec<(bitcoin::hash_types::Txid, Option<bitcoin::hash_types::BlockHash>)> {
365                 let mut ret = (self.get_relevant_txids)(self.this_arg);
366                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item.to_rust(); let mut local_orig_ret_0_1 = { /*orig_ret_0_1*/ let orig_ret_0_1_opt = orig_ret_0_1; if orig_ret_0_1_opt.is_none() { None } else { Some({ { ::bitcoin::hash_types::BlockHash::from_slice(&{ orig_ret_0_1_opt.take() }.data[..]).unwrap() }})} }; let mut local_ret_0 = (::bitcoin::hash_types::Txid::from_slice(&orig_ret_0_0.data[..]).unwrap(), local_orig_ret_0_1); local_ret_0 }); };
367                 local_ret
368         }
369 }
370
371 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
372 // directly as a Deref trait in higher-level structs:
373 impl core::ops::Deref for Confirm {
374         type Target = Self;
375         fn deref(&self) -> &Self {
376                 self
377         }
378 }
379 impl core::ops::DerefMut for Confirm {
380         fn deref_mut(&mut self) -> &mut Self {
381                 self
382         }
383 }
384 /// Calls the free function if one is set
385 #[no_mangle]
386 pub extern "C" fn Confirm_free(this_ptr: Confirm) { }
387 impl Drop for Confirm {
388         fn drop(&mut self) {
389                 if let Some(f) = self.free {
390                         f(self.this_arg);
391                 }
392         }
393 }
394 /// An enum representing the status of a channel monitor update persistence.
395 ///
396 /// These are generally used as the return value for an implementation of [`Persist`] which is used
397 /// as the storage layer for a [`ChainMonitor`]. See the docs on [`Persist`] for a high-level
398 /// explanation of how to handle different cases.
399 ///
400 /// While `UnrecoverableError` is provided as a failure variant, it is not truly \"handled\" on the
401 /// calling side, and generally results in an immediate panic. For those who prefer to avoid
402 /// panics, `InProgress` can be used and you can retry the update operation in the background or
403 /// shut down cleanly.
404 ///
405 /// Note that channels should generally *not* be force-closed after a persistence failure.
406 /// Force-closing with the latest [`ChannelMonitorUpdate`] applied may result in a transaction
407 /// being broadcast which can only be spent by the latest [`ChannelMonitor`]! Thus, if the
408 /// latest [`ChannelMonitor`] is not durably persisted anywhere and exists only in memory, naively
409 /// calling [`ChannelManager::force_close_broadcasting_latest_txn`] *may result in loss of funds*!
410 ///
411 /// [`Persist`]: chainmonitor::Persist
412 /// [`ChainMonitor`]: chainmonitor::ChainMonitor
413 /// [`ChannelManager::force_close_broadcasting_latest_txn`]: crate::ln::channelmanager::ChannelManager::force_close_broadcasting_latest_txn
414 #[derive(Clone)]
415 #[must_use]
416 #[repr(C)]
417 pub enum ChannelMonitorUpdateStatus {
418         /// The update has been durably persisted and all copies of the relevant [`ChannelMonitor`]
419         /// have been updated.
420         ///
421         /// This includes performing any `fsync()` calls required to ensure the update is guaranteed to
422         /// be available on restart even if the application crashes.
423         Completed,
424         /// Indicates that the update will happen asynchronously in the background or that a transient
425         /// failure occurred which is being retried in the background and will eventually complete.
426         ///
427         /// This will \"freeze\" a channel, preventing us from revoking old states or submitting a new
428         /// commitment transaction to the counterparty. Once the update(s) which are `InProgress` have
429         /// been completed, a [`MonitorEvent::Completed`] can be used to restore the channel to an
430         /// operational state.
431         ///
432         /// Even when a channel has been \"frozen\", updates to the [`ChannelMonitor`] can continue to
433         /// occur (e.g. if an inbound HTLC which we forwarded was claimed upstream, resulting in us
434         /// attempting to claim it on this channel) and those updates must still be persisted.
435         ///
436         /// No updates to the channel will be made which could invalidate other [`ChannelMonitor`]s
437         /// until a [`MonitorEvent::Completed`] is provided, even if you return no error on a later
438         /// monitor update for the same channel.
439         ///
440         /// For deployments where a copy of [`ChannelMonitor`]s and other local state are backed up in
441         /// a remote location (with local copies persisted immediately), it is anticipated that all
442         /// updates will return [`InProgress`] until the remote copies could be updated.
443         ///
444         /// Note that while fully asynchronous persistence of [`ChannelMonitor`] data is generally
445         /// reliable, this feature is considered beta, and a handful of edge-cases remain. Until the
446         /// remaining cases are fixed, in rare cases, *using this feature may lead to funds loss*.
447         ///
448         /// [`InProgress`]: ChannelMonitorUpdateStatus::InProgress
449         InProgress,
450         /// Indicates that an update has failed and will not complete at any point in the future.
451         ///
452         /// Currently returning this variant will cause LDK to immediately panic to encourage immediate
453         /// shutdown. In the future this may be updated to disconnect peers and refuse to continue
454         /// normal operation without a panic.
455         ///
456         /// Applications which wish to perform an orderly shutdown after failure should consider
457         /// returning [`InProgress`] instead and simply shut down without ever marking the update
458         /// complete.
459         ///
460         /// [`InProgress`]: ChannelMonitorUpdateStatus::InProgress
461         UnrecoverableError,
462 }
463 use lightning::chain::ChannelMonitorUpdateStatus as ChannelMonitorUpdateStatusImport;
464 pub(crate) type nativeChannelMonitorUpdateStatus = ChannelMonitorUpdateStatusImport;
465
466 impl ChannelMonitorUpdateStatus {
467         #[allow(unused)]
468         pub(crate) fn to_native(&self) -> nativeChannelMonitorUpdateStatus {
469                 match self {
470                         ChannelMonitorUpdateStatus::Completed => nativeChannelMonitorUpdateStatus::Completed,
471                         ChannelMonitorUpdateStatus::InProgress => nativeChannelMonitorUpdateStatus::InProgress,
472                         ChannelMonitorUpdateStatus::UnrecoverableError => nativeChannelMonitorUpdateStatus::UnrecoverableError,
473                 }
474         }
475         #[allow(unused)]
476         pub(crate) fn into_native(self) -> nativeChannelMonitorUpdateStatus {
477                 match self {
478                         ChannelMonitorUpdateStatus::Completed => nativeChannelMonitorUpdateStatus::Completed,
479                         ChannelMonitorUpdateStatus::InProgress => nativeChannelMonitorUpdateStatus::InProgress,
480                         ChannelMonitorUpdateStatus::UnrecoverableError => nativeChannelMonitorUpdateStatus::UnrecoverableError,
481                 }
482         }
483         #[allow(unused)]
484         pub(crate) fn from_native(native: &nativeChannelMonitorUpdateStatus) -> Self {
485                 match native {
486                         nativeChannelMonitorUpdateStatus::Completed => ChannelMonitorUpdateStatus::Completed,
487                         nativeChannelMonitorUpdateStatus::InProgress => ChannelMonitorUpdateStatus::InProgress,
488                         nativeChannelMonitorUpdateStatus::UnrecoverableError => ChannelMonitorUpdateStatus::UnrecoverableError,
489                 }
490         }
491         #[allow(unused)]
492         pub(crate) fn native_into(native: nativeChannelMonitorUpdateStatus) -> Self {
493                 match native {
494                         nativeChannelMonitorUpdateStatus::Completed => ChannelMonitorUpdateStatus::Completed,
495                         nativeChannelMonitorUpdateStatus::InProgress => ChannelMonitorUpdateStatus::InProgress,
496                         nativeChannelMonitorUpdateStatus::UnrecoverableError => ChannelMonitorUpdateStatus::UnrecoverableError,
497                 }
498         }
499 }
500 /// Creates a copy of the ChannelMonitorUpdateStatus
501 #[no_mangle]
502 pub extern "C" fn ChannelMonitorUpdateStatus_clone(orig: &ChannelMonitorUpdateStatus) -> ChannelMonitorUpdateStatus {
503         orig.clone()
504 }
505 #[allow(unused)]
506 /// Used only if an object of this type is returned as a trait impl by a method
507 pub(crate) extern "C" fn ChannelMonitorUpdateStatus_clone_void(this_ptr: *const c_void) -> *mut c_void {
508         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ChannelMonitorUpdateStatus)).clone() })) as *mut c_void
509 }
510 #[allow(unused)]
511 /// Used only if an object of this type is returned as a trait impl by a method
512 pub(crate) extern "C" fn ChannelMonitorUpdateStatus_free_void(this_ptr: *mut c_void) {
513         let _ = unsafe { Box::from_raw(this_ptr as *mut ChannelMonitorUpdateStatus) };
514 }
515 #[no_mangle]
516 /// Utility method to constructs a new Completed-variant ChannelMonitorUpdateStatus
517 pub extern "C" fn ChannelMonitorUpdateStatus_completed() -> ChannelMonitorUpdateStatus {
518         ChannelMonitorUpdateStatus::Completed}
519 #[no_mangle]
520 /// Utility method to constructs a new InProgress-variant ChannelMonitorUpdateStatus
521 pub extern "C" fn ChannelMonitorUpdateStatus_in_progress() -> ChannelMonitorUpdateStatus {
522         ChannelMonitorUpdateStatus::InProgress}
523 #[no_mangle]
524 /// Utility method to constructs a new UnrecoverableError-variant ChannelMonitorUpdateStatus
525 pub extern "C" fn ChannelMonitorUpdateStatus_unrecoverable_error() -> ChannelMonitorUpdateStatus {
526         ChannelMonitorUpdateStatus::UnrecoverableError}
527 /// Checks if two ChannelMonitorUpdateStatuss contain equal inner contents.
528 /// This ignores pointers and is_owned flags and looks at the values in fields.
529 #[no_mangle]
530 pub extern "C" fn ChannelMonitorUpdateStatus_eq(a: &ChannelMonitorUpdateStatus, b: &ChannelMonitorUpdateStatus) -> bool {
531         if &a.to_native() == &b.to_native() { true } else { false }
532 }
533 /// The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as
534 /// blocks are connected and disconnected.
535 ///
536 /// Each channel is associated with a [`ChannelMonitor`]. Implementations of this trait are
537 /// responsible for maintaining a set of monitors such that they can be updated as channel state
538 /// changes. On each update, *all copies* of a [`ChannelMonitor`] must be updated and the update
539 /// persisted to disk to ensure that the latest [`ChannelMonitor`] state can be reloaded if the
540 /// application crashes.
541 ///
542 /// See method documentation and [`ChannelMonitorUpdateStatus`] for specific requirements.
543 #[repr(C)]
544 pub struct Watch {
545         /// An opaque pointer which is passed to your function implementations as an argument.
546         /// This has no meaning in the LDK, and can be NULL or any other value.
547         pub this_arg: *mut c_void,
548         /// Watches a channel identified by `funding_txo` using `monitor`.
549         ///
550         /// Implementations are responsible for watching the chain for the funding transaction along
551         /// with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
552         /// calling [`block_connected`] and [`block_disconnected`] on the monitor.
553         ///
554         /// A return of `Err(())` indicates that the channel should immediately be force-closed without
555         /// broadcasting the funding transaction.
556         ///
557         /// If the given `funding_txo` has previously been registered via `watch_channel`, `Err(())`
558         /// must be returned.
559         ///
560         /// [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch
561         /// [`block_connected`]: channelmonitor::ChannelMonitor::block_connected
562         /// [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected
563         pub watch_channel: extern "C" fn (this_arg: *const c_void, funding_txo: crate::lightning::chain::transaction::OutPoint, monitor: crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_ChannelMonitorUpdateStatusNoneZ,
564         /// Updates a channel identified by `funding_txo` by applying `update` to its monitor.
565         ///
566         /// Implementations must call [`ChannelMonitor::update_monitor`] with the given update. This
567         /// may fail (returning an `Err(())`), in which case this should return
568         /// [`ChannelMonitorUpdateStatus::InProgress`] (and the update should never complete). This
569         /// generally implies the channel has been closed (either by the funding outpoint being spent
570         /// on-chain or the [`ChannelMonitor`] having decided to do so and broadcasted a transaction),
571         /// and the [`ChannelManager`] state will be updated once it sees the funding spend on-chain.
572         ///
573         /// In general, persistence failures should be retried after returning
574         /// [`ChannelMonitorUpdateStatus::InProgress`] and eventually complete. If a failure truly
575         /// cannot be retried, the node should shut down immediately after returning
576         /// [`ChannelMonitorUpdateStatus::UnrecoverableError`], see its documentation for more info.
577         ///
578         /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
579         pub update_channel: extern "C" fn (this_arg: *const c_void, funding_txo: crate::lightning::chain::transaction::OutPoint, update: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::lightning::chain::ChannelMonitorUpdateStatus,
580         /// Returns any monitor events since the last call. Subsequent calls must only return new
581         /// events.
582         ///
583         /// Note that after any block- or transaction-connection calls to a [`ChannelMonitor`], no
584         /// further events may be returned here until the [`ChannelMonitor`] has been fully persisted
585         /// to disk.
586         ///
587         /// For details on asynchronous [`ChannelMonitor`] updating and returning
588         /// [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`].
589         pub release_pending_monitor_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ,
590         /// Frees any resources associated with this object given its this_arg pointer.
591         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
592         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
593 }
594 unsafe impl Send for Watch {}
595 unsafe impl Sync for Watch {}
596 #[allow(unused)]
597 pub(crate) fn Watch_clone_fields(orig: &Watch) -> Watch {
598         Watch {
599                 this_arg: orig.this_arg,
600                 watch_channel: Clone::clone(&orig.watch_channel),
601                 update_channel: Clone::clone(&orig.update_channel),
602                 release_pending_monitor_events: Clone::clone(&orig.release_pending_monitor_events),
603                 free: Clone::clone(&orig.free),
604         }
605 }
606
607 use lightning::chain::Watch as rustWatch;
608 impl rustWatch<crate::lightning::sign::WriteableEcdsaChannelSigner> for Watch {
609         fn watch_channel(&self, mut funding_txo: lightning::chain::transaction::OutPoint, mut monitor: lightning::chain::channelmonitor::ChannelMonitor<crate::lightning::sign::WriteableEcdsaChannelSigner>) -> Result<lightning::chain::ChannelMonitorUpdateStatus, ()> {
610                 let mut ret = (self.watch_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true }, crate::lightning::chain::channelmonitor::ChannelMonitor { inner: ObjOps::heap_alloc(monitor), is_owned: true });
611                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_native() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
612                 local_ret
613         }
614         fn update_channel(&self, mut funding_txo: lightning::chain::transaction::OutPoint, mut update: &lightning::chain::channelmonitor::ChannelMonitorUpdate) -> lightning::chain::ChannelMonitorUpdateStatus {
615                 let mut ret = (self.update_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(funding_txo), is_owned: true }, &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: unsafe { ObjOps::nonnull_ptr_to_inner((update as *const lightning::chain::channelmonitor::ChannelMonitorUpdate<>) as *mut _) }, is_owned: false });
616                 ret.into_native()
617         }
618         fn release_pending_monitor_events(&self) -> Vec<(lightning::chain::transaction::OutPoint, Vec<lightning::chain::channelmonitor::MonitorEvent>, Option<bitcoin::secp256k1::PublicKey>)> {
619                 let mut ret = (self.release_pending_monitor_events)(self.this_arg);
620                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item.to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_native() }); }; let mut local_orig_ret_0_2 = if orig_ret_0_2.is_null() { None } else { Some( { orig_ret_0_2.into_rust() }) }; let mut local_ret_0 = (*unsafe { Box::from_raw(orig_ret_0_0.take_inner()) }, local_orig_ret_0_1, local_orig_ret_0_2); local_ret_0 }); };
621                 local_ret
622         }
623 }
624
625 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
626 // directly as a Deref trait in higher-level structs:
627 impl core::ops::Deref for Watch {
628         type Target = Self;
629         fn deref(&self) -> &Self {
630                 self
631         }
632 }
633 impl core::ops::DerefMut for Watch {
634         fn deref_mut(&mut self) -> &mut Self {
635                 self
636         }
637 }
638 /// Calls the free function if one is set
639 #[no_mangle]
640 pub extern "C" fn Watch_free(this_ptr: Watch) { }
641 impl Drop for Watch {
642         fn drop(&mut self) {
643                 if let Some(f) = self.free {
644                         f(self.this_arg);
645                 }
646         }
647 }
648 /// The `Filter` trait defines behavior for indicating chain activity of interest pertaining to
649 /// channels.
650 ///
651 /// This is useful in order to have a [`Watch`] implementation convey to a chain source which
652 /// transactions to be notified of. Notification may take the form of pre-filtering blocks or, in
653 /// the case of [BIP 157]/[BIP 158], only fetching a block if the compact filter matches. If
654 /// receiving full blocks from a chain source, any further filtering is unnecessary.
655 ///
656 /// After an output has been registered, subsequent block retrievals from the chain source must not
657 /// exclude any transactions matching the new criteria nor any in-block descendants of such
658 /// transactions.
659 ///
660 /// Note that use as part of a [`Watch`] implementation involves reentrancy. Therefore, the `Filter`
661 /// should not block on I/O. Implementations should instead queue the newly monitored data to be
662 /// processed later. Then, in order to block until the data has been processed, any [`Watch`]
663 /// invocation that has called the `Filter` must return [`InProgress`].
664 ///
665 /// [`InProgress`]: ChannelMonitorUpdateStatus::InProgress
666 /// [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
667 /// [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
668 #[repr(C)]
669 pub struct Filter {
670         /// An opaque pointer which is passed to your function implementations as an argument.
671         /// This has no meaning in the LDK, and can be NULL or any other value.
672         pub this_arg: *mut c_void,
673         /// Registers interest in a transaction with `txid` and having an output with `script_pubkey` as
674         /// a spending condition.
675         pub register_tx: extern "C" fn (this_arg: *const c_void, txid: *const [u8; 32], script_pubkey: crate::c_types::u8slice),
676         /// Registers interest in spends of a transaction output.
677         ///
678         /// Note that this method might be called during processing of a new block. You therefore need
679         /// to ensure that also dependent output spents within an already connected block are correctly
680         /// handled, e.g., by re-scanning the block in question whenever new outputs have been
681         /// registered mid-processing.
682         pub register_output: extern "C" fn (this_arg: *const c_void, output: crate::lightning::chain::WatchedOutput),
683         /// Frees any resources associated with this object given its this_arg pointer.
684         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
685         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
686 }
687 unsafe impl Send for Filter {}
688 unsafe impl Sync for Filter {}
689 #[allow(unused)]
690 pub(crate) fn Filter_clone_fields(orig: &Filter) -> Filter {
691         Filter {
692                 this_arg: orig.this_arg,
693                 register_tx: Clone::clone(&orig.register_tx),
694                 register_output: Clone::clone(&orig.register_output),
695                 free: Clone::clone(&orig.free),
696         }
697 }
698
699 use lightning::chain::Filter as rustFilter;
700 impl rustFilter for Filter {
701         fn register_tx(&self, mut txid: &bitcoin::hash_types::Txid, mut script_pubkey: &bitcoin::blockdata::script::Script) {
702                 (self.register_tx)(self.this_arg, txid.as_inner(), crate::c_types::u8slice::from_slice(&script_pubkey[..]))
703         }
704         fn register_output(&self, mut output: lightning::chain::WatchedOutput) {
705                 (self.register_output)(self.this_arg, crate::lightning::chain::WatchedOutput { inner: ObjOps::heap_alloc(output), is_owned: true })
706         }
707 }
708
709 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
710 // directly as a Deref trait in higher-level structs:
711 impl core::ops::Deref for Filter {
712         type Target = Self;
713         fn deref(&self) -> &Self {
714                 self
715         }
716 }
717 impl core::ops::DerefMut for Filter {
718         fn deref_mut(&mut self) -> &mut Self {
719                 self
720         }
721 }
722 /// Calls the free function if one is set
723 #[no_mangle]
724 pub extern "C" fn Filter_free(this_ptr: Filter) { }
725 impl Drop for Filter {
726         fn drop(&mut self) {
727                 if let Some(f) = self.free {
728                         f(self.this_arg);
729                 }
730         }
731 }
732
733 use lightning::chain::WatchedOutput as nativeWatchedOutputImport;
734 pub(crate) type nativeWatchedOutput = nativeWatchedOutputImport;
735
736 /// A transaction output watched by a [`ChannelMonitor`] for spends on-chain.
737 ///
738 /// Used to convey to a [`Filter`] such an output with a given spending condition. Any transaction
739 /// spending the output must be given to [`ChannelMonitor::block_connected`] either directly or via
740 /// [`Confirm::transactions_confirmed`].
741 ///
742 /// If `block_hash` is `Some`, this indicates the output was created in the corresponding block and
743 /// may have been spent there. See [`Filter::register_output`] for details.
744 ///
745 /// [`ChannelMonitor`]: channelmonitor::ChannelMonitor
746 /// [`ChannelMonitor::block_connected`]: channelmonitor::ChannelMonitor::block_connected
747 #[must_use]
748 #[repr(C)]
749 pub struct WatchedOutput {
750         /// A pointer to the opaque Rust object.
751
752         /// Nearly everywhere, inner must be non-null, however in places where
753         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
754         pub inner: *mut nativeWatchedOutput,
755         /// Indicates that this is the only struct which contains the same pointer.
756
757         /// Rust functions which take ownership of an object provided via an argument require
758         /// this to be true and invalidate the object pointed to by inner.
759         pub is_owned: bool,
760 }
761
762 impl Drop for WatchedOutput {
763         fn drop(&mut self) {
764                 if self.is_owned && !<*mut nativeWatchedOutput>::is_null(self.inner) {
765                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
766                 }
767         }
768 }
769 /// Frees any resources used by the WatchedOutput, if is_owned is set and inner is non-NULL.
770 #[no_mangle]
771 pub extern "C" fn WatchedOutput_free(this_obj: WatchedOutput) { }
772 #[allow(unused)]
773 /// Used only if an object of this type is returned as a trait impl by a method
774 pub(crate) extern "C" fn WatchedOutput_free_void(this_ptr: *mut c_void) {
775         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeWatchedOutput) };
776 }
777 #[allow(unused)]
778 impl WatchedOutput {
779         pub(crate) fn get_native_ref(&self) -> &'static nativeWatchedOutput {
780                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
781         }
782         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeWatchedOutput {
783                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
784         }
785         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
786         pub(crate) fn take_inner(mut self) -> *mut nativeWatchedOutput {
787                 assert!(self.is_owned);
788                 let ret = ObjOps::untweak_ptr(self.inner);
789                 self.inner = core::ptr::null_mut();
790                 ret
791         }
792 }
793 /// First block where the transaction output may have been spent.
794 #[no_mangle]
795 pub extern "C" fn WatchedOutput_get_block_hash(this_ptr: &WatchedOutput) -> crate::c_types::derived::COption_ThirtyTwoBytesZ {
796         let mut inner_val = &mut this_ptr.get_native_mut_ref().block_hash;
797         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*inner_val.as_ref().unwrap()).clone().into_inner() } }) };
798         local_inner_val
799 }
800 /// First block where the transaction output may have been spent.
801 #[no_mangle]
802 pub extern "C" fn WatchedOutput_set_block_hash(this_ptr: &mut WatchedOutput, mut val: crate::c_types::derived::COption_ThirtyTwoBytesZ) {
803         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::bitcoin::hash_types::BlockHash::from_slice(&{ val_opt.take() }.data[..]).unwrap() }})} };
804         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.block_hash = local_val;
805 }
806 /// Outpoint identifying the transaction output.
807 #[no_mangle]
808 pub extern "C" fn WatchedOutput_get_outpoint(this_ptr: &WatchedOutput) -> crate::lightning::chain::transaction::OutPoint {
809         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
810         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::transaction::OutPoint<>) as *mut _) }, is_owned: false }
811 }
812 /// Outpoint identifying the transaction output.
813 #[no_mangle]
814 pub extern "C" fn WatchedOutput_set_outpoint(this_ptr: &mut WatchedOutput, mut val: crate::lightning::chain::transaction::OutPoint) {
815         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
816 }
817 /// Spending condition of the transaction output.
818 #[no_mangle]
819 pub extern "C" fn WatchedOutput_get_script_pubkey(this_ptr: &WatchedOutput) -> crate::c_types::u8slice {
820         let mut inner_val = &mut this_ptr.get_native_mut_ref().script_pubkey;
821         crate::c_types::u8slice::from_slice(&inner_val[..])
822 }
823 /// Spending condition of the transaction output.
824 #[no_mangle]
825 pub extern "C" fn WatchedOutput_set_script_pubkey(this_ptr: &mut WatchedOutput, mut val: crate::c_types::derived::CVec_u8Z) {
826         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.script_pubkey = ::bitcoin::blockdata::script::Script::from(val.into_rust());
827 }
828 /// Constructs a new WatchedOutput given each field
829 #[must_use]
830 #[no_mangle]
831 pub extern "C" fn WatchedOutput_new(mut block_hash_arg: crate::c_types::derived::COption_ThirtyTwoBytesZ, mut outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut script_pubkey_arg: crate::c_types::derived::CVec_u8Z) -> WatchedOutput {
832         let mut local_block_hash_arg = { /*block_hash_arg*/ let block_hash_arg_opt = block_hash_arg; if block_hash_arg_opt.is_none() { None } else { Some({ { ::bitcoin::hash_types::BlockHash::from_slice(&{ block_hash_arg_opt.take() }.data[..]).unwrap() }})} };
833         WatchedOutput { inner: ObjOps::heap_alloc(nativeWatchedOutput {
834                 block_hash: local_block_hash_arg,
835                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
836                 script_pubkey: ::bitcoin::blockdata::script::Script::from(script_pubkey_arg.into_rust()),
837         }), is_owned: true }
838 }
839 impl Clone for WatchedOutput {
840         fn clone(&self) -> Self {
841                 Self {
842                         inner: if <*mut nativeWatchedOutput>::is_null(self.inner) { core::ptr::null_mut() } else {
843                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
844                         is_owned: true,
845                 }
846         }
847 }
848 #[allow(unused)]
849 /// Used only if an object of this type is returned as a trait impl by a method
850 pub(crate) extern "C" fn WatchedOutput_clone_void(this_ptr: *const c_void) -> *mut c_void {
851         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeWatchedOutput)).clone() })) as *mut c_void
852 }
853 #[no_mangle]
854 /// Creates a copy of the WatchedOutput
855 pub extern "C" fn WatchedOutput_clone(orig: &WatchedOutput) -> WatchedOutput {
856         orig.clone()
857 }
858 /// Checks if two WatchedOutputs contain equal inner contents.
859 /// This ignores pointers and is_owned flags and looks at the values in fields.
860 /// Two objects with NULL inner values will be considered "equal" here.
861 #[no_mangle]
862 pub extern "C" fn WatchedOutput_eq(a: &WatchedOutput, b: &WatchedOutput) -> bool {
863         if a.inner == b.inner { return true; }
864         if a.inner.is_null() || b.inner.is_null() { return false; }
865         if a.get_native_ref() == b.get_native_ref() { true } else { false }
866 }
867 /// Generates a non-cryptographic 64-bit hash of the WatchedOutput.
868 #[no_mangle]
869 pub extern "C" fn WatchedOutput_hash(o: &WatchedOutput) -> u64 {
870         if o.inner.is_null() { return 0; }
871         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
872         #[allow(deprecated)]
873         let mut hasher = core::hash::SipHasher::new();
874         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
875         core::hash::Hasher::finish(&hasher)
876 }