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 core::ffi::c_void;
15 use core::convert::Infallible;
16 use bitcoin::hashes::Hash;
17 use crate::c_types::*;
18 #[cfg(feature="no-std")]
19 use alloc::{vec::Vec, boxed::Box};
22 use lightning::events::bump_transaction::ChannelDerivationParameters as nativeChannelDerivationParametersImport;
23 pub(crate) type nativeChannelDerivationParameters = nativeChannelDerivationParametersImport;
25 /// The parameters required to derive a channel signer via [`SignerProvider`].
28 pub struct ChannelDerivationParameters {
29 /// A pointer to the opaque Rust object.
31 /// Nearly everywhere, inner must be non-null, however in places where
32 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
33 pub inner: *mut nativeChannelDerivationParameters,
34 /// Indicates that this is the only struct which contains the same pointer.
36 /// Rust functions which take ownership of an object provided via an argument require
37 /// this to be true and invalidate the object pointed to by inner.
41 impl Drop for ChannelDerivationParameters {
43 if self.is_owned && !<*mut nativeChannelDerivationParameters>::is_null(self.inner) {
44 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
48 /// Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL.
50 pub extern "C" fn ChannelDerivationParameters_free(this_obj: ChannelDerivationParameters) { }
52 /// Used only if an object of this type is returned as a trait impl by a method
53 pub(crate) extern "C" fn ChannelDerivationParameters_free_void(this_ptr: *mut c_void) {
54 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDerivationParameters) };
57 impl ChannelDerivationParameters {
58 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDerivationParameters {
59 unsafe { &*ObjOps::untweak_ptr(self.inner) }
61 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDerivationParameters {
62 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
64 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
65 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDerivationParameters {
66 assert!(self.is_owned);
67 let ret = ObjOps::untweak_ptr(self.inner);
68 self.inner = core::ptr::null_mut();
72 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
74 pub extern "C" fn ChannelDerivationParameters_get_value_satoshis(this_ptr: &ChannelDerivationParameters) -> u64 {
75 let mut inner_val = &mut this_ptr.get_native_mut_ref().value_satoshis;
78 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
80 pub extern "C" fn ChannelDerivationParameters_set_value_satoshis(this_ptr: &mut ChannelDerivationParameters, mut val: u64) {
81 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.value_satoshis = val;
83 /// The unique identifier to re-derive the signer for the associated channel.
85 pub extern "C" fn ChannelDerivationParameters_get_keys_id(this_ptr: &ChannelDerivationParameters) -> *const [u8; 32] {
86 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_id;
89 /// The unique identifier to re-derive the signer for the associated channel.
91 pub extern "C" fn ChannelDerivationParameters_set_keys_id(this_ptr: &mut ChannelDerivationParameters, mut val: crate::c_types::ThirtyTwoBytes) {
92 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_id = val.data;
94 /// The necessary channel parameters that need to be provided to the re-derived signer through
95 /// [`ChannelSigner::provide_channel_parameters`].
97 /// [`ChannelSigner::provide_channel_parameters`]: crate::sign::ChannelSigner::provide_channel_parameters
99 pub extern "C" fn ChannelDerivationParameters_get_transaction_parameters(this_ptr: &ChannelDerivationParameters) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
100 let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_parameters;
101 crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false }
103 /// The necessary channel parameters that need to be provided to the re-derived signer through
104 /// [`ChannelSigner::provide_channel_parameters`].
106 /// [`ChannelSigner::provide_channel_parameters`]: crate::sign::ChannelSigner::provide_channel_parameters
108 pub extern "C" fn ChannelDerivationParameters_set_transaction_parameters(this_ptr: &mut ChannelDerivationParameters, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
109 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_parameters = *unsafe { Box::from_raw(val.take_inner()) };
111 /// Constructs a new ChannelDerivationParameters given each field
114 pub extern "C" fn ChannelDerivationParameters_new(mut value_satoshis_arg: u64, mut keys_id_arg: crate::c_types::ThirtyTwoBytes, mut transaction_parameters_arg: crate::lightning::ln::chan_utils::ChannelTransactionParameters) -> ChannelDerivationParameters {
115 ChannelDerivationParameters { inner: ObjOps::heap_alloc(nativeChannelDerivationParameters {
116 value_satoshis: value_satoshis_arg,
117 keys_id: keys_id_arg.data,
118 transaction_parameters: *unsafe { Box::from_raw(transaction_parameters_arg.take_inner()) },
121 impl Clone for ChannelDerivationParameters {
122 fn clone(&self) -> Self {
124 inner: if <*mut nativeChannelDerivationParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
125 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
131 /// Used only if an object of this type is returned as a trait impl by a method
132 pub(crate) extern "C" fn ChannelDerivationParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
133 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDerivationParameters)).clone() })) as *mut c_void
136 /// Creates a copy of the ChannelDerivationParameters
137 pub extern "C" fn ChannelDerivationParameters_clone(orig: &ChannelDerivationParameters) -> ChannelDerivationParameters {
140 /// Checks if two ChannelDerivationParameterss contain equal inner contents.
141 /// This ignores pointers and is_owned flags and looks at the values in fields.
142 /// Two objects with NULL inner values will be considered "equal" here.
144 pub extern "C" fn ChannelDerivationParameters_eq(a: &ChannelDerivationParameters, b: &ChannelDerivationParameters) -> bool {
145 if a.inner == b.inner { return true; }
146 if a.inner.is_null() || b.inner.is_null() { return false; }
147 if a.get_native_ref() == b.get_native_ref() { true } else { false }
150 use lightning::events::bump_transaction::AnchorDescriptor as nativeAnchorDescriptorImport;
151 pub(crate) type nativeAnchorDescriptor = nativeAnchorDescriptorImport;
153 /// A descriptor used to sign for a commitment transaction's anchor output.
156 pub struct AnchorDescriptor {
157 /// A pointer to the opaque Rust object.
159 /// Nearly everywhere, inner must be non-null, however in places where
160 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
161 pub inner: *mut nativeAnchorDescriptor,
162 /// Indicates that this is the only struct which contains the same pointer.
164 /// Rust functions which take ownership of an object provided via an argument require
165 /// this to be true and invalidate the object pointed to by inner.
169 impl Drop for AnchorDescriptor {
171 if self.is_owned && !<*mut nativeAnchorDescriptor>::is_null(self.inner) {
172 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
176 /// Frees any resources used by the AnchorDescriptor, if is_owned is set and inner is non-NULL.
178 pub extern "C" fn AnchorDescriptor_free(this_obj: AnchorDescriptor) { }
180 /// Used only if an object of this type is returned as a trait impl by a method
181 pub(crate) extern "C" fn AnchorDescriptor_free_void(this_ptr: *mut c_void) {
182 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeAnchorDescriptor) };
185 impl AnchorDescriptor {
186 pub(crate) fn get_native_ref(&self) -> &'static nativeAnchorDescriptor {
187 unsafe { &*ObjOps::untweak_ptr(self.inner) }
189 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeAnchorDescriptor {
190 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
192 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
193 pub(crate) fn take_inner(mut self) -> *mut nativeAnchorDescriptor {
194 assert!(self.is_owned);
195 let ret = ObjOps::untweak_ptr(self.inner);
196 self.inner = core::ptr::null_mut();
200 /// The parameters required to derive the signer for the anchor input.
202 pub extern "C" fn AnchorDescriptor_get_channel_derivation_parameters(this_ptr: &AnchorDescriptor) -> crate::lightning::events::bump_transaction::ChannelDerivationParameters {
203 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters;
204 crate::lightning::events::bump_transaction::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::events::bump_transaction::ChannelDerivationParameters<>) as *mut _) }, is_owned: false }
206 /// The parameters required to derive the signer for the anchor input.
208 pub extern "C" fn AnchorDescriptor_set_channel_derivation_parameters(this_ptr: &mut AnchorDescriptor, mut val: crate::lightning::events::bump_transaction::ChannelDerivationParameters) {
209 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) };
211 /// The transaction input's outpoint corresponding to the commitment transaction's anchor
214 pub extern "C" fn AnchorDescriptor_get_outpoint(this_ptr: &AnchorDescriptor) -> crate::lightning::chain::transaction::OutPoint {
215 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
216 crate::c_types::bitcoin_to_C_outpoint(inner_val)
218 /// The transaction input's outpoint corresponding to the commitment transaction's anchor
221 pub extern "C" fn AnchorDescriptor_set_outpoint(this_ptr: &mut AnchorDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
222 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
224 /// Constructs a new AnchorDescriptor given each field
227 pub extern "C" fn AnchorDescriptor_new(mut channel_derivation_parameters_arg: crate::lightning::events::bump_transaction::ChannelDerivationParameters, mut outpoint_arg: crate::lightning::chain::transaction::OutPoint) -> AnchorDescriptor {
228 AnchorDescriptor { inner: ObjOps::heap_alloc(nativeAnchorDescriptor {
229 channel_derivation_parameters: *unsafe { Box::from_raw(channel_derivation_parameters_arg.take_inner()) },
230 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
233 impl Clone for AnchorDescriptor {
234 fn clone(&self) -> Self {
236 inner: if <*mut nativeAnchorDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
237 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
243 /// Used only if an object of this type is returned as a trait impl by a method
244 pub(crate) extern "C" fn AnchorDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
245 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAnchorDescriptor)).clone() })) as *mut c_void
248 /// Creates a copy of the AnchorDescriptor
249 pub extern "C" fn AnchorDescriptor_clone(orig: &AnchorDescriptor) -> AnchorDescriptor {
252 /// Checks if two AnchorDescriptors contain equal inner contents.
253 /// This ignores pointers and is_owned flags and looks at the values in fields.
254 /// Two objects with NULL inner values will be considered "equal" here.
256 pub extern "C" fn AnchorDescriptor_eq(a: &AnchorDescriptor, b: &AnchorDescriptor) -> bool {
257 if a.inner == b.inner { return true; }
258 if a.inner.is_null() || b.inner.is_null() { return false; }
259 if a.get_native_ref() == b.get_native_ref() { true } else { false }
261 /// Returns the UTXO to be spent by the anchor input, which can be obtained via
262 /// [`Self::unsigned_tx_input`].
265 pub extern "C" fn AnchorDescriptor_previous_utxo(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor) -> crate::c_types::TxOut {
266 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo();
267 crate::c_types::TxOut::from_rust(&ret)
270 /// Returns the unsigned transaction input spending the anchor output in the commitment
274 pub extern "C" fn AnchorDescriptor_unsigned_tx_input(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor) -> crate::c_types::TxIn {
275 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input();
276 crate::c_types::TxIn::from_rust(&ret)
279 /// Returns the witness script of the anchor output in the commitment transaction.
282 pub extern "C" fn AnchorDescriptor_witness_script(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor) -> crate::c_types::derived::CVec_u8Z {
283 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script();
284 ret.into_bytes().into()
287 /// Returns the fully signed witness required to spend the anchor output in the commitment
291 pub extern "C" fn AnchorDescriptor_tx_input_witness(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor, mut signature: crate::c_types::Signature) -> crate::c_types::Witness {
292 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_input_witness(&signature.into_rust());
293 crate::c_types::Witness::from_bitcoin(&ret)
296 /// Derives the channel signer required to sign the anchor input.
299 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::WriteableEcdsaChannelSigner {
300 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider);
305 use lightning::events::bump_transaction::HTLCDescriptor as nativeHTLCDescriptorImport;
306 pub(crate) type nativeHTLCDescriptor = nativeHTLCDescriptorImport;
308 /// A descriptor used to sign for a commitment transaction's HTLC output.
311 pub struct HTLCDescriptor {
312 /// A pointer to the opaque Rust object.
314 /// Nearly everywhere, inner must be non-null, however in places where
315 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
316 pub inner: *mut nativeHTLCDescriptor,
317 /// Indicates that this is the only struct which contains the same pointer.
319 /// Rust functions which take ownership of an object provided via an argument require
320 /// this to be true and invalidate the object pointed to by inner.
324 impl Drop for HTLCDescriptor {
326 if self.is_owned && !<*mut nativeHTLCDescriptor>::is_null(self.inner) {
327 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
331 /// Frees any resources used by the HTLCDescriptor, if is_owned is set and inner is non-NULL.
333 pub extern "C" fn HTLCDescriptor_free(this_obj: HTLCDescriptor) { }
335 /// Used only if an object of this type is returned as a trait impl by a method
336 pub(crate) extern "C" fn HTLCDescriptor_free_void(this_ptr: *mut c_void) {
337 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCDescriptor) };
340 impl HTLCDescriptor {
341 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCDescriptor {
342 unsafe { &*ObjOps::untweak_ptr(self.inner) }
344 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCDescriptor {
345 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
347 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
348 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCDescriptor {
349 assert!(self.is_owned);
350 let ret = ObjOps::untweak_ptr(self.inner);
351 self.inner = core::ptr::null_mut();
355 /// The parameters required to derive the signer for the HTLC input.
357 pub extern "C" fn HTLCDescriptor_get_channel_derivation_parameters(this_ptr: &HTLCDescriptor) -> crate::lightning::events::bump_transaction::ChannelDerivationParameters {
358 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters;
359 crate::lightning::events::bump_transaction::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::events::bump_transaction::ChannelDerivationParameters<>) as *mut _) }, is_owned: false }
361 /// The parameters required to derive the signer for the HTLC input.
363 pub extern "C" fn HTLCDescriptor_set_channel_derivation_parameters(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::events::bump_transaction::ChannelDerivationParameters) {
364 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) };
366 /// The number of the commitment transaction in which the HTLC output lives.
368 pub extern "C" fn HTLCDescriptor_get_per_commitment_number(this_ptr: &HTLCDescriptor) -> u64 {
369 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_number;
372 /// The number of the commitment transaction in which the HTLC output lives.
374 pub extern "C" fn HTLCDescriptor_set_per_commitment_number(this_ptr: &mut HTLCDescriptor, mut val: u64) {
375 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_number = val;
377 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
378 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
379 /// arrive at unique keys per commitment.
381 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
383 pub extern "C" fn HTLCDescriptor_get_per_commitment_point(this_ptr: &HTLCDescriptor) -> crate::c_types::PublicKey {
384 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
385 crate::c_types::PublicKey::from_rust(&inner_val)
387 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
388 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
389 /// arrive at unique keys per commitment.
391 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
393 pub extern "C" fn HTLCDescriptor_set_per_commitment_point(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::PublicKey) {
394 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
396 /// The details of the HTLC as it appears in the commitment transaction.
398 pub extern "C" fn HTLCDescriptor_get_htlc(this_ptr: &HTLCDescriptor) -> crate::lightning::ln::chan_utils::HTLCOutputInCommitment {
399 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc;
400 crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false }
402 /// The details of the HTLC as it appears in the commitment transaction.
404 pub extern "C" fn HTLCDescriptor_set_htlc(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::ln::chan_utils::HTLCOutputInCommitment) {
405 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc = *unsafe { Box::from_raw(val.take_inner()) };
407 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
410 pub extern "C" fn HTLCDescriptor_get_preimage(this_ptr: &HTLCDescriptor) -> crate::c_types::derived::COption_PaymentPreimageZ {
411 let mut inner_val = &mut this_ptr.get_native_mut_ref().preimage;
412 let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_PaymentPreimageZ::None } else { crate::c_types::derived::COption_PaymentPreimageZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*inner_val.as_ref().unwrap()).clone().0 } }) };
415 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
418 pub extern "C" fn HTLCDescriptor_set_preimage(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::derived::COption_PaymentPreimageZ) {
419 let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentPreimage({ val_opt.take() }.data) }})} };
420 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.preimage = local_val;
422 /// The counterparty's signature required to spend the HTLC output.
424 pub extern "C" fn HTLCDescriptor_get_counterparty_sig(this_ptr: &HTLCDescriptor) -> crate::c_types::Signature {
425 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig;
426 crate::c_types::Signature::from_rust(&inner_val)
428 /// The counterparty's signature required to spend the HTLC output.
430 pub extern "C" fn HTLCDescriptor_set_counterparty_sig(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::Signature) {
431 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust();
433 impl Clone for HTLCDescriptor {
434 fn clone(&self) -> Self {
436 inner: if <*mut nativeHTLCDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
437 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
443 /// Used only if an object of this type is returned as a trait impl by a method
444 pub(crate) extern "C" fn HTLCDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
445 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCDescriptor)).clone() })) as *mut c_void
448 /// Creates a copy of the HTLCDescriptor
449 pub extern "C" fn HTLCDescriptor_clone(orig: &HTLCDescriptor) -> HTLCDescriptor {
452 /// Checks if two HTLCDescriptors contain equal inner contents.
453 /// This ignores pointers and is_owned flags and looks at the values in fields.
454 /// Two objects with NULL inner values will be considered "equal" here.
456 pub extern "C" fn HTLCDescriptor_eq(a: &HTLCDescriptor, b: &HTLCDescriptor) -> bool {
457 if a.inner == b.inner { return true; }
458 if a.inner.is_null() || b.inner.is_null() { return false; }
459 if a.get_native_ref() == b.get_native_ref() { true } else { false }
461 /// Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint
462 /// being spent by the HTLC input in the HTLC transaction.
465 pub extern "C" fn HTLCDescriptor_outpoint(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::lightning::chain::transaction::OutPoint {
466 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.outpoint();
467 crate::c_types::bitcoin_to_C_outpoint(&ret)
470 /// Returns the UTXO to be spent by the HTLC input, which can be obtained via
471 /// [`Self::unsigned_tx_input`].
474 pub extern "C" fn HTLCDescriptor_previous_utxo(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::TxOut {
475 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo(secp256k1::global::SECP256K1);
476 crate::c_types::TxOut::from_rust(&ret)
479 /// Returns the unsigned transaction input spending the HTLC output in the commitment
483 pub extern "C" fn HTLCDescriptor_unsigned_tx_input(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::TxIn {
484 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input();
485 crate::c_types::TxIn::from_rust(&ret)
488 /// Returns the delayed output created as a result of spending the HTLC output in the commitment
492 pub extern "C" fn HTLCDescriptor_tx_output(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::TxOut {
493 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_output(secp256k1::global::SECP256K1);
494 crate::c_types::TxOut::from_rust(&ret)
497 /// Returns the witness script of the HTLC output in the commitment transaction.
500 pub extern "C" fn HTLCDescriptor_witness_script(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z {
501 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script(secp256k1::global::SECP256K1);
502 ret.into_bytes().into()
505 /// Returns the fully signed witness required to spend the HTLC output in the commitment
509 pub extern "C" fn HTLCDescriptor_tx_input_witness(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor, mut signature: crate::c_types::Signature, mut witness_script: crate::c_types::u8slice) -> crate::c_types::Witness {
510 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_input_witness(&signature.into_rust(), &::bitcoin::blockdata::script::Script::from(Vec::from(witness_script.to_slice())));
511 crate::c_types::Witness::from_bitcoin(&ret)
514 /// Derives the channel signer required to sign the HTLC input.
517 pub extern "C" fn HTLCDescriptor_derive_channel_signer(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor, signer_provider: &crate::lightning::sign::SignerProvider) -> crate::lightning::sign::WriteableEcdsaChannelSigner {
518 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider);
522 /// Represents the different types of transactions, originating from LDK, to be bumped.
526 pub enum BumpTransactionEvent {
527 /// Indicates that a channel featuring anchor outputs is to be closed by broadcasting the local
528 /// commitment transaction. Since commitment transactions have a static feerate pre-agreed upon,
529 /// they may need additional fees to be attached through a child transaction using the popular
530 /// [Child-Pays-For-Parent](https://bitcoinops.org/en/topics/cpfp) fee bumping technique. This
531 /// child transaction must include the anchor input described within `anchor_descriptor` along
532 /// with additional inputs to meet the target feerate. Failure to meet the target feerate
533 /// decreases the confirmation odds of the transaction package (which includes the commitment
534 /// and child anchor transactions), possibly resulting in a loss of funds. Once the transaction
535 /// is constructed, it must be fully signed for and broadcast by the consumer of the event
536 /// along with the `commitment_tx` enclosed. Note that the `commitment_tx` must always be
537 /// broadcast first, as the child anchor transaction depends on it.
539 /// The consumer should be able to sign for any of the additional inputs included within the
540 /// child anchor transaction. To sign its anchor input, an [`EcdsaChannelSigner`] should be
541 /// re-derived through [`AnchorDescriptor::derive_channel_signer`]. The anchor input signature
542 /// can be computed with [`EcdsaChannelSigner::sign_holder_anchor_input`], which can then be
543 /// provided to [`build_anchor_input_witness`] along with the `funding_pubkey` to obtain the
544 /// full witness required to spend.
546 /// It is possible to receive more than one instance of this event if a valid child anchor
547 /// transaction is never broadcast or is but not with a sufficient fee to be mined. Care should
548 /// be taken by the consumer of the event to ensure any future iterations of the child anchor
549 /// transaction adhere to the [Replace-By-Fee
550 /// rules](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md)
551 /// for fee bumps to be accepted into the mempool, and eventually the chain. As the frequency of
552 /// these events is not user-controlled, users may ignore/drop the event if they are no longer
553 /// able to commit external confirmed funds to the child anchor transaction.
555 /// The set of `pending_htlcs` on the commitment transaction to be broadcast can be inspected to
556 /// determine whether a significant portion of the channel's funds are allocated to HTLCs,
557 /// enabling users to make their own decisions regarding the importance of the commitment
558 /// transaction's confirmation. Note that this is not required, but simply exists as an option
559 /// for users to override LDK's behavior. On commitments with no HTLCs (indicated by those with
560 /// an empty `pending_htlcs`), confirmation of the commitment transaction can be considered to
563 /// [`EcdsaChannelSigner`]: crate::sign::EcdsaChannelSigner
564 /// [`EcdsaChannelSigner::sign_holder_anchor_input`]: crate::sign::EcdsaChannelSigner::sign_holder_anchor_input
565 /// [`build_anchor_input_witness`]: crate::ln::chan_utils::build_anchor_input_witness
567 /// The unique identifier for the claim of the anchor output in the commitment transaction.
569 /// The identifier must map to the set of external UTXOs assigned to the claim, such that
570 /// they can be reused when a new claim with the same identifier needs to be made, resulting
571 /// in a fee-bumping attempt.
572 claim_id: crate::c_types::ThirtyTwoBytes,
573 /// The target feerate that the transaction package, which consists of the commitment
574 /// transaction and the to-be-crafted child anchor transaction, must meet.
575 package_target_feerate_sat_per_1000_weight: u32,
576 /// The channel's commitment transaction to bump the fee of. This transaction should be
577 /// broadcast along with the anchor transaction constructed as a result of consuming this
579 commitment_tx: crate::c_types::Transaction,
580 /// The absolute fee in satoshis of the commitment transaction. This can be used along the
581 /// with weight of the commitment transaction to determine its feerate.
582 commitment_tx_fee_satoshis: u64,
583 /// The descriptor to sign the anchor input of the anchor transaction constructed as a
584 /// result of consuming this event.
585 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor,
586 /// The set of pending HTLCs on the commitment transaction that need to be resolved once the
587 /// commitment transaction confirms.
588 pending_htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ,
590 /// Indicates that a channel featuring anchor outputs has unilaterally closed on-chain by a
591 /// holder commitment transaction and its HTLC(s) need to be resolved on-chain. With the
592 /// zero-HTLC-transaction-fee variant of anchor outputs, the pre-signed HTLC
593 /// transactions have a zero fee, thus requiring additional inputs and/or outputs to be attached
594 /// for a timely confirmation within the chain. These additional inputs and/or outputs must be
595 /// appended to the resulting HTLC transaction to meet the target feerate. Failure to meet the
596 /// target feerate decreases the confirmation odds of the transaction, possibly resulting in a
597 /// loss of funds. Once the transaction meets the target feerate, it must be signed for and
598 /// broadcast by the consumer of the event.
600 /// The consumer should be able to sign for any of the non-HTLC inputs added to the resulting
601 /// HTLC transaction. To sign HTLC inputs, an [`EcdsaChannelSigner`] should be re-derived
602 /// through [`HTLCDescriptor::derive_channel_signer`]. Each HTLC input's signature can be
603 /// computed with [`EcdsaChannelSigner::sign_holder_htlc_transaction`], which can then be
604 /// provided to [`HTLCDescriptor::tx_input_witness`] to obtain the fully signed witness required
607 /// It is possible to receive more than one instance of this event if a valid HTLC transaction
608 /// is never broadcast or is but not with a sufficient fee to be mined. Care should be taken by
609 /// the consumer of the event to ensure any future iterations of the HTLC transaction adhere to
610 /// the [Replace-By-Fee
611 /// rules](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md)
612 /// for fee bumps to be accepted into the mempool, and eventually the chain. As the frequency of
613 /// these events is not user-controlled, users may ignore/drop the event if either they are no
614 /// longer able to commit external confirmed funds to the HTLC transaction or the fee committed
615 /// to the HTLC transaction is greater in value than the HTLCs being claimed.
617 /// [`EcdsaChannelSigner`]: crate::sign::EcdsaChannelSigner
618 /// [`EcdsaChannelSigner::sign_holder_htlc_transaction`]: crate::sign::EcdsaChannelSigner::sign_holder_htlc_transaction
619 /// [`HTLCDescriptor::tx_input_witness`]: HTLCDescriptor::tx_input_witness
621 /// The unique identifier for the claim of the HTLCs in the confirmed commitment
624 /// The identifier must map to the set of external UTXOs assigned to the claim, such that
625 /// they can be reused when a new claim with the same identifier needs to be made, resulting
626 /// in a fee-bumping attempt.
627 claim_id: crate::c_types::ThirtyTwoBytes,
628 /// The target feerate that the resulting HTLC transaction must meet.
629 target_feerate_sat_per_1000_weight: u32,
630 /// The set of pending HTLCs on the confirmed commitment that need to be claimed, preferably
631 /// by the same transaction.
632 htlc_descriptors: crate::c_types::derived::CVec_HTLCDescriptorZ,
633 /// The locktime required for the resulting HTLC transaction.
637 use lightning::events::bump_transaction::BumpTransactionEvent as BumpTransactionEventImport;
638 pub(crate) type nativeBumpTransactionEvent = BumpTransactionEventImport;
640 impl BumpTransactionEvent {
642 pub(crate) fn to_native(&self) -> nativeBumpTransactionEvent {
644 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, } => {
645 let mut claim_id_nonref = Clone::clone(claim_id);
646 let mut package_target_feerate_sat_per_1000_weight_nonref = Clone::clone(package_target_feerate_sat_per_1000_weight);
647 let mut commitment_tx_nonref = Clone::clone(commitment_tx);
648 let mut commitment_tx_fee_satoshis_nonref = Clone::clone(commitment_tx_fee_satoshis);
649 let mut anchor_descriptor_nonref = Clone::clone(anchor_descriptor);
650 let mut pending_htlcs_nonref = Clone::clone(pending_htlcs);
651 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()) } }); };
652 nativeBumpTransactionEvent::ChannelClose {
653 claim_id: ::lightning::chain::ClaimId(claim_id_nonref.data),
654 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight_nonref,
655 commitment_tx: commitment_tx_nonref.into_bitcoin(),
656 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis_nonref,
657 anchor_descriptor: *unsafe { Box::from_raw(anchor_descriptor_nonref.take_inner()) },
658 pending_htlcs: local_pending_htlcs_nonref,
661 BumpTransactionEvent::HTLCResolution {ref claim_id, ref target_feerate_sat_per_1000_weight, ref htlc_descriptors, ref tx_lock_time, } => {
662 let mut claim_id_nonref = Clone::clone(claim_id);
663 let mut target_feerate_sat_per_1000_weight_nonref = Clone::clone(target_feerate_sat_per_1000_weight);
664 let mut htlc_descriptors_nonref = Clone::clone(htlc_descriptors);
665 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()) } }); };
666 let mut tx_lock_time_nonref = Clone::clone(tx_lock_time);
667 nativeBumpTransactionEvent::HTLCResolution {
668 claim_id: ::lightning::chain::ClaimId(claim_id_nonref.data),
669 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight_nonref,
670 htlc_descriptors: local_htlc_descriptors_nonref,
671 tx_lock_time: ::bitcoin::PackedLockTime(tx_lock_time_nonref),
677 pub(crate) fn into_native(self) -> nativeBumpTransactionEvent {
679 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, } => {
680 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()) } }); };
681 nativeBumpTransactionEvent::ChannelClose {
682 claim_id: ::lightning::chain::ClaimId(claim_id.data),
683 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight,
684 commitment_tx: commitment_tx.into_bitcoin(),
685 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis,
686 anchor_descriptor: *unsafe { Box::from_raw(anchor_descriptor.take_inner()) },
687 pending_htlcs: local_pending_htlcs,
690 BumpTransactionEvent::HTLCResolution {mut claim_id, mut target_feerate_sat_per_1000_weight, mut htlc_descriptors, mut tx_lock_time, } => {
691 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()) } }); };
692 nativeBumpTransactionEvent::HTLCResolution {
693 claim_id: ::lightning::chain::ClaimId(claim_id.data),
694 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight,
695 htlc_descriptors: local_htlc_descriptors,
696 tx_lock_time: ::bitcoin::PackedLockTime(tx_lock_time),
702 pub(crate) fn from_native(native: &nativeBumpTransactionEvent) -> Self {
704 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, } => {
705 let mut claim_id_nonref = Clone::clone(claim_id);
706 let mut package_target_feerate_sat_per_1000_weight_nonref = Clone::clone(package_target_feerate_sat_per_1000_weight);
707 let mut commitment_tx_nonref = Clone::clone(commitment_tx);
708 let mut commitment_tx_fee_satoshis_nonref = Clone::clone(commitment_tx_fee_satoshis);
709 let mut anchor_descriptor_nonref = Clone::clone(anchor_descriptor);
710 let mut pending_htlcs_nonref = Clone::clone(pending_htlcs);
711 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 } }); };
712 BumpTransactionEvent::ChannelClose {
713 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id_nonref.0 },
714 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight_nonref,
715 commitment_tx: crate::c_types::Transaction::from_bitcoin(&commitment_tx_nonref),
716 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis_nonref,
717 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor { inner: ObjOps::heap_alloc(anchor_descriptor_nonref), is_owned: true },
718 pending_htlcs: local_pending_htlcs_nonref.into(),
721 nativeBumpTransactionEvent::HTLCResolution {ref claim_id, ref target_feerate_sat_per_1000_weight, ref htlc_descriptors, ref tx_lock_time, } => {
722 let mut claim_id_nonref = Clone::clone(claim_id);
723 let mut target_feerate_sat_per_1000_weight_nonref = Clone::clone(target_feerate_sat_per_1000_weight);
724 let mut htlc_descriptors_nonref = Clone::clone(htlc_descriptors);
725 let mut local_htlc_descriptors_nonref = Vec::new(); for mut item in htlc_descriptors_nonref.drain(..) { local_htlc_descriptors_nonref.push( { crate::lightning::events::bump_transaction::HTLCDescriptor { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
726 let mut tx_lock_time_nonref = Clone::clone(tx_lock_time);
727 BumpTransactionEvent::HTLCResolution {
728 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id_nonref.0 },
729 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight_nonref,
730 htlc_descriptors: local_htlc_descriptors_nonref.into(),
731 tx_lock_time: tx_lock_time_nonref.0,
737 pub(crate) fn native_into(native: nativeBumpTransactionEvent) -> Self {
739 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, } => {
740 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 } }); };
741 BumpTransactionEvent::ChannelClose {
742 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id.0 },
743 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight,
744 commitment_tx: crate::c_types::Transaction::from_bitcoin(&commitment_tx),
745 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis,
746 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor { inner: ObjOps::heap_alloc(anchor_descriptor), is_owned: true },
747 pending_htlcs: local_pending_htlcs.into(),
750 nativeBumpTransactionEvent::HTLCResolution {mut claim_id, mut target_feerate_sat_per_1000_weight, mut htlc_descriptors, mut tx_lock_time, } => {
751 let mut local_htlc_descriptors = Vec::new(); for mut item in htlc_descriptors.drain(..) { local_htlc_descriptors.push( { crate::lightning::events::bump_transaction::HTLCDescriptor { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
752 BumpTransactionEvent::HTLCResolution {
753 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id.0 },
754 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight,
755 htlc_descriptors: local_htlc_descriptors.into(),
756 tx_lock_time: tx_lock_time.0,
762 /// Frees any resources used by the BumpTransactionEvent
764 pub extern "C" fn BumpTransactionEvent_free(this_ptr: BumpTransactionEvent) { }
765 /// Creates a copy of the BumpTransactionEvent
767 pub extern "C" fn BumpTransactionEvent_clone(orig: &BumpTransactionEvent) -> BumpTransactionEvent {
771 /// Utility method to constructs a new ChannelClose-variant BumpTransactionEvent
772 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 {
773 BumpTransactionEvent::ChannelClose {
775 package_target_feerate_sat_per_1000_weight,
777 commitment_tx_fee_satoshis,
783 /// Utility method to constructs a new HTLCResolution-variant BumpTransactionEvent
784 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 {
785 BumpTransactionEvent::HTLCResolution {
787 target_feerate_sat_per_1000_weight,
792 /// Checks if two BumpTransactionEvents contain equal inner contents.
793 /// This ignores pointers and is_owned flags and looks at the values in fields.
795 pub extern "C" fn BumpTransactionEvent_eq(a: &BumpTransactionEvent, b: &BumpTransactionEvent) -> bool {
796 if &a.to_native() == &b.to_native() { true } else { false }
799 use lightning::events::bump_transaction::Input as nativeInputImport;
800 pub(crate) type nativeInput = nativeInputImport;
802 /// An input that must be included in a transaction when performing coin selection through
803 /// [`CoinSelectionSource::select_confirmed_utxos`]. It is guaranteed to be a SegWit input, so it
804 /// must have an empty [`TxIn::script_sig`] when spent.
808 /// A pointer to the opaque Rust object.
810 /// Nearly everywhere, inner must be non-null, however in places where
811 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
812 pub inner: *mut nativeInput,
813 /// Indicates that this is the only struct which contains the same pointer.
815 /// Rust functions which take ownership of an object provided via an argument require
816 /// this to be true and invalidate the object pointed to by inner.
820 impl Drop for Input {
822 if self.is_owned && !<*mut nativeInput>::is_null(self.inner) {
823 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
827 /// Frees any resources used by the Input, if is_owned is set and inner is non-NULL.
829 pub extern "C" fn Input_free(this_obj: Input) { }
831 /// Used only if an object of this type is returned as a trait impl by a method
832 pub(crate) extern "C" fn Input_free_void(this_ptr: *mut c_void) {
833 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInput) };
837 pub(crate) fn get_native_ref(&self) -> &'static nativeInput {
838 unsafe { &*ObjOps::untweak_ptr(self.inner) }
840 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInput {
841 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
843 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
844 pub(crate) fn take_inner(mut self) -> *mut nativeInput {
845 assert!(self.is_owned);
846 let ret = ObjOps::untweak_ptr(self.inner);
847 self.inner = core::ptr::null_mut();
851 /// The unique identifier of the input.
853 pub extern "C" fn Input_get_outpoint(this_ptr: &Input) -> crate::lightning::chain::transaction::OutPoint {
854 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
855 crate::c_types::bitcoin_to_C_outpoint(inner_val)
857 /// The unique identifier of the input.
859 pub extern "C" fn Input_set_outpoint(this_ptr: &mut Input, mut val: crate::lightning::chain::transaction::OutPoint) {
860 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
862 /// The UTXO being spent by the input.
864 pub extern "C" fn Input_get_previous_utxo(this_ptr: &Input) -> crate::c_types::TxOut {
865 let mut inner_val = &mut this_ptr.get_native_mut_ref().previous_utxo;
866 crate::c_types::TxOut::from_rust(inner_val)
868 /// The UTXO being spent by the input.
870 pub extern "C" fn Input_set_previous_utxo(this_ptr: &mut Input, mut val: crate::c_types::TxOut) {
871 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previous_utxo = val.into_rust();
873 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
874 /// [`TxIn::witness`], each with their lengths included, required to satisfy the output's
877 pub extern "C" fn Input_get_satisfaction_weight(this_ptr: &Input) -> u64 {
878 let mut inner_val = &mut this_ptr.get_native_mut_ref().satisfaction_weight;
881 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
882 /// [`TxIn::witness`], each with their lengths included, required to satisfy the output's
885 pub extern "C" fn Input_set_satisfaction_weight(this_ptr: &mut Input, mut val: u64) {
886 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.satisfaction_weight = val;
888 /// Constructs a new Input given each field
891 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 {
892 Input { inner: ObjOps::heap_alloc(nativeInput {
893 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
894 previous_utxo: previous_utxo_arg.into_rust(),
895 satisfaction_weight: satisfaction_weight_arg,
898 impl Clone for Input {
899 fn clone(&self) -> Self {
901 inner: if <*mut nativeInput>::is_null(self.inner) { core::ptr::null_mut() } else {
902 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
908 /// Used only if an object of this type is returned as a trait impl by a method
909 pub(crate) extern "C" fn Input_clone_void(this_ptr: *const c_void) -> *mut c_void {
910 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInput)).clone() })) as *mut c_void
913 /// Creates a copy of the Input
914 pub extern "C" fn Input_clone(orig: &Input) -> Input {
917 /// Generates a non-cryptographic 64-bit hash of the Input.
919 pub extern "C" fn Input_hash(o: &Input) -> u64 {
920 if o.inner.is_null() { return 0; }
921 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
923 let mut hasher = core::hash::SipHasher::new();
924 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
925 core::hash::Hasher::finish(&hasher)
927 /// Checks if two Inputs contain equal inner contents.
928 /// This ignores pointers and is_owned flags and looks at the values in fields.
929 /// Two objects with NULL inner values will be considered "equal" here.
931 pub extern "C" fn Input_eq(a: &Input, b: &Input) -> bool {
932 if a.inner == b.inner { return true; }
933 if a.inner.is_null() || b.inner.is_null() { return false; }
934 if a.get_native_ref() == b.get_native_ref() { true } else { false }
937 use lightning::events::bump_transaction::Utxo as nativeUtxoImport;
938 pub(crate) type nativeUtxo = nativeUtxoImport;
940 /// An unspent transaction output that is available to spend resulting from a successful
941 /// [`CoinSelection`] attempt.
945 /// A pointer to the opaque Rust object.
947 /// Nearly everywhere, inner must be non-null, however in places where
948 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
949 pub inner: *mut nativeUtxo,
950 /// Indicates that this is the only struct which contains the same pointer.
952 /// Rust functions which take ownership of an object provided via an argument require
953 /// this to be true and invalidate the object pointed to by inner.
959 if self.is_owned && !<*mut nativeUtxo>::is_null(self.inner) {
960 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
964 /// Frees any resources used by the Utxo, if is_owned is set and inner is non-NULL.
966 pub extern "C" fn Utxo_free(this_obj: Utxo) { }
968 /// Used only if an object of this type is returned as a trait impl by a method
969 pub(crate) extern "C" fn Utxo_free_void(this_ptr: *mut c_void) {
970 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUtxo) };
974 pub(crate) fn get_native_ref(&self) -> &'static nativeUtxo {
975 unsafe { &*ObjOps::untweak_ptr(self.inner) }
977 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUtxo {
978 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
980 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
981 pub(crate) fn take_inner(mut self) -> *mut nativeUtxo {
982 assert!(self.is_owned);
983 let ret = ObjOps::untweak_ptr(self.inner);
984 self.inner = core::ptr::null_mut();
988 /// The unique identifier of the output.
990 pub extern "C" fn Utxo_get_outpoint(this_ptr: &Utxo) -> crate::lightning::chain::transaction::OutPoint {
991 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
992 crate::c_types::bitcoin_to_C_outpoint(inner_val)
994 /// The unique identifier of the output.
996 pub extern "C" fn Utxo_set_outpoint(this_ptr: &mut Utxo, mut val: crate::lightning::chain::transaction::OutPoint) {
997 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
999 /// The output to spend.
1001 pub extern "C" fn Utxo_get_output(this_ptr: &Utxo) -> crate::c_types::TxOut {
1002 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
1003 crate::c_types::TxOut::from_rust(inner_val)
1005 /// The output to spend.
1007 pub extern "C" fn Utxo_set_output(this_ptr: &mut Utxo, mut val: crate::c_types::TxOut) {
1008 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
1010 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
1011 /// with their lengths included, required to satisfy the output's script. The weight consumed by
1012 /// the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
1014 pub extern "C" fn Utxo_get_satisfaction_weight(this_ptr: &Utxo) -> u64 {
1015 let mut inner_val = &mut this_ptr.get_native_mut_ref().satisfaction_weight;
1018 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
1019 /// with their lengths included, required to satisfy the output's script. The weight consumed by
1020 /// the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
1022 pub extern "C" fn Utxo_set_satisfaction_weight(this_ptr: &mut Utxo, mut val: u64) {
1023 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.satisfaction_weight = val;
1025 /// Constructs a new Utxo given each field
1028 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 {
1029 Utxo { inner: ObjOps::heap_alloc(nativeUtxo {
1030 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
1031 output: output_arg.into_rust(),
1032 satisfaction_weight: satisfaction_weight_arg,
1033 }), is_owned: true }
1035 impl Clone for Utxo {
1036 fn clone(&self) -> Self {
1038 inner: if <*mut nativeUtxo>::is_null(self.inner) { core::ptr::null_mut() } else {
1039 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1045 /// Used only if an object of this type is returned as a trait impl by a method
1046 pub(crate) extern "C" fn Utxo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1047 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUtxo)).clone() })) as *mut c_void
1050 /// Creates a copy of the Utxo
1051 pub extern "C" fn Utxo_clone(orig: &Utxo) -> Utxo {
1054 /// Generates a non-cryptographic 64-bit hash of the Utxo.
1056 pub extern "C" fn Utxo_hash(o: &Utxo) -> u64 {
1057 if o.inner.is_null() { return 0; }
1058 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1059 #[allow(deprecated)]
1060 let mut hasher = core::hash::SipHasher::new();
1061 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1062 core::hash::Hasher::finish(&hasher)
1064 /// Checks if two Utxos contain equal inner contents.
1065 /// This ignores pointers and is_owned flags and looks at the values in fields.
1066 /// Two objects with NULL inner values will be considered "equal" here.
1068 pub extern "C" fn Utxo_eq(a: &Utxo, b: &Utxo) -> bool {
1069 if a.inner == b.inner { return true; }
1070 if a.inner.is_null() || b.inner.is_null() { return false; }
1071 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1073 /// Returns a `Utxo` with the `satisfaction_weight` estimate for a legacy P2PKH output.
1076 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 {
1077 let mut ret = lightning::events::bump_transaction::Utxo::new_p2pkh(crate::c_types::C_to_bitcoin_outpoint(outpoint), value, &bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(unsafe { *pubkey_hash }.clone())));
1078 crate::lightning::events::bump_transaction::Utxo { inner: ObjOps::heap_alloc(ret), is_owned: true }
1082 use lightning::events::bump_transaction::CoinSelection as nativeCoinSelectionImport;
1083 pub(crate) type nativeCoinSelection = nativeCoinSelectionImport;
1085 /// The result of a successful coin selection attempt for a transaction requiring additional UTXOs
1086 /// to cover its fees.
1089 pub struct CoinSelection {
1090 /// A pointer to the opaque Rust object.
1092 /// Nearly everywhere, inner must be non-null, however in places where
1093 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1094 pub inner: *mut nativeCoinSelection,
1095 /// Indicates that this is the only struct which contains the same pointer.
1097 /// Rust functions which take ownership of an object provided via an argument require
1098 /// this to be true and invalidate the object pointed to by inner.
1102 impl Drop for CoinSelection {
1103 fn drop(&mut self) {
1104 if self.is_owned && !<*mut nativeCoinSelection>::is_null(self.inner) {
1105 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1109 /// Frees any resources used by the CoinSelection, if is_owned is set and inner is non-NULL.
1111 pub extern "C" fn CoinSelection_free(this_obj: CoinSelection) { }
1113 /// Used only if an object of this type is returned as a trait impl by a method
1114 pub(crate) extern "C" fn CoinSelection_free_void(this_ptr: *mut c_void) {
1115 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCoinSelection) };
1118 impl CoinSelection {
1119 pub(crate) fn get_native_ref(&self) -> &'static nativeCoinSelection {
1120 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1122 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCoinSelection {
1123 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1125 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1126 pub(crate) fn take_inner(mut self) -> *mut nativeCoinSelection {
1127 assert!(self.is_owned);
1128 let ret = ObjOps::untweak_ptr(self.inner);
1129 self.inner = core::ptr::null_mut();
1133 /// The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
1134 /// requiring additional fees.
1136 pub extern "C" fn CoinSelection_get_confirmed_utxos(this_ptr: &CoinSelection) -> crate::c_types::derived::CVec_UtxoZ {
1137 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmed_utxos;
1138 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 } }); };
1139 local_inner_val.into()
1141 /// The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
1142 /// requiring additional fees.
1144 pub extern "C" fn CoinSelection_set_confirmed_utxos(this_ptr: &mut CoinSelection, mut val: crate::c_types::derived::CVec_UtxoZ) {
1145 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1146 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmed_utxos = local_val;
1148 /// An additional output tracking whether any change remained after coin selection. This output
1149 /// should always have a value above dust for its given `script_pubkey`. It should not be
1150 /// spent until the transaction it belongs to confirms to ensure mempool descendant limits are
1151 /// not met. This implies no other party should be able to spend it except us.
1153 pub extern "C" fn CoinSelection_get_change_output(this_ptr: &CoinSelection) -> crate::c_types::derived::COption_TxOutZ {
1154 let mut inner_val = &mut this_ptr.get_native_mut_ref().change_output;
1155 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()) }) };
1158 /// An additional output tracking whether any change remained after coin selection. This output
1159 /// should always have a value above dust for its given `script_pubkey`. It should not be
1160 /// spent until the transaction it belongs to confirms to ensure mempool descendant limits are
1161 /// not met. This implies no other party should be able to spend it except us.
1163 pub extern "C" fn CoinSelection_set_change_output(this_ptr: &mut CoinSelection, mut val: crate::c_types::derived::COption_TxOutZ) {
1164 let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_rust() }})} };
1165 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.change_output = local_val;
1167 /// Constructs a new CoinSelection given each field
1170 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 {
1171 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()) } }); };
1172 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() }})} };
1173 CoinSelection { inner: ObjOps::heap_alloc(nativeCoinSelection {
1174 confirmed_utxos: local_confirmed_utxos_arg,
1175 change_output: local_change_output_arg,
1176 }), is_owned: true }
1178 impl Clone for CoinSelection {
1179 fn clone(&self) -> Self {
1181 inner: if <*mut nativeCoinSelection>::is_null(self.inner) { core::ptr::null_mut() } else {
1182 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1188 /// Used only if an object of this type is returned as a trait impl by a method
1189 pub(crate) extern "C" fn CoinSelection_clone_void(this_ptr: *const c_void) -> *mut c_void {
1190 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCoinSelection)).clone() })) as *mut c_void
1193 /// Creates a copy of the CoinSelection
1194 pub extern "C" fn CoinSelection_clone(orig: &CoinSelection) -> CoinSelection {
1197 /// An abstraction over a bitcoin wallet that can perform coin selection over a set of UTXOs and can
1198 /// sign for them. The coin selection method aims to mimic Bitcoin Core's `fundrawtransaction` RPC,
1199 /// which most wallets should be able to satisfy. Otherwise, consider implementing [`WalletSource`],
1200 /// which can provide a default implementation of this trait when used with [`Wallet`].
1202 pub struct CoinSelectionSource {
1203 /// An opaque pointer which is passed to your function implementations as an argument.
1204 /// This has no meaning in the LDK, and can be NULL or any other value.
1205 pub this_arg: *mut c_void,
1206 /// Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
1207 /// available to spend. Implementations are free to pick their coin selection algorithm of
1208 /// choice, as long as the following requirements are met:
1210 /// 1. `must_spend` contains a set of [`Input`]s that must be included in the transaction
1211 /// throughout coin selection, but must not be returned as part of the result.
1212 /// 2. `must_pay_to` contains a set of [`TxOut`]s that must be included in the transaction
1213 /// throughout coin selection. In some cases, like when funding an anchor transaction, this
1214 /// set is empty. Implementations should ensure they handle this correctly on their end,
1215 /// e.g., Bitcoin Core's `fundrawtransaction` RPC requires at least one output to be
1216 /// provided, in which case a zero-value empty OP_RETURN output can be used instead.
1217 /// 3. Enough inputs must be selected/contributed for the resulting transaction (including the
1218 /// inputs and outputs noted above) to meet `target_feerate_sat_per_1000_weight`.
1220 /// Implementations must take note that [`Input::satisfaction_weight`] only tracks the weight of
1221 /// the input's `script_sig` and `witness`. Some wallets, like Bitcoin Core's, may require
1222 /// providing the full input weight. Failing to do so may lead to underestimating fee bumps and
1223 /// delaying block inclusion.
1225 /// The `claim_id` must map to the set of external UTXOs assigned to the claim, such that they
1226 /// can be re-used within new fee-bumped iterations of the original claiming transaction,
1227 /// ensuring that claims don't double spend each other. If a specific `claim_id` has never had a
1228 /// transaction associated with it, and all of the available UTXOs have already been assigned to
1229 /// other claims, implementations must be willing to double spend their UTXOs. The choice of
1230 /// which UTXOs to double spend is left to the implementation, but it must strive to keep the
1231 /// set of other claims being double spent to a minimum.
1232 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,
1233 /// Signs and provides the full witness for all inputs within the transaction known to the
1234 /// trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
1235 pub sign_tx: extern "C" fn (this_arg: *const c_void, tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_TransactionNoneZ,
1236 /// Frees any resources associated with this object given its this_arg pointer.
1237 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1238 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1240 unsafe impl Send for CoinSelectionSource {}
1241 unsafe impl Sync for CoinSelectionSource {}
1243 pub(crate) extern "C" fn CoinSelectionSource_clone_fields(orig: &CoinSelectionSource) -> CoinSelectionSource {
1244 CoinSelectionSource {
1245 this_arg: orig.this_arg,
1246 select_confirmed_utxos: Clone::clone(&orig.select_confirmed_utxos),
1247 sign_tx: Clone::clone(&orig.sign_tx),
1248 free: Clone::clone(&orig.free),
1252 use lightning::events::bump_transaction::CoinSelectionSource as rustCoinSelectionSource;
1253 impl rustCoinSelectionSource for CoinSelectionSource {
1254 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, ()> {
1255 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 } }); };
1256 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) }); };
1257 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);
1258 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)) })*/ })};
1261 fn sign_tx(&self, mut tx: bitcoin::Transaction) -> Result<bitcoin::Transaction, ()> {
1262 let mut ret = (self.sign_tx)(self.this_arg, crate::c_types::Transaction::from_bitcoin(&tx));
1263 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)) })*/ })};
1268 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1269 // directly as a Deref trait in higher-level structs:
1270 impl core::ops::Deref for CoinSelectionSource {
1272 fn deref(&self) -> &Self {
1276 /// Calls the free function if one is set
1278 pub extern "C" fn CoinSelectionSource_free(this_ptr: CoinSelectionSource) { }
1279 impl Drop for CoinSelectionSource {
1280 fn drop(&mut self) {
1281 if let Some(f) = self.free {
1286 /// An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
1287 /// provide a default implementation to [`CoinSelectionSource`].
1289 pub struct WalletSource {
1290 /// An opaque pointer which is passed to your function implementations as an argument.
1291 /// This has no meaning in the LDK, and can be NULL or any other value.
1292 pub this_arg: *mut c_void,
1293 /// Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
1294 pub list_confirmed_utxos: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_UtxoZNoneZ,
1295 /// Returns a script to use for change above dust resulting from a successful coin selection
1297 pub get_change_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_ScriptNoneZ,
1298 /// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
1299 /// the transaction known to the wallet (i.e., any provided via
1300 /// [`WalletSource::list_confirmed_utxos`]).
1301 pub sign_tx: extern "C" fn (this_arg: *const c_void, tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_TransactionNoneZ,
1302 /// Frees any resources associated with this object given its this_arg pointer.
1303 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1304 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1306 unsafe impl Send for WalletSource {}
1307 unsafe impl Sync for WalletSource {}
1309 pub(crate) extern "C" fn WalletSource_clone_fields(orig: &WalletSource) -> WalletSource {
1311 this_arg: orig.this_arg,
1312 list_confirmed_utxos: Clone::clone(&orig.list_confirmed_utxos),
1313 get_change_script: Clone::clone(&orig.get_change_script),
1314 sign_tx: Clone::clone(&orig.sign_tx),
1315 free: Clone::clone(&orig.free),
1319 use lightning::events::bump_transaction::WalletSource as rustWalletSource;
1320 impl rustWalletSource for WalletSource {
1321 fn list_confirmed_utxos(&self) -> Result<Vec<lightning::events::bump_transaction::Utxo>, ()> {
1322 let mut ret = (self.list_confirmed_utxos)(self.this_arg);
1323 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)) })*/ })};
1326 fn get_change_script(&self) -> Result<bitcoin::Script, ()> {
1327 let mut ret = (self.get_change_script)(self.this_arg);
1328 let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::blockdata::script::Script::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)) })*/ })};
1331 fn sign_tx(&self, mut tx: bitcoin::Transaction) -> Result<bitcoin::Transaction, ()> {
1332 let mut ret = (self.sign_tx)(self.this_arg, crate::c_types::Transaction::from_bitcoin(&tx));
1333 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)) })*/ })};
1338 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1339 // directly as a Deref trait in higher-level structs:
1340 impl core::ops::Deref for WalletSource {
1342 fn deref(&self) -> &Self {
1346 /// Calls the free function if one is set
1348 pub extern "C" fn WalletSource_free(this_ptr: WalletSource) { }
1349 impl Drop for WalletSource {
1350 fn drop(&mut self) {
1351 if let Some(f) = self.free {
1357 use lightning::events::bump_transaction::Wallet as nativeWalletImport;
1358 pub(crate) type nativeWallet = nativeWalletImport<crate::lightning::events::bump_transaction::WalletSource, crate::lightning::util::logger::Logger>;
1360 /// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
1361 /// avoid conflicting double spends. If not enough UTXOs are available to do so, conflicting double
1362 /// spends may happen.
1366 /// A pointer to the opaque Rust object.
1368 /// Nearly everywhere, inner must be non-null, however in places where
1369 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1370 pub inner: *mut nativeWallet,
1371 /// Indicates that this is the only struct which contains the same pointer.
1373 /// Rust functions which take ownership of an object provided via an argument require
1374 /// this to be true and invalidate the object pointed to by inner.
1378 impl Drop for Wallet {
1379 fn drop(&mut self) {
1380 if self.is_owned && !<*mut nativeWallet>::is_null(self.inner) {
1381 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1385 /// Frees any resources used by the Wallet, if is_owned is set and inner is non-NULL.
1387 pub extern "C" fn Wallet_free(this_obj: Wallet) { }
1389 /// Used only if an object of this type is returned as a trait impl by a method
1390 pub(crate) extern "C" fn Wallet_free_void(this_ptr: *mut c_void) {
1391 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeWallet) };
1395 pub(crate) fn get_native_ref(&self) -> &'static nativeWallet {
1396 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1398 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeWallet {
1399 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1401 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1402 pub(crate) fn take_inner(mut self) -> *mut nativeWallet {
1403 assert!(self.is_owned);
1404 let ret = ObjOps::untweak_ptr(self.inner);
1405 self.inner = core::ptr::null_mut();
1409 /// Returns a new instance backed by the given [`WalletSource`] that serves as an implementation
1410 /// of [`CoinSelectionSource`].
1413 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 {
1414 let mut ret = lightning::events::bump_transaction::Wallet::new(source, logger);
1415 crate::lightning::events::bump_transaction::Wallet { inner: ObjOps::heap_alloc(ret), is_owned: true }
1418 impl From<nativeWallet> for crate::lightning::events::bump_transaction::CoinSelectionSource {
1419 fn from(obj: nativeWallet) -> Self {
1420 let mut rust_obj = Wallet { inner: ObjOps::heap_alloc(obj), is_owned: true };
1421 let mut ret = Wallet_as_CoinSelectionSource(&rust_obj);
1422 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1423 rust_obj.inner = core::ptr::null_mut();
1424 ret.free = Some(Wallet_free_void);
1428 /// Constructs a new CoinSelectionSource which calls the relevant methods on this_arg.
1429 /// This copies the `inner` pointer in this_arg and thus the returned CoinSelectionSource must be freed before this_arg is
1431 pub extern "C" fn Wallet_as_CoinSelectionSource(this_arg: &Wallet) -> crate::lightning::events::bump_transaction::CoinSelectionSource {
1432 crate::lightning::events::bump_transaction::CoinSelectionSource {
1433 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1435 select_confirmed_utxos: Wallet_CoinSelectionSource_select_confirmed_utxos,
1436 sign_tx: Wallet_CoinSelectionSource_sign_tx,
1441 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 {
1442 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()) } }); };
1443 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() }); };
1444 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);
1445 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() };
1449 extern "C" fn Wallet_CoinSelectionSource_sign_tx(this_arg: *const c_void, mut tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_TransactionNoneZ {
1450 let mut ret = <nativeWallet as lightning::events::bump_transaction::CoinSelectionSource<>>::sign_tx(unsafe { &mut *(this_arg as *mut nativeWallet) }, tx.into_bitcoin());
1451 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() };
1456 use lightning::events::bump_transaction::BumpTransactionEventHandler as nativeBumpTransactionEventHandlerImport;
1457 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>;
1459 /// A handler for [`Event::BumpTransaction`] events that sources confirmed UTXOs from a
1460 /// [`CoinSelectionSource`] to fee bump transactions via Child-Pays-For-Parent (CPFP) or
1461 /// Replace-By-Fee (RBF).
1463 /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
1466 pub struct BumpTransactionEventHandler {
1467 /// A pointer to the opaque Rust object.
1469 /// Nearly everywhere, inner must be non-null, however in places where
1470 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1471 pub inner: *mut nativeBumpTransactionEventHandler,
1472 /// Indicates that this is the only struct which contains the same pointer.
1474 /// Rust functions which take ownership of an object provided via an argument require
1475 /// this to be true and invalidate the object pointed to by inner.
1479 impl Drop for BumpTransactionEventHandler {
1480 fn drop(&mut self) {
1481 if self.is_owned && !<*mut nativeBumpTransactionEventHandler>::is_null(self.inner) {
1482 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1486 /// Frees any resources used by the BumpTransactionEventHandler, if is_owned is set and inner is non-NULL.
1488 pub extern "C" fn BumpTransactionEventHandler_free(this_obj: BumpTransactionEventHandler) { }
1490 /// Used only if an object of this type is returned as a trait impl by a method
1491 pub(crate) extern "C" fn BumpTransactionEventHandler_free_void(this_ptr: *mut c_void) {
1492 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBumpTransactionEventHandler) };
1495 impl BumpTransactionEventHandler {
1496 pub(crate) fn get_native_ref(&self) -> &'static nativeBumpTransactionEventHandler {
1497 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1499 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBumpTransactionEventHandler {
1500 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1502 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1503 pub(crate) fn take_inner(mut self) -> *mut nativeBumpTransactionEventHandler {
1504 assert!(self.is_owned);
1505 let ret = ObjOps::untweak_ptr(self.inner);
1506 self.inner = core::ptr::null_mut();
1510 /// Returns a new instance capable of handling [`Event::BumpTransaction`] events.
1512 /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
1515 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 {
1516 let mut ret = lightning::events::bump_transaction::BumpTransactionEventHandler::new(broadcaster, utxo_source, signer_provider, logger);
1517 crate::lightning::events::bump_transaction::BumpTransactionEventHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
1520 /// Handles all variants of [`BumpTransactionEvent`].
1522 pub extern "C" fn BumpTransactionEventHandler_handle_event(this_arg: &crate::lightning::events::bump_transaction::BumpTransactionEventHandler, event: &crate::lightning::events::bump_transaction::BumpTransactionEvent) {
1523 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_event(&event.to_native())