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