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