1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! Utilities for bumping transactions originating from [`Event`]s.
11 //! [`Event`]: crate::events::Event
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};
23 use lightning::events::bump_transaction::AnchorDescriptor as nativeAnchorDescriptorImport;
24 pub(crate) type nativeAnchorDescriptor = nativeAnchorDescriptorImport;
26 /// A descriptor used to sign for a commitment transaction's anchor output.
29 pub struct AnchorDescriptor {
30 /// A pointer to the opaque Rust object.
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.
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.
42 impl Drop for AnchorDescriptor {
44 if self.is_owned && !<*mut nativeAnchorDescriptor>::is_null(self.inner) {
45 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
49 /// Frees any resources used by the AnchorDescriptor, if is_owned is set and inner is non-NULL.
51 pub extern "C" fn AnchorDescriptor_free(this_obj: AnchorDescriptor) { }
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) };
58 impl AnchorDescriptor {
59 pub(crate) fn get_native_ref(&self) -> &'static nativeAnchorDescriptor {
60 unsafe { &*ObjOps::untweak_ptr(self.inner) }
62 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeAnchorDescriptor {
63 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
73 /// The parameters required to derive the signer for the anchor input.
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 }
79 /// The parameters required to derive the signer for the anchor input.
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()) };
84 /// The transaction input's outpoint corresponding to the commitment transaction's anchor
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)
91 /// The transaction input's outpoint corresponding to the commitment transaction's anchor
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);
97 /// Constructs a new AnchorDescriptor given each field
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),
106 impl Clone for AnchorDescriptor {
107 fn clone(&self) -> 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()) },
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
121 /// Creates a copy of the AnchorDescriptor
122 pub extern "C" fn AnchorDescriptor_clone(orig: &AnchorDescriptor) -> AnchorDescriptor {
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.
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 }
137 /// Returns the UTXO to be spent by the anchor input, which can be obtained via
138 /// [`Self::unsigned_tx_input`].
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)
146 /// Returns the unsigned transaction input spending the anchor output in the commitment
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)
155 /// Returns the witness script of the anchor output in the commitment transaction.
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()
163 /// Returns the fully signed witness required to spend the anchor output in the commitment
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)
172 /// Derives the channel signer required to sign the anchor input.
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);
180 /// Represents the different types of transactions, originating from LDK, to be bumped.
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.
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.
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.
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
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
225 /// The unique identifier for the claim of the anchor output in the commitment transaction.
227 /// The identifier must map to the set of external UTXOs assigned to the claim, such that
228 /// they can be reused when a new claim with the same identifier needs to be made, resulting
229 /// in a fee-bumping attempt.
230 claim_id: crate::c_types::ThirtyTwoBytes,
231 /// The target feerate that the transaction package, which consists of the commitment
232 /// transaction and the to-be-crafted child anchor transaction, must meet.
233 package_target_feerate_sat_per_1000_weight: u32,
234 /// The channel's commitment transaction to bump the fee of. This transaction should be
235 /// broadcast along with the anchor transaction constructed as a result of consuming this
237 commitment_tx: crate::c_types::Transaction,
238 /// The absolute fee in satoshis of the commitment transaction. This can be used along the
239 /// with weight of the commitment transaction to determine its feerate.
240 commitment_tx_fee_satoshis: u64,
241 /// The descriptor to sign the anchor input of the anchor transaction constructed as a
242 /// result of consuming this event.
243 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor,
244 /// The set of pending HTLCs on the commitment transaction that need to be resolved once the
245 /// commitment transaction confirms.
246 pending_htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ,
248 /// Indicates that a channel featuring anchor outputs has unilaterally closed on-chain by a
249 /// holder commitment transaction and its HTLC(s) need to be resolved on-chain. With the
250 /// zero-HTLC-transaction-fee variant of anchor outputs, the pre-signed HTLC
251 /// transactions have a zero fee, thus requiring additional inputs and/or outputs to be attached
252 /// for a timely confirmation within the chain. These additional inputs and/or outputs must be
253 /// appended to the resulting HTLC transaction to meet the target feerate. Failure to meet the
254 /// target feerate decreases the confirmation odds of the transaction, possibly resulting in a
255 /// loss of funds. Once the transaction meets the target feerate, it must be signed for and
256 /// broadcast by the consumer of the event.
258 /// The consumer should be able to sign for any of the non-HTLC inputs added to the resulting
259 /// HTLC transaction. To sign HTLC inputs, an [`EcdsaChannelSigner`] should be re-derived
260 /// through [`HTLCDescriptor::derive_channel_signer`]. Each HTLC input's signature can be
261 /// computed with [`EcdsaChannelSigner::sign_holder_htlc_transaction`], which can then be
262 /// provided to [`HTLCDescriptor::tx_input_witness`] to obtain the fully signed witness required
265 /// It is possible to receive more than one instance of this event if a valid HTLC transaction
266 /// is never broadcast or is but not with a sufficient fee to be mined. Care should be taken by
267 /// the consumer of the event to ensure any future iterations of the HTLC transaction adhere to
268 /// the [Replace-By-Fee
269 /// rules](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md)
270 /// for fee bumps to be accepted into the mempool, and eventually the chain. As the frequency of
271 /// these events is not user-controlled, users may ignore/drop the event if either they are no
272 /// longer able to commit external confirmed funds to the HTLC transaction or the fee committed
273 /// to the HTLC transaction is greater in value than the HTLCs being claimed.
275 /// [`EcdsaChannelSigner`]: crate::sign::ecdsa::EcdsaChannelSigner
276 /// [`EcdsaChannelSigner::sign_holder_htlc_transaction`]: crate::sign::ecdsa::EcdsaChannelSigner::sign_holder_htlc_transaction
278 /// The unique identifier for the claim of the HTLCs in the confirmed commitment
281 /// The identifier must map to the set of external UTXOs assigned to the claim, such that
282 /// they can be reused when a new claim with the same identifier needs to be made, resulting
283 /// in a fee-bumping attempt.
284 claim_id: crate::c_types::ThirtyTwoBytes,
285 /// The target feerate that the resulting HTLC transaction must meet.
286 target_feerate_sat_per_1000_weight: u32,
287 /// The set of pending HTLCs on the confirmed commitment that need to be claimed, preferably
288 /// by the same transaction.
289 htlc_descriptors: crate::c_types::derived::CVec_HTLCDescriptorZ,
290 /// The locktime required for the resulting HTLC transaction.
294 use lightning::events::bump_transaction::BumpTransactionEvent as BumpTransactionEventImport;
295 pub(crate) type nativeBumpTransactionEvent = BumpTransactionEventImport;
297 impl BumpTransactionEvent {
299 pub(crate) fn to_native(&self) -> nativeBumpTransactionEvent {
301 BumpTransactionEvent::ChannelClose {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, } => {
302 let mut claim_id_nonref = Clone::clone(claim_id);
303 let mut package_target_feerate_sat_per_1000_weight_nonref = Clone::clone(package_target_feerate_sat_per_1000_weight);
304 let mut commitment_tx_nonref = Clone::clone(commitment_tx);
305 let mut commitment_tx_fee_satoshis_nonref = Clone::clone(commitment_tx_fee_satoshis);
306 let mut anchor_descriptor_nonref = Clone::clone(anchor_descriptor);
307 let mut pending_htlcs_nonref = Clone::clone(pending_htlcs);
308 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()) } }); };
309 nativeBumpTransactionEvent::ChannelClose {
310 claim_id: ::lightning::chain::ClaimId(claim_id_nonref.data),
311 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight_nonref,
312 commitment_tx: commitment_tx_nonref.into_bitcoin(),
313 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis_nonref,
314 anchor_descriptor: *unsafe { Box::from_raw(anchor_descriptor_nonref.take_inner()) },
315 pending_htlcs: local_pending_htlcs_nonref,
318 BumpTransactionEvent::HTLCResolution {ref claim_id, ref target_feerate_sat_per_1000_weight, ref htlc_descriptors, ref tx_lock_time, } => {
319 let mut claim_id_nonref = Clone::clone(claim_id);
320 let mut target_feerate_sat_per_1000_weight_nonref = Clone::clone(target_feerate_sat_per_1000_weight);
321 let mut htlc_descriptors_nonref = Clone::clone(htlc_descriptors);
322 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()) } }); };
323 let mut tx_lock_time_nonref = Clone::clone(tx_lock_time);
324 nativeBumpTransactionEvent::HTLCResolution {
325 claim_id: ::lightning::chain::ClaimId(claim_id_nonref.data),
326 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight_nonref,
327 htlc_descriptors: local_htlc_descriptors_nonref,
328 tx_lock_time: ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus(tx_lock_time_nonref),
334 pub(crate) fn into_native(self) -> nativeBumpTransactionEvent {
336 BumpTransactionEvent::ChannelClose {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, } => {
337 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()) } }); };
338 nativeBumpTransactionEvent::ChannelClose {
339 claim_id: ::lightning::chain::ClaimId(claim_id.data),
340 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight,
341 commitment_tx: commitment_tx.into_bitcoin(),
342 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis,
343 anchor_descriptor: *unsafe { Box::from_raw(anchor_descriptor.take_inner()) },
344 pending_htlcs: local_pending_htlcs,
347 BumpTransactionEvent::HTLCResolution {mut claim_id, mut target_feerate_sat_per_1000_weight, mut htlc_descriptors, mut tx_lock_time, } => {
348 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()) } }); };
349 nativeBumpTransactionEvent::HTLCResolution {
350 claim_id: ::lightning::chain::ClaimId(claim_id.data),
351 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight,
352 htlc_descriptors: local_htlc_descriptors,
353 tx_lock_time: ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus(tx_lock_time),
359 pub(crate) fn from_native(native: &BumpTransactionEventImport) -> Self {
360 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBumpTransactionEvent) };
362 nativeBumpTransactionEvent::ChannelClose {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, } => {
363 let mut claim_id_nonref = Clone::clone(claim_id);
364 let mut package_target_feerate_sat_per_1000_weight_nonref = Clone::clone(package_target_feerate_sat_per_1000_weight);
365 let mut commitment_tx_nonref = Clone::clone(commitment_tx);
366 let mut commitment_tx_fee_satoshis_nonref = Clone::clone(commitment_tx_fee_satoshis);
367 let mut anchor_descriptor_nonref = Clone::clone(anchor_descriptor);
368 let mut pending_htlcs_nonref = Clone::clone(pending_htlcs);
369 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 } }); };
370 BumpTransactionEvent::ChannelClose {
371 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id_nonref.0 },
372 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight_nonref,
373 commitment_tx: crate::c_types::Transaction::from_bitcoin(&commitment_tx_nonref),
374 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis_nonref,
375 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor { inner: ObjOps::heap_alloc(anchor_descriptor_nonref), is_owned: true },
376 pending_htlcs: local_pending_htlcs_nonref.into(),
379 nativeBumpTransactionEvent::HTLCResolution {ref claim_id, ref target_feerate_sat_per_1000_weight, ref htlc_descriptors, ref tx_lock_time, } => {
380 let mut claim_id_nonref = Clone::clone(claim_id);
381 let mut target_feerate_sat_per_1000_weight_nonref = Clone::clone(target_feerate_sat_per_1000_weight);
382 let mut htlc_descriptors_nonref = Clone::clone(htlc_descriptors);
383 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 } }); };
384 let mut tx_lock_time_nonref = Clone::clone(tx_lock_time);
385 BumpTransactionEvent::HTLCResolution {
386 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id_nonref.0 },
387 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight_nonref,
388 htlc_descriptors: local_htlc_descriptors_nonref.into(),
389 tx_lock_time: tx_lock_time_nonref.to_consensus_u32(),
395 pub(crate) fn native_into(native: nativeBumpTransactionEvent) -> Self {
397 nativeBumpTransactionEvent::ChannelClose {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, } => {
398 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 } }); };
399 BumpTransactionEvent::ChannelClose {
400 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id.0 },
401 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight,
402 commitment_tx: crate::c_types::Transaction::from_bitcoin(&commitment_tx),
403 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis,
404 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor { inner: ObjOps::heap_alloc(anchor_descriptor), is_owned: true },
405 pending_htlcs: local_pending_htlcs.into(),
408 nativeBumpTransactionEvent::HTLCResolution {mut claim_id, mut target_feerate_sat_per_1000_weight, mut htlc_descriptors, mut tx_lock_time, } => {
409 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 } }); };
410 BumpTransactionEvent::HTLCResolution {
411 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id.0 },
412 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight,
413 htlc_descriptors: local_htlc_descriptors.into(),
414 tx_lock_time: tx_lock_time.to_consensus_u32(),
420 /// Frees any resources used by the BumpTransactionEvent
422 pub extern "C" fn BumpTransactionEvent_free(this_ptr: BumpTransactionEvent) { }
423 /// Creates a copy of the BumpTransactionEvent
425 pub extern "C" fn BumpTransactionEvent_clone(orig: &BumpTransactionEvent) -> BumpTransactionEvent {
429 /// Used only if an object of this type is returned as a trait impl by a method
430 pub(crate) extern "C" fn BumpTransactionEvent_clone_void(this_ptr: *const c_void) -> *mut c_void {
431 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const BumpTransactionEvent)).clone() })) as *mut c_void
434 /// Used only if an object of this type is returned as a trait impl by a method
435 pub(crate) extern "C" fn BumpTransactionEvent_free_void(this_ptr: *mut c_void) {
436 let _ = unsafe { Box::from_raw(this_ptr as *mut BumpTransactionEvent) };
439 /// Utility method to constructs a new ChannelClose-variant BumpTransactionEvent
440 pub extern "C" fn BumpTransactionEvent_channel_close(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 {
441 BumpTransactionEvent::ChannelClose {
443 package_target_feerate_sat_per_1000_weight,
445 commitment_tx_fee_satoshis,
451 /// Utility method to constructs a new HTLCResolution-variant BumpTransactionEvent
452 pub extern "C" fn BumpTransactionEvent_htlcresolution(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 {
453 BumpTransactionEvent::HTLCResolution {
455 target_feerate_sat_per_1000_weight,
460 /// Get a string which allows debug introspection of a BumpTransactionEvent object
461 pub extern "C" fn BumpTransactionEvent_debug_str_void(o: *const c_void) -> Str {
462 alloc::format!("{:?}", unsafe { o as *const crate::lightning::events::bump_transaction::BumpTransactionEvent }).into()}
463 /// Checks if two BumpTransactionEvents contain equal inner contents.
464 /// This ignores pointers and is_owned flags and looks at the values in fields.
466 pub extern "C" fn BumpTransactionEvent_eq(a: &BumpTransactionEvent, b: &BumpTransactionEvent) -> bool {
467 if &a.to_native() == &b.to_native() { true } else { false }
470 use lightning::events::bump_transaction::Input as nativeInputImport;
471 pub(crate) type nativeInput = nativeInputImport;
473 /// An input that must be included in a transaction when performing coin selection through
474 /// [`CoinSelectionSource::select_confirmed_utxos`]. It is guaranteed to be a SegWit input, so it
475 /// must have an empty [`TxIn::script_sig`] when spent.
479 /// A pointer to the opaque Rust object.
481 /// Nearly everywhere, inner must be non-null, however in places where
482 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
483 pub inner: *mut nativeInput,
484 /// Indicates that this is the only struct which contains the same pointer.
486 /// Rust functions which take ownership of an object provided via an argument require
487 /// this to be true and invalidate the object pointed to by inner.
491 impl Drop for Input {
493 if self.is_owned && !<*mut nativeInput>::is_null(self.inner) {
494 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
498 /// Frees any resources used by the Input, if is_owned is set and inner is non-NULL.
500 pub extern "C" fn Input_free(this_obj: Input) { }
502 /// Used only if an object of this type is returned as a trait impl by a method
503 pub(crate) extern "C" fn Input_free_void(this_ptr: *mut c_void) {
504 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInput) };
508 pub(crate) fn get_native_ref(&self) -> &'static nativeInput {
509 unsafe { &*ObjOps::untweak_ptr(self.inner) }
511 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInput {
512 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
514 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
515 pub(crate) fn take_inner(mut self) -> *mut nativeInput {
516 assert!(self.is_owned);
517 let ret = ObjOps::untweak_ptr(self.inner);
518 self.inner = core::ptr::null_mut();
522 /// The unique identifier of the input.
524 pub extern "C" fn Input_get_outpoint(this_ptr: &Input) -> crate::lightning::chain::transaction::OutPoint {
525 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
526 crate::c_types::bitcoin_to_C_outpoint(inner_val)
528 /// The unique identifier of the input.
530 pub extern "C" fn Input_set_outpoint(this_ptr: &mut Input, mut val: crate::lightning::chain::transaction::OutPoint) {
531 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
533 /// The UTXO being spent by the input.
535 pub extern "C" fn Input_get_previous_utxo(this_ptr: &Input) -> crate::c_types::TxOut {
536 let mut inner_val = &mut this_ptr.get_native_mut_ref().previous_utxo;
537 crate::c_types::TxOut::from_rust(inner_val)
539 /// The UTXO being spent by the input.
541 pub extern "C" fn Input_set_previous_utxo(this_ptr: &mut Input, mut val: crate::c_types::TxOut) {
542 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previous_utxo = val.into_rust();
544 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
545 /// [`TxIn::witness`], each with their lengths included, required to satisfy the output's
548 pub extern "C" fn Input_get_satisfaction_weight(this_ptr: &Input) -> u64 {
549 let mut inner_val = &mut this_ptr.get_native_mut_ref().satisfaction_weight;
552 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
553 /// [`TxIn::witness`], each with their lengths included, required to satisfy the output's
556 pub extern "C" fn Input_set_satisfaction_weight(this_ptr: &mut Input, mut val: u64) {
557 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.satisfaction_weight = val;
559 /// Constructs a new Input given each field
562 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 {
563 Input { inner: ObjOps::heap_alloc(nativeInput {
564 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
565 previous_utxo: previous_utxo_arg.into_rust(),
566 satisfaction_weight: satisfaction_weight_arg,
569 impl Clone for Input {
570 fn clone(&self) -> Self {
572 inner: if <*mut nativeInput>::is_null(self.inner) { core::ptr::null_mut() } else {
573 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
579 /// Used only if an object of this type is returned as a trait impl by a method
580 pub(crate) extern "C" fn Input_clone_void(this_ptr: *const c_void) -> *mut c_void {
581 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInput)).clone() })) as *mut c_void
584 /// Creates a copy of the Input
585 pub extern "C" fn Input_clone(orig: &Input) -> Input {
588 /// Get a string which allows debug introspection of a Input object
589 pub extern "C" fn Input_debug_str_void(o: *const c_void) -> Str {
590 alloc::format!("{:?}", unsafe { o as *const crate::lightning::events::bump_transaction::Input }).into()}
591 /// Generates a non-cryptographic 64-bit hash of the Input.
593 pub extern "C" fn Input_hash(o: &Input) -> u64 {
594 if o.inner.is_null() { return 0; }
595 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
597 let mut hasher = core::hash::SipHasher::new();
598 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
599 core::hash::Hasher::finish(&hasher)
601 /// Checks if two Inputs contain equal inner contents.
602 /// This ignores pointers and is_owned flags and looks at the values in fields.
603 /// Two objects with NULL inner values will be considered "equal" here.
605 pub extern "C" fn Input_eq(a: &Input, b: &Input) -> bool {
606 if a.inner == b.inner { return true; }
607 if a.inner.is_null() || b.inner.is_null() { return false; }
608 if a.get_native_ref() == b.get_native_ref() { true } else { false }
611 use lightning::events::bump_transaction::Utxo as nativeUtxoImport;
612 pub(crate) type nativeUtxo = nativeUtxoImport;
614 /// An unspent transaction output that is available to spend resulting from a successful
615 /// [`CoinSelection`] attempt.
619 /// A pointer to the opaque Rust object.
621 /// Nearly everywhere, inner must be non-null, however in places where
622 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
623 pub inner: *mut nativeUtxo,
624 /// Indicates that this is the only struct which contains the same pointer.
626 /// Rust functions which take ownership of an object provided via an argument require
627 /// this to be true and invalidate the object pointed to by inner.
633 if self.is_owned && !<*mut nativeUtxo>::is_null(self.inner) {
634 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
638 /// Frees any resources used by the Utxo, if is_owned is set and inner is non-NULL.
640 pub extern "C" fn Utxo_free(this_obj: Utxo) { }
642 /// Used only if an object of this type is returned as a trait impl by a method
643 pub(crate) extern "C" fn Utxo_free_void(this_ptr: *mut c_void) {
644 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUtxo) };
648 pub(crate) fn get_native_ref(&self) -> &'static nativeUtxo {
649 unsafe { &*ObjOps::untweak_ptr(self.inner) }
651 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUtxo {
652 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
654 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
655 pub(crate) fn take_inner(mut self) -> *mut nativeUtxo {
656 assert!(self.is_owned);
657 let ret = ObjOps::untweak_ptr(self.inner);
658 self.inner = core::ptr::null_mut();
662 /// The unique identifier of the output.
664 pub extern "C" fn Utxo_get_outpoint(this_ptr: &Utxo) -> crate::lightning::chain::transaction::OutPoint {
665 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
666 crate::c_types::bitcoin_to_C_outpoint(inner_val)
668 /// The unique identifier of the output.
670 pub extern "C" fn Utxo_set_outpoint(this_ptr: &mut Utxo, mut val: crate::lightning::chain::transaction::OutPoint) {
671 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
673 /// The output to spend.
675 pub extern "C" fn Utxo_get_output(this_ptr: &Utxo) -> crate::c_types::TxOut {
676 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
677 crate::c_types::TxOut::from_rust(inner_val)
679 /// The output to spend.
681 pub extern "C" fn Utxo_set_output(this_ptr: &mut Utxo, mut val: crate::c_types::TxOut) {
682 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
684 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
685 /// with their lengths included, required to satisfy the output's script. The weight consumed by
686 /// the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
688 pub extern "C" fn Utxo_get_satisfaction_weight(this_ptr: &Utxo) -> u64 {
689 let mut inner_val = &mut this_ptr.get_native_mut_ref().satisfaction_weight;
692 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
693 /// with their lengths included, required to satisfy the output's script. The weight consumed by
694 /// the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
696 pub extern "C" fn Utxo_set_satisfaction_weight(this_ptr: &mut Utxo, mut val: u64) {
697 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.satisfaction_weight = val;
699 /// Constructs a new Utxo given each field
702 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 {
703 Utxo { inner: ObjOps::heap_alloc(nativeUtxo {
704 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
705 output: output_arg.into_rust(),
706 satisfaction_weight: satisfaction_weight_arg,
709 impl Clone for Utxo {
710 fn clone(&self) -> Self {
712 inner: if <*mut nativeUtxo>::is_null(self.inner) { core::ptr::null_mut() } else {
713 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
719 /// Used only if an object of this type is returned as a trait impl by a method
720 pub(crate) extern "C" fn Utxo_clone_void(this_ptr: *const c_void) -> *mut c_void {
721 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUtxo)).clone() })) as *mut c_void
724 /// Creates a copy of the Utxo
725 pub extern "C" fn Utxo_clone(orig: &Utxo) -> Utxo {
728 /// Get a string which allows debug introspection of a Utxo object
729 pub extern "C" fn Utxo_debug_str_void(o: *const c_void) -> Str {
730 alloc::format!("{:?}", unsafe { o as *const crate::lightning::events::bump_transaction::Utxo }).into()}
731 /// Generates a non-cryptographic 64-bit hash of the Utxo.
733 pub extern "C" fn Utxo_hash(o: &Utxo) -> u64 {
734 if o.inner.is_null() { return 0; }
735 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
737 let mut hasher = core::hash::SipHasher::new();
738 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
739 core::hash::Hasher::finish(&hasher)
741 /// Checks if two Utxos contain equal inner contents.
742 /// This ignores pointers and is_owned flags and looks at the values in fields.
743 /// Two objects with NULL inner values will be considered "equal" here.
745 pub extern "C" fn Utxo_eq(a: &Utxo, b: &Utxo) -> bool {
746 if a.inner == b.inner { return true; }
747 if a.inner.is_null() || b.inner.is_null() { return false; }
748 if a.get_native_ref() == b.get_native_ref() { true } else { false }
750 /// Returns a `Utxo` with the `satisfaction_weight` estimate for a legacy P2PKH output.
753 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 {
754 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())));
755 crate::lightning::events::bump_transaction::Utxo { inner: ObjOps::heap_alloc(ret), is_owned: true }
759 use lightning::events::bump_transaction::CoinSelection as nativeCoinSelectionImport;
760 pub(crate) type nativeCoinSelection = nativeCoinSelectionImport;
762 /// The result of a successful coin selection attempt for a transaction requiring additional UTXOs
763 /// to cover its fees.
766 pub struct CoinSelection {
767 /// A pointer to the opaque Rust object.
769 /// Nearly everywhere, inner must be non-null, however in places where
770 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
771 pub inner: *mut nativeCoinSelection,
772 /// Indicates that this is the only struct which contains the same pointer.
774 /// Rust functions which take ownership of an object provided via an argument require
775 /// this to be true and invalidate the object pointed to by inner.
779 impl Drop for CoinSelection {
781 if self.is_owned && !<*mut nativeCoinSelection>::is_null(self.inner) {
782 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
786 /// Frees any resources used by the CoinSelection, if is_owned is set and inner is non-NULL.
788 pub extern "C" fn CoinSelection_free(this_obj: CoinSelection) { }
790 /// Used only if an object of this type is returned as a trait impl by a method
791 pub(crate) extern "C" fn CoinSelection_free_void(this_ptr: *mut c_void) {
792 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCoinSelection) };
796 pub(crate) fn get_native_ref(&self) -> &'static nativeCoinSelection {
797 unsafe { &*ObjOps::untweak_ptr(self.inner) }
799 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCoinSelection {
800 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
802 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
803 pub(crate) fn take_inner(mut self) -> *mut nativeCoinSelection {
804 assert!(self.is_owned);
805 let ret = ObjOps::untweak_ptr(self.inner);
806 self.inner = core::ptr::null_mut();
810 /// The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
811 /// requiring additional fees.
813 pub extern "C" fn CoinSelection_get_confirmed_utxos(this_ptr: &CoinSelection) -> crate::c_types::derived::CVec_UtxoZ {
814 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmed_utxos;
815 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 } }); };
816 local_inner_val.into()
818 /// The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
819 /// requiring additional fees.
821 pub extern "C" fn CoinSelection_set_confirmed_utxos(this_ptr: &mut CoinSelection, mut val: crate::c_types::derived::CVec_UtxoZ) {
822 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
823 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmed_utxos = local_val;
825 /// An additional output tracking whether any change remained after coin selection. This output
826 /// should always have a value above dust for its given `script_pubkey`. It should not be
827 /// spent until the transaction it belongs to confirms to ensure mempool descendant limits are
828 /// not met. This implies no other party should be able to spend it except us.
830 pub extern "C" fn CoinSelection_get_change_output(this_ptr: &CoinSelection) -> crate::c_types::derived::COption_TxOutZ {
831 let mut inner_val = &mut this_ptr.get_native_mut_ref().change_output;
832 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()) }) };
835 /// An additional output tracking whether any change remained after coin selection. This output
836 /// should always have a value above dust for its given `script_pubkey`. It should not be
837 /// spent until the transaction it belongs to confirms to ensure mempool descendant limits are
838 /// not met. This implies no other party should be able to spend it except us.
840 pub extern "C" fn CoinSelection_set_change_output(this_ptr: &mut CoinSelection, mut val: crate::c_types::derived::COption_TxOutZ) {
841 let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_rust() }})} };
842 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.change_output = local_val;
844 /// Constructs a new CoinSelection given each field
847 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 {
848 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()) } }); };
849 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() }})} };
850 CoinSelection { inner: ObjOps::heap_alloc(nativeCoinSelection {
851 confirmed_utxos: local_confirmed_utxos_arg,
852 change_output: local_change_output_arg,
855 impl Clone for CoinSelection {
856 fn clone(&self) -> Self {
858 inner: if <*mut nativeCoinSelection>::is_null(self.inner) { core::ptr::null_mut() } else {
859 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
865 /// Used only if an object of this type is returned as a trait impl by a method
866 pub(crate) extern "C" fn CoinSelection_clone_void(this_ptr: *const c_void) -> *mut c_void {
867 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCoinSelection)).clone() })) as *mut c_void
870 /// Creates a copy of the CoinSelection
871 pub extern "C" fn CoinSelection_clone(orig: &CoinSelection) -> CoinSelection {
874 /// Get a string which allows debug introspection of a CoinSelection object
875 pub extern "C" fn CoinSelection_debug_str_void(o: *const c_void) -> Str {
876 alloc::format!("{:?}", unsafe { o as *const crate::lightning::events::bump_transaction::CoinSelection }).into()}
877 /// An abstraction over a bitcoin wallet that can perform coin selection over a set of UTXOs and can
878 /// sign for them. The coin selection method aims to mimic Bitcoin Core's `fundrawtransaction` RPC,
879 /// which most wallets should be able to satisfy. Otherwise, consider implementing [`WalletSource`],
880 /// which can provide a default implementation of this trait when used with [`Wallet`].
882 pub struct CoinSelectionSource {
883 /// An opaque pointer which is passed to your function implementations as an argument.
884 /// This has no meaning in the LDK, and can be NULL or any other value.
885 pub this_arg: *mut c_void,
886 /// Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
887 /// available to spend. Implementations are free to pick their coin selection algorithm of
888 /// choice, as long as the following requirements are met:
890 /// 1. `must_spend` contains a set of [`Input`]s that must be included in the transaction
891 /// throughout coin selection, but must not be returned as part of the result.
892 /// 2. `must_pay_to` contains a set of [`TxOut`]s that must be included in the transaction
893 /// throughout coin selection. In some cases, like when funding an anchor transaction, this
894 /// set is empty. Implementations should ensure they handle this correctly on their end,
895 /// e.g., Bitcoin Core's `fundrawtransaction` RPC requires at least one output to be
896 /// provided, in which case a zero-value empty OP_RETURN output can be used instead.
897 /// 3. Enough inputs must be selected/contributed for the resulting transaction (including the
898 /// inputs and outputs noted above) to meet `target_feerate_sat_per_1000_weight`.
900 /// Implementations must take note that [`Input::satisfaction_weight`] only tracks the weight of
901 /// the input's `script_sig` and `witness`. Some wallets, like Bitcoin Core's, may require
902 /// providing the full input weight. Failing to do so may lead to underestimating fee bumps and
903 /// delaying block inclusion.
905 /// The `claim_id` must map to the set of external UTXOs assigned to the claim, such that they
906 /// can be re-used within new fee-bumped iterations of the original claiming transaction,
907 /// ensuring that claims don't double spend each other. If a specific `claim_id` has never had a
908 /// transaction associated with it, and all of the available UTXOs have already been assigned to
909 /// other claims, implementations must be willing to double spend their UTXOs. The choice of
910 /// which UTXOs to double spend is left to the implementation, but it must strive to keep the
911 /// set of other claims being double spent to a minimum.
912 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,
913 /// Signs and provides the full witness for all inputs within the transaction known to the
914 /// trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
916 /// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
917 /// unsigned transaction and then sign it with your wallet.
918 pub sign_psbt: extern "C" fn (this_arg: *const c_void, psbt: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_TransactionNoneZ,
919 /// Frees any resources associated with this object given its this_arg pointer.
920 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
921 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
923 unsafe impl Send for CoinSelectionSource {}
924 unsafe impl Sync for CoinSelectionSource {}
926 pub(crate) fn CoinSelectionSource_clone_fields(orig: &CoinSelectionSource) -> CoinSelectionSource {
927 CoinSelectionSource {
928 this_arg: orig.this_arg,
929 select_confirmed_utxos: Clone::clone(&orig.select_confirmed_utxos),
930 sign_psbt: Clone::clone(&orig.sign_psbt),
931 free: Clone::clone(&orig.free),
935 use lightning::events::bump_transaction::CoinSelectionSource as rustCoinSelectionSource;
936 impl rustCoinSelectionSource for CoinSelectionSource {
937 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, ()> {
938 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 } }); };
939 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) }); };
940 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);
941 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)) })*/ })};
944 fn sign_psbt(&self, mut psbt: bitcoin::psbt::PartiallySignedTransaction) -> Result<bitcoin::Transaction, ()> {
945 let mut ret = (self.sign_psbt)(self.this_arg, psbt.serialize().into());
946 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)) })*/ })};
951 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
952 // directly as a Deref trait in higher-level structs:
953 impl core::ops::Deref for CoinSelectionSource {
955 fn deref(&self) -> &Self {
959 impl core::ops::DerefMut for CoinSelectionSource {
960 fn deref_mut(&mut self) -> &mut Self {
964 /// Calls the free function if one is set
966 pub extern "C" fn CoinSelectionSource_free(this_ptr: CoinSelectionSource) { }
967 impl Drop for CoinSelectionSource {
969 if let Some(f) = self.free {
974 /// An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
975 /// provide a default implementation to [`CoinSelectionSource`].
977 pub struct WalletSource {
978 /// An opaque pointer which is passed to your function implementations as an argument.
979 /// This has no meaning in the LDK, and can be NULL or any other value.
980 pub this_arg: *mut c_void,
981 /// Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
982 pub list_confirmed_utxos: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_UtxoZNoneZ,
983 /// Returns a script to use for change above dust resulting from a successful coin selection
985 pub get_change_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ,
986 /// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
987 /// the transaction known to the wallet (i.e., any provided via
988 /// [`WalletSource::list_confirmed_utxos`]).
990 /// If your wallet does not support signing PSBTs you can call `psbt.extract_tx()` to get the
991 /// unsigned transaction and then sign it with your wallet.
992 pub sign_psbt: extern "C" fn (this_arg: *const c_void, psbt: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_TransactionNoneZ,
993 /// Frees any resources associated with this object given its this_arg pointer.
994 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
995 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
997 unsafe impl Send for WalletSource {}
998 unsafe impl Sync for WalletSource {}
1000 pub(crate) fn WalletSource_clone_fields(orig: &WalletSource) -> WalletSource {
1002 this_arg: orig.this_arg,
1003 list_confirmed_utxos: Clone::clone(&orig.list_confirmed_utxos),
1004 get_change_script: Clone::clone(&orig.get_change_script),
1005 sign_psbt: Clone::clone(&orig.sign_psbt),
1006 free: Clone::clone(&orig.free),
1010 use lightning::events::bump_transaction::WalletSource as rustWalletSource;
1011 impl rustWalletSource for WalletSource {
1012 fn list_confirmed_utxos(&self) -> Result<Vec<lightning::events::bump_transaction::Utxo>, ()> {
1013 let mut ret = (self.list_confirmed_utxos)(self.this_arg);
1014 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)) })*/ })};
1017 fn get_change_script(&self) -> Result<bitcoin::ScriptBuf, ()> {
1018 let mut ret = (self.get_change_script)(self.this_arg);
1019 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)) })*/ })};
1022 fn sign_psbt(&self, mut psbt: bitcoin::psbt::PartiallySignedTransaction) -> Result<bitcoin::Transaction, ()> {
1023 let mut ret = (self.sign_psbt)(self.this_arg, psbt.serialize().into());
1024 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)) })*/ })};
1029 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1030 // directly as a Deref trait in higher-level structs:
1031 impl core::ops::Deref for WalletSource {
1033 fn deref(&self) -> &Self {
1037 impl core::ops::DerefMut for WalletSource {
1038 fn deref_mut(&mut self) -> &mut Self {
1042 /// Calls the free function if one is set
1044 pub extern "C" fn WalletSource_free(this_ptr: WalletSource) { }
1045 impl Drop for WalletSource {
1046 fn drop(&mut self) {
1047 if let Some(f) = self.free {
1053 use lightning::events::bump_transaction::Wallet as nativeWalletImport;
1054 pub(crate) type nativeWallet = nativeWalletImport<crate::lightning::events::bump_transaction::WalletSource, crate::lightning::util::logger::Logger>;
1056 /// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
1057 /// avoid conflicting double spends. If not enough UTXOs are available to do so, conflicting double
1058 /// spends may happen.
1062 /// A pointer to the opaque Rust object.
1064 /// Nearly everywhere, inner must be non-null, however in places where
1065 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1066 pub inner: *mut nativeWallet,
1067 /// Indicates that this is the only struct which contains the same pointer.
1069 /// Rust functions which take ownership of an object provided via an argument require
1070 /// this to be true and invalidate the object pointed to by inner.
1074 impl Drop for Wallet {
1075 fn drop(&mut self) {
1076 if self.is_owned && !<*mut nativeWallet>::is_null(self.inner) {
1077 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1081 /// Frees any resources used by the Wallet, if is_owned is set and inner is non-NULL.
1083 pub extern "C" fn Wallet_free(this_obj: Wallet) { }
1085 /// Used only if an object of this type is returned as a trait impl by a method
1086 pub(crate) extern "C" fn Wallet_free_void(this_ptr: *mut c_void) {
1087 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeWallet) };
1091 pub(crate) fn get_native_ref(&self) -> &'static nativeWallet {
1092 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1094 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeWallet {
1095 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1097 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1098 pub(crate) fn take_inner(mut self) -> *mut nativeWallet {
1099 assert!(self.is_owned);
1100 let ret = ObjOps::untweak_ptr(self.inner);
1101 self.inner = core::ptr::null_mut();
1105 /// Returns a new instance backed by the given [`WalletSource`] that serves as an implementation
1106 /// of [`CoinSelectionSource`].
1109 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 {
1110 let mut ret = lightning::events::bump_transaction::Wallet::new(source, logger);
1111 crate::lightning::events::bump_transaction::Wallet { inner: ObjOps::heap_alloc(ret), is_owned: true }
1114 impl From<nativeWallet> for crate::lightning::events::bump_transaction::CoinSelectionSource {
1115 fn from(obj: nativeWallet) -> Self {
1116 let rust_obj = crate::lightning::events::bump_transaction::Wallet { inner: ObjOps::heap_alloc(obj), is_owned: true };
1117 let mut ret = Wallet_as_CoinSelectionSource(&rust_obj);
1118 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
1119 core::mem::forget(rust_obj);
1120 ret.free = Some(Wallet_free_void);
1124 /// Constructs a new CoinSelectionSource which calls the relevant methods on this_arg.
1125 /// This copies the `inner` pointer in this_arg and thus the returned CoinSelectionSource must be freed before this_arg is
1127 pub extern "C" fn Wallet_as_CoinSelectionSource(this_arg: &Wallet) -> crate::lightning::events::bump_transaction::CoinSelectionSource {
1128 crate::lightning::events::bump_transaction::CoinSelectionSource {
1129 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1131 select_confirmed_utxos: Wallet_CoinSelectionSource_select_confirmed_utxos,
1132 sign_psbt: Wallet_CoinSelectionSource_sign_psbt,
1137 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 {
1138 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()) } }); };
1139 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() }); };
1140 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);
1141 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() };
1145 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 {
1146 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"));
1147 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() };
1152 use lightning::events::bump_transaction::BumpTransactionEventHandler as nativeBumpTransactionEventHandlerImport;
1153 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>;
1155 /// A handler for [`Event::BumpTransaction`] events that sources confirmed UTXOs from a
1156 /// [`CoinSelectionSource`] to fee bump transactions via Child-Pays-For-Parent (CPFP) or
1157 /// Replace-By-Fee (RBF).
1159 /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
1162 pub struct BumpTransactionEventHandler {
1163 /// A pointer to the opaque Rust object.
1165 /// Nearly everywhere, inner must be non-null, however in places where
1166 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1167 pub inner: *mut nativeBumpTransactionEventHandler,
1168 /// Indicates that this is the only struct which contains the same pointer.
1170 /// Rust functions which take ownership of an object provided via an argument require
1171 /// this to be true and invalidate the object pointed to by inner.
1175 impl Drop for BumpTransactionEventHandler {
1176 fn drop(&mut self) {
1177 if self.is_owned && !<*mut nativeBumpTransactionEventHandler>::is_null(self.inner) {
1178 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1182 /// Frees any resources used by the BumpTransactionEventHandler, if is_owned is set and inner is non-NULL.
1184 pub extern "C" fn BumpTransactionEventHandler_free(this_obj: BumpTransactionEventHandler) { }
1186 /// Used only if an object of this type is returned as a trait impl by a method
1187 pub(crate) extern "C" fn BumpTransactionEventHandler_free_void(this_ptr: *mut c_void) {
1188 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBumpTransactionEventHandler) };
1191 impl BumpTransactionEventHandler {
1192 pub(crate) fn get_native_ref(&self) -> &'static nativeBumpTransactionEventHandler {
1193 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1195 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBumpTransactionEventHandler {
1196 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1198 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1199 pub(crate) fn take_inner(mut self) -> *mut nativeBumpTransactionEventHandler {
1200 assert!(self.is_owned);
1201 let ret = ObjOps::untweak_ptr(self.inner);
1202 self.inner = core::ptr::null_mut();
1206 /// Returns a new instance capable of handling [`Event::BumpTransaction`] events.
1208 /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
1211 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 {
1212 let mut ret = lightning::events::bump_transaction::BumpTransactionEventHandler::new(broadcaster, utxo_source, signer_provider, logger);
1213 crate::lightning::events::bump_transaction::BumpTransactionEventHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
1216 /// Handles all variants of [`BumpTransactionEvent`].
1218 pub extern "C" fn BumpTransactionEventHandler_handle_event(this_arg: &crate::lightning::events::bump_transaction::BumpTransactionEventHandler, event: &crate::lightning::events::bump_transaction::BumpTransactionEvent) {
1219 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_event(&event.to_native())