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::ChannelDerivationParameters as nativeChannelDerivationParametersImport;
24 pub(crate) type nativeChannelDerivationParameters = nativeChannelDerivationParametersImport;
26 /// The parameters required to derive a channel signer via [`SignerProvider`].
29 pub struct ChannelDerivationParameters {
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 nativeChannelDerivationParameters,
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 ChannelDerivationParameters {
44 if self.is_owned && !<*mut nativeChannelDerivationParameters>::is_null(self.inner) {
45 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
49 /// Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL.
51 pub extern "C" fn ChannelDerivationParameters_free(this_obj: ChannelDerivationParameters) { }
53 /// Used only if an object of this type is returned as a trait impl by a method
54 pub(crate) extern "C" fn ChannelDerivationParameters_free_void(this_ptr: *mut c_void) {
55 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDerivationParameters) };
58 impl ChannelDerivationParameters {
59 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDerivationParameters {
60 unsafe { &*ObjOps::untweak_ptr(self.inner) }
62 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDerivationParameters {
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 nativeChannelDerivationParameters {
67 assert!(self.is_owned);
68 let ret = ObjOps::untweak_ptr(self.inner);
69 self.inner = core::ptr::null_mut();
73 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
75 pub extern "C" fn ChannelDerivationParameters_get_value_satoshis(this_ptr: &ChannelDerivationParameters) -> u64 {
76 let mut inner_val = &mut this_ptr.get_native_mut_ref().value_satoshis;
79 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
81 pub extern "C" fn ChannelDerivationParameters_set_value_satoshis(this_ptr: &mut ChannelDerivationParameters, mut val: u64) {
82 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.value_satoshis = val;
84 /// The unique identifier to re-derive the signer for the associated channel.
86 pub extern "C" fn ChannelDerivationParameters_get_keys_id(this_ptr: &ChannelDerivationParameters) -> *const [u8; 32] {
87 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_id;
90 /// The unique identifier to re-derive the signer for the associated channel.
92 pub extern "C" fn ChannelDerivationParameters_set_keys_id(this_ptr: &mut ChannelDerivationParameters, mut val: crate::c_types::ThirtyTwoBytes) {
93 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_id = val.data;
95 /// The necessary channel parameters that need to be provided to the re-derived signer through
96 /// [`ChannelSigner::provide_channel_parameters`].
98 /// [`ChannelSigner::provide_channel_parameters`]: crate::sign::ChannelSigner::provide_channel_parameters
100 pub extern "C" fn ChannelDerivationParameters_get_transaction_parameters(this_ptr: &ChannelDerivationParameters) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
101 let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_parameters;
102 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 }
104 /// The necessary channel parameters that need to be provided to the re-derived signer through
105 /// [`ChannelSigner::provide_channel_parameters`].
107 /// [`ChannelSigner::provide_channel_parameters`]: crate::sign::ChannelSigner::provide_channel_parameters
109 pub extern "C" fn ChannelDerivationParameters_set_transaction_parameters(this_ptr: &mut ChannelDerivationParameters, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
110 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_parameters = *unsafe { Box::from_raw(val.take_inner()) };
112 /// Constructs a new ChannelDerivationParameters given each field
115 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 {
116 ChannelDerivationParameters { inner: ObjOps::heap_alloc(nativeChannelDerivationParameters {
117 value_satoshis: value_satoshis_arg,
118 keys_id: keys_id_arg.data,
119 transaction_parameters: *unsafe { Box::from_raw(transaction_parameters_arg.take_inner()) },
122 impl Clone for ChannelDerivationParameters {
123 fn clone(&self) -> Self {
125 inner: if <*mut nativeChannelDerivationParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
126 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
132 /// Used only if an object of this type is returned as a trait impl by a method
133 pub(crate) extern "C" fn ChannelDerivationParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
134 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelDerivationParameters)).clone() })) as *mut c_void
137 /// Creates a copy of the ChannelDerivationParameters
138 pub extern "C" fn ChannelDerivationParameters_clone(orig: &ChannelDerivationParameters) -> ChannelDerivationParameters {
141 /// Checks if two ChannelDerivationParameterss contain equal inner contents.
142 /// This ignores pointers and is_owned flags and looks at the values in fields.
143 /// Two objects with NULL inner values will be considered "equal" here.
145 pub extern "C" fn ChannelDerivationParameters_eq(a: &ChannelDerivationParameters, b: &ChannelDerivationParameters) -> bool {
146 if a.inner == b.inner { return true; }
147 if a.inner.is_null() || b.inner.is_null() { return false; }
148 if a.get_native_ref() == b.get_native_ref() { true } else { false }
151 /// Serialize the ChannelDerivationParameters object into a byte array which can be read by ChannelDerivationParameters_read
152 pub extern "C" fn ChannelDerivationParameters_write(obj: &crate::lightning::events::bump_transaction::ChannelDerivationParameters) -> crate::c_types::derived::CVec_u8Z {
153 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
156 pub(crate) extern "C" fn ChannelDerivationParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
157 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDerivationParameters) })
160 /// Read a ChannelDerivationParameters from a byte array, created by ChannelDerivationParameters_write
161 pub extern "C" fn ChannelDerivationParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDerivationParametersDecodeErrorZ {
162 let res: Result<lightning::events::bump_transaction::ChannelDerivationParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
163 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::events::bump_transaction::ChannelDerivationParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
167 use lightning::events::bump_transaction::AnchorDescriptor as nativeAnchorDescriptorImport;
168 pub(crate) type nativeAnchorDescriptor = nativeAnchorDescriptorImport;
170 /// A descriptor used to sign for a commitment transaction's anchor output.
173 pub struct AnchorDescriptor {
174 /// A pointer to the opaque Rust object.
176 /// Nearly everywhere, inner must be non-null, however in places where
177 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
178 pub inner: *mut nativeAnchorDescriptor,
179 /// Indicates that this is the only struct which contains the same pointer.
181 /// Rust functions which take ownership of an object provided via an argument require
182 /// this to be true and invalidate the object pointed to by inner.
186 impl Drop for AnchorDescriptor {
188 if self.is_owned && !<*mut nativeAnchorDescriptor>::is_null(self.inner) {
189 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
193 /// Frees any resources used by the AnchorDescriptor, if is_owned is set and inner is non-NULL.
195 pub extern "C" fn AnchorDescriptor_free(this_obj: AnchorDescriptor) { }
197 /// Used only if an object of this type is returned as a trait impl by a method
198 pub(crate) extern "C" fn AnchorDescriptor_free_void(this_ptr: *mut c_void) {
199 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeAnchorDescriptor) };
202 impl AnchorDescriptor {
203 pub(crate) fn get_native_ref(&self) -> &'static nativeAnchorDescriptor {
204 unsafe { &*ObjOps::untweak_ptr(self.inner) }
206 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeAnchorDescriptor {
207 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
209 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
210 pub(crate) fn take_inner(mut self) -> *mut nativeAnchorDescriptor {
211 assert!(self.is_owned);
212 let ret = ObjOps::untweak_ptr(self.inner);
213 self.inner = core::ptr::null_mut();
217 /// The parameters required to derive the signer for the anchor input.
219 pub extern "C" fn AnchorDescriptor_get_channel_derivation_parameters(this_ptr: &AnchorDescriptor) -> crate::lightning::events::bump_transaction::ChannelDerivationParameters {
220 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters;
221 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 }
223 /// The parameters required to derive the signer for the anchor input.
225 pub extern "C" fn AnchorDescriptor_set_channel_derivation_parameters(this_ptr: &mut AnchorDescriptor, mut val: crate::lightning::events::bump_transaction::ChannelDerivationParameters) {
226 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) };
228 /// The transaction input's outpoint corresponding to the commitment transaction's anchor
231 pub extern "C" fn AnchorDescriptor_get_outpoint(this_ptr: &AnchorDescriptor) -> crate::lightning::chain::transaction::OutPoint {
232 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
233 crate::c_types::bitcoin_to_C_outpoint(inner_val)
235 /// The transaction input's outpoint corresponding to the commitment transaction's anchor
238 pub extern "C" fn AnchorDescriptor_set_outpoint(this_ptr: &mut AnchorDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
239 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
241 /// Constructs a new AnchorDescriptor given each field
244 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 {
245 AnchorDescriptor { inner: ObjOps::heap_alloc(nativeAnchorDescriptor {
246 channel_derivation_parameters: *unsafe { Box::from_raw(channel_derivation_parameters_arg.take_inner()) },
247 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
250 impl Clone for AnchorDescriptor {
251 fn clone(&self) -> Self {
253 inner: if <*mut nativeAnchorDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
254 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
260 /// Used only if an object of this type is returned as a trait impl by a method
261 pub(crate) extern "C" fn AnchorDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
262 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAnchorDescriptor)).clone() })) as *mut c_void
265 /// Creates a copy of the AnchorDescriptor
266 pub extern "C" fn AnchorDescriptor_clone(orig: &AnchorDescriptor) -> AnchorDescriptor {
269 /// Checks if two AnchorDescriptors contain equal inner contents.
270 /// This ignores pointers and is_owned flags and looks at the values in fields.
271 /// Two objects with NULL inner values will be considered "equal" here.
273 pub extern "C" fn AnchorDescriptor_eq(a: &AnchorDescriptor, b: &AnchorDescriptor) -> bool {
274 if a.inner == b.inner { return true; }
275 if a.inner.is_null() || b.inner.is_null() { return false; }
276 if a.get_native_ref() == b.get_native_ref() { true } else { false }
278 /// Returns the UTXO to be spent by the anchor input, which can be obtained via
279 /// [`Self::unsigned_tx_input`].
282 pub extern "C" fn AnchorDescriptor_previous_utxo(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor) -> crate::c_types::TxOut {
283 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo();
284 crate::c_types::TxOut::from_rust(&ret)
287 /// Returns the unsigned transaction input spending the anchor output in the commitment
291 pub extern "C" fn AnchorDescriptor_unsigned_tx_input(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor) -> crate::c_types::TxIn {
292 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input();
293 crate::c_types::TxIn::from_rust(&ret)
296 /// Returns the witness script of the anchor output in the commitment transaction.
299 pub extern "C" fn AnchorDescriptor_witness_script(this_arg: &crate::lightning::events::bump_transaction::AnchorDescriptor) -> crate::c_types::derived::CVec_u8Z {
300 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script();
301 ret.into_bytes().into()
304 /// Returns the fully signed witness required to spend the anchor output in the commitment
308 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 {
309 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_input_witness(&signature.into_rust());
310 crate::c_types::Witness::from_bitcoin(&ret)
313 /// Derives the channel signer required to sign the anchor input.
316 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 {
317 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider);
322 use lightning::events::bump_transaction::HTLCDescriptor as nativeHTLCDescriptorImport;
323 pub(crate) type nativeHTLCDescriptor = nativeHTLCDescriptorImport;
325 /// A descriptor used to sign for a commitment transaction's HTLC output.
328 pub struct HTLCDescriptor {
329 /// A pointer to the opaque Rust object.
331 /// Nearly everywhere, inner must be non-null, however in places where
332 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
333 pub inner: *mut nativeHTLCDescriptor,
334 /// Indicates that this is the only struct which contains the same pointer.
336 /// Rust functions which take ownership of an object provided via an argument require
337 /// this to be true and invalidate the object pointed to by inner.
341 impl Drop for HTLCDescriptor {
343 if self.is_owned && !<*mut nativeHTLCDescriptor>::is_null(self.inner) {
344 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
348 /// Frees any resources used by the HTLCDescriptor, if is_owned is set and inner is non-NULL.
350 pub extern "C" fn HTLCDescriptor_free(this_obj: HTLCDescriptor) { }
352 /// Used only if an object of this type is returned as a trait impl by a method
353 pub(crate) extern "C" fn HTLCDescriptor_free_void(this_ptr: *mut c_void) {
354 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCDescriptor) };
357 impl HTLCDescriptor {
358 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCDescriptor {
359 unsafe { &*ObjOps::untweak_ptr(self.inner) }
361 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCDescriptor {
362 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
364 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
365 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCDescriptor {
366 assert!(self.is_owned);
367 let ret = ObjOps::untweak_ptr(self.inner);
368 self.inner = core::ptr::null_mut();
372 /// The parameters required to derive the signer for the HTLC input.
374 pub extern "C" fn HTLCDescriptor_get_channel_derivation_parameters(this_ptr: &HTLCDescriptor) -> crate::lightning::events::bump_transaction::ChannelDerivationParameters {
375 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters;
376 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 }
378 /// The parameters required to derive the signer for the HTLC input.
380 pub extern "C" fn HTLCDescriptor_set_channel_derivation_parameters(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::events::bump_transaction::ChannelDerivationParameters) {
381 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) };
383 /// The number of the commitment transaction in which the HTLC output lives.
385 pub extern "C" fn HTLCDescriptor_get_per_commitment_number(this_ptr: &HTLCDescriptor) -> u64 {
386 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_number;
389 /// The number of the commitment transaction in which the HTLC output lives.
391 pub extern "C" fn HTLCDescriptor_set_per_commitment_number(this_ptr: &mut HTLCDescriptor, mut val: u64) {
392 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_number = val;
394 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
395 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
396 /// arrive at unique keys per commitment.
398 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
400 pub extern "C" fn HTLCDescriptor_get_per_commitment_point(this_ptr: &HTLCDescriptor) -> crate::c_types::PublicKey {
401 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
402 crate::c_types::PublicKey::from_rust(&inner_val)
404 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
405 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
406 /// arrive at unique keys per commitment.
408 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
410 pub extern "C" fn HTLCDescriptor_set_per_commitment_point(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::PublicKey) {
411 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
413 /// The details of the HTLC as it appears in the commitment transaction.
415 pub extern "C" fn HTLCDescriptor_get_htlc(this_ptr: &HTLCDescriptor) -> crate::lightning::ln::chan_utils::HTLCOutputInCommitment {
416 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc;
417 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 }
419 /// The details of the HTLC as it appears in the commitment transaction.
421 pub extern "C" fn HTLCDescriptor_set_htlc(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::ln::chan_utils::HTLCOutputInCommitment) {
422 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc = *unsafe { Box::from_raw(val.take_inner()) };
424 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
427 pub extern "C" fn HTLCDescriptor_get_preimage(this_ptr: &HTLCDescriptor) -> crate::c_types::derived::COption_ThirtyTwoBytesZ {
428 let mut inner_val = &mut this_ptr.get_native_mut_ref().preimage;
429 let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*inner_val.as_ref().unwrap()).clone().0 } }) };
432 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
435 pub extern "C" fn HTLCDescriptor_set_preimage(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::derived::COption_ThirtyTwoBytesZ) {
436 let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentPreimage({ val_opt.take() }.data) }})} };
437 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.preimage = local_val;
439 /// The counterparty's signature required to spend the HTLC output.
441 pub extern "C" fn HTLCDescriptor_get_counterparty_sig(this_ptr: &HTLCDescriptor) -> crate::c_types::ECDSASignature {
442 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig;
443 crate::c_types::ECDSASignature::from_rust(&inner_val)
445 /// The counterparty's signature required to spend the HTLC output.
447 pub extern "C" fn HTLCDescriptor_set_counterparty_sig(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::ECDSASignature) {
448 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust();
450 impl Clone for HTLCDescriptor {
451 fn clone(&self) -> Self {
453 inner: if <*mut nativeHTLCDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
454 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
460 /// Used only if an object of this type is returned as a trait impl by a method
461 pub(crate) extern "C" fn HTLCDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
462 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCDescriptor)).clone() })) as *mut c_void
465 /// Creates a copy of the HTLCDescriptor
466 pub extern "C" fn HTLCDescriptor_clone(orig: &HTLCDescriptor) -> HTLCDescriptor {
469 /// Checks if two HTLCDescriptors contain equal inner contents.
470 /// This ignores pointers and is_owned flags and looks at the values in fields.
471 /// Two objects with NULL inner values will be considered "equal" here.
473 pub extern "C" fn HTLCDescriptor_eq(a: &HTLCDescriptor, b: &HTLCDescriptor) -> bool {
474 if a.inner == b.inner { return true; }
475 if a.inner.is_null() || b.inner.is_null() { return false; }
476 if a.get_native_ref() == b.get_native_ref() { true } else { false }
479 /// Serialize the HTLCDescriptor object into a byte array which can be read by HTLCDescriptor_read
480 pub extern "C" fn HTLCDescriptor_write(obj: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z {
481 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
484 pub(crate) extern "C" fn HTLCDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
485 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCDescriptor) })
488 /// Read a HTLCDescriptor from a byte array, created by HTLCDescriptor_write
489 pub extern "C" fn HTLCDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCDescriptorDecodeErrorZ {
490 let res: Result<lightning::events::bump_transaction::HTLCDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
491 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::events::bump_transaction::HTLCDescriptor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
494 /// Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint
495 /// being spent by the HTLC input in the HTLC transaction.
498 pub extern "C" fn HTLCDescriptor_outpoint(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::lightning::chain::transaction::OutPoint {
499 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.outpoint();
500 crate::c_types::bitcoin_to_C_outpoint(&ret)
503 /// Returns the UTXO to be spent by the HTLC input, which can be obtained via
504 /// [`Self::unsigned_tx_input`].
507 pub extern "C" fn HTLCDescriptor_previous_utxo(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::TxOut {
508 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo(secp256k1::global::SECP256K1);
509 crate::c_types::TxOut::from_rust(&ret)
512 /// Returns the unsigned transaction input spending the HTLC output in the commitment
516 pub extern "C" fn HTLCDescriptor_unsigned_tx_input(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::TxIn {
517 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input();
518 crate::c_types::TxIn::from_rust(&ret)
521 /// Returns the delayed output created as a result of spending the HTLC output in the commitment
525 pub extern "C" fn HTLCDescriptor_tx_output(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::TxOut {
526 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_output(secp256k1::global::SECP256K1);
527 crate::c_types::TxOut::from_rust(&ret)
530 /// Returns the witness script of the HTLC output in the commitment transaction.
533 pub extern "C" fn HTLCDescriptor_witness_script(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z {
534 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script(secp256k1::global::SECP256K1);
535 ret.into_bytes().into()
538 /// Returns the fully signed witness required to spend the HTLC output in the commitment
542 pub extern "C" fn HTLCDescriptor_tx_input_witness(this_arg: &crate::lightning::events::bump_transaction::HTLCDescriptor, mut signature: crate::c_types::ECDSASignature, mut witness_script: crate::c_types::u8slice) -> crate::c_types::Witness {
543 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())));
544 crate::c_types::Witness::from_bitcoin(&ret)
547 /// Derives the channel signer required to sign the HTLC input.
550 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 {
551 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider);
555 /// Represents the different types of transactions, originating from LDK, to be bumped.
559 pub enum BumpTransactionEvent {
560 /// Indicates that a channel featuring anchor outputs is to be closed by broadcasting the local
561 /// commitment transaction. Since commitment transactions have a static feerate pre-agreed upon,
562 /// they may need additional fees to be attached through a child transaction using the popular
563 /// [Child-Pays-For-Parent](https://bitcoinops.org/en/topics/cpfp) fee bumping technique. This
564 /// child transaction must include the anchor input described within `anchor_descriptor` along
565 /// with additional inputs to meet the target feerate. Failure to meet the target feerate
566 /// decreases the confirmation odds of the transaction package (which includes the commitment
567 /// and child anchor transactions), possibly resulting in a loss of funds. Once the transaction
568 /// is constructed, it must be fully signed for and broadcast by the consumer of the event
569 /// along with the `commitment_tx` enclosed. Note that the `commitment_tx` must always be
570 /// broadcast first, as the child anchor transaction depends on it.
572 /// The consumer should be able to sign for any of the additional inputs included within the
573 /// child anchor transaction. To sign its anchor input, an [`EcdsaChannelSigner`] should be
574 /// re-derived through [`AnchorDescriptor::derive_channel_signer`]. The anchor input signature
575 /// can be computed with [`EcdsaChannelSigner::sign_holder_anchor_input`], which can then be
576 /// provided to [`build_anchor_input_witness`] along with the `funding_pubkey` to obtain the
577 /// full witness required to spend.
579 /// It is possible to receive more than one instance of this event if a valid child anchor
580 /// transaction is never broadcast or is but not with a sufficient fee to be mined. Care should
581 /// be taken by the consumer of the event to ensure any future iterations of the child anchor
582 /// transaction adhere to the [Replace-By-Fee
583 /// rules](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md)
584 /// for fee bumps to be accepted into the mempool, and eventually the chain. As the frequency of
585 /// these events is not user-controlled, users may ignore/drop the event if they are no longer
586 /// able to commit external confirmed funds to the child anchor transaction.
588 /// The set of `pending_htlcs` on the commitment transaction to be broadcast can be inspected to
589 /// determine whether a significant portion of the channel's funds are allocated to HTLCs,
590 /// enabling users to make their own decisions regarding the importance of the commitment
591 /// transaction's confirmation. Note that this is not required, but simply exists as an option
592 /// for users to override LDK's behavior. On commitments with no HTLCs (indicated by those with
593 /// an empty `pending_htlcs`), confirmation of the commitment transaction can be considered to
596 /// [`EcdsaChannelSigner`]: crate::sign::EcdsaChannelSigner
597 /// [`EcdsaChannelSigner::sign_holder_anchor_input`]: crate::sign::EcdsaChannelSigner::sign_holder_anchor_input
598 /// [`build_anchor_input_witness`]: crate::ln::chan_utils::build_anchor_input_witness
600 /// The unique identifier for the claim of the anchor output in the commitment transaction.
602 /// The identifier must map to the set of external UTXOs assigned to the claim, such that
603 /// they can be reused when a new claim with the same identifier needs to be made, resulting
604 /// in a fee-bumping attempt.
605 claim_id: crate::c_types::ThirtyTwoBytes,
606 /// The target feerate that the transaction package, which consists of the commitment
607 /// transaction and the to-be-crafted child anchor transaction, must meet.
608 package_target_feerate_sat_per_1000_weight: u32,
609 /// The channel's commitment transaction to bump the fee of. This transaction should be
610 /// broadcast along with the anchor transaction constructed as a result of consuming this
612 commitment_tx: crate::c_types::Transaction,
613 /// The absolute fee in satoshis of the commitment transaction. This can be used along the
614 /// with weight of the commitment transaction to determine its feerate.
615 commitment_tx_fee_satoshis: u64,
616 /// The descriptor to sign the anchor input of the anchor transaction constructed as a
617 /// result of consuming this event.
618 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor,
619 /// The set of pending HTLCs on the commitment transaction that need to be resolved once the
620 /// commitment transaction confirms.
621 pending_htlcs: crate::c_types::derived::CVec_HTLCOutputInCommitmentZ,
623 /// Indicates that a channel featuring anchor outputs has unilaterally closed on-chain by a
624 /// holder commitment transaction and its HTLC(s) need to be resolved on-chain. With the
625 /// zero-HTLC-transaction-fee variant of anchor outputs, the pre-signed HTLC
626 /// transactions have a zero fee, thus requiring additional inputs and/or outputs to be attached
627 /// for a timely confirmation within the chain. These additional inputs and/or outputs must be
628 /// appended to the resulting HTLC transaction to meet the target feerate. Failure to meet the
629 /// target feerate decreases the confirmation odds of the transaction, possibly resulting in a
630 /// loss of funds. Once the transaction meets the target feerate, it must be signed for and
631 /// broadcast by the consumer of the event.
633 /// The consumer should be able to sign for any of the non-HTLC inputs added to the resulting
634 /// HTLC transaction. To sign HTLC inputs, an [`EcdsaChannelSigner`] should be re-derived
635 /// through [`HTLCDescriptor::derive_channel_signer`]. Each HTLC input's signature can be
636 /// computed with [`EcdsaChannelSigner::sign_holder_htlc_transaction`], which can then be
637 /// provided to [`HTLCDescriptor::tx_input_witness`] to obtain the fully signed witness required
640 /// It is possible to receive more than one instance of this event if a valid HTLC transaction
641 /// is never broadcast or is but not with a sufficient fee to be mined. Care should be taken by
642 /// the consumer of the event to ensure any future iterations of the HTLC transaction adhere to
643 /// the [Replace-By-Fee
644 /// rules](https://github.com/bitcoin/bitcoin/blob/master/doc/policy/mempool-replacements.md)
645 /// for fee bumps to be accepted into the mempool, and eventually the chain. As the frequency of
646 /// these events is not user-controlled, users may ignore/drop the event if either they are no
647 /// longer able to commit external confirmed funds to the HTLC transaction or the fee committed
648 /// to the HTLC transaction is greater in value than the HTLCs being claimed.
650 /// [`EcdsaChannelSigner`]: crate::sign::EcdsaChannelSigner
651 /// [`EcdsaChannelSigner::sign_holder_htlc_transaction`]: crate::sign::EcdsaChannelSigner::sign_holder_htlc_transaction
652 /// [`HTLCDescriptor::tx_input_witness`]: HTLCDescriptor::tx_input_witness
654 /// The unique identifier for the claim of the HTLCs in the confirmed commitment
657 /// The identifier must map to the set of external UTXOs assigned to the claim, such that
658 /// they can be reused when a new claim with the same identifier needs to be made, resulting
659 /// in a fee-bumping attempt.
660 claim_id: crate::c_types::ThirtyTwoBytes,
661 /// The target feerate that the resulting HTLC transaction must meet.
662 target_feerate_sat_per_1000_weight: u32,
663 /// The set of pending HTLCs on the confirmed commitment that need to be claimed, preferably
664 /// by the same transaction.
665 htlc_descriptors: crate::c_types::derived::CVec_HTLCDescriptorZ,
666 /// The locktime required for the resulting HTLC transaction.
670 use lightning::events::bump_transaction::BumpTransactionEvent as BumpTransactionEventImport;
671 pub(crate) type nativeBumpTransactionEvent = BumpTransactionEventImport;
673 impl BumpTransactionEvent {
675 pub(crate) fn to_native(&self) -> nativeBumpTransactionEvent {
677 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, } => {
678 let mut claim_id_nonref = Clone::clone(claim_id);
679 let mut package_target_feerate_sat_per_1000_weight_nonref = Clone::clone(package_target_feerate_sat_per_1000_weight);
680 let mut commitment_tx_nonref = Clone::clone(commitment_tx);
681 let mut commitment_tx_fee_satoshis_nonref = Clone::clone(commitment_tx_fee_satoshis);
682 let mut anchor_descriptor_nonref = Clone::clone(anchor_descriptor);
683 let mut pending_htlcs_nonref = Clone::clone(pending_htlcs);
684 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()) } }); };
685 nativeBumpTransactionEvent::ChannelClose {
686 claim_id: ::lightning::chain::ClaimId(claim_id_nonref.data),
687 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight_nonref,
688 commitment_tx: commitment_tx_nonref.into_bitcoin(),
689 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis_nonref,
690 anchor_descriptor: *unsafe { Box::from_raw(anchor_descriptor_nonref.take_inner()) },
691 pending_htlcs: local_pending_htlcs_nonref,
694 BumpTransactionEvent::HTLCResolution {ref claim_id, ref target_feerate_sat_per_1000_weight, ref htlc_descriptors, ref tx_lock_time, } => {
695 let mut claim_id_nonref = Clone::clone(claim_id);
696 let mut target_feerate_sat_per_1000_weight_nonref = Clone::clone(target_feerate_sat_per_1000_weight);
697 let mut htlc_descriptors_nonref = Clone::clone(htlc_descriptors);
698 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()) } }); };
699 let mut tx_lock_time_nonref = Clone::clone(tx_lock_time);
700 nativeBumpTransactionEvent::HTLCResolution {
701 claim_id: ::lightning::chain::ClaimId(claim_id_nonref.data),
702 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight_nonref,
703 htlc_descriptors: local_htlc_descriptors_nonref,
704 tx_lock_time: ::bitcoin::PackedLockTime(tx_lock_time_nonref),
710 pub(crate) fn into_native(self) -> nativeBumpTransactionEvent {
712 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, } => {
713 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()) } }); };
714 nativeBumpTransactionEvent::ChannelClose {
715 claim_id: ::lightning::chain::ClaimId(claim_id.data),
716 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight,
717 commitment_tx: commitment_tx.into_bitcoin(),
718 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis,
719 anchor_descriptor: *unsafe { Box::from_raw(anchor_descriptor.take_inner()) },
720 pending_htlcs: local_pending_htlcs,
723 BumpTransactionEvent::HTLCResolution {mut claim_id, mut target_feerate_sat_per_1000_weight, mut htlc_descriptors, mut tx_lock_time, } => {
724 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()) } }); };
725 nativeBumpTransactionEvent::HTLCResolution {
726 claim_id: ::lightning::chain::ClaimId(claim_id.data),
727 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight,
728 htlc_descriptors: local_htlc_descriptors,
729 tx_lock_time: ::bitcoin::PackedLockTime(tx_lock_time),
735 pub(crate) fn from_native(native: &nativeBumpTransactionEvent) -> Self {
737 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, } => {
738 let mut claim_id_nonref = Clone::clone(claim_id);
739 let mut package_target_feerate_sat_per_1000_weight_nonref = Clone::clone(package_target_feerate_sat_per_1000_weight);
740 let mut commitment_tx_nonref = Clone::clone(commitment_tx);
741 let mut commitment_tx_fee_satoshis_nonref = Clone::clone(commitment_tx_fee_satoshis);
742 let mut anchor_descriptor_nonref = Clone::clone(anchor_descriptor);
743 let mut pending_htlcs_nonref = Clone::clone(pending_htlcs);
744 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 } }); };
745 BumpTransactionEvent::ChannelClose {
746 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id_nonref.0 },
747 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight_nonref,
748 commitment_tx: crate::c_types::Transaction::from_bitcoin(&commitment_tx_nonref),
749 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis_nonref,
750 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor { inner: ObjOps::heap_alloc(anchor_descriptor_nonref), is_owned: true },
751 pending_htlcs: local_pending_htlcs_nonref.into(),
754 nativeBumpTransactionEvent::HTLCResolution {ref claim_id, ref target_feerate_sat_per_1000_weight, ref htlc_descriptors, ref tx_lock_time, } => {
755 let mut claim_id_nonref = Clone::clone(claim_id);
756 let mut target_feerate_sat_per_1000_weight_nonref = Clone::clone(target_feerate_sat_per_1000_weight);
757 let mut htlc_descriptors_nonref = Clone::clone(htlc_descriptors);
758 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 } }); };
759 let mut tx_lock_time_nonref = Clone::clone(tx_lock_time);
760 BumpTransactionEvent::HTLCResolution {
761 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id_nonref.0 },
762 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight_nonref,
763 htlc_descriptors: local_htlc_descriptors_nonref.into(),
764 tx_lock_time: tx_lock_time_nonref.0,
770 pub(crate) fn native_into(native: nativeBumpTransactionEvent) -> Self {
772 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, } => {
773 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 } }); };
774 BumpTransactionEvent::ChannelClose {
775 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id.0 },
776 package_target_feerate_sat_per_1000_weight: package_target_feerate_sat_per_1000_weight,
777 commitment_tx: crate::c_types::Transaction::from_bitcoin(&commitment_tx),
778 commitment_tx_fee_satoshis: commitment_tx_fee_satoshis,
779 anchor_descriptor: crate::lightning::events::bump_transaction::AnchorDescriptor { inner: ObjOps::heap_alloc(anchor_descriptor), is_owned: true },
780 pending_htlcs: local_pending_htlcs.into(),
783 nativeBumpTransactionEvent::HTLCResolution {mut claim_id, mut target_feerate_sat_per_1000_weight, mut htlc_descriptors, mut tx_lock_time, } => {
784 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 } }); };
785 BumpTransactionEvent::HTLCResolution {
786 claim_id: crate::c_types::ThirtyTwoBytes { data: claim_id.0 },
787 target_feerate_sat_per_1000_weight: target_feerate_sat_per_1000_weight,
788 htlc_descriptors: local_htlc_descriptors.into(),
789 tx_lock_time: tx_lock_time.0,
795 /// Frees any resources used by the BumpTransactionEvent
797 pub extern "C" fn BumpTransactionEvent_free(this_ptr: BumpTransactionEvent) { }
798 /// Creates a copy of the BumpTransactionEvent
800 pub extern "C" fn BumpTransactionEvent_clone(orig: &BumpTransactionEvent) -> BumpTransactionEvent {
804 /// Utility method to constructs a new ChannelClose-variant BumpTransactionEvent
805 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 {
806 BumpTransactionEvent::ChannelClose {
808 package_target_feerate_sat_per_1000_weight,
810 commitment_tx_fee_satoshis,
816 /// Utility method to constructs a new HTLCResolution-variant BumpTransactionEvent
817 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 {
818 BumpTransactionEvent::HTLCResolution {
820 target_feerate_sat_per_1000_weight,
825 /// Checks if two BumpTransactionEvents contain equal inner contents.
826 /// This ignores pointers and is_owned flags and looks at the values in fields.
828 pub extern "C" fn BumpTransactionEvent_eq(a: &BumpTransactionEvent, b: &BumpTransactionEvent) -> bool {
829 if &a.to_native() == &b.to_native() { true } else { false }
832 use lightning::events::bump_transaction::Input as nativeInputImport;
833 pub(crate) type nativeInput = nativeInputImport;
835 /// An input that must be included in a transaction when performing coin selection through
836 /// [`CoinSelectionSource::select_confirmed_utxos`]. It is guaranteed to be a SegWit input, so it
837 /// must have an empty [`TxIn::script_sig`] when spent.
841 /// A pointer to the opaque Rust object.
843 /// Nearly everywhere, inner must be non-null, however in places where
844 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
845 pub inner: *mut nativeInput,
846 /// Indicates that this is the only struct which contains the same pointer.
848 /// Rust functions which take ownership of an object provided via an argument require
849 /// this to be true and invalidate the object pointed to by inner.
853 impl Drop for Input {
855 if self.is_owned && !<*mut nativeInput>::is_null(self.inner) {
856 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
860 /// Frees any resources used by the Input, if is_owned is set and inner is non-NULL.
862 pub extern "C" fn Input_free(this_obj: Input) { }
864 /// Used only if an object of this type is returned as a trait impl by a method
865 pub(crate) extern "C" fn Input_free_void(this_ptr: *mut c_void) {
866 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInput) };
870 pub(crate) fn get_native_ref(&self) -> &'static nativeInput {
871 unsafe { &*ObjOps::untweak_ptr(self.inner) }
873 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInput {
874 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
876 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
877 pub(crate) fn take_inner(mut self) -> *mut nativeInput {
878 assert!(self.is_owned);
879 let ret = ObjOps::untweak_ptr(self.inner);
880 self.inner = core::ptr::null_mut();
884 /// The unique identifier of the input.
886 pub extern "C" fn Input_get_outpoint(this_ptr: &Input) -> crate::lightning::chain::transaction::OutPoint {
887 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
888 crate::c_types::bitcoin_to_C_outpoint(inner_val)
890 /// The unique identifier of the input.
892 pub extern "C" fn Input_set_outpoint(this_ptr: &mut Input, mut val: crate::lightning::chain::transaction::OutPoint) {
893 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
895 /// The UTXO being spent by the input.
897 pub extern "C" fn Input_get_previous_utxo(this_ptr: &Input) -> crate::c_types::TxOut {
898 let mut inner_val = &mut this_ptr.get_native_mut_ref().previous_utxo;
899 crate::c_types::TxOut::from_rust(inner_val)
901 /// The UTXO being spent by the input.
903 pub extern "C" fn Input_set_previous_utxo(this_ptr: &mut Input, mut val: crate::c_types::TxOut) {
904 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previous_utxo = val.into_rust();
906 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
907 /// [`TxIn::witness`], each with their lengths included, required to satisfy the output's
910 pub extern "C" fn Input_get_satisfaction_weight(this_ptr: &Input) -> u64 {
911 let mut inner_val = &mut this_ptr.get_native_mut_ref().satisfaction_weight;
914 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
915 /// [`TxIn::witness`], each with their lengths included, required to satisfy the output's
918 pub extern "C" fn Input_set_satisfaction_weight(this_ptr: &mut Input, mut val: u64) {
919 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.satisfaction_weight = val;
921 /// Constructs a new Input given each field
924 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 {
925 Input { inner: ObjOps::heap_alloc(nativeInput {
926 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
927 previous_utxo: previous_utxo_arg.into_rust(),
928 satisfaction_weight: satisfaction_weight_arg,
931 impl Clone for Input {
932 fn clone(&self) -> Self {
934 inner: if <*mut nativeInput>::is_null(self.inner) { core::ptr::null_mut() } else {
935 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
941 /// Used only if an object of this type is returned as a trait impl by a method
942 pub(crate) extern "C" fn Input_clone_void(this_ptr: *const c_void) -> *mut c_void {
943 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInput)).clone() })) as *mut c_void
946 /// Creates a copy of the Input
947 pub extern "C" fn Input_clone(orig: &Input) -> Input {
950 /// Generates a non-cryptographic 64-bit hash of the Input.
952 pub extern "C" fn Input_hash(o: &Input) -> u64 {
953 if o.inner.is_null() { return 0; }
954 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
956 let mut hasher = core::hash::SipHasher::new();
957 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
958 core::hash::Hasher::finish(&hasher)
960 /// Checks if two Inputs contain equal inner contents.
961 /// This ignores pointers and is_owned flags and looks at the values in fields.
962 /// Two objects with NULL inner values will be considered "equal" here.
964 pub extern "C" fn Input_eq(a: &Input, b: &Input) -> bool {
965 if a.inner == b.inner { return true; }
966 if a.inner.is_null() || b.inner.is_null() { return false; }
967 if a.get_native_ref() == b.get_native_ref() { true } else { false }
970 use lightning::events::bump_transaction::Utxo as nativeUtxoImport;
971 pub(crate) type nativeUtxo = nativeUtxoImport;
973 /// An unspent transaction output that is available to spend resulting from a successful
974 /// [`CoinSelection`] attempt.
978 /// A pointer to the opaque Rust object.
980 /// Nearly everywhere, inner must be non-null, however in places where
981 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
982 pub inner: *mut nativeUtxo,
983 /// Indicates that this is the only struct which contains the same pointer.
985 /// Rust functions which take ownership of an object provided via an argument require
986 /// this to be true and invalidate the object pointed to by inner.
992 if self.is_owned && !<*mut nativeUtxo>::is_null(self.inner) {
993 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
997 /// Frees any resources used by the Utxo, if is_owned is set and inner is non-NULL.
999 pub extern "C" fn Utxo_free(this_obj: Utxo) { }
1001 /// Used only if an object of this type is returned as a trait impl by a method
1002 pub(crate) extern "C" fn Utxo_free_void(this_ptr: *mut c_void) {
1003 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUtxo) };
1007 pub(crate) fn get_native_ref(&self) -> &'static nativeUtxo {
1008 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1010 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUtxo {
1011 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1013 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1014 pub(crate) fn take_inner(mut self) -> *mut nativeUtxo {
1015 assert!(self.is_owned);
1016 let ret = ObjOps::untweak_ptr(self.inner);
1017 self.inner = core::ptr::null_mut();
1021 /// The unique identifier of the output.
1023 pub extern "C" fn Utxo_get_outpoint(this_ptr: &Utxo) -> crate::lightning::chain::transaction::OutPoint {
1024 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
1025 crate::c_types::bitcoin_to_C_outpoint(inner_val)
1027 /// The unique identifier of the output.
1029 pub extern "C" fn Utxo_set_outpoint(this_ptr: &mut Utxo, mut val: crate::lightning::chain::transaction::OutPoint) {
1030 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = crate::c_types::C_to_bitcoin_outpoint(val);
1032 /// The output to spend.
1034 pub extern "C" fn Utxo_get_output(this_ptr: &Utxo) -> crate::c_types::TxOut {
1035 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
1036 crate::c_types::TxOut::from_rust(inner_val)
1038 /// The output to spend.
1040 pub extern "C" fn Utxo_set_output(this_ptr: &mut Utxo, mut val: crate::c_types::TxOut) {
1041 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
1043 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
1044 /// with their lengths included, required to satisfy the output's script. The weight consumed by
1045 /// the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
1047 pub extern "C" fn Utxo_get_satisfaction_weight(this_ptr: &Utxo) -> u64 {
1048 let mut inner_val = &mut this_ptr.get_native_mut_ref().satisfaction_weight;
1051 /// The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each
1052 /// with their lengths included, required to satisfy the output's script. The weight consumed by
1053 /// the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
1055 pub extern "C" fn Utxo_set_satisfaction_weight(this_ptr: &mut Utxo, mut val: u64) {
1056 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.satisfaction_weight = val;
1058 /// Constructs a new Utxo given each field
1061 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 {
1062 Utxo { inner: ObjOps::heap_alloc(nativeUtxo {
1063 outpoint: crate::c_types::C_to_bitcoin_outpoint(outpoint_arg),
1064 output: output_arg.into_rust(),
1065 satisfaction_weight: satisfaction_weight_arg,
1066 }), is_owned: true }
1068 impl Clone for Utxo {
1069 fn clone(&self) -> Self {
1071 inner: if <*mut nativeUtxo>::is_null(self.inner) { core::ptr::null_mut() } else {
1072 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1078 /// Used only if an object of this type is returned as a trait impl by a method
1079 pub(crate) extern "C" fn Utxo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1080 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUtxo)).clone() })) as *mut c_void
1083 /// Creates a copy of the Utxo
1084 pub extern "C" fn Utxo_clone(orig: &Utxo) -> Utxo {
1087 /// Generates a non-cryptographic 64-bit hash of the Utxo.
1089 pub extern "C" fn Utxo_hash(o: &Utxo) -> u64 {
1090 if o.inner.is_null() { return 0; }
1091 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1092 #[allow(deprecated)]
1093 let mut hasher = core::hash::SipHasher::new();
1094 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1095 core::hash::Hasher::finish(&hasher)
1097 /// Checks if two Utxos contain equal inner contents.
1098 /// This ignores pointers and is_owned flags and looks at the values in fields.
1099 /// Two objects with NULL inner values will be considered "equal" here.
1101 pub extern "C" fn Utxo_eq(a: &Utxo, b: &Utxo) -> bool {
1102 if a.inner == b.inner { return true; }
1103 if a.inner.is_null() || b.inner.is_null() { return false; }
1104 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1106 /// Returns a `Utxo` with the `satisfaction_weight` estimate for a legacy P2PKH output.
1109 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 {
1110 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())));
1111 crate::lightning::events::bump_transaction::Utxo { inner: ObjOps::heap_alloc(ret), is_owned: true }
1115 use lightning::events::bump_transaction::CoinSelection as nativeCoinSelectionImport;
1116 pub(crate) type nativeCoinSelection = nativeCoinSelectionImport;
1118 /// The result of a successful coin selection attempt for a transaction requiring additional UTXOs
1119 /// to cover its fees.
1122 pub struct CoinSelection {
1123 /// A pointer to the opaque Rust object.
1125 /// Nearly everywhere, inner must be non-null, however in places where
1126 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1127 pub inner: *mut nativeCoinSelection,
1128 /// Indicates that this is the only struct which contains the same pointer.
1130 /// Rust functions which take ownership of an object provided via an argument require
1131 /// this to be true and invalidate the object pointed to by inner.
1135 impl Drop for CoinSelection {
1136 fn drop(&mut self) {
1137 if self.is_owned && !<*mut nativeCoinSelection>::is_null(self.inner) {
1138 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1142 /// Frees any resources used by the CoinSelection, if is_owned is set and inner is non-NULL.
1144 pub extern "C" fn CoinSelection_free(this_obj: CoinSelection) { }
1146 /// Used only if an object of this type is returned as a trait impl by a method
1147 pub(crate) extern "C" fn CoinSelection_free_void(this_ptr: *mut c_void) {
1148 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCoinSelection) };
1151 impl CoinSelection {
1152 pub(crate) fn get_native_ref(&self) -> &'static nativeCoinSelection {
1153 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1155 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCoinSelection {
1156 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1158 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1159 pub(crate) fn take_inner(mut self) -> *mut nativeCoinSelection {
1160 assert!(self.is_owned);
1161 let ret = ObjOps::untweak_ptr(self.inner);
1162 self.inner = core::ptr::null_mut();
1166 /// The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
1167 /// requiring additional fees.
1169 pub extern "C" fn CoinSelection_get_confirmed_utxos(this_ptr: &CoinSelection) -> crate::c_types::derived::CVec_UtxoZ {
1170 let mut inner_val = &mut this_ptr.get_native_mut_ref().confirmed_utxos;
1171 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 } }); };
1172 local_inner_val.into()
1174 /// The set of UTXOs (with at least 1 confirmation) to spend and use within a transaction
1175 /// requiring additional fees.
1177 pub extern "C" fn CoinSelection_set_confirmed_utxos(this_ptr: &mut CoinSelection, mut val: crate::c_types::derived::CVec_UtxoZ) {
1178 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1179 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.confirmed_utxos = local_val;
1181 /// An additional output tracking whether any change remained after coin selection. This output
1182 /// should always have a value above dust for its given `script_pubkey`. It should not be
1183 /// spent until the transaction it belongs to confirms to ensure mempool descendant limits are
1184 /// not met. This implies no other party should be able to spend it except us.
1186 pub extern "C" fn CoinSelection_get_change_output(this_ptr: &CoinSelection) -> crate::c_types::derived::COption_TxOutZ {
1187 let mut inner_val = &mut this_ptr.get_native_mut_ref().change_output;
1188 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()) }) };
1191 /// An additional output tracking whether any change remained after coin selection. This output
1192 /// should always have a value above dust for its given `script_pubkey`. It should not be
1193 /// spent until the transaction it belongs to confirms to ensure mempool descendant limits are
1194 /// not met. This implies no other party should be able to spend it except us.
1196 pub extern "C" fn CoinSelection_set_change_output(this_ptr: &mut CoinSelection, mut val: crate::c_types::derived::COption_TxOutZ) {
1197 let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_rust() }})} };
1198 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.change_output = local_val;
1200 /// Constructs a new CoinSelection given each field
1203 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 {
1204 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()) } }); };
1205 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() }})} };
1206 CoinSelection { inner: ObjOps::heap_alloc(nativeCoinSelection {
1207 confirmed_utxos: local_confirmed_utxos_arg,
1208 change_output: local_change_output_arg,
1209 }), is_owned: true }
1211 impl Clone for CoinSelection {
1212 fn clone(&self) -> Self {
1214 inner: if <*mut nativeCoinSelection>::is_null(self.inner) { core::ptr::null_mut() } else {
1215 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1221 /// Used only if an object of this type is returned as a trait impl by a method
1222 pub(crate) extern "C" fn CoinSelection_clone_void(this_ptr: *const c_void) -> *mut c_void {
1223 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCoinSelection)).clone() })) as *mut c_void
1226 /// Creates a copy of the CoinSelection
1227 pub extern "C" fn CoinSelection_clone(orig: &CoinSelection) -> CoinSelection {
1230 /// An abstraction over a bitcoin wallet that can perform coin selection over a set of UTXOs and can
1231 /// sign for them. The coin selection method aims to mimic Bitcoin Core's `fundrawtransaction` RPC,
1232 /// which most wallets should be able to satisfy. Otherwise, consider implementing [`WalletSource`],
1233 /// which can provide a default implementation of this trait when used with [`Wallet`].
1235 pub struct CoinSelectionSource {
1236 /// An opaque pointer which is passed to your function implementations as an argument.
1237 /// This has no meaning in the LDK, and can be NULL or any other value.
1238 pub this_arg: *mut c_void,
1239 /// Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
1240 /// available to spend. Implementations are free to pick their coin selection algorithm of
1241 /// choice, as long as the following requirements are met:
1243 /// 1. `must_spend` contains a set of [`Input`]s that must be included in the transaction
1244 /// throughout coin selection, but must not be returned as part of the result.
1245 /// 2. `must_pay_to` contains a set of [`TxOut`]s that must be included in the transaction
1246 /// throughout coin selection. In some cases, like when funding an anchor transaction, this
1247 /// set is empty. Implementations should ensure they handle this correctly on their end,
1248 /// e.g., Bitcoin Core's `fundrawtransaction` RPC requires at least one output to be
1249 /// provided, in which case a zero-value empty OP_RETURN output can be used instead.
1250 /// 3. Enough inputs must be selected/contributed for the resulting transaction (including the
1251 /// inputs and outputs noted above) to meet `target_feerate_sat_per_1000_weight`.
1253 /// Implementations must take note that [`Input::satisfaction_weight`] only tracks the weight of
1254 /// the input's `script_sig` and `witness`. Some wallets, like Bitcoin Core's, may require
1255 /// providing the full input weight. Failing to do so may lead to underestimating fee bumps and
1256 /// delaying block inclusion.
1258 /// The `claim_id` must map to the set of external UTXOs assigned to the claim, such that they
1259 /// can be re-used within new fee-bumped iterations of the original claiming transaction,
1260 /// ensuring that claims don't double spend each other. If a specific `claim_id` has never had a
1261 /// transaction associated with it, and all of the available UTXOs have already been assigned to
1262 /// other claims, implementations must be willing to double spend their UTXOs. The choice of
1263 /// which UTXOs to double spend is left to the implementation, but it must strive to keep the
1264 /// set of other claims being double spent to a minimum.
1265 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,
1266 /// Signs and provides the full witness for all inputs within the transaction known to the
1267 /// trait (i.e., any provided via [`CoinSelectionSource::select_confirmed_utxos`]).
1268 pub sign_tx: extern "C" fn (this_arg: *const c_void, tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_TransactionNoneZ,
1269 /// Frees any resources associated with this object given its this_arg pointer.
1270 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1271 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1273 unsafe impl Send for CoinSelectionSource {}
1274 unsafe impl Sync for CoinSelectionSource {}
1275 pub(crate) fn CoinSelectionSource_clone_fields(orig: &CoinSelectionSource) -> CoinSelectionSource {
1276 CoinSelectionSource {
1277 this_arg: orig.this_arg,
1278 select_confirmed_utxos: Clone::clone(&orig.select_confirmed_utxos),
1279 sign_tx: Clone::clone(&orig.sign_tx),
1280 free: Clone::clone(&orig.free),
1284 use lightning::events::bump_transaction::CoinSelectionSource as rustCoinSelectionSource;
1285 impl rustCoinSelectionSource for CoinSelectionSource {
1286 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, ()> {
1287 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 } }); };
1288 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) }); };
1289 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);
1290 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)) })*/ })};
1293 fn sign_tx(&self, mut tx: bitcoin::Transaction) -> Result<bitcoin::Transaction, ()> {
1294 let mut ret = (self.sign_tx)(self.this_arg, crate::c_types::Transaction::from_bitcoin(&tx));
1295 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)) })*/ })};
1300 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1301 // directly as a Deref trait in higher-level structs:
1302 impl core::ops::Deref for CoinSelectionSource {
1304 fn deref(&self) -> &Self {
1308 impl core::ops::DerefMut for CoinSelectionSource {
1309 fn deref_mut(&mut self) -> &mut Self {
1313 /// Calls the free function if one is set
1315 pub extern "C" fn CoinSelectionSource_free(this_ptr: CoinSelectionSource) { }
1316 impl Drop for CoinSelectionSource {
1317 fn drop(&mut self) {
1318 if let Some(f) = self.free {
1323 /// An alternative to [`CoinSelectionSource`] that can be implemented and used along [`Wallet`] to
1324 /// provide a default implementation to [`CoinSelectionSource`].
1326 pub struct WalletSource {
1327 /// An opaque pointer which is passed to your function implementations as an argument.
1328 /// This has no meaning in the LDK, and can be NULL or any other value.
1329 pub this_arg: *mut c_void,
1330 /// Returns all UTXOs, with at least 1 confirmation each, that are available to spend.
1331 pub list_confirmed_utxos: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_UtxoZNoneZ,
1332 /// Returns a script to use for change above dust resulting from a successful coin selection
1334 pub get_change_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ,
1335 /// Signs and provides the full [`TxIn::script_sig`] and [`TxIn::witness`] for all inputs within
1336 /// the transaction known to the wallet (i.e., any provided via
1337 /// [`WalletSource::list_confirmed_utxos`]).
1338 pub sign_tx: extern "C" fn (this_arg: *const c_void, tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_TransactionNoneZ,
1339 /// Frees any resources associated with this object given its this_arg pointer.
1340 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1341 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1343 unsafe impl Send for WalletSource {}
1344 unsafe impl Sync for WalletSource {}
1345 pub(crate) fn WalletSource_clone_fields(orig: &WalletSource) -> WalletSource {
1347 this_arg: orig.this_arg,
1348 list_confirmed_utxos: Clone::clone(&orig.list_confirmed_utxos),
1349 get_change_script: Clone::clone(&orig.get_change_script),
1350 sign_tx: Clone::clone(&orig.sign_tx),
1351 free: Clone::clone(&orig.free),
1355 use lightning::events::bump_transaction::WalletSource as rustWalletSource;
1356 impl rustWalletSource for WalletSource {
1357 fn list_confirmed_utxos(&self) -> Result<Vec<lightning::events::bump_transaction::Utxo>, ()> {
1358 let mut ret = (self.list_confirmed_utxos)(self.this_arg);
1359 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)) })*/ })};
1362 fn get_change_script(&self) -> Result<bitcoin::Script, ()> {
1363 let mut ret = (self.get_change_script)(self.this_arg);
1364 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)) })*/ })};
1367 fn sign_tx(&self, mut tx: bitcoin::Transaction) -> Result<bitcoin::Transaction, ()> {
1368 let mut ret = (self.sign_tx)(self.this_arg, crate::c_types::Transaction::from_bitcoin(&tx));
1369 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)) })*/ })};
1374 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1375 // directly as a Deref trait in higher-level structs:
1376 impl core::ops::Deref for WalletSource {
1378 fn deref(&self) -> &Self {
1382 impl core::ops::DerefMut for WalletSource {
1383 fn deref_mut(&mut self) -> &mut Self {
1387 /// Calls the free function if one is set
1389 pub extern "C" fn WalletSource_free(this_ptr: WalletSource) { }
1390 impl Drop for WalletSource {
1391 fn drop(&mut self) {
1392 if let Some(f) = self.free {
1398 use lightning::events::bump_transaction::Wallet as nativeWalletImport;
1399 pub(crate) type nativeWallet = nativeWalletImport<crate::lightning::events::bump_transaction::WalletSource, crate::lightning::util::logger::Logger>;
1401 /// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
1402 /// avoid conflicting double spends. If not enough UTXOs are available to do so, conflicting double
1403 /// spends may happen.
1407 /// A pointer to the opaque Rust object.
1409 /// Nearly everywhere, inner must be non-null, however in places where
1410 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1411 pub inner: *mut nativeWallet,
1412 /// Indicates that this is the only struct which contains the same pointer.
1414 /// Rust functions which take ownership of an object provided via an argument require
1415 /// this to be true and invalidate the object pointed to by inner.
1419 impl Drop for Wallet {
1420 fn drop(&mut self) {
1421 if self.is_owned && !<*mut nativeWallet>::is_null(self.inner) {
1422 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1426 /// Frees any resources used by the Wallet, if is_owned is set and inner is non-NULL.
1428 pub extern "C" fn Wallet_free(this_obj: Wallet) { }
1430 /// Used only if an object of this type is returned as a trait impl by a method
1431 pub(crate) extern "C" fn Wallet_free_void(this_ptr: *mut c_void) {
1432 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeWallet) };
1436 pub(crate) fn get_native_ref(&self) -> &'static nativeWallet {
1437 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1439 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeWallet {
1440 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1442 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1443 pub(crate) fn take_inner(mut self) -> *mut nativeWallet {
1444 assert!(self.is_owned);
1445 let ret = ObjOps::untweak_ptr(self.inner);
1446 self.inner = core::ptr::null_mut();
1450 /// Returns a new instance backed by the given [`WalletSource`] that serves as an implementation
1451 /// of [`CoinSelectionSource`].
1454 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 {
1455 let mut ret = lightning::events::bump_transaction::Wallet::new(source, logger);
1456 crate::lightning::events::bump_transaction::Wallet { inner: ObjOps::heap_alloc(ret), is_owned: true }
1459 impl From<nativeWallet> for crate::lightning::events::bump_transaction::CoinSelectionSource {
1460 fn from(obj: nativeWallet) -> Self {
1461 let mut rust_obj = Wallet { inner: ObjOps::heap_alloc(obj), is_owned: true };
1462 let mut ret = Wallet_as_CoinSelectionSource(&rust_obj);
1463 // 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
1464 rust_obj.inner = core::ptr::null_mut();
1465 ret.free = Some(Wallet_free_void);
1469 /// Constructs a new CoinSelectionSource which calls the relevant methods on this_arg.
1470 /// This copies the `inner` pointer in this_arg and thus the returned CoinSelectionSource must be freed before this_arg is
1472 pub extern "C" fn Wallet_as_CoinSelectionSource(this_arg: &Wallet) -> crate::lightning::events::bump_transaction::CoinSelectionSource {
1473 crate::lightning::events::bump_transaction::CoinSelectionSource {
1474 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1476 select_confirmed_utxos: Wallet_CoinSelectionSource_select_confirmed_utxos,
1477 sign_tx: Wallet_CoinSelectionSource_sign_tx,
1482 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 {
1483 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()) } }); };
1484 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() }); };
1485 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);
1486 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() };
1490 extern "C" fn Wallet_CoinSelectionSource_sign_tx(this_arg: *const c_void, mut tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_TransactionNoneZ {
1491 let mut ret = <nativeWallet as lightning::events::bump_transaction::CoinSelectionSource<>>::sign_tx(unsafe { &mut *(this_arg as *mut nativeWallet) }, tx.into_bitcoin());
1492 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() };
1497 use lightning::events::bump_transaction::BumpTransactionEventHandler as nativeBumpTransactionEventHandlerImport;
1498 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>;
1500 /// A handler for [`Event::BumpTransaction`] events that sources confirmed UTXOs from a
1501 /// [`CoinSelectionSource`] to fee bump transactions via Child-Pays-For-Parent (CPFP) or
1502 /// Replace-By-Fee (RBF).
1504 /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
1507 pub struct BumpTransactionEventHandler {
1508 /// A pointer to the opaque Rust object.
1510 /// Nearly everywhere, inner must be non-null, however in places where
1511 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1512 pub inner: *mut nativeBumpTransactionEventHandler,
1513 /// Indicates that this is the only struct which contains the same pointer.
1515 /// Rust functions which take ownership of an object provided via an argument require
1516 /// this to be true and invalidate the object pointed to by inner.
1520 impl Drop for BumpTransactionEventHandler {
1521 fn drop(&mut self) {
1522 if self.is_owned && !<*mut nativeBumpTransactionEventHandler>::is_null(self.inner) {
1523 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1527 /// Frees any resources used by the BumpTransactionEventHandler, if is_owned is set and inner is non-NULL.
1529 pub extern "C" fn BumpTransactionEventHandler_free(this_obj: BumpTransactionEventHandler) { }
1531 /// Used only if an object of this type is returned as a trait impl by a method
1532 pub(crate) extern "C" fn BumpTransactionEventHandler_free_void(this_ptr: *mut c_void) {
1533 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBumpTransactionEventHandler) };
1536 impl BumpTransactionEventHandler {
1537 pub(crate) fn get_native_ref(&self) -> &'static nativeBumpTransactionEventHandler {
1538 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1540 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBumpTransactionEventHandler {
1541 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1543 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1544 pub(crate) fn take_inner(mut self) -> *mut nativeBumpTransactionEventHandler {
1545 assert!(self.is_owned);
1546 let ret = ObjOps::untweak_ptr(self.inner);
1547 self.inner = core::ptr::null_mut();
1551 /// Returns a new instance capable of handling [`Event::BumpTransaction`] events.
1553 /// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
1556 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 {
1557 let mut ret = lightning::events::bump_transaction::BumpTransactionEventHandler::new(broadcaster, utxo_source, signer_provider, logger);
1558 crate::lightning::events::bump_transaction::BumpTransactionEventHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
1561 /// Handles all variants of [`BumpTransactionEvent`].
1563 pub extern "C" fn BumpTransactionEventHandler_handle_event(this_arg: &crate::lightning::events::bump_transaction::BumpTransactionEventHandler, event: &crate::lightning::events::bump_transaction::BumpTransactionEvent) {
1564 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_event(&event.to_native())