+/// A trait that describes a wallet capable of creating a spending [`Transaction`] from a set of
+/// [`SpendableOutputDescriptor`]s.
+#[repr(C)]
+pub struct OutputSpender {
+ /// An opaque pointer which is passed to your function implementations as an argument.
+ /// This has no meaning in the LDK, and can be NULL or any other value.
+ pub this_arg: *mut c_void,
+ /// Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
+ /// output to the given change destination (if sufficient change value remains). The
+ /// transaction will have a feerate, at least, of the given value.
+ ///
+ /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
+ /// transaction will have a locktime of 0. It it recommended to set this to the current block
+ /// height to avoid fee sniping, unless you have some specific reason to use a different
+ /// locktime.
+ ///
+ /// Returns `Err(())` if the output value is greater than the input value minus required fee,
+ /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
+ /// does not match the one we can spend.
+ pub spend_spendable_outputs: extern "C" fn (this_arg: *const c_void, descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, outputs: crate::c_types::derived::CVec_TxOutZ, change_destination_script: crate::c_types::derived::CVec_u8Z, feerate_sat_per_1000_weight: u32, locktime: crate::c_types::derived::COption_u32Z) -> crate::c_types::derived::CResult_TransactionNoneZ,
+ /// Frees any resources associated with this object given its this_arg pointer.
+ /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
+ pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
+}
+unsafe impl Send for OutputSpender {}
+unsafe impl Sync for OutputSpender {}
+#[allow(unused)]
+pub(crate) fn OutputSpender_clone_fields(orig: &OutputSpender) -> OutputSpender {
+ OutputSpender {
+ this_arg: orig.this_arg,
+ spend_spendable_outputs: Clone::clone(&orig.spend_spendable_outputs),
+ free: Clone::clone(&orig.free),
+ }
+}
+
+use lightning::sign::OutputSpender as rustOutputSpender;
+impl rustOutputSpender for OutputSpender {
+ fn spend_spendable_outputs<C:bitcoin::secp256k1::Signing>(&self, mut descriptors: &[&lightning::sign::SpendableOutputDescriptor], mut outputs: Vec<bitcoin::blockdata::transaction::TxOut>, mut change_destination_script: bitcoin::blockdata::script::ScriptBuf, mut feerate_sat_per_1000_weight: u32, mut locktime: Option<bitcoin::blockdata::locktime::absolute::LockTime>, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<C>) -> Result<bitcoin::blockdata::transaction::Transaction, ()> {
+ let mut local_descriptors = Vec::new(); for item in descriptors.iter() { local_descriptors.push( { crate::lightning::sign::SpendableOutputDescriptor::from_native((*item)) }); };
+ let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::c_types::TxOut::from_rust(&item) }); };
+ let mut local_locktime = if locktime.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { locktime.unwrap().to_consensus_u32() }) };
+ let mut ret = (self.spend_spendable_outputs)(self.this_arg, local_descriptors.into(), local_outputs.into(), change_destination_script.to_bytes().into(), feerate_sat_per_1000_weight, local_locktime);
+ let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_bitcoin() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
+ local_ret
+ }
+}
+
+// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
+// directly as a Deref trait in higher-level structs:
+impl core::ops::Deref for OutputSpender {
+ type Target = Self;
+ fn deref(&self) -> &Self {
+ self
+ }
+}
+impl core::ops::DerefMut for OutputSpender {
+ fn deref_mut(&mut self) -> &mut Self {
+ self
+ }
+}
+/// Calls the free function if one is set
+#[no_mangle]
+pub extern "C" fn OutputSpender_free(this_ptr: OutputSpender) { }
+impl Drop for OutputSpender {
+ fn drop(&mut self) {
+ if let Some(f) = self.free {
+ f(self.this_arg);
+ }
+ }
+}