Update auto-generated bindings with new upstream invoice creation
[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 std::str::FromStr;
12 use std::ffi::c_void;
13 use bitcoin::hashes::Hash;
14 use crate::c_types::*;
15
16 pub mod chaininterface;
17 pub mod chainmonitor;
18 pub mod channelmonitor;
19 pub mod transaction;
20 pub mod keysinterface;
21 /// An error when accessing the chain via [`Access`].
22 #[must_use]
23 #[derive(Clone)]
24 #[repr(C)]
25 pub enum AccessError {
26         /// The requested chain is unknown.
27         UnknownChain,
28         /// The requested transaction doesn't exist or hasn't confirmed.
29         UnknownTx,
30 }
31 use lightning::chain::AccessError as nativeAccessError;
32 impl AccessError {
33         #[allow(unused)]
34         pub(crate) fn to_native(&self) -> nativeAccessError {
35                 match self {
36                         AccessError::UnknownChain => nativeAccessError::UnknownChain,
37                         AccessError::UnknownTx => nativeAccessError::UnknownTx,
38                 }
39         }
40         #[allow(unused)]
41         pub(crate) fn into_native(self) -> nativeAccessError {
42                 match self {
43                         AccessError::UnknownChain => nativeAccessError::UnknownChain,
44                         AccessError::UnknownTx => nativeAccessError::UnknownTx,
45                 }
46         }
47         #[allow(unused)]
48         pub(crate) fn from_native(native: &nativeAccessError) -> Self {
49                 match native {
50                         nativeAccessError::UnknownChain => AccessError::UnknownChain,
51                         nativeAccessError::UnknownTx => AccessError::UnknownTx,
52                 }
53         }
54         #[allow(unused)]
55         pub(crate) fn native_into(native: nativeAccessError) -> Self {
56                 match native {
57                         nativeAccessError::UnknownChain => AccessError::UnknownChain,
58                         nativeAccessError::UnknownTx => AccessError::UnknownTx,
59                 }
60         }
61 }
62 /// Creates a copy of the AccessError
63 #[no_mangle]
64 pub extern "C" fn AccessError_clone(orig: &AccessError) -> AccessError {
65         orig.clone()
66 }
67 /// The `Access` trait defines behavior for accessing chain data and state, such as blocks and
68 /// UTXOs.
69 #[repr(C)]
70 pub struct Access {
71         /// An opaque pointer which is passed to your function implementations as an argument.
72         /// This has no meaning in the LDK, and can be NULL or any other value.
73         pub this_arg: *mut c_void,
74         /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
75         /// Returns an error if `genesis_hash` is for a different chain or if such a transaction output
76         /// is unknown.
77         ///
78         /// [`short_channel_id`]: https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#definition-of-short_channel_id
79         #[must_use]
80         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,
81         /// Frees any resources associated with this object given its this_arg pointer.
82         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
83         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
84 }
85
86 use lightning::chain::Access as rustAccess;
87 impl rustAccess for Access {
88         fn get_utxo(&self, mut genesis_hash: &bitcoin::hash_types::BlockHash, mut short_channel_id: u64) -> Result<bitcoin::blockdata::transaction::TxOut, lightning::chain::AccessError> {
89                 let mut ret = (self.get_utxo)(self.this_arg, genesis_hash.as_inner(), short_channel_id);
90                 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() })};
91                 local_ret
92         }
93 }
94
95 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
96 // directly as a Deref trait in higher-level structs:
97 impl std::ops::Deref for Access {
98         type Target = Self;
99         fn deref(&self) -> &Self {
100                 self
101         }
102 }
103 /// Calls the free function if one is set
104 #[no_mangle]
105 pub extern "C" fn Access_free(this_ptr: Access) { }
106 impl Drop for Access {
107         fn drop(&mut self) {
108                 if let Some(f) = self.free {
109                         f(self.this_arg);
110                 }
111         }
112 }
113 /// The `Listen` trait is used to notify when blocks have been connected or disconnected from the
114 /// chain.
115 ///
116 /// Useful when needing to replay chain data upon startup or as new chain events occur. Clients
117 /// sourcing chain data using a block-oriented API should prefer this interface over [`Confirm`].
118 /// Such clients fetch the entire header chain whereas clients using [`Confirm`] only fetch headers
119 /// when needed.
120 #[repr(C)]
121 pub struct Listen {
122         /// An opaque pointer which is passed to your function implementations as an argument.
123         /// This has no meaning in the LDK, and can be NULL or any other value.
124         pub this_arg: *mut c_void,
125         /// Notifies the listener that a block was added at the given height.
126         pub block_connected: extern "C" fn (this_arg: *const c_void, block: crate::c_types::u8slice, height: u32),
127         /// Notifies the listener that a block was removed at the given height.
128         pub block_disconnected: extern "C" fn (this_arg: *const c_void, header: *const [u8; 80], height: u32),
129         /// Frees any resources associated with this object given its this_arg pointer.
130         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
131         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
132 }
133
134 use lightning::chain::Listen as rustListen;
135 impl rustListen for Listen {
136         fn block_connected(&self, mut block: &bitcoin::blockdata::block::Block, mut height: u32) {
137                 let mut local_block = ::bitcoin::consensus::encode::serialize(block);
138                 (self.block_connected)(self.this_arg, crate::c_types::u8slice::from_slice(&local_block), height)
139         }
140         fn block_disconnected(&self, mut header: &bitcoin::blockdata::block::BlockHeader, mut height: u32) {
141                 let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s };
142                 (self.block_disconnected)(self.this_arg, &local_header, height)
143         }
144 }
145
146 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
147 // directly as a Deref trait in higher-level structs:
148 impl std::ops::Deref for Listen {
149         type Target = Self;
150         fn deref(&self) -> &Self {
151                 self
152         }
153 }
154 /// Calls the free function if one is set
155 #[no_mangle]
156 pub extern "C" fn Listen_free(this_ptr: Listen) { }
157 impl Drop for Listen {
158         fn drop(&mut self) {
159                 if let Some(f) = self.free {
160                         f(self.this_arg);
161                 }
162         }
163 }
164 /// The `Confirm` trait is used to notify when transactions have been confirmed on chain or
165 /// unconfirmed during a chain reorganization.
166 ///
167 /// Clients sourcing chain data using a transaction-oriented API should prefer this interface over
168 /// [`Listen`]. For instance, an Electrum client may implement [`Filter`] by subscribing to activity
169 /// related to registered transactions and outputs. Upon notification, it would pass along the
170 /// matching transactions using this interface.
171 ///
172 /// # Use
173 ///
174 /// The intended use is as follows:
175 /// - Call [`transactions_confirmed`] to process any on-chain activity of interest.
176 /// - Call [`transaction_unconfirmed`] to process any transaction returned by [`get_relevant_txids`]
177 ///   that has been reorganized out of the chain.
178 /// - Call [`best_block_updated`] whenever a new chain tip becomes available.
179 ///
180 /// # Order
181 ///
182 /// Clients must call these methods in chain order. Specifically:
183 /// - Transactions confirmed in a block must be given before transactions confirmed in a later
184 ///   block.
185 /// - Dependent transactions within the same block must be given in topological order, possibly in
186 ///   separate calls.
187 /// - Unconfirmed transactions must be given after the original confirmations and before any
188 ///   reconfirmation.
189 ///
190 /// See individual method documentation for further details.
191 ///
192 /// [`transactions_confirmed`]: Self::transactions_confirmed
193 /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
194 /// [`best_block_updated`]: Self::best_block_updated
195 /// [`get_relevant_txids`]: Self::get_relevant_txids
196 #[repr(C)]
197 pub struct Confirm {
198         /// An opaque pointer which is passed to your function implementations as an argument.
199         /// This has no meaning in the LDK, and can be NULL or any other value.
200         pub this_arg: *mut c_void,
201         /// Processes transactions confirmed in a block with a given header and height.
202         ///
203         /// Should be called for any transactions registered by [`Filter::register_tx`] or any
204         /// transactions spending an output registered by [`Filter::register_output`]. Such transactions
205         /// appearing in the same block do not need to be included in the same call; instead, multiple
206         /// calls with additional transactions may be made so long as they are made in [chain order].
207         ///
208         /// May be called before or after [`best_block_updated`] for the corresponding block. However,
209         /// in the event of a chain reorganization, it must not be called with a `header` that is no
210         /// longer in the chain as of the last call to [`best_block_updated`].
211         ///
212         /// [chain order]: Confirm#Order
213         /// [`best_block_updated`]: Self::best_block_updated
214         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),
215         /// Processes a transaction that is no longer confirmed as result of a chain reorganization.
216         ///
217         /// Should be called for any transaction returned by [`get_relevant_txids`] if it has been
218         /// reorganized out of the best chain. Once called, the given transaction should not be returned
219         /// by [`get_relevant_txids`] unless it has been reconfirmed via [`transactions_confirmed`].
220         ///
221         /// [`get_relevant_txids`]: Self::get_relevant_txids
222         /// [`transactions_confirmed`]: Self::transactions_confirmed
223         pub transaction_unconfirmed: extern "C" fn (this_arg: *const c_void, txid: *const [u8; 32]),
224         /// Processes an update to the best header connected at the given height.
225         ///
226         /// Should be called when a new header is available but may be skipped for intermediary blocks
227         /// if they become available at the same time.
228         pub best_block_updated: extern "C" fn (this_arg: *const c_void, header: *const [u8; 80], height: u32),
229         /// Returns transactions that should be monitored for reorganization out of the chain.
230         ///
231         /// Should include any transactions passed to [`transactions_confirmed`] that have insufficient
232         /// confirmations to be safe from a chain reorganization. Should not include any transactions
233         /// passed to [`transaction_unconfirmed`] unless later reconfirmed.
234         ///
235         /// May be called to determine the subset of transactions that must still be monitored for
236         /// reorganization. Will be idempotent between calls but may change as a result of calls to the
237         /// other interface methods. Thus, this is useful to determine which transactions may need to be
238         /// given to [`transaction_unconfirmed`].
239         ///
240         /// [`transactions_confirmed`]: Self::transactions_confirmed
241         /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
242         #[must_use]
243         pub get_relevant_txids: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ,
244         /// Frees any resources associated with this object given its this_arg pointer.
245         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
246         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
247 }
248
249 use lightning::chain::Confirm as rustConfirm;
250 impl rustConfirm for Confirm {
251         fn transactions_confirmed(&self, mut header: &bitcoin::blockdata::block::BlockHeader, mut txdata: &lightning::chain::transaction::TransactionData, mut height: u32) {
252                 let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s };
253                 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 }); };
254                 (self.transactions_confirmed)(self.this_arg, &local_header, local_txdata.into(), height)
255         }
256         fn transaction_unconfirmed(&self, mut txid: &bitcoin::hash_types::Txid) {
257                 (self.transaction_unconfirmed)(self.this_arg, txid.as_inner())
258         }
259         fn best_block_updated(&self, mut header: &bitcoin::blockdata::block::BlockHeader, mut height: u32) {
260                 let mut local_header = { let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(header)); s };
261                 (self.best_block_updated)(self.this_arg, &local_header, height)
262         }
263         fn get_relevant_txids(&self) -> Vec<bitcoin::hash_types::Txid> {
264                 let mut ret = (self.get_relevant_txids)(self.this_arg);
265                 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() }); };
266                 local_ret
267         }
268 }
269
270 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
271 // directly as a Deref trait in higher-level structs:
272 impl std::ops::Deref for Confirm {
273         type Target = Self;
274         fn deref(&self) -> &Self {
275                 self
276         }
277 }
278 /// Calls the free function if one is set
279 #[no_mangle]
280 pub extern "C" fn Confirm_free(this_ptr: Confirm) { }
281 impl Drop for Confirm {
282         fn drop(&mut self) {
283                 if let Some(f) = self.free {
284                         f(self.this_arg);
285                 }
286         }
287 }
288 /// The `Watch` trait defines behavior for watching on-chain activity pertaining to channels as
289 /// blocks are connected and disconnected.
290 ///
291 /// Each channel is associated with a [`ChannelMonitor`]. Implementations of this trait are
292 /// responsible for maintaining a set of monitors such that they can be updated accordingly as
293 /// channel state changes and HTLCs are resolved. See method documentation for specific
294 /// requirements.
295 ///
296 /// Implementations **must** ensure that updates are successfully applied and persisted upon method
297 /// completion. If an update fails with a [`PermanentFailure`], then it must immediately shut down
298 /// without taking any further action such as persisting the current state.
299 ///
300 /// If an implementation maintains multiple instances of a channel's monitor (e.g., by storing
301 /// backup copies), then it must ensure that updates are applied across all instances. Otherwise, it
302 /// could result in a revoked transaction being broadcast, allowing the counterparty to claim all
303 /// funds in the channel. See [`ChannelMonitorUpdateErr`] for more details about how to handle
304 /// multiple instances.
305 ///
306 /// [`ChannelMonitor`]: channelmonitor::ChannelMonitor
307 /// [`ChannelMonitorUpdateErr`]: channelmonitor::ChannelMonitorUpdateErr
308 /// [`PermanentFailure`]: channelmonitor::ChannelMonitorUpdateErr::PermanentFailure
309 #[repr(C)]
310 pub struct Watch {
311         /// An opaque pointer which is passed to your function implementations as an argument.
312         /// This has no meaning in the LDK, and can be NULL or any other value.
313         pub this_arg: *mut c_void,
314         /// Watches a channel identified by `funding_txo` using `monitor`.
315         ///
316         /// Implementations are responsible for watching the chain for the funding transaction along
317         /// with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
318         /// calling [`block_connected`] and [`block_disconnected`] on the monitor.
319         ///
320         /// [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch
321         /// [`block_connected`]: channelmonitor::ChannelMonitor::block_connected
322         /// [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected
323         #[must_use]
324         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,
325         /// Updates a channel identified by `funding_txo` by applying `update` to its monitor.
326         ///
327         /// Implementations must call [`update_monitor`] with the given update. See
328         /// [`ChannelMonitorUpdateErr`] for invariants around returning an error.
329         ///
330         /// [`update_monitor`]: channelmonitor::ChannelMonitor::update_monitor
331         /// [`ChannelMonitorUpdateErr`]: channelmonitor::ChannelMonitorUpdateErr
332         #[must_use]
333         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,
334         /// Returns any monitor events since the last call. Subsequent calls must only return new
335         /// events.
336         #[must_use]
337         pub release_pending_monitor_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_MonitorEventZ,
338         /// Frees any resources associated with this object given its this_arg pointer.
339         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
340         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
341 }
342
343 use lightning::chain::Watch as rustWatch;
344 impl rustWatch<crate::lightning::chain::keysinterface::Sign> for Watch {
345         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::channelmonitor::ChannelMonitorUpdateErr> {
346                 let mut ret = (self.watch_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, crate::lightning::chain::channelmonitor::ChannelMonitor { inner: Box::into_raw(Box::new(monitor)), is_owned: true });
347                 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() })};
348                 local_ret
349         }
350         fn update_channel(&self, mut funding_txo: lightning::chain::transaction::OutPoint, mut update: lightning::chain::channelmonitor::ChannelMonitorUpdate) -> Result<(), lightning::chain::channelmonitor::ChannelMonitorUpdateErr> {
351                 let mut ret = (self.update_channel)(self.this_arg, crate::lightning::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(funding_txo)), is_owned: true }, crate::lightning::chain::channelmonitor::ChannelMonitorUpdate { inner: Box::into_raw(Box::new(update)), is_owned: true });
352                 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() })};
353                 local_ret
354         }
355         fn release_pending_monitor_events(&self) -> Vec<lightning::chain::channelmonitor::MonitorEvent> {
356                 let mut ret = (self.release_pending_monitor_events)(self.this_arg);
357                 let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
358                 local_ret
359         }
360 }
361
362 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
363 // directly as a Deref trait in higher-level structs:
364 impl std::ops::Deref for Watch {
365         type Target = Self;
366         fn deref(&self) -> &Self {
367                 self
368         }
369 }
370 /// Calls the free function if one is set
371 #[no_mangle]
372 pub extern "C" fn Watch_free(this_ptr: Watch) { }
373 impl Drop for Watch {
374         fn drop(&mut self) {
375                 if let Some(f) = self.free {
376                         f(self.this_arg);
377                 }
378         }
379 }
380 /// The `Filter` trait defines behavior for indicating chain activity of interest pertaining to
381 /// channels.
382 ///
383 /// This is useful in order to have a [`Watch`] implementation convey to a chain source which
384 /// transactions to be notified of. Notification may take the form of pre-filtering blocks or, in
385 /// the case of [BIP 157]/[BIP 158], only fetching a block if the compact filter matches. If
386 /// receiving full blocks from a chain source, any further filtering is unnecessary.
387 ///
388 /// After an output has been registered, subsequent block retrievals from the chain source must not
389 /// exclude any transactions matching the new criteria nor any in-block descendants of such
390 /// transactions.
391 ///
392 /// Note that use as part of a [`Watch`] implementation involves reentrancy. Therefore, the `Filter`
393 /// should not block on I/O. Implementations should instead queue the newly monitored data to be
394 /// processed later. Then, in order to block until the data has been processed, any [`Watch`]
395 /// invocation that has called the `Filter` must return [`TemporaryFailure`].
396 ///
397 /// [`TemporaryFailure`]: channelmonitor::ChannelMonitorUpdateErr::TemporaryFailure
398 /// [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
399 /// [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
400 #[repr(C)]
401 pub struct Filter {
402         /// An opaque pointer which is passed to your function implementations as an argument.
403         /// This has no meaning in the LDK, and can be NULL or any other value.
404         pub this_arg: *mut c_void,
405         /// Registers interest in a transaction with `txid` and having an output with `script_pubkey` as
406         /// a spending condition.
407         pub register_tx: extern "C" fn (this_arg: *const c_void, txid: *const [u8; 32], script_pubkey: crate::c_types::u8slice),
408         /// Registers interest in spends of a transaction output.
409         ///
410         /// Optionally, when `output.block_hash` is set, should return any transaction spending the
411         /// output that is found in the corresponding block along with its index.
412         ///
413         /// This return value is useful for Electrum clients in order to supply in-block descendant
414         /// transactions which otherwise were not included. This is not necessary for other clients if
415         /// such descendant transactions were already included (e.g., when a BIP 157 client provides the
416         /// full block).
417         #[must_use]
418         pub register_output: extern "C" fn (this_arg: *const c_void, output: crate::lightning::chain::WatchedOutput) -> crate::c_types::derived::COption_C2Tuple_usizeTransactionZZ,
419         /// Frees any resources associated with this object given its this_arg pointer.
420         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
421         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
422 }
423
424 use lightning::chain::Filter as rustFilter;
425 impl rustFilter for Filter {
426         fn register_tx(&self, mut txid: &bitcoin::hash_types::Txid, mut script_pubkey: &bitcoin::blockdata::script::Script) {
427                 (self.register_tx)(self.this_arg, txid.as_inner(), crate::c_types::u8slice::from_slice(&script_pubkey[..]))
428         }
429         fn register_output(&self, mut output: lightning::chain::WatchedOutput) -> Option<(usize, bitcoin::blockdata::transaction::Transaction)> {
430                 let mut ret = (self.register_output)(self.this_arg, crate::lightning::chain::WatchedOutput { inner: Box::into_raw(Box::new(output)), is_owned: true });
431                 let mut local_ret = if ret.is_some() { Some( { let (mut orig_ret_0_0, mut orig_ret_0_1) = ret.take().to_rust(); let mut local_ret_0 = (orig_ret_0_0, orig_ret_0_1.into_bitcoin()); local_ret_0 }) } else { None };
432                 local_ret
433         }
434 }
435
436 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
437 // directly as a Deref trait in higher-level structs:
438 impl std::ops::Deref for Filter {
439         type Target = Self;
440         fn deref(&self) -> &Self {
441                 self
442         }
443 }
444 /// Calls the free function if one is set
445 #[no_mangle]
446 pub extern "C" fn Filter_free(this_ptr: Filter) { }
447 impl Drop for Filter {
448         fn drop(&mut self) {
449                 if let Some(f) = self.free {
450                         f(self.this_arg);
451                 }
452         }
453 }
454
455 use lightning::chain::WatchedOutput as nativeWatchedOutputImport;
456 type nativeWatchedOutput = nativeWatchedOutputImport;
457
458 /// A transaction output watched by a [`ChannelMonitor`] for spends on-chain.
459 ///
460 /// Used to convey to a [`Filter`] such an output with a given spending condition. Any transaction
461 /// spending the output must be given to [`ChannelMonitor::block_connected`] either directly or via
462 /// the return value of [`Filter::register_output`].
463 ///
464 /// If `block_hash` is `Some`, this indicates the output was created in the corresponding block and
465 /// may have been spent there. See [`Filter::register_output`] for details.
466 ///
467 /// [`ChannelMonitor`]: channelmonitor::ChannelMonitor
468 /// [`ChannelMonitor::block_connected`]: channelmonitor::ChannelMonitor::block_connected
469 #[must_use]
470 #[repr(C)]
471 pub struct WatchedOutput {
472         /// A pointer to the opaque Rust object.
473
474         /// Nearly everywhere, inner must be non-null, however in places where
475         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
476         pub inner: *mut nativeWatchedOutput,
477         /// Indicates that this is the only struct which contains the same pointer.
478
479         /// Rust functions which take ownership of an object provided via an argument require
480         /// this to be true and invalidate the object pointed to by inner.
481         pub is_owned: bool,
482 }
483
484 impl Drop for WatchedOutput {
485         fn drop(&mut self) {
486                 if self.is_owned && !<*mut nativeWatchedOutput>::is_null(self.inner) {
487                         let _ = unsafe { Box::from_raw(self.inner) };
488                 }
489         }
490 }
491 /// Frees any resources used by the WatchedOutput, if is_owned is set and inner is non-NULL.
492 #[no_mangle]
493 pub extern "C" fn WatchedOutput_free(this_obj: WatchedOutput) { }
494 #[allow(unused)]
495 /// Used only if an object of this type is returned as a trait impl by a method
496 extern "C" fn WatchedOutput_free_void(this_ptr: *mut c_void) {
497         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeWatchedOutput); }
498 }
499 #[allow(unused)]
500 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
501 impl WatchedOutput {
502         pub(crate) fn take_inner(mut self) -> *mut nativeWatchedOutput {
503                 assert!(self.is_owned);
504                 let ret = self.inner;
505                 self.inner = std::ptr::null_mut();
506                 ret
507         }
508 }
509 /// First block where the transaction output may have been spent.
510 #[no_mangle]
511 pub extern "C" fn WatchedOutput_get_block_hash(this_ptr: &WatchedOutput) -> crate::c_types::ThirtyTwoBytes {
512         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.block_hash;
513         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() } } };
514         local_inner_val
515 }
516 /// First block where the transaction output may have been spent.
517 #[no_mangle]
518 pub extern "C" fn WatchedOutput_set_block_hash(this_ptr: &mut WatchedOutput, mut val: crate::c_types::ThirtyTwoBytes) {
519         let mut local_val = if val.data == [0; 32] { None } else { Some( { ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap() }) };
520         unsafe { &mut *this_ptr.inner }.block_hash = local_val;
521 }
522 /// Outpoint identifying the transaction output.
523 #[no_mangle]
524 pub extern "C" fn WatchedOutput_get_outpoint(this_ptr: &WatchedOutput) -> crate::lightning::chain::transaction::OutPoint {
525         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.outpoint;
526         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
527 }
528 /// Outpoint identifying the transaction output.
529 #[no_mangle]
530 pub extern "C" fn WatchedOutput_set_outpoint(this_ptr: &mut WatchedOutput, mut val: crate::lightning::chain::transaction::OutPoint) {
531         unsafe { &mut *this_ptr.inner }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
532 }
533 /// Spending condition of the transaction output.
534 #[no_mangle]
535 pub extern "C" fn WatchedOutput_get_script_pubkey(this_ptr: &WatchedOutput) -> crate::c_types::u8slice {
536         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.script_pubkey;
537         crate::c_types::u8slice::from_slice(&inner_val[..])
538 }
539 /// Spending condition of the transaction output.
540 #[no_mangle]
541 pub extern "C" fn WatchedOutput_set_script_pubkey(this_ptr: &mut WatchedOutput, mut val: crate::c_types::derived::CVec_u8Z) {
542         unsafe { &mut *this_ptr.inner }.script_pubkey = ::bitcoin::blockdata::script::Script::from(val.into_rust());
543 }
544 /// Constructs a new WatchedOutput given each field
545 #[must_use]
546 #[no_mangle]
547 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 {
548         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() }) };
549         WatchedOutput { inner: Box::into_raw(Box::new(nativeWatchedOutput {
550                 block_hash: local_block_hash_arg,
551                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
552                 script_pubkey: ::bitcoin::blockdata::script::Script::from(script_pubkey_arg.into_rust()),
553         })), is_owned: true }
554 }