+
+use lightning::chain::WatchedOutput as nativeWatchedOutputImport;
+type nativeWatchedOutput = nativeWatchedOutputImport;
+
+/// A transaction output watched by a [`ChannelMonitor`] for spends on-chain.
+///
+/// Used to convey to a [`Filter`] such an output with a given spending condition. Any transaction
+/// spending the output must be given to [`ChannelMonitor::block_connected`] either directly or via
+/// the return value of [`Filter::register_output`].
+///
+/// If `block_hash` is `Some`, this indicates the output was created in the corresponding block and
+/// may have been spent there. See [`Filter::register_output`] for details.
+///
+/// [`ChannelMonitor`]: channelmonitor::ChannelMonitor
+/// [`ChannelMonitor::block_connected`]: channelmonitor::ChannelMonitor::block_connected
+#[must_use]
+#[repr(C)]
+pub struct WatchedOutput {
+ /// A pointer to the opaque Rust object.
+
+ /// Nearly everywhere, inner must be non-null, however in places where
+ /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+ pub inner: *mut nativeWatchedOutput,
+ /// Indicates that this is the only struct which contains the same pointer.
+
+ /// Rust functions which take ownership of an object provided via an argument require
+ /// this to be true and invalidate the object pointed to by inner.
+ pub is_owned: bool,
+}
+
+impl Drop for WatchedOutput {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeWatchedOutput>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(self.inner) };
+ }
+ }
+}
+/// Frees any resources used by the WatchedOutput, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_free(this_obj: WatchedOutput) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+extern "C" fn WatchedOutput_free_void(this_ptr: *mut c_void) {
+ unsafe { let _ = Box::from_raw(this_ptr as *mut nativeWatchedOutput); }
+}
+#[allow(unused)]
+/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+impl WatchedOutput {
+ pub(crate) fn take_inner(mut self) -> *mut nativeWatchedOutput {
+ assert!(self.is_owned);
+ let ret = self.inner;
+ self.inner = std::ptr::null_mut();
+ ret
+ }
+}
+/// First block where the transaction output may have been spent.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_get_block_hash(this_ptr: &WatchedOutput) -> crate::c_types::ThirtyTwoBytes {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.block_hash;
+ 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() } } };
+ local_inner_val
+}
+/// First block where the transaction output may have been spent.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_set_block_hash(this_ptr: &mut WatchedOutput, mut val: crate::c_types::ThirtyTwoBytes) {
+ let mut local_val = if val.data == [0; 32] { None } else { Some( { ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap() }) };
+ unsafe { &mut *this_ptr.inner }.block_hash = local_val;
+}
+/// Outpoint identifying the transaction output.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_get_outpoint(this_ptr: &WatchedOutput) -> crate::chain::transaction::OutPoint {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.outpoint;
+ crate::chain::transaction::OutPoint { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
+}
+/// Outpoint identifying the transaction output.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_set_outpoint(this_ptr: &mut WatchedOutput, mut val: crate::chain::transaction::OutPoint) {
+ unsafe { &mut *this_ptr.inner }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
+}
+/// Spending condition of the transaction output.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_get_script_pubkey(this_ptr: &WatchedOutput) -> crate::c_types::u8slice {
+ let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.script_pubkey;
+ crate::c_types::u8slice::from_slice(&(*inner_val)[..])
+}
+/// Spending condition of the transaction output.
+#[no_mangle]
+pub extern "C" fn WatchedOutput_set_script_pubkey(this_ptr: &mut WatchedOutput, mut val: crate::c_types::derived::CVec_u8Z) {
+ unsafe { &mut *this_ptr.inner }.script_pubkey = ::bitcoin::blockdata::script::Script::from(val.into_rust());
+}
+/// Constructs a new WatchedOutput given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn WatchedOutput_new(mut block_hash_arg: crate::c_types::ThirtyTwoBytes, mut outpoint_arg: crate::chain::transaction::OutPoint, mut script_pubkey_arg: crate::c_types::derived::CVec_u8Z) -> WatchedOutput {
+ 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() }) };
+ WatchedOutput { inner: Box::into_raw(Box::new(nativeWatchedOutput {
+ block_hash: local_block_hash_arg,
+ outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
+ script_pubkey: ::bitcoin::blockdata::script::Script::from(script_pubkey_arg.into_rust()),
+ })), is_owned: true }
+}