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