Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / events / bump_transaction.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 //! Utilities for bumping transactions originating from [`Event`]s.
10 //!
11 //! [`Event`]: crate::events::Event
12
13 use alloc::str::FromStr;
14 use alloc::string::String;
15 use core::ffi::c_void;
16 use core::convert::Infallible;
17 use bitcoin::hashes::Hash;
18 use crate::c_types::*;
19 #[cfg(feature="no-std")]
20 use alloc::{vec::Vec, boxed::Box};
21
22
23 use lightning::events::bump_transaction::AnchorDescriptor as nativeAnchorDescriptorImport;
24 pub(crate) type nativeAnchorDescriptor = nativeAnchorDescriptorImport;
25
26 /// A descriptor used to sign for a commitment transaction's anchor output.
27 #[must_use]
28 #[repr(C)]
29 pub struct AnchorDescriptor {
30         /// A pointer to the opaque Rust object.
31
32         /// Nearly everywhere, inner must be non-null, however in places where
33         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
34         pub inner: *mut nativeAnchorDescriptor,
35         /// Indicates that this is the only struct which contains the same pointer.
36
37         /// Rust functions which take ownership of an object provided via an argument require
38         /// this to be true and invalidate the object pointed to by inner.
39         pub is_owned: bool,
40 }
41
42 impl Drop for AnchorDescriptor {
43         fn drop(&mut self) {
44                 if self.is_owned && !<*mut nativeAnchorDescriptor>::is_null(self.inner) {
45                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
46                 }
47         }
48 }
49 /// Frees any resources used by the AnchorDescriptor, if is_owned is set and inner is non-NULL.
50 #[no_mangle]
51 pub extern "C" fn AnchorDescriptor_free(this_obj: AnchorDescriptor) { }
52 #[allow(unused)]
53 /// Used only if an object of this type is returned as a trait impl by a method
54 pub(crate) extern "C" fn AnchorDescriptor_free_void(this_ptr: *mut c_void) {
55         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeAnchorDescriptor) };
56 }
57 #[allow(unused)]
58 impl AnchorDescriptor {
59         pub(crate) fn get_native_ref(&self) -> &'static nativeAnchorDescriptor {
60                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
61         }
62         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeAnchorDescriptor {
63                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
64         }
65         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
66         pub(crate) fn take_inner(mut self) -> *mut nativeAnchorDescriptor {
67                 assert!(self.is_owned);
68                 let ret = ObjOps::untweak_ptr(self.inner);
69                 self.inner = core::ptr::null_mut();
70                 ret
71         }
72 }
73 /// The parameters required to derive the signer for the anchor input.
74 #[no_mangle]
75 pub extern "C" fn AnchorDescriptor_get_channel_derivation_parameters(this_ptr: &AnchorDescriptor) -> crate::lightning::sign::ChannelDerivationParameters {
76         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters;
77         crate::lightning::sign::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::sign::ChannelDerivationParameters<>) as *mut _) }, is_owned: false }
78 }
79 /// The parameters required to derive the signer for the anchor input.
80 #[no_mangle]
81 pub extern "C" fn AnchorDescriptor_set_channel_derivation_parameters(this_ptr: &mut AnchorDescriptor, mut val: crate::lightning::sign::ChannelDerivationParameters) {
82         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) };
83 }
84 /// The transaction input's outpoint corresponding to the commitment transaction's anchor
85 /// output.
86 #[no_mangle]
87 pub extern "C" fn AnchorDescriptor_get_outpoint(this_ptr: &AnchorDescriptor) -> crate::lightning::chain::transaction::OutPoint {
88         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
89         crate::c_types::bitcoin_to_C_outpoint(inner_val)
90 }
91 /// The transaction input's outpoint corresponding to the commitment transaction's anchor
92 /// output.
93 #[no_mangle]
94 pub extern "C" fn AnchorDescriptor_set_outpoint(this_ptr: &mut AnchorDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
95         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
96 }
97 /// Constructs a new AnchorDescriptor given each field
98 #[must_use]
99 #[no_mangle]
100 pub extern "C" fn AnchorDescriptor_new(mut channel_derivation_parameters_arg: crate::lightning::sign::ChannelDerivationParameters, mut outpoint_arg: crate::lightning::chain::transaction::OutPoint) -> AnchorDescriptor {
101         AnchorDescriptor { inner: ObjOps::heap_alloc(nativeAnchorDescriptor {
102                 channel_derivation_parameters: *unsafe { Box::from_raw(channel_derivation_parameters_arg.take_inner()) },
103                 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
104         }), is_owned: true }
105 }
106 impl Clone for AnchorDescriptor {
107         fn clone(&self) -> Self {
108                 Self {
109                         inner: if <*mut nativeAnchorDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
110                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
111                         is_owned: true,
112                 }
113         }
114 }
115 #[allow(unused)]
116 /// Used only if an object of this type is returned as a trait impl by a method
117 pub(crate) extern "C" fn AnchorDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
118         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeAnchorDescriptor)).clone() })) as *mut c_void
119 }
120 #[no_mangle]
121 /// Creates a copy of the AnchorDescriptor
122 pub extern "C" fn AnchorDescriptor_clone(orig: &AnchorDescriptor) -> AnchorDescriptor {
123         orig.clone()
124 }
125 /// Get a string which allows debug introspection of a AnchorDescriptor object
126 pub extern "C" fn AnchorDescriptor_debug_str_void(o: *const c_void) -> Str {
127         alloc::format!("{:?}", unsafe { o as *const crate::lightning::events::bump_transaction::AnchorDescriptor }).into()}
128 /// Checks if two AnchorDescriptors contain equal inner contents.
129 /// This ignores pointers and is_owned flags and looks at the values in fields.
130 /// Two objects with NULL inner values will be considered "equal" here.
131 #[no_mangle]
132 pub extern "C" fn AnchorDescriptor_eq(a: &AnchorDescriptor, b: &AnchorDescriptor) -> bool {
133         if a.inner == b.inner { return true; }
134         if a.inner.is_null() || b.inner.is_null() { return false; }
135         if a.get_native_ref() == b.get_native_ref() { true } else { false }
136 }
137 /// Returns the UTXO to be spent by the anchor input, which can be obtained via
138 /// [`Self::unsigned_tx_input`].
139 #[must_use]
140 #[no_mangle]
141 pub extern "C" fn AnchorDescriptor_previous_utxo(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor) -> crate::c_types::TxOut {
142         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo();
143         crate::c_types::TxOut::from_rust(&ret)
144 }
145
146 /// Returns the unsigned transaction input spending the anchor output in the commitment
147 /// transaction.
148 #[must_use]
149 #[no_mangle]
150 pub extern "C" fn AnchorDescriptor_unsigned_tx_input(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor) -> crate::c_types::TxIn {
151         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input();
152         crate::c_types::TxIn::from_rust(&ret)
153 }
154
155 /// Returns the witness script of the anchor output in the commitment transaction.
156 #[must_use]
157 #[no_mangle]
158 pub extern "C" fn AnchorDescriptor_witness_script(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor) -> crate::c_types::derived::CVec_u8Z {
159         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script();
160         ret.to_bytes().into()
161 }
162
163 /// Returns the fully signed witness required to spend the anchor output in the commitment
164 /// transaction.
165 #[must_use]
166 #[no_mangle]
167 pub extern "C" fn AnchorDescriptor_tx_input_witness(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor, mut signature: crate::c_types::ECDSASignature) -> crate::c_types::Witness {
168         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_input_witness(&signature.into_rust());
169         crate::c_types::Witness::from_bitcoin(&ret)
170 }
171
172 /// Derives the channel signer required to sign the anchor input.
173 #[must_use]
174 #[no_mangle]
175 pub extern "C" fn AnchorDescriptor_derive_channel_signer(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor, signer_provider: &crate::lightning::sign::SignerProvider) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
176         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider);
177         Into::into(ret)
178 }
179
180 /// Represents the different types of transactions, originating from LDK, to be bumped.
181 #[derive(Clone)]
182 #[must_use]
183 #[repr(C)]
184 pub enum BumpTransactionEvent {
185         /// Indicates that a channel featuring anchor outputs is to be closed by broadcasting the local
186         /// commitment transaction. Since commitment transactions have a static feerate pre-agreed upon,
187         /// they may need additional fees to be attached through a child transaction using the popular
188         /// [Child-Pays-For-Parent](https://bitcoinops.org/en/topics/cpfp) fee bumping technique. This
189         /// child transaction must include the anchor input described within `anchor_descriptor` along
190         /// with additional inputs to meet the target feerate. Failure to meet the target feerate
191         /// decreases the confirmation odds of the transaction package (which includes the commitment
192         /// and child anchor transactions), possibly resulting in a loss of funds. Once the transaction
193         /// is constructed, it must be fully signed for and broadcast by the consumer of the event
194         /// along with the `commitment_tx` enclosed. Note that the `commitment_tx` must always be
195         /// broadcast first, as the child anchor transaction depends on it.
196         ///
197         /// The consumer should be able to sign for any of the additional inputs included within the
198         /// child anchor transaction. To sign its anchor input, an [`EcdsaChannelSigner`] should be
199         /// re-derived through [`AnchorDescriptor::derive_channel_signer`]. The anchor input signature
200         /// can be computed with [`EcdsaChannelSigner::sign_holder_anchor_input`], which can then be
201         /// provided to [`build_anchor_input_witness`] along with the `funding_pubkey` to obtain the
202         /// full witness required to spend.
203         ///
204         /// It is possible to receive more than one instance of this event if a valid child anchor
205         /// transaction is never broadcast or is but not with a sufficient fee to be mined. Care should
206         /// be taken by the consumer of the event to ensure any future iterations of the child anchor
207         /// transaction adhere to the [Replace-By-Fee
208         /// rules](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md)
209         /// for fee bumps to be accepted into the mempool, and eventually the chain. As the frequency of
210         /// these events is not user-controlled, users may ignore/drop the event if they are no longer
211         /// able to commit external confirmed funds to the child anchor transaction.
212         ///
213         /// The set of `pending_htlcs` on the commitment transaction to be broadcast can be inspected to
214         /// determine whether a significant portion of the channel's funds are allocated to HTLCs,
215         /// enabling users to make their own decisions regarding the importance of the commitment
216         /// transaction's confirmation. Note that this is not required, but simply exists as an option
217         /// for users to override LDK's behavior. On commitments with no HTLCs (indicated by those with
218         /// an empty `pending_htlcs`), confirmation of the commitment transaction can be considered to
219         /// be not urgent.
220         ///
221         /// [`EcdsaChannelSigner`]: crate::sign::ecdsa::EcdsaChannelSigner
222         /// [`EcdsaChannelSigner::sign_holder_anchor_input`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_holder_anchor_input
223         /// [`build_anchor_input_witness`]: crate::ln::chan_utils::build_anchor_input_witness
224         ChannelClose {
225                 /// The `channel_id` of the channel which has been closed.
226                 channel_id: crate::lightning::ln::types::ChannelId,
227                 /// Counterparty in the closed channel.
228                 counterparty_node_id: crate::c_types::PublicKey,
229                 /// The unique identifier for the claim of the anchor output in the commitment transaction.
230                 ///
231                 /// The identifier must map to the set of external UTXOs assigned to the claim, such that
232                 /// they can be reused when a new claim with the same identifier needs to be made, resulting
233                 /// in a fee-bumping attempt.
234                 claim_id: crate::c_types::ThirtyTwoBytes,
235                 /// The target feerate that the transaction package, which consists of the commitment
236                 /// transaction and the to-be-crafted child anchor transaction, must meet.
237                 package_target_feerate_sat_per_1000_weight: u32,
238                 /// The channel's commitment transaction to bump the fee of. This transaction should be
239                 /// broadcast along with the anchor transaction constructed as a result of consuming this
240                 /// event.
241                 commitment_tx: crate::c_types::Transaction,
242                 /// The absolute fee in satoshis of the commitment transaction. This can be used along the
243                 /// with weight of the commitment transaction to determine its feerate.
244                 commitment_tx_fee_satoshis: u64,
245                 /// The descriptor to sign the anchor input of the anchor transaction constructed as a
246                 /// result of consuming this event.
247                 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor,
248                 /// The set of pending HTLCs on the commitment transaction that need to be resolved once the
249                 /// commitment transaction confirms.
250                 pending_htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ,
251         },
252         /// Indicates that a channel featuring anchor outputs has unilaterally closed on-chain by a
253         /// holder commitment transaction and its HTLC(s) need to be resolved on-chain. With the
254         /// zero-HTLC-transaction-fee variant of anchor outputs, the pre-signed HTLC
255         /// transactions have a zero fee, thus requiring additional inputs and/or outputs to be attached
256         /// for a timely confirmation within the chain. These additional inputs and/or outputs must be
257         /// appended to the resulting HTLC transaction to meet the target feerate. Failure to meet the
258         /// target feerate decreases the confirmation odds of the transaction, possibly resulting in a
259         /// loss of funds. Once the transaction meets the target feerate, it must be signed for and
260         /// broadcast by the consumer of the event.
261         ///
262         /// The consumer should be able to sign for any of the non-HTLC inputs added to the resulting
263         /// HTLC transaction. To sign HTLC inputs, an [`EcdsaChannelSigner`] should be re-derived
264         /// through [`HTLCDescriptor::derive_channel_signer`]. Each HTLC input's signature can be
265         /// computed with [`EcdsaChannelSigner::sign_holder_htlc_transaction`], which can then be
266         /// provided to [`HTLCDescriptor::tx_input_witness`] to obtain the fully signed witness required
267         /// to spend.
268         ///
269         /// It is possible to receive more than one instance of this event if a valid HTLC transaction
270         /// is never broadcast or is but not with a sufficient fee to be mined. Care should be taken by
271         /// the consumer of the event to ensure any future iterations of the HTLC transaction adhere to
272         /// the [Replace-By-Fee
273         /// rules](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md)
274         /// for fee bumps to be accepted into the mempool, and eventually the chain. As the frequency of
275         /// these events is not user-controlled, users may ignore/drop the event if either they are no
276         /// longer able to commit external confirmed funds to the HTLC transaction or the fee committed
277         /// to the HTLC transaction is greater in value than the HTLCs being claimed.
278         ///
279         /// [`EcdsaChannelSigner`]: crate::sign::ecdsa::EcdsaChannelSigner
280         /// [`EcdsaChannelSigner::sign_holder_htlc_transaction`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_holder_htlc_transaction
281         HTLCResolution {
282                 /// The `channel_id` of the channel which has been closed.
283                 channel_id: crate::lightning::ln::types::ChannelId,
284                 /// Counterparty in the closed channel.
285                 counterparty_node_id: crate::c_types::PublicKey,
286                 /// The unique identifier for the claim of the HTLCs in the confirmed commitment
287                 /// transaction.
288                 ///
289                 /// The identifier must map to the set of external UTXOs assigned to the claim, such that
290                 /// they can be reused when a new claim with the same identifier needs to be made, resulting
291                 /// in a fee-bumping attempt.
292                 claim_id: crate::c_types::ThirtyTwoBytes,
293                 /// The target feerate that the resulting HTLC transaction must meet.
294                 target_feerate_sat_per_1000_weight: u32,
295                 /// The set of pending HTLCs on the confirmed commitment that need to be claimed, preferably
296                 /// by the same transaction.
297                 htlc_descriptors: crate::c_types::derived::CVec_HTLCDescriptorZ,
298                 /// The locktime required for the resulting HTLC transaction.
299                 tx_lock_time: u32,
300         },
301 }
302 use lightning::events::bump_transaction::BumpTransactionEvent as BumpTransactionEventImport;
303 pub(crate) type nativeBumpTransactionEvent = BumpTransactionEventImport;
304
305 impl BumpTransactionEvent {
306         #[allow(unused)]
307         pub(crate) fn to_native(&self) -> nativeBumpTransactionEvent {
308                 match self {
309                         BumpTransactionEvent::ChannelClose {ref channel_id, ref counterparty_node_id, ref claim_id, ref package_target_feerate_sat_per_1000_weight, ref commitment_tx, ref commitment_tx_fee_satoshis, ref anchor_descriptor, ref pending_htlcs, } => {
310                                 let mut channel_id_nonref = Clone::clone(channel_id);
311                                 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
312                                 let mut claim_id_nonref = Clone::clone(claim_id);
313                                 let mut package_target_feerate_sat_per_1000_weight_nonref = Clone::clone(package_target_feerate_sat_per_1000_weight);
314                                 let mut commitment_tx_nonref = Clone::clone(commitment_tx);
315                                 let mut commitment_tx_fee_satoshis_nonref = Clone::clone(commitment_tx_fee_satoshis);
316                                 let mut anchor_descriptor_nonref = Clone::clone(anchor_descriptor);
317                                 let mut pending_htlcs_nonref = Clone::clone(pending_htlcs);
318                                 let mut local_pending_htlcs_nonref = Vec::new(); for mut item in pending_htlcs_nonref.into_rust().drain(..) { local_pending_htlcs_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
319                                 nativeBumpTransactionEvent::ChannelClose {
320                                         channel_id: *unsafe { Box::from_raw(channel_id_nonref.take_inner()) },
321                                         counterparty_node_id: counterparty_node_id_nonref.into_rust(),
322                                         claim_id: ::lightning::chain::ClaimId(claim_id_nonref.data),
323                                         package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight_nonref,
324                                         commitment_tx: commitment_tx_nonref.into_bitcoin(),
325                                         commitment_tx_fee_satoshis: commitment_tx_fee_satoshis_nonref,
326                                         anchor_descriptor: *unsafe { Box::from_raw(anchor_descriptor_nonref.take_inner()) },
327                                         pending_htlcs: local_pending_htlcs_nonref,
328                                 }
329                         },
330                         BumpTransactionEvent::HTLCResolution {ref channel_id, ref counterparty_node_id, ref claim_id, ref target_feerate_sat_per_1000_weight, ref htlc_descriptors, ref tx_lock_time, } => {
331                                 let mut channel_id_nonref = Clone::clone(channel_id);
332                                 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
333                                 let mut claim_id_nonref = Clone::clone(claim_id);
334                                 let mut target_feerate_sat_per_1000_weight_nonref = Clone::clone(target_feerate_sat_per_1000_weight);
335                                 let mut htlc_descriptors_nonref = Clone::clone(htlc_descriptors);
336                                 let mut local_htlc_descriptors_nonref = Vec::new(); for mut item in htlc_descriptors_nonref.into_rust().drain(..) { local_htlc_descriptors_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
337                                 let mut tx_lock_time_nonref = Clone::clone(tx_lock_time);
338                                 nativeBumpTransactionEvent::HTLCResolution {
339                                         channel_id: *unsafe { Box::from_raw(channel_id_nonref.take_inner()) },
340                                         counterparty_node_id: counterparty_node_id_nonref.into_rust(),
341                                         claim_id: ::lightning::chain::ClaimId(claim_id_nonref.data),
342                                         target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight_nonref,
343                                         htlc_descriptors: local_htlc_descriptors_nonref,
344                                         tx_lock_time: ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus(tx_lock_time_nonref),
345                                 }
346                         },
347                 }
348         }
349         #[allow(unused)]
350         pub(crate) fn into_native(self) -> nativeBumpTransactionEvent {
351                 match self {
352                         BumpTransactionEvent::ChannelClose {mut channel_id, mut counterparty_node_id, mut claim_id, mut package_target_feerate_sat_per_1000_weight, mut commitment_tx, mut commitment_tx_fee_satoshis, mut anchor_descriptor, mut pending_htlcs, } => {
353                                 let mut local_pending_htlcs = Vec::new(); for mut item in pending_htlcs.into_rust().drain(..) { local_pending_htlcs.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
354                                 nativeBumpTransactionEvent::ChannelClose {
355                                         channel_id: *unsafe { Box::from_raw(channel_id.take_inner()) },
356                                         counterparty_node_id: counterparty_node_id.into_rust(),
357                                         claim_id: ::lightning::chain::ClaimId(claim_id.data),
358                                         package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight,
359                                         commitment_tx: commitment_tx.into_bitcoin(),
360                                         commitment_tx_fee_satoshis: commitment_tx_fee_satoshis,
361                                         anchor_descriptor: *unsafe { Box::from_raw(anchor_descriptor.take_inner()) },
362                                         pending_htlcs: local_pending_htlcs,
363                                 }
364                         },
365                         BumpTransactionEvent::HTLCResolution {mut channel_id, mut counterparty_node_id, mut claim_id, mut target_feerate_sat_per_1000_weight, mut htlc_descriptors, mut tx_lock_time, } => {
366                                 let mut local_htlc_descriptors = Vec::new(); for mut item in htlc_descriptors.into_rust().drain(..) { local_htlc_descriptors.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
367                                 nativeBumpTransactionEvent::HTLCResolution {
368                                         channel_id: *unsafe { Box::from_raw(channel_id.take_inner()) },
369                                         counterparty_node_id: counterparty_node_id.into_rust(),
370                                         claim_id: ::lightning::chain::ClaimId(claim_id.data),
371                                         target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight,
372                                         htlc_descriptors: local_htlc_descriptors,
373                                         tx_lock_time: ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus(tx_lock_time),
374                                 }
375                         },
376                 }
377         }
378         #[allow(unused)]
379         pub(crate) fn from_native(native: &BumpTransactionEventImport) -> Self {
380                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBumpTransactionEvent) };
381                 match native {
382                         nativeBumpTransactionEvent::ChannelClose {ref channel_id, ref counterparty_node_id, ref claim_id, ref package_target_feerate_sat_per_1000_weight, ref commitment_tx, ref commitment_tx_fee_satoshis, ref anchor_descriptor, ref pending_htlcs, } => {
383                                 let mut channel_id_nonref = Clone::clone(channel_id);
384                                 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
385                                 let mut claim_id_nonref = Clone::clone(claim_id);
386                                 let mut package_target_feerate_sat_per_1000_weight_nonref = Clone::clone(package_target_feerate_sat_per_1000_weight);
387                                 let mut commitment_tx_nonref = Clone::clone(commitment_tx);
388                                 let mut commitment_tx_fee_satoshis_nonref = Clone::clone(commitment_tx_fee_satoshis);
389                                 let mut anchor_descriptor_nonref = Clone::clone(anchor_descriptor);
390                                 let mut pending_htlcs_nonref = Clone::clone(pending_htlcs);
391                                 let mut local_pending_htlcs_nonref = Vec::new(); for mut item in pending_htlcs_nonref.drain(..) { local_pending_htlcs_nonref.push( { crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
392                                 BumpTransactionEvent::ChannelClose {
393                                         channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id_nonref), is_owned: true },
394                                         counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
395                                         claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id_nonref.0 },
396                                         package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight_nonref,
397                                         commitment_tx: crate::c_types::Transaction::from_bitcoin(&commitment_tx_nonref),
398                                         commitment_tx_fee_satoshis: commitment_tx_fee_satoshis_nonref,
399                                         anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor { inner: ObjOps::heap_alloc(anchor_descriptor_nonref), is_owned: true },
400                                         pending_htlcs: local_pending_htlcs_nonref.into(),
401                                 }
402                         },
403                         nativeBumpTransactionEvent::HTLCResolution {ref channel_id, ref counterparty_node_id, ref claim_id, ref target_feerate_sat_per_1000_weight, ref htlc_descriptors, ref tx_lock_time, } => {
404                                 let mut channel_id_nonref = Clone::clone(channel_id);
405                                 let mut counterparty_node_id_nonref = Clone::clone(counterparty_node_id);
406                                 let mut claim_id_nonref = Clone::clone(claim_id);
407                                 let mut target_feerate_sat_per_1000_weight_nonref = Clone::clone(target_feerate_sat_per_1000_weight);
408                                 let mut htlc_descriptors_nonref = Clone::clone(htlc_descriptors);
409                                 let mut local_htlc_descriptors_nonref = Vec::new(); for mut item in htlc_descriptors_nonref.drain(..) { local_htlc_descriptors_nonref.push( { crate::lightning::sign::HTLCDescriptor { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
410                                 let mut tx_lock_time_nonref = Clone::clone(tx_lock_time);
411                                 BumpTransactionEvent::HTLCResolution {
412                                         channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id_nonref), is_owned: true },
413                                         counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
414                                         claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id_nonref.0 },
415                                         target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight_nonref,
416                                         htlc_descriptors: local_htlc_descriptors_nonref.into(),
417                                         tx_lock_time: tx_lock_time_nonref.to_consensus_u32(),
418                                 }
419                         },
420                 }
421         }
422         #[allow(unused)]
423         pub(crate) fn native_into(native: nativeBumpTransactionEvent) -> Self {
424                 match native {
425                         nativeBumpTransactionEvent::ChannelClose {mut channel_id, mut counterparty_node_id, mut claim_id, mut package_target_feerate_sat_per_1000_weight, mut commitment_tx, mut commitment_tx_fee_satoshis, mut anchor_descriptor, mut pending_htlcs, } => {
426                                 let mut local_pending_htlcs = Vec::new(); for mut item in pending_htlcs.drain(..) { local_pending_htlcs.push( { crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
427                                 BumpTransactionEvent::ChannelClose {
428                                         channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id), is_owned: true },
429                                         counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
430                                         claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id.0 },
431                                         package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight,
432                                         commitment_tx: crate::c_types::Transaction::from_bitcoin(&commitment_tx),
433                                         commitment_tx_fee_satoshis: commitment_tx_fee_satoshis,
434                                         anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor { inner: ObjOps::heap_alloc(anchor_descriptor), is_owned: true },
435                                         pending_htlcs: local_pending_htlcs.into(),
436                                 }
437                         },
438                         nativeBumpTransactionEvent::HTLCResolution {mut channel_id, mut counterparty_node_id, mut claim_id, mut target_feerate_sat_per_1000_weight, mut htlc_descriptors, mut tx_lock_time, } => {
439                                 let mut local_htlc_descriptors = Vec::new(); for mut item in htlc_descriptors.drain(..) { local_htlc_descriptors.push( { crate::lightning::sign::HTLCDescriptor { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
440                                 BumpTransactionEvent::HTLCResolution {
441                                         channel_id: crate::lightning::ln::types::ChannelId { inner: ObjOps::heap_alloc(channel_id), is_owned: true },
442                                         counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
443                                         claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id.0 },
444                                         target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight,
445                                         htlc_descriptors: local_htlc_descriptors.into(),
446                                         tx_lock_time: tx_lock_time.to_consensus_u32(),
447                                 }
448                         },
449                 }
450         }
451 }
452 /// Frees any resources used by the BumpTransactionEvent
453 #[no_mangle]
454 pub extern "C" fn BumpTransactionEvent_free(this_ptr: BumpTransactionEvent) { }
455 /// Creates a copy of the BumpTransactionEvent
456 #[no_mangle]
457 pub extern "C" fn BumpTransactionEvent_clone(orig: &BumpTransactionEvent) -> BumpTransactionEvent {
458         orig.clone()
459 }
460 #[allow(unused)]
461 /// Used only if an object of this type is returned as a trait impl by a method
462 pub(crate) extern "C" fn BumpTransactionEvent_clone_void(this_ptr: *const c_void) -> *mut c_void {
463         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const BumpTransactionEvent)).clone() })) as *mut c_void
464 }
465 #[allow(unused)]
466 /// Used only if an object of this type is returned as a trait impl by a method
467 pub(crate) extern "C" fn BumpTransactionEvent_free_void(this_ptr: *mut c_void) {
468         let _ = unsafe { Box::from_raw(this_ptr as *mut BumpTransactionEvent) };
469 }
470 #[no_mangle]
471 /// Utility method to constructs a new ChannelClose-variant BumpTransactionEvent
472 pub extern "C" fn BumpTransactionEvent_channel_close(channel_id: crate::lightning::ln::types::ChannelId, counterparty_node_id: crate::c_types::PublicKey, claim_id: crate::c_types::ThirtyTwoBytes, package_target_feerate_sat_per_1000_weight: u32, commitment_tx: crate::c_types::Transaction, commitment_tx_fee_satoshis: u64, anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor, pending_htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ) -> BumpTransactionEvent {
473         BumpTransactionEvent::ChannelClose {
474                 channel_id,
475                 counterparty_node_id,
476                 claim_id,
477                 package_target_feerate_sat_per_1000_weight,
478                 commitment_tx,
479                 commitment_tx_fee_satoshis,
480                 anchor_descriptor,
481                 pending_htlcs,
482         }
483 }
484 #[no_mangle]
485 /// Utility method to constructs a new HTLCResolution-variant BumpTransactionEvent
486 pub extern "C" fn BumpTransactionEvent_htlcresolution(channel_id: crate::lightning::ln::types::ChannelId, counterparty_node_id: crate::c_types::PublicKey, claim_id: crate::c_types::ThirtyTwoBytes, target_feerate_sat_per_1000_weight: u32, htlc_descriptors: crate::c_types::derived::CVec_HTLCDescriptorZ, tx_lock_time: u32) -> BumpTransactionEvent {
487         BumpTransactionEvent::HTLCResolution {
488                 channel_id,
489                 counterparty_node_id,
490                 claim_id,
491                 target_feerate_sat_per_1000_weight,
492                 htlc_descriptors,
493                 tx_lock_time,
494         }
495 }
496 /// Get a string which allows debug introspection of a BumpTransactionEvent object
497 pub extern "C" fn BumpTransactionEvent_debug_str_void(o: *const c_void) -> Str {
498         alloc::format!("{:?}", unsafe { o as *const crate::lightning::events::bump_transaction::BumpTransactionEvent }).into()}
499 /// Checks if two BumpTransactionEvents contain equal inner contents.
500 /// This ignores pointers and is_owned flags and looks at the values in fields.
501 #[no_mangle]
502 pub extern "C" fn BumpTransactionEvent_eq(a: &BumpTransactionEvent, b: &BumpTransactionEvent) -> bool {
503         if &a.to_native() == &b.to_native() { true } else { false }
504 }
505
506 use lightning::events::bump_transaction::Input as nativeInputImport;
507 pub(crate) type nativeInput = nativeInputImport;
508
509 /// An input that must be included in a transaction when performing coin selection through
510 /// [`CoinSelectionSource::select_confirmed_utxos`]. It is guaranteed to be a SegWit input, so it
511 /// must have an empty [`TxIn::script_sig`] when spent.
512 #[must_use]
513 #[repr(C)]
514 pub struct Input {
515         /// A pointer to the opaque Rust object.
516
517         /// Nearly everywhere, inner must be non-null, however in places where
518         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
519         pub inner: *mut nativeInput,
520         /// Indicates that this is the only struct which contains the same pointer.
521
522         /// Rust functions which take ownership of an object provided via an argument require
523         /// this to be true and invalidate the object pointed to by inner.
524         pub is_owned: bool,
525 }
526
527 impl Drop for Input {
528         fn drop(&mut self) {
529                 if self.is_owned && !<*mut nativeInput>::is_null(self.inner) {
530                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
531                 }
532         }
533 }
534 /// Frees any resources used by the Input, if is_owned is set and inner is non-NULL.
535 #[no_mangle]
536 pub extern "C" fn Input_free(this_obj: Input) { }
537 #[allow(unused)]
538 /// Used only if an object of this type is returned as a trait impl by a method
539 pub(crate) extern "C" fn Input_free_void(this_ptr: *mut c_void) {
540         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInput) };
541 }
542 #[allow(unused)]
543 impl Input {
544         pub(crate) fn get_native_ref(&self) -> &'static nativeInput {
545                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
546         }
547         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInput {
548                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
549         }
550         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
551         pub(crate) fn take_inner(mut self) -> *mut nativeInput {
552                 assert!(self.is_owned);
553                 let ret = ObjOps::untweak_ptr(self.inner);
554                 self.inner = core::ptr::null_mut();
555                 ret
556         }
557 }
558 /// The unique identifier of the input.
559 #[no_mangle]
560 pub extern "C" fn Input_get_outpoint(this_ptr: &Input) -> crate::lightning::chain::transaction::OutPoint {
561         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
562         crate::c_types::bitcoin_to_C_outpoint(inner_val)
563 }
564 /// The unique identifier of the input.
565 #[no_mangle]
566 pub extern "C" fn Input_set_outpoint(this_ptr: &mut Input, mut val: crate::lightning::chain::transaction::OutPoint) {
567         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
568 }
569 /// The UTXO being spent by the input.
570 #[no_mangle]
571 pub extern "C" fn Input_get_previous_utxo(this_ptr: &Input) -> crate::c_types::TxOut {
572         let mut inner_val = &mut this_ptr.get_native_mut_ref().previous_utxo;
573         crate::c_types::TxOut::from_rust(inner_val)
574 }
575 /// The UTXO being spent by the input.
576 #[no_mangle]
577 pub extern "C" fn Input_set_previous_utxo(this_ptr: &mut Input, mut val: crate::c_types::TxOut) {
578         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previous_utxo = val.into_rust();
579 }
580 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
581 /// [`TxIn::witness`], each with their lengths included, required to satisfy the output's
582 /// script.
583 #[no_mangle]
584 pub extern "C" fn Input_get_satisfaction_weight(this_ptr: &Input) -> u64 {
585         let mut inner_val = &mut this_ptr.get_native_mut_ref().satisfaction_weight;
586         *inner_val
587 }
588 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
589 /// [`TxIn::witness`], each with their lengths included, required to satisfy the output's
590 /// script.
591 #[no_mangle]
592 pub extern "C" fn Input_set_satisfaction_weight(this_ptr: &mut Input, mut val: u64) {
593         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.satisfaction_weight = val;
594 }
595 /// Constructs a new Input given each field
596 #[must_use]
597 #[no_mangle]
598 pub extern "C" fn Input_new(mut outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut previous_utxo_arg: crate::c_types::TxOut, mut satisfaction_weight_arg: u64) -> Input {
599         Input { inner: ObjOps::heap_alloc(nativeInput {
600                 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
601                 previous_utxo: previous_utxo_arg.into_rust(),
602                 satisfaction_weight: satisfaction_weight_arg,
603         }), is_owned: true }
604 }
605 impl Clone for Input {
606         fn clone(&self) -> Self {
607                 Self {
608                         inner: if <*mut nativeInput>::is_null(self.inner) { core::ptr::null_mut() } else {
609                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
610                         is_owned: true,
611                 }
612         }
613 }
614 #[allow(unused)]
615 /// Used only if an object of this type is returned as a trait impl by a method
616 pub(crate) extern "C" fn Input_clone_void(this_ptr: *const c_void) -> *mut c_void {
617         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInput)).clone() })) as *mut c_void
618 }
619 #[no_mangle]
620 /// Creates a copy of the Input
621 pub extern "C" fn Input_clone(orig: &Input) -> Input {
622         orig.clone()
623 }
624 /// Get a string which allows debug introspection of a Input object
625 pub extern "C" fn Input_debug_str_void(o: *const c_void) -> Str {
626         alloc::format!("{:?}", unsafe { o as *const crate::lightning::events::bump_transaction::Input }).into()}
627 /// Generates a non-cryptographic 64-bit hash of the Input.
628 #[no_mangle]
629 pub extern "C" fn Input_hash(o: &Input) -> u64 {
630         if o.inner.is_null() { return 0; }
631         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
632         #[allow(deprecated)]
633         let mut hasher = core::hash::SipHasher::new();
634         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
635         core::hash::Hasher::finish(&hasher)
636 }
637 /// Checks if two Inputs contain equal inner contents.
638 /// This ignores pointers and is_owned flags and looks at the values in fields.
639 /// Two objects with NULL inner values will be considered "equal" here.
640 #[no_mangle]
641 pub extern "C" fn Input_eq(a: &Input, b: &Input) -> bool {
642         if a.inner == b.inner { return true; }
643         if a.inner.is_null() || b.inner.is_null() { return false; }
644         if a.get_native_ref() == b.get_native_ref() { true } else { false }
645 }
646
647 use lightning::events::bump_transaction::Utxo as nativeUtxoImport;
648 pub(crate) type nativeUtxo = nativeUtxoImport;
649
650 /// An unspent transaction output that is available to spend resulting from a successful
651 /// [`CoinSelection`] attempt.
652 #[must_use]
653 #[repr(C)]
654 pub struct Utxo {
655         /// A pointer to the opaque Rust object.
656
657         /// Nearly everywhere, inner must be non-null, however in places where
658         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
659         pub inner: *mut nativeUtxo,
660         /// Indicates that this is the only struct which contains the same pointer.
661
662         /// Rust functions which take ownership of an object provided via an argument require
663         /// this to be true and invalidate the object pointed to by inner.
664         pub is_owned: bool,
665 }
666
667 impl Drop for Utxo {
668         fn drop(&mut self) {
669                 if self.is_owned && !<*mut nativeUtxo>::is_null(self.inner) {
670                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
671                 }
672         }
673 }
674 /// Frees any resources used by the Utxo, if is_owned is set and inner is non-NULL.
675 #[no_mangle]
676 pub extern "C" fn Utxo_free(this_obj: Utxo) { }
677 #[allow(unused)]
678 /// Used only if an object of this type is returned as a trait impl by a method
679 pub(crate) extern "C" fn Utxo_free_void(this_ptr: *mut c_void) {
680         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUtxo) };
681 }
682 #[allow(unused)]
683 impl Utxo {
684         pub(crate) fn get_native_ref(&self) -> &'static nativeUtxo {
685                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
686         }
687         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUtxo {
688                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
689         }
690         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
691         pub(crate) fn take_inner(mut self) -> *mut nativeUtxo {
692                 assert!(self.is_owned);
693                 let ret = ObjOps::untweak_ptr(self.inner);
694                 self.inner = core::ptr::null_mut();
695                 ret
696         }
697 }
698 /// The unique identifier of the output.
699 #[no_mangle]
700 pub extern "C" fn Utxo_get_outpoint(this_ptr: &Utxo) -> crate::lightning::chain::transaction::OutPoint {
701         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
702         crate::c_types::bitcoin_to_C_outpoint(inner_val)
703 }
704 /// The unique identifier of the output.
705 #[no_mangle]
706 pub extern "C" fn Utxo_set_outpoint(this_ptr: &mut Utxo, mut val: crate::lightning::chain::transaction::OutPoint) {
707         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
708 }
709 /// The output to spend.
710 #[no_mangle]
711 pub extern "C" fn Utxo_get_output(this_ptr: &Utxo) -> crate::c_types::TxOut {
712         let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
713         crate::c_types::TxOut::from_rust(inner_val)
714 }
715 /// The output to spend.
716 #[no_mangle]
717 pub extern "C" fn Utxo_set_output(this_ptr: &mut Utxo, mut val: crate::c_types::TxOut) {
718         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
719 }
720 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
721 /// with their lengths included, required to satisfy the output's script. The weight consumed by
722 /// the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
723 #[no_mangle]
724 pub extern "C" fn Utxo_get_satisfaction_weight(this_ptr: &Utxo) -> u64 {
725         let mut inner_val = &mut this_ptr.get_native_mut_ref().satisfaction_weight;
726         *inner_val
727 }
728 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
729 /// with their lengths included, required to satisfy the output's script. The weight consumed by
730 /// the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
731 #[no_mangle]
732 pub extern "C" fn Utxo_set_satisfaction_weight(this_ptr: &mut Utxo, mut val: u64) {
733         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.satisfaction_weight = val;
734 }
735 /// Constructs a new Utxo given each field
736 #[must_use]
737 #[no_mangle]
738 pub extern "C" fn Utxo_new(mut outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut output_arg: crate::c_types::TxOut, mut satisfaction_weight_arg: u64) -> Utxo {
739         Utxo { inner: ObjOps::heap_alloc(nativeUtxo {
740                 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
741                 output: output_arg.into_rust(),
742                 satisfaction_weight: satisfaction_weight_arg,
743         }), is_owned: true }
744 }
745 impl Clone for Utxo {
746         fn clone(&self) -> Self {
747                 Self {
748                         inner: if <*mut nativeUtxo>::is_null(self.inner) { core::ptr::null_mut() } else {
749                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
750                         is_owned: true,
751                 }
752         }
753 }
754 #[allow(unused)]
755 /// Used only if an object of this type is returned as a trait impl by a method
756 pub(crate) extern "C" fn Utxo_clone_void(this_ptr: *const c_void) -> *mut c_void {
757         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUtxo)).clone() })) as *mut c_void
758 }
759 #[no_mangle]
760 /// Creates a copy of the Utxo
761 pub extern "C" fn Utxo_clone(orig: &Utxo) -> Utxo {
762         orig.clone()
763 }
764 /// Get a string which allows debug introspection of a Utxo object
765 pub extern "C" fn Utxo_debug_str_void(o: *const c_void) -> Str {
766         alloc::format!("{:?}", unsafe { o as *const crate::lightning::events::bump_transaction::Utxo }).into()}
767 /// Generates a non-cryptographic 64-bit hash of the Utxo.
768 #[no_mangle]
769 pub extern "C" fn Utxo_hash(o: &Utxo) -> u64 {
770         if o.inner.is_null() { return 0; }
771         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
772         #[allow(deprecated)]
773         let mut hasher = core::hash::SipHasher::new();
774         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
775         core::hash::Hasher::finish(&hasher)
776 }
777 /// Checks if two Utxos contain equal inner contents.
778 /// This ignores pointers and is_owned flags and looks at the values in fields.
779 /// Two objects with NULL inner values will be considered "equal" here.
780 #[no_mangle]
781 pub extern "C" fn Utxo_eq(a: &Utxo, b: &Utxo) -> bool {
782         if a.inner == b.inner { return true; }
783         if a.inner.is_null() || b.inner.is_null() { return false; }
784         if a.get_native_ref() == b.get_native_ref() { true } else { false }
785 }
786 /// Returns a `Utxo` with the `satisfaction_weight` estimate for a legacy P2PKH output.
787 #[must_use]
788 #[no_mangle]
789 pub extern "C" fn Utxo_new_p2pkh(mut outpoint: crate::lightning::chain::transaction::OutPoint, mut value: u64, pubkey_hash: *const [u8; 20]) -> crate::lightning::events::bump_transaction::Utxo {
790         let mut ret = lightning::events::bump_transaction::Utxo::new_p2pkh(crate::c_types::C_to_bitcoin_outpoint(outpoint), value, &bitcoin::hash_types::PubkeyHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(unsafe { *pubkey_hash }.clone())));
791         crate::lightning::events::bump_transaction::Utxo { inner: ObjOps::heap_alloc(ret), is_owned: true }
792 }
793
794
795 use lightning::events::bump_transaction::CoinSelection as nativeCoinSelectionImport;
796 pub(crate) type nativeCoinSelection = nativeCoinSelectionImport;
797
798 /// The result of a successful coin selection attempt for a transaction requiring additional UTXOs
799 /// to cover its fees.
800 #[must_use]
801 #[repr(C)]
802 pub struct CoinSelection {
803         /// A pointer to the opaque Rust object.
804
805         /// Nearly everywhere, inner must be non-null, however in places where
806         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
807         pub inner: *mut nativeCoinSelection,
808         /// Indicates that this is the only struct which contains the same pointer.
809
810         /// Rust functions which take ownership of an object provided via an argument require
811         /// this to be true and invalidate the object pointed to by inner.
812         pub is_owned: bool,
813 }
814
815 impl Drop for CoinSelection {
816         fn drop(&mut self) {
817                 if self.is_owned && !<*mut nativeCoinSelection>::is_null(self.inner) {
818                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
819                 }
820         }
821 }
822 /// Frees any resources used by the CoinSelection, if is_owned is set and inner is non-NULL.
823 #[no_mangle]
824 pub extern "C" fn CoinSelection_free(this_obj: CoinSelection) { }
825 #[allow(unused)]
826 /// Used only if an object of this type is returned as a trait impl by a method
827 pub(crate) extern "C" fn CoinSelection_free_void(this_ptr: *mut c_void) {
828         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCoinSelection) };
829 }
830 #[allow(unused)]
831 impl CoinSelection {
832         pub(crate) fn get_native_ref(&self) -> &'static nativeCoinSelection {
833                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
834         }
835         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCoinSelection {
836                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
837         }
838         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
839         pub(crate) fn take_inner(mut self) -> *mut nativeCoinSelection {
840                 assert!(self.is_owned);
841                 let ret = ObjOps::untweak_ptr(self.inner);
842                 self.inner = core::ptr::null_mut();
843                 ret
844         }
845 }
846 /// The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
847 /// requiring additional fees.
848 #[no_mangle]
849 pub extern "C" fn CoinSelection_get_confirmed_utxos(this_ptr: &CoinSelection) -> crate::c_types::derived::CVec_UtxoZ {
850         let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmed_utxos;
851         let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::events::bump_transaction::Utxo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::events::bump_transaction::Utxo<>) as *mut _) }, is_owned: false } }); };
852         local_inner_val.into()
853 }
854 /// The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
855 /// requiring additional fees.
856 #[no_mangle]
857 pub extern "C" fn CoinSelection_set_confirmed_utxos(this_ptr: &mut CoinSelection, mut val: crate::c_types::derived::CVec_UtxoZ) {
858         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
859         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmed_utxos = local_val;
860 }
861 /// An additional output tracking whether any change remained after coin selection. This output
862 /// should always have a value above dust for its given `script_pubkey`. It should not be
863 /// spent until the transaction it belongs to confirms to ensure mempool descendant limits are
864 /// not met. This implies no other party should be able to spend it except us.
865 #[no_mangle]
866 pub extern "C" fn CoinSelection_get_change_output(this_ptr: &CoinSelection) -> crate::c_types::derived::COption_TxOutZ {
867         let mut inner_val = &mut this_ptr.get_native_mut_ref().change_output;
868         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_TxOutZ::None } else { crate::c_types::derived::COption_TxOutZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::TxOut::from_rust(&(*inner_val.as_ref().unwrap()).clone()) }) };
869         local_inner_val
870 }
871 /// An additional output tracking whether any change remained after coin selection. This output
872 /// should always have a value above dust for its given `script_pubkey`. It should not be
873 /// spent until the transaction it belongs to confirms to ensure mempool descendant limits are
874 /// not met. This implies no other party should be able to spend it except us.
875 #[no_mangle]
876 pub extern "C" fn CoinSelection_set_change_output(this_ptr: &mut CoinSelection, mut val: crate::c_types::derived::COption_TxOutZ) {
877         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_rust() }})} };
878         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.change_output = local_val;
879 }
880 /// Constructs a new CoinSelection given each field
881 #[must_use]
882 #[no_mangle]
883 pub extern "C" fn CoinSelection_new(mut confirmed_utxos_arg: crate::c_types::derived::CVec_UtxoZ, mut change_output_arg: crate::c_types::derived::COption_TxOutZ) -> CoinSelection {
884         let mut local_confirmed_utxos_arg = Vec::new(); for mut item in confirmed_utxos_arg.into_rust().drain(..) { local_confirmed_utxos_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
885         let mut local_change_output_arg = { /*change_output_arg*/ let change_output_arg_opt = change_output_arg; if change_output_arg_opt.is_none() { None } else { Some({ { { change_output_arg_opt.take() }.into_rust() }})} };
886         CoinSelection { inner: ObjOps::heap_alloc(nativeCoinSelection {
887                 confirmed_utxos: local_confirmed_utxos_arg,
888                 change_output: local_change_output_arg,
889         }), is_owned: true }
890 }
891 impl Clone for CoinSelection {
892         fn clone(&self) -> Self {
893                 Self {
894                         inner: if <*mut nativeCoinSelection>::is_null(self.inner) { core::ptr::null_mut() } else {
895                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
896                         is_owned: true,
897                 }
898         }
899 }
900 #[allow(unused)]
901 /// Used only if an object of this type is returned as a trait impl by a method
902 pub(crate) extern "C" fn CoinSelection_clone_void(this_ptr: *const c_void) -> *mut c_void {
903         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCoinSelection)).clone() })) as *mut c_void
904 }
905 #[no_mangle]
906 /// Creates a copy of the CoinSelection
907 pub extern "C" fn CoinSelection_clone(orig: &CoinSelection) -> CoinSelection {
908         orig.clone()
909 }
910 /// Get a string which allows debug introspection of a CoinSelection object
911 pub extern "C" fn CoinSelection_debug_str_void(o: *const c_void) -> Str {
912         alloc::format!("{:?}", unsafe { o as *const crate::lightning::events::bump_transaction::CoinSelection }).into()}
913 /// An abstraction over a bitcoin wallet that can perform coin selection over a set of UTXOs and can
914 /// sign for them. The coin selection method aims to mimic Bitcoin Core's `fundrawtransaction` RPC,
915 /// which most wallets should be able to satisfy. Otherwise, consider implementing [`WalletSource`],
916 /// which can provide a default implementation of this trait when used with [`Wallet`].
917 #[repr(C)]
918 pub struct CoinSelectionSource {
919         /// An opaque pointer which is passed to your function implementations as an argument.
920         /// This has no meaning in the LDK, and can be NULL or any other value.
921         pub this_arg: *mut c_void,
922         /// Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
923         /// available to spend. Implementations are free to pick their coin selection algorithm of
924         /// choice, as long as the following requirements are met:
925         ///
926         /// 1. `must_spend` contains a set of [`Input`]s that must be included in the transaction
927         ///    throughout coin selection, but must not be returned as part of the result.
928         /// 2. `must_pay_to` contains a set of [`TxOut`]s that must be included in the transaction
929         ///    throughout coin selection. In some cases, like when funding an anchor transaction, this
930         ///    set is empty. Implementations should ensure they handle this correctly on their end,
931         ///    e.g., Bitcoin Core's `fundrawtransaction` RPC requires at least one output to be
932         ///    provided, in which case a zero-value empty OP_RETURN output can be used instead.
933         /// 3. Enough inputs must be selected/contributed for the resulting transaction (including the
934         ///    inputs and outputs noted above) to meet `target_feerate_sat_per_1000_weight`.
935         ///
936         /// Implementations must take note that [`Input::satisfaction_weight`] only tracks the weight of
937         /// the input's `script_sig` and `witness`. Some wallets, like Bitcoin Core's, may require
938         /// providing the full input weight. Failing to do so may lead to underestimating fee bumps and
939         /// delaying block inclusion.
940         ///
941         /// The `claim_id` must map to the set of external UTXOs assigned to the claim, such that they
942         /// can be re-used within new fee-bumped iterations of the original claiming transaction,
943         /// ensuring that claims don't double spend each other. If a specific `claim_id` has never had a
944         /// transaction associated with it, and all of the available UTXOs have already been assigned to
945         /// other claims, implementations must be willing to double spend their UTXOs. The choice of
946         /// which UTXOs to double spend is left to the implementation, but it must strive to keep the
947         /// set of other claims being double spent to a minimum.
948         pub select_confirmed_utxos: extern "C" fn (this_arg: *const c_void, claim_id: crate::c_types::ThirtyTwoBytes, must_spend: crate::c_types::derived::CVec_InputZ, must_pay_to: crate::c_types::derived::CVec_TxOutZ, target_feerate_sat_per_1000_weight: u32) -> crate::c_types::derived::CResult_CoinSelectionNoneZ,
949         /// Signs and provides the full witness for all inputs within the transaction known to the
950         /// trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
951         ///
952         /// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
953         /// unsigned transaction and then sign it with your wallet.
954         pub sign_psbt: extern "C" fn (this_arg: *const c_void, psbt: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_TransactionNoneZ,
955         /// Frees any resources associated with this object given its this_arg pointer.
956         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
957         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
958 }
959 unsafe impl Send for CoinSelectionSource {}
960 unsafe impl Sync for CoinSelectionSource {}
961 #[allow(unused)]
962 pub(crate) fn CoinSelectionSource_clone_fields(orig: &CoinSelectionSource) -> CoinSelectionSource {
963         CoinSelectionSource {
964                 this_arg: orig.this_arg,
965                 select_confirmed_utxos: Clone::clone(&orig.select_confirmed_utxos),
966                 sign_psbt: Clone::clone(&orig.sign_psbt),
967                 free: Clone::clone(&orig.free),
968         }
969 }
970
971 use lightning::events::bump_transaction::CoinSelectionSource as rustCoinSelectionSource;
972 impl rustCoinSelectionSource for CoinSelectionSource {
973         fn select_confirmed_utxos(&self, mut claim_id: lightning::chain::ClaimId, mut must_spend: Vec<lightning::events::bump_transaction::Input>, mut must_pay_to: &[bitcoin::TxOut], mut target_feerate_sat_per_1000_weight: u32) -> Result<lightning::events::bump_transaction::CoinSelection, ()> {
974                 let mut local_must_spend = Vec::new(); for mut item in must_spend.drain(..) { local_must_spend.push( { crate::lightning::events::bump_transaction::Input { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
975                 let mut local_must_pay_to_clone = Vec::new(); local_must_pay_to_clone.extend_from_slice(must_pay_to); let mut must_pay_to = local_must_pay_to_clone; let mut local_must_pay_to = Vec::new(); for mut item in must_pay_to.drain(..) { local_must_pay_to.push( { crate::c_types::TxOut::from_rust(&item) }); };
976                 let mut ret = (self.select_confirmed_utxos)(self.this_arg, crate::c_types::ThirtyTwoBytes { data: claim_id.0 }, local_must_spend.into(), local_must_pay_to.into(), target_feerate_sat_per_1000_weight);
977                 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
978                 local_ret
979         }
980         fn sign_psbt(&self, mut psbt: bitcoin::psbt::PartiallySignedTransaction) -> Result<bitcoin::Transaction, ()> {
981                 let mut ret = (self.sign_psbt)(self.this_arg, psbt.serialize().into());
982                 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)) })*/ })};
983                 local_ret
984         }
985 }
986
987 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
988 // directly as a Deref trait in higher-level structs:
989 impl core::ops::Deref for CoinSelectionSource {
990         type Target = Self;
991         fn deref(&self) -> &Self {
992                 self
993         }
994 }
995 impl core::ops::DerefMut for CoinSelectionSource {
996         fn deref_mut(&mut self) -> &mut Self {
997                 self
998         }
999 }
1000 /// Calls the free function if one is set
1001 #[no_mangle]
1002 pub extern "C" fn CoinSelectionSource_free(this_ptr: CoinSelectionSource) { }
1003 impl Drop for CoinSelectionSource {
1004         fn drop(&mut self) {
1005                 if let Some(f) = self.free {
1006                         f(self.this_arg);
1007                 }
1008         }
1009 }
1010 /// An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
1011 /// provide a default implementation to [`CoinSelectionSource`].
1012 #[repr(C)]
1013 pub struct WalletSource {
1014         /// An opaque pointer which is passed to your function implementations as an argument.
1015         /// This has no meaning in the LDK, and can be NULL or any other value.
1016         pub this_arg: *mut c_void,
1017         /// Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
1018         pub list_confirmed_utxos: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_UtxoZNoneZ,
1019         /// Returns a script to use for change above dust resulting from a successful coin selection
1020         /// attempt.
1021         pub get_change_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ,
1022         /// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
1023         /// the transaction known to the wallet (i.e., any provided via
1024         /// [`WalletSource::list_confirmed_utxos`]).
1025         ///
1026         /// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
1027         /// unsigned transaction and then sign it with your wallet.
1028         pub sign_psbt: extern "C" fn (this_arg: *const c_void, psbt: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_TransactionNoneZ,
1029         /// Frees any resources associated with this object given its this_arg pointer.
1030         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1031         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1032 }
1033 unsafe impl Send for WalletSource {}
1034 unsafe impl Sync for WalletSource {}
1035 #[allow(unused)]
1036 pub(crate) fn WalletSource_clone_fields(orig: &WalletSource) -> WalletSource {
1037         WalletSource {
1038                 this_arg: orig.this_arg,
1039                 list_confirmed_utxos: Clone::clone(&orig.list_confirmed_utxos),
1040                 get_change_script: Clone::clone(&orig.get_change_script),
1041                 sign_psbt: Clone::clone(&orig.sign_psbt),
1042                 free: Clone::clone(&orig.free),
1043         }
1044 }
1045
1046 use lightning::events::bump_transaction::WalletSource as rustWalletSource;
1047 impl rustWalletSource for WalletSource {
1048         fn list_confirmed_utxos(&self) -> Result<Vec<lightning::events::bump_transaction::Utxo>, ()> {
1049                 let mut ret = (self.list_confirmed_utxos)(self.this_arg);
1050                 let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = Vec::new(); for mut item in (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust().drain(..) { local_ret_0.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1051                 local_ret
1052         }
1053         fn get_change_script(&self) -> Result<bitcoin::ScriptBuf, ()> {
1054                 let mut ret = (self.get_change_script)(self.this_arg);
1055                 let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::blockdata::script::ScriptBuf::from((*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)) })*/ })};
1056                 local_ret
1057         }
1058         fn sign_psbt(&self, mut psbt: bitcoin::psbt::PartiallySignedTransaction) -> Result<bitcoin::Transaction, ()> {
1059                 let mut ret = (self.sign_psbt)(self.this_arg, psbt.serialize().into());
1060                 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)) })*/ })};
1061                 local_ret
1062         }
1063 }
1064
1065 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1066 // directly as a Deref trait in higher-level structs:
1067 impl core::ops::Deref for WalletSource {
1068         type Target = Self;
1069         fn deref(&self) -> &Self {
1070                 self
1071         }
1072 }
1073 impl core::ops::DerefMut for WalletSource {
1074         fn deref_mut(&mut self) -> &mut Self {
1075                 self
1076         }
1077 }
1078 /// Calls the free function if one is set
1079 #[no_mangle]
1080 pub extern "C" fn WalletSource_free(this_ptr: WalletSource) { }
1081 impl Drop for WalletSource {
1082         fn drop(&mut self) {
1083                 if let Some(f) = self.free {
1084                         f(self.this_arg);
1085                 }
1086         }
1087 }
1088
1089 use lightning::events::bump_transaction::Wallet as nativeWalletImport;
1090 pub(crate) type nativeWallet = nativeWalletImport<crate::lightning::events::bump_transaction::WalletSource, crate::lightning::util::logger::Logger, >;
1091
1092 /// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
1093 /// avoid conflicting double spends. If not enough UTXOs are available to do so, conflicting double
1094 /// spends may happen.
1095 #[must_use]
1096 #[repr(C)]
1097 pub struct Wallet {
1098         /// A pointer to the opaque Rust object.
1099
1100         /// Nearly everywhere, inner must be non-null, however in places where
1101         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1102         pub inner: *mut nativeWallet,
1103         /// Indicates that this is the only struct which contains the same pointer.
1104
1105         /// Rust functions which take ownership of an object provided via an argument require
1106         /// this to be true and invalidate the object pointed to by inner.
1107         pub is_owned: bool,
1108 }
1109
1110 impl Drop for Wallet {
1111         fn drop(&mut self) {
1112                 if self.is_owned && !<*mut nativeWallet>::is_null(self.inner) {
1113                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1114                 }
1115         }
1116 }
1117 /// Frees any resources used by the Wallet, if is_owned is set and inner is non-NULL.
1118 #[no_mangle]
1119 pub extern "C" fn Wallet_free(this_obj: Wallet) { }
1120 #[allow(unused)]
1121 /// Used only if an object of this type is returned as a trait impl by a method
1122 pub(crate) extern "C" fn Wallet_free_void(this_ptr: *mut c_void) {
1123         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeWallet) };
1124 }
1125 #[allow(unused)]
1126 impl Wallet {
1127         pub(crate) fn get_native_ref(&self) -> &'static nativeWallet {
1128                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1129         }
1130         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeWallet {
1131                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1132         }
1133         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1134         pub(crate) fn take_inner(mut self) -> *mut nativeWallet {
1135                 assert!(self.is_owned);
1136                 let ret = ObjOps::untweak_ptr(self.inner);
1137                 self.inner = core::ptr::null_mut();
1138                 ret
1139         }
1140 }
1141 /// Returns a new instance backed by the given [`WalletSource`] that serves as an implementation
1142 /// of [`CoinSelectionSource`].
1143 #[must_use]
1144 #[no_mangle]
1145 pub extern "C" fn Wallet_new(mut source: crate::lightning::events::bump_transaction::WalletSource, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::events::bump_transaction::Wallet {
1146         let mut ret = lightning::events::bump_transaction::Wallet::new(source, logger);
1147         crate::lightning::events::bump_transaction::Wallet { inner: ObjOps::heap_alloc(ret), is_owned: true }
1148 }
1149
1150 impl From<nativeWallet> for crate::lightning::events::bump_transaction::CoinSelectionSource {
1151         fn from(obj: nativeWallet) -> Self {
1152                 let rust_obj = crate::lightning::events::bump_transaction::Wallet { inner: ObjOps::heap_alloc(obj), is_owned: true };
1153                 let mut ret = Wallet_as_CoinSelectionSource(&rust_obj);
1154                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
1155                 core::mem::forget(rust_obj);
1156                 ret.free = Some(Wallet_free_void);
1157                 ret
1158         }
1159 }
1160 /// Constructs a new CoinSelectionSource which calls the relevant methods on this_arg.
1161 /// This copies the `inner` pointer in this_arg and thus the returned CoinSelectionSource must be freed before this_arg is
1162 #[no_mangle]
1163 pub extern "C" fn Wallet_as_CoinSelectionSource(this_arg: &Wallet) -> crate::lightning::events::bump_transaction::CoinSelectionSource {
1164         crate::lightning::events::bump_transaction::CoinSelectionSource {
1165                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1166                 free: None,
1167                 select_confirmed_utxos: Wallet_CoinSelectionSource_select_confirmed_utxos,
1168                 sign_psbt: Wallet_CoinSelectionSource_sign_psbt,
1169         }
1170 }
1171
1172 #[must_use]
1173 extern "C" fn Wallet_CoinSelectionSource_select_confirmed_utxos(this_arg: *const c_void, mut claim_id: crate::c_types::ThirtyTwoBytes, mut must_spend: crate::c_types::derived::CVec_InputZ, mut must_pay_to: crate::c_types::derived::CVec_TxOutZ, mut target_feerate_sat_per_1000_weight: u32) -> crate::c_types::derived::CResult_CoinSelectionNoneZ {
1174         let mut local_must_spend = Vec::new(); for mut item in must_spend.into_rust().drain(..) { local_must_spend.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1175         let mut local_must_pay_to = Vec::new(); for mut item in must_pay_to.into_rust().drain(..) { local_must_pay_to.push( { item.into_rust() }); };
1176         let mut ret = <nativeWallet as lightning::events::bump_transaction::CoinSelectionSource>::select_confirmed_utxos(unsafe { &mut *(this_arg as *mut nativeWallet) }, ::lightning::chain::ClaimId(claim_id.data), local_must_spend, &local_must_pay_to[..], target_feerate_sat_per_1000_weight);
1177         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::events::bump_transaction::CoinSelection { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1178         local_ret
1179 }
1180 #[must_use]
1181 extern "C" fn Wallet_CoinSelectionSource_sign_psbt(this_arg: *const c_void, mut psbt: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_TransactionNoneZ {
1182         let mut ret = <nativeWallet as lightning::events::bump_transaction::CoinSelectionSource>::sign_psbt(unsafe { &mut *(this_arg as *mut nativeWallet) }, ::bitcoin::psbt::PartiallySignedTransaction::deserialize(psbt.as_slice()).expect("Invalid PSBT format"));
1183         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Transaction::from_bitcoin(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1184         local_ret
1185 }
1186
1187
1188 use lightning::events::bump_transaction::BumpTransactionEventHandler as nativeBumpTransactionEventHandlerImport;
1189 pub(crate) type nativeBumpTransactionEventHandler = nativeBumpTransactionEventHandlerImport<crate::lightning::chain::chaininterface::BroadcasterInterface, crate::lightning::events::bump_transaction::CoinSelectionSource, crate::lightning::sign::SignerProvider, crate::lightning::util::logger::Logger, >;
1190
1191 /// A handler for [`Event::BumpTransaction`] events that sources confirmed UTXOs from a
1192 /// [`CoinSelectionSource`] to fee bump transactions via Child-Pays-For-Parent (CPFP) or
1193 /// Replace-By-Fee (RBF).
1194 ///
1195 /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
1196 #[must_use]
1197 #[repr(C)]
1198 pub struct BumpTransactionEventHandler {
1199         /// A pointer to the opaque Rust object.
1200
1201         /// Nearly everywhere, inner must be non-null, however in places where
1202         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1203         pub inner: *mut nativeBumpTransactionEventHandler,
1204         /// Indicates that this is the only struct which contains the same pointer.
1205
1206         /// Rust functions which take ownership of an object provided via an argument require
1207         /// this to be true and invalidate the object pointed to by inner.
1208         pub is_owned: bool,
1209 }
1210
1211 impl Drop for BumpTransactionEventHandler {
1212         fn drop(&mut self) {
1213                 if self.is_owned && !<*mut nativeBumpTransactionEventHandler>::is_null(self.inner) {
1214                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1215                 }
1216         }
1217 }
1218 /// Frees any resources used by the BumpTransactionEventHandler, if is_owned is set and inner is non-NULL.
1219 #[no_mangle]
1220 pub extern "C" fn BumpTransactionEventHandler_free(this_obj: BumpTransactionEventHandler) { }
1221 #[allow(unused)]
1222 /// Used only if an object of this type is returned as a trait impl by a method
1223 pub(crate) extern "C" fn BumpTransactionEventHandler_free_void(this_ptr: *mut c_void) {
1224         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBumpTransactionEventHandler) };
1225 }
1226 #[allow(unused)]
1227 impl BumpTransactionEventHandler {
1228         pub(crate) fn get_native_ref(&self) -> &'static nativeBumpTransactionEventHandler {
1229                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1230         }
1231         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBumpTransactionEventHandler {
1232                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1233         }
1234         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1235         pub(crate) fn take_inner(mut self) -> *mut nativeBumpTransactionEventHandler {
1236                 assert!(self.is_owned);
1237                 let ret = ObjOps::untweak_ptr(self.inner);
1238                 self.inner = core::ptr::null_mut();
1239                 ret
1240         }
1241 }
1242 /// Returns a new instance capable of handling [`Event::BumpTransaction`] events.
1243 ///
1244 /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
1245 #[must_use]
1246 #[no_mangle]
1247 pub extern "C" fn BumpTransactionEventHandler_new(mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut utxo_source: crate::lightning::events::bump_transaction::CoinSelectionSource, mut signer_provider: crate::lightning::sign::SignerProvider, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::events::bump_transaction::BumpTransactionEventHandler {
1248         let mut ret = lightning::events::bump_transaction::BumpTransactionEventHandler::new(broadcaster, utxo_source, signer_provider, logger);
1249         crate::lightning::events::bump_transaction::BumpTransactionEventHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
1250 }
1251
1252 /// Handles all variants of [`BumpTransactionEvent`].
1253 #[no_mangle]
1254 pub extern "C" fn BumpTransactionEventHandler_handle_event(this_arg: &crate::lightning::events::bump_transaction::BumpTransactionEventHandler, event: &crate::lightning::events::bump_transaction::BumpTransactionEvent) {
1255         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_event(&event.to_native())
1256 }
1257