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 //! Provides keys to LDK and defines some useful objects describing spendable on-chain outputs.
11 //! The provided output descriptors follow a custom LDK data format and are currently not fully
12 //! compatible with Bitcoin Core output descriptors.
14 use alloc::str::FromStr;
15 use alloc::string::String;
16 use core::ffi::c_void;
17 use core::convert::Infallible;
18 use bitcoin::hashes::Hash;
19 use crate::c_types::*;
20 #[cfg(feature="no-std")]
21 use alloc::{vec::Vec, boxed::Box};
26 use alloc::str::FromStr;
27 use alloc::string::String;
28 use core::ffi::c_void;
29 use core::convert::Infallible;
30 use bitcoin::hashes::Hash;
31 use crate::c_types::*;
32 #[cfg(feature="no-std")]
33 use alloc::{vec::Vec, boxed::Box};
37 use lightning::sign::DelayedPaymentOutputDescriptor as nativeDelayedPaymentOutputDescriptorImport;
38 pub(crate) type nativeDelayedPaymentOutputDescriptor = nativeDelayedPaymentOutputDescriptorImport;
40 /// Information about a spendable output to a P2WSH script.
42 /// See [`SpendableOutputDescriptor::DelayedPaymentOutput`] for more details on how to spend this.
45 pub struct DelayedPaymentOutputDescriptor {
46 /// A pointer to the opaque Rust object.
48 /// Nearly everywhere, inner must be non-null, however in places where
49 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
50 pub inner: *mut nativeDelayedPaymentOutputDescriptor,
51 /// Indicates that this is the only struct which contains the same pointer.
53 /// Rust functions which take ownership of an object provided via an argument require
54 /// this to be true and invalidate the object pointed to by inner.
58 impl Drop for DelayedPaymentOutputDescriptor {
60 if self.is_owned && !<*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) {
61 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
65 /// Frees any resources used by the DelayedPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
67 pub extern "C" fn DelayedPaymentOutputDescriptor_free(this_obj: DelayedPaymentOutputDescriptor) { }
69 /// Used only if an object of this type is returned as a trait impl by a method
70 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
71 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDelayedPaymentOutputDescriptor) };
74 impl DelayedPaymentOutputDescriptor {
75 pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentOutputDescriptor {
76 unsafe { &*ObjOps::untweak_ptr(self.inner) }
78 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentOutputDescriptor {
79 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
81 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
82 pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentOutputDescriptor {
83 assert!(self.is_owned);
84 let ret = ObjOps::untweak_ptr(self.inner);
85 self.inner = core::ptr::null_mut();
89 /// The outpoint which is spendable.
91 pub extern "C" fn DelayedPaymentOutputDescriptor_get_outpoint(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
92 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
93 crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::transaction::OutPoint<>) as *mut _) }, is_owned: false }
95 /// The outpoint which is spendable.
97 pub extern "C" fn DelayedPaymentOutputDescriptor_set_outpoint(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
98 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
100 /// Per commitment point to derive the delayed payment key by key holder.
102 pub extern "C" fn DelayedPaymentOutputDescriptor_get_per_commitment_point(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
103 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
104 crate::c_types::PublicKey::from_rust(&inner_val)
106 /// Per commitment point to derive the delayed payment key by key holder.
108 pub extern "C" fn DelayedPaymentOutputDescriptor_set_per_commitment_point(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
109 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
111 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
112 /// the witness_script.
114 pub extern "C" fn DelayedPaymentOutputDescriptor_get_to_self_delay(this_ptr: &DelayedPaymentOutputDescriptor) -> u16 {
115 let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay;
118 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
119 /// the witness_script.
121 pub extern "C" fn DelayedPaymentOutputDescriptor_set_to_self_delay(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u16) {
122 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val;
124 /// The output which is referenced by the given outpoint.
126 pub extern "C" fn DelayedPaymentOutputDescriptor_get_output(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::TxOut {
127 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
128 crate::c_types::TxOut::from_rust(inner_val)
130 /// The output which is referenced by the given outpoint.
132 pub extern "C" fn DelayedPaymentOutputDescriptor_set_output(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
133 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
135 /// The revocation point specific to the commitment transaction which was broadcast. Used to
136 /// derive the witnessScript for this output.
138 pub extern "C" fn DelayedPaymentOutputDescriptor_get_revocation_pubkey(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::ln::channel_keys::RevocationKey {
139 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_pubkey;
140 crate::lightning::ln::channel_keys::RevocationKey { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::channel_keys::RevocationKey<>) as *mut _) }, is_owned: false }
142 /// The revocation point specific to the commitment transaction which was broadcast. Used to
143 /// derive the witnessScript for this output.
145 pub extern "C" fn DelayedPaymentOutputDescriptor_set_revocation_pubkey(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::ln::channel_keys::RevocationKey) {
146 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_pubkey = *unsafe { Box::from_raw(val.take_inner()) };
148 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
149 /// This may be useful in re-deriving keys used in the channel to spend the output.
151 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &DelayedPaymentOutputDescriptor) -> *const [u8; 32] {
152 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
155 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
156 /// This may be useful in re-deriving keys used in the channel to spend the output.
158 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
159 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
161 /// The value of the channel which this output originated from, possibly indirectly.
163 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &DelayedPaymentOutputDescriptor) -> u64 {
164 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
167 /// The value of the channel which this output originated from, possibly indirectly.
169 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u64) {
170 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
172 /// The channel public keys and other parameters needed to generate a spending transaction or
173 /// to provide to a re-derived signer through [`ChannelSigner::provide_channel_parameters`].
175 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.123 or later.
177 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
179 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_transaction_parameters(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
180 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_transaction_parameters;
181 let mut local_inner_val = crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _ }, is_owned: false };
184 /// The channel public keys and other parameters needed to generate a spending transaction or
185 /// to provide to a re-derived signer through [`ChannelSigner::provide_channel_parameters`].
187 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.123 or later.
189 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
191 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_transaction_parameters(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
192 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
193 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_transaction_parameters = local_val;
195 /// Constructs a new DelayedPaymentOutputDescriptor given each field
197 /// Note that channel_transaction_parameters_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
200 pub extern "C" fn DelayedPaymentOutputDescriptor_new(mut outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut per_commitment_point_arg: crate::c_types::PublicKey, mut to_self_delay_arg: u16, mut output_arg: crate::c_types::TxOut, mut revocation_pubkey_arg: crate::lightning::ln::channel_keys::RevocationKey, mut channel_keys_id_arg: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis_arg: u64, mut channel_transaction_parameters_arg: crate::lightning::ln::chan_utils::ChannelTransactionParameters) -> DelayedPaymentOutputDescriptor {
201 let mut local_channel_transaction_parameters_arg = if channel_transaction_parameters_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_transaction_parameters_arg.take_inner()) } }) };
202 DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeDelayedPaymentOutputDescriptor {
203 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
204 per_commitment_point: per_commitment_point_arg.into_rust(),
205 to_self_delay: to_self_delay_arg,
206 output: output_arg.into_rust(),
207 revocation_pubkey: *unsafe { Box::from_raw(revocation_pubkey_arg.take_inner()) },
208 channel_keys_id: channel_keys_id_arg.data,
209 channel_value_satoshis: channel_value_satoshis_arg,
210 channel_transaction_parameters: local_channel_transaction_parameters_arg,
213 impl Clone for DelayedPaymentOutputDescriptor {
214 fn clone(&self) -> Self {
216 inner: if <*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
217 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
223 /// Used only if an object of this type is returned as a trait impl by a method
224 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
225 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void
228 /// Creates a copy of the DelayedPaymentOutputDescriptor
229 pub extern "C" fn DelayedPaymentOutputDescriptor_clone(orig: &DelayedPaymentOutputDescriptor) -> DelayedPaymentOutputDescriptor {
232 /// Get a string which allows debug introspection of a DelayedPaymentOutputDescriptor object
233 pub extern "C" fn DelayedPaymentOutputDescriptor_debug_str_void(o: *const c_void) -> Str {
234 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::DelayedPaymentOutputDescriptor }).into()}
235 /// Generates a non-cryptographic 64-bit hash of the DelayedPaymentOutputDescriptor.
237 pub extern "C" fn DelayedPaymentOutputDescriptor_hash(o: &DelayedPaymentOutputDescriptor) -> u64 {
238 if o.inner.is_null() { return 0; }
239 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
241 let mut hasher = core::hash::SipHasher::new();
242 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
243 core::hash::Hasher::finish(&hasher)
245 /// Checks if two DelayedPaymentOutputDescriptors contain equal inner contents.
246 /// This ignores pointers and is_owned flags and looks at the values in fields.
247 /// Two objects with NULL inner values will be considered "equal" here.
249 pub extern "C" fn DelayedPaymentOutputDescriptor_eq(a: &DelayedPaymentOutputDescriptor, b: &DelayedPaymentOutputDescriptor) -> bool {
250 if a.inner == b.inner { return true; }
251 if a.inner.is_null() || b.inner.is_null() { return false; }
252 if a.get_native_ref() == b.get_native_ref() { true } else { false }
255 /// Serialize the DelayedPaymentOutputDescriptor object into a byte array which can be read by DelayedPaymentOutputDescriptor_read
256 pub extern "C" fn DelayedPaymentOutputDescriptor_write(obj: &crate::lightning::sign::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
257 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
260 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
261 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentOutputDescriptor) })
264 /// Read a DelayedPaymentOutputDescriptor from a byte array, created by DelayedPaymentOutputDescriptor_write
265 pub extern "C" fn DelayedPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentOutputDescriptorDecodeErrorZ {
266 let res: Result<lightning::sign::DelayedPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
267 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::DelayedPaymentOutputDescriptor { 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() };
271 use lightning::sign::StaticPaymentOutputDescriptor as nativeStaticPaymentOutputDescriptorImport;
272 pub(crate) type nativeStaticPaymentOutputDescriptor = nativeStaticPaymentOutputDescriptorImport;
274 /// Information about a spendable output to our \"payment key\".
276 /// See [`SpendableOutputDescriptor::StaticPaymentOutput`] for more details on how to spend this.
279 pub struct StaticPaymentOutputDescriptor {
280 /// A pointer to the opaque Rust object.
282 /// Nearly everywhere, inner must be non-null, however in places where
283 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
284 pub inner: *mut nativeStaticPaymentOutputDescriptor,
285 /// Indicates that this is the only struct which contains the same pointer.
287 /// Rust functions which take ownership of an object provided via an argument require
288 /// this to be true and invalidate the object pointed to by inner.
292 impl Drop for StaticPaymentOutputDescriptor {
294 if self.is_owned && !<*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) {
295 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
299 /// Frees any resources used by the StaticPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
301 pub extern "C" fn StaticPaymentOutputDescriptor_free(this_obj: StaticPaymentOutputDescriptor) { }
303 /// Used only if an object of this type is returned as a trait impl by a method
304 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
305 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeStaticPaymentOutputDescriptor) };
308 impl StaticPaymentOutputDescriptor {
309 pub(crate) fn get_native_ref(&self) -> &'static nativeStaticPaymentOutputDescriptor {
310 unsafe { &*ObjOps::untweak_ptr(self.inner) }
312 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeStaticPaymentOutputDescriptor {
313 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
315 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
316 pub(crate) fn take_inner(mut self) -> *mut nativeStaticPaymentOutputDescriptor {
317 assert!(self.is_owned);
318 let ret = ObjOps::untweak_ptr(self.inner);
319 self.inner = core::ptr::null_mut();
323 /// The outpoint which is spendable.
325 pub extern "C" fn StaticPaymentOutputDescriptor_get_outpoint(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
326 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
327 crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::transaction::OutPoint<>) as *mut _) }, is_owned: false }
329 /// The outpoint which is spendable.
331 pub extern "C" fn StaticPaymentOutputDescriptor_set_outpoint(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
332 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
334 /// The output which is referenced by the given outpoint.
336 pub extern "C" fn StaticPaymentOutputDescriptor_get_output(this_ptr: &StaticPaymentOutputDescriptor) -> crate::c_types::TxOut {
337 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
338 crate::c_types::TxOut::from_rust(inner_val)
340 /// The output which is referenced by the given outpoint.
342 pub extern "C" fn StaticPaymentOutputDescriptor_set_output(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
343 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
345 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
346 /// This may be useful in re-deriving keys used in the channel to spend the output.
348 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &StaticPaymentOutputDescriptor) -> *const [u8; 32] {
349 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
352 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
353 /// This may be useful in re-deriving keys used in the channel to spend the output.
355 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
356 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
358 /// The value of the channel which this transactions spends.
360 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &StaticPaymentOutputDescriptor) -> u64 {
361 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
364 /// The value of the channel which this transactions spends.
366 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: u64) {
367 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
369 /// The necessary channel parameters that need to be provided to the re-derived signer through
370 /// [`ChannelSigner::provide_channel_parameters`].
372 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
374 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
376 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_transaction_parameters(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
377 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_transaction_parameters;
378 let mut local_inner_val = crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _ }, is_owned: false };
381 /// The necessary channel parameters that need to be provided to the re-derived signer through
382 /// [`ChannelSigner::provide_channel_parameters`].
384 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
386 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
388 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_transaction_parameters(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
389 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
390 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_transaction_parameters = local_val;
392 /// Constructs a new StaticPaymentOutputDescriptor given each field
394 /// Note that channel_transaction_parameters_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
397 pub extern "C" fn StaticPaymentOutputDescriptor_new(mut outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut output_arg: crate::c_types::TxOut, mut channel_keys_id_arg: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis_arg: u64, mut channel_transaction_parameters_arg: crate::lightning::ln::chan_utils::ChannelTransactionParameters) -> StaticPaymentOutputDescriptor {
398 let mut local_channel_transaction_parameters_arg = if channel_transaction_parameters_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_transaction_parameters_arg.take_inner()) } }) };
399 StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeStaticPaymentOutputDescriptor {
400 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
401 output: output_arg.into_rust(),
402 channel_keys_id: channel_keys_id_arg.data,
403 channel_value_satoshis: channel_value_satoshis_arg,
404 channel_transaction_parameters: local_channel_transaction_parameters_arg,
407 impl Clone for StaticPaymentOutputDescriptor {
408 fn clone(&self) -> Self {
410 inner: if <*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
411 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
417 /// Used only if an object of this type is returned as a trait impl by a method
418 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
419 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void
422 /// Creates a copy of the StaticPaymentOutputDescriptor
423 pub extern "C" fn StaticPaymentOutputDescriptor_clone(orig: &StaticPaymentOutputDescriptor) -> StaticPaymentOutputDescriptor {
426 /// Get a string which allows debug introspection of a StaticPaymentOutputDescriptor object
427 pub extern "C" fn StaticPaymentOutputDescriptor_debug_str_void(o: *const c_void) -> Str {
428 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::StaticPaymentOutputDescriptor }).into()}
429 /// Generates a non-cryptographic 64-bit hash of the StaticPaymentOutputDescriptor.
431 pub extern "C" fn StaticPaymentOutputDescriptor_hash(o: &StaticPaymentOutputDescriptor) -> u64 {
432 if o.inner.is_null() { return 0; }
433 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
435 let mut hasher = core::hash::SipHasher::new();
436 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
437 core::hash::Hasher::finish(&hasher)
439 /// Checks if two StaticPaymentOutputDescriptors contain equal inner contents.
440 /// This ignores pointers and is_owned flags and looks at the values in fields.
441 /// Two objects with NULL inner values will be considered "equal" here.
443 pub extern "C" fn StaticPaymentOutputDescriptor_eq(a: &StaticPaymentOutputDescriptor, b: &StaticPaymentOutputDescriptor) -> bool {
444 if a.inner == b.inner { return true; }
445 if a.inner.is_null() || b.inner.is_null() { return false; }
446 if a.get_native_ref() == b.get_native_ref() { true } else { false }
448 /// Returns the `witness_script` of the spendable output.
450 /// Note that this will only return `Some` for [`StaticPaymentOutputDescriptor`]s that
451 /// originated from an anchor outputs channel, as they take the form of a P2WSH script.
454 pub extern "C" fn StaticPaymentOutputDescriptor_witness_script(this_arg: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::COption_CVec_u8ZZ {
455 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script();
456 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { ret.unwrap().to_bytes().into() }) };
460 /// The maximum length a well-formed witness spending one of these should have.
461 /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
465 pub extern "C" fn StaticPaymentOutputDescriptor_max_witness_length(this_arg: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> u64 {
466 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.max_witness_length();
471 /// Serialize the StaticPaymentOutputDescriptor object into a byte array which can be read by StaticPaymentOutputDescriptor_read
472 pub extern "C" fn StaticPaymentOutputDescriptor_write(obj: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
473 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
476 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
477 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeStaticPaymentOutputDescriptor) })
480 /// Read a StaticPaymentOutputDescriptor from a byte array, created by StaticPaymentOutputDescriptor_write
481 pub extern "C" fn StaticPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_StaticPaymentOutputDescriptorDecodeErrorZ {
482 let res: Result<lightning::sign::StaticPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
483 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::StaticPaymentOutputDescriptor { 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() };
486 /// Describes the necessary information to spend a spendable output.
488 /// When on-chain outputs are created by LDK (which our counterparty is not able to claim at any
489 /// point in the future) a [`SpendableOutputs`] event is generated which you must track and be able
490 /// to spend on-chain. The information needed to do this is provided in this enum, including the
491 /// outpoint describing which `txid` and output `index` is available, the full output which exists
492 /// at that `txid`/`index`, and any keys or other information required to sign.
494 /// [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
498 pub enum SpendableOutputDescriptor {
499 /// An output to a script which was provided via [`SignerProvider`] directly, either from
500 /// [`get_destination_script`] or [`get_shutdown_scriptpubkey`], thus you should already
501 /// know how to spend it. No secret keys are provided as LDK was never given any key.
502 /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
503 /// on-chain using the payment preimage or after it has timed out.
505 /// [`get_shutdown_scriptpubkey`]: SignerProvider::get_shutdown_scriptpubkey
506 /// [`get_destination_script`]: SignerProvider::get_shutdown_scriptpubkey
508 /// The outpoint which is spendable.
509 outpoint: crate::lightning::chain::transaction::OutPoint,
510 /// The output which is referenced by the given outpoint.
511 output: crate::c_types::TxOut,
512 /// The `channel_keys_id` for the channel which this output came from.
514 /// For channels which were generated on LDK 0.0.119 or later, this is the value which was
515 /// passed to the [`SignerProvider::get_destination_script`] call which provided this
518 /// For channels which were generated prior to LDK 0.0.119, no such argument existed,
519 /// however this field may still be filled in if such data is available.
521 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
522 channel_keys_id: crate::c_types::ThirtyTwoBytes,
524 /// An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
527 /// The witness in the spending input should be:
529 /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
532 /// Note that the `nSequence` field in the spending input must be set to
533 /// [`DelayedPaymentOutputDescriptor::to_self_delay`] (which means the transaction is not
534 /// broadcastable until at least [`DelayedPaymentOutputDescriptor::to_self_delay`] blocks after
535 /// the outpoint confirms, see [BIP
536 /// 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)). Also note that LDK
537 /// won't generate a [`SpendableOutputDescriptor`] until the corresponding block height
540 /// These are generally the result of a \"revocable\" output to us, spendable only by us unless
541 /// it is an output from an old state which we broadcast (which should never happen).
543 /// To derive the delayed payment key which is used to sign this input, you must pass the
544 /// holder [`InMemorySigner::delayed_payment_base_key`] (i.e., the private key which corresponds to the
545 /// [`ChannelPublicKeys::delayed_payment_basepoint`] in [`ChannelSigner::pubkeys`]) and the provided
546 /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to [`chan_utils::derive_private_key`]. The DelayedPaymentKey can be
547 /// generated without the secret key using [`DelayedPaymentKey::from_basepoint`] and only the
548 /// [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`ChannelSigner::pubkeys`].
550 /// To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
551 /// used in the witness script generation), you must pass the counterparty
552 /// [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
553 /// [`ChannelSigner::provide_channel_parameters`]) and the provided
554 /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
555 /// [`RevocationKey`].
557 /// The witness script which is hashed and included in the output `script_pubkey` may be
558 /// regenerated by passing the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] (derived
559 /// as explained above), our delayed payment pubkey (derived as explained above), and the
560 /// [`DelayedPaymentOutputDescriptor::to_self_delay`] contained here to
561 /// [`chan_utils::get_revokeable_redeemscript`].
562 DelayedPaymentOutput(
563 crate::lightning::sign::DelayedPaymentOutputDescriptor),
564 /// An output spendable exclusively by our payment key (i.e., the private key that corresponds
565 /// to the `payment_point` in [`ChannelSigner::pubkeys`]). The output type depends on the
566 /// channel type negotiated.
568 /// On an anchor outputs channel, the witness in the spending input is:
570 /// <BIP 143 signature> <witness script>
573 /// Otherwise, it is:
575 /// <BIP 143 signature> <payment key>
578 /// These are generally the result of our counterparty having broadcast the current state,
579 /// allowing us to claim the non-HTLC-encumbered outputs immediately, or after one confirmation
580 /// in the case of anchor outputs channels.
582 crate::lightning::sign::StaticPaymentOutputDescriptor),
584 use lightning::sign::SpendableOutputDescriptor as SpendableOutputDescriptorImport;
585 pub(crate) type nativeSpendableOutputDescriptor = SpendableOutputDescriptorImport;
587 impl SpendableOutputDescriptor {
589 pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor {
591 SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, ref channel_keys_id, } => {
592 let mut outpoint_nonref = Clone::clone(outpoint);
593 let mut output_nonref = Clone::clone(output);
594 let mut channel_keys_id_nonref = Clone::clone(channel_keys_id);
595 let mut local_channel_keys_id_nonref = if channel_keys_id_nonref.data == [0; 32] { None } else { Some( { channel_keys_id_nonref.data }) };
596 nativeSpendableOutputDescriptor::StaticOutput {
597 outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
598 output: output_nonref.into_rust(),
599 channel_keys_id: local_channel_keys_id_nonref,
602 SpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
603 let mut a_nonref = Clone::clone(a);
604 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
605 *unsafe { Box::from_raw(a_nonref.take_inner()) },
608 SpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
609 let mut a_nonref = Clone::clone(a);
610 nativeSpendableOutputDescriptor::StaticPaymentOutput (
611 *unsafe { Box::from_raw(a_nonref.take_inner()) },
617 pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor {
619 SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, mut channel_keys_id, } => {
620 let mut local_channel_keys_id = if channel_keys_id.data == [0; 32] { None } else { Some( { channel_keys_id.data }) };
621 nativeSpendableOutputDescriptor::StaticOutput {
622 outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
623 output: output.into_rust(),
624 channel_keys_id: local_channel_keys_id,
627 SpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
628 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
629 *unsafe { Box::from_raw(a.take_inner()) },
632 SpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
633 nativeSpendableOutputDescriptor::StaticPaymentOutput (
634 *unsafe { Box::from_raw(a.take_inner()) },
640 pub(crate) fn from_native(native: &SpendableOutputDescriptorImport) -> Self {
641 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSpendableOutputDescriptor) };
643 nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, ref channel_keys_id, } => {
644 let mut outpoint_nonref = Clone::clone(outpoint);
645 let mut output_nonref = Clone::clone(output);
646 let mut channel_keys_id_nonref = Clone::clone(channel_keys_id);
647 let mut local_channel_keys_id_nonref = if channel_keys_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (channel_keys_id_nonref.unwrap()) } } };
648 SpendableOutputDescriptor::StaticOutput {
649 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true },
650 output: crate::c_types::TxOut::from_rust(&output_nonref),
651 channel_keys_id: local_channel_keys_id_nonref,
654 nativeSpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
655 let mut a_nonref = Clone::clone(a);
656 SpendableOutputDescriptor::DelayedPaymentOutput (
657 crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
660 nativeSpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
661 let mut a_nonref = Clone::clone(a);
662 SpendableOutputDescriptor::StaticPaymentOutput (
663 crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
669 pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self {
671 nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, mut channel_keys_id, } => {
672 let mut local_channel_keys_id = if channel_keys_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else { { crate::c_types::ThirtyTwoBytes { data: (channel_keys_id.unwrap()) } } };
673 SpendableOutputDescriptor::StaticOutput {
674 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true },
675 output: crate::c_types::TxOut::from_rust(&output),
676 channel_keys_id: local_channel_keys_id,
679 nativeSpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
680 SpendableOutputDescriptor::DelayedPaymentOutput (
681 crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
684 nativeSpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
685 SpendableOutputDescriptor::StaticPaymentOutput (
686 crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
692 /// Frees any resources used by the SpendableOutputDescriptor
694 pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { }
695 /// Creates a copy of the SpendableOutputDescriptor
697 pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor {
701 /// Used only if an object of this type is returned as a trait impl by a method
702 pub(crate) extern "C" fn SpendableOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
703 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SpendableOutputDescriptor)).clone() })) as *mut c_void
706 /// Used only if an object of this type is returned as a trait impl by a method
707 pub(crate) extern "C" fn SpendableOutputDescriptor_free_void(this_ptr: *mut c_void) {
708 let _ = unsafe { Box::from_raw(this_ptr as *mut SpendableOutputDescriptor) };
711 /// Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
712 pub extern "C" fn SpendableOutputDescriptor_static_output(outpoint: crate::lightning::chain::transaction::OutPoint, output: crate::c_types::TxOut, channel_keys_id: crate::c_types::ThirtyTwoBytes) -> SpendableOutputDescriptor {
713 SpendableOutputDescriptor::StaticOutput {
720 /// Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
721 pub extern "C" fn SpendableOutputDescriptor_delayed_payment_output(a: crate::lightning::sign::DelayedPaymentOutputDescriptor) -> SpendableOutputDescriptor {
722 SpendableOutputDescriptor::DelayedPaymentOutput(a, )
725 /// Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
726 pub extern "C" fn SpendableOutputDescriptor_static_payment_output(a: crate::lightning::sign::StaticPaymentOutputDescriptor) -> SpendableOutputDescriptor {
727 SpendableOutputDescriptor::StaticPaymentOutput(a, )
729 /// Get a string which allows debug introspection of a SpendableOutputDescriptor object
730 pub extern "C" fn SpendableOutputDescriptor_debug_str_void(o: *const c_void) -> Str {
731 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::SpendableOutputDescriptor }).into()}
732 /// Generates a non-cryptographic 64-bit hash of the SpendableOutputDescriptor.
734 pub extern "C" fn SpendableOutputDescriptor_hash(o: &SpendableOutputDescriptor) -> u64 {
735 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
737 let mut hasher = core::hash::SipHasher::new();
738 core::hash::Hash::hash(&o.to_native(), &mut hasher);
739 core::hash::Hasher::finish(&hasher)
741 /// Checks if two SpendableOutputDescriptors contain equal inner contents.
742 /// This ignores pointers and is_owned flags and looks at the values in fields.
744 pub extern "C" fn SpendableOutputDescriptor_eq(a: &SpendableOutputDescriptor, b: &SpendableOutputDescriptor) -> bool {
745 if &a.to_native() == &b.to_native() { true } else { false }
748 /// Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
749 pub extern "C" fn SpendableOutputDescriptor_write(obj: &crate::lightning::sign::SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
750 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
753 pub(crate) extern "C" fn SpendableOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
754 SpendableOutputDescriptor_write(unsafe { &*(obj as *const SpendableOutputDescriptor) })
757 /// Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
758 pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
759 let res: Result<lightning::sign::SpendableOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
760 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::SpendableOutputDescriptor::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
763 /// Creates an unsigned [`PartiallySignedTransaction`] which spends the given descriptors to
764 /// the given outputs, plus an output to the given change destination (if sufficient
765 /// change value remains). The PSBT will have a feerate, at least, of the given value.
767 /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
768 /// transaction will have a locktime of 0. It it recommended to set this to the current block
769 /// height to avoid fee sniping, unless you have some specific reason to use a different
772 /// Returns the PSBT and expected max transaction weight.
774 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
775 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
776 /// does not match the one we can spend.
778 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
781 pub extern "C" fn SpendableOutputDescriptor_create_spendable_outputs_psbt(mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut outputs: crate::c_types::derived::CVec_TxOutZ, mut change_destination_script: crate::c_types::derived::CVec_u8Z, mut feerate_sat_per_1000_weight: u32, mut locktime: crate::c_types::derived::COption_u32Z) -> crate::c_types::derived::CResult_C2Tuple_CVec_u8Zu64ZNoneZ {
782 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
783 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
784 let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus({ locktime_opt.take() }) }})} };
785 let mut ret = lightning::sign::SpendableOutputDescriptor::create_spendable_outputs_psbt(secp256k1::global::SECP256K1, &local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::ScriptBuf::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime);
786 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (orig_ret_0_0.serialize().into(), orig_ret_0_1).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
791 use lightning::sign::ChannelDerivationParameters as nativeChannelDerivationParametersImport;
792 pub(crate) type nativeChannelDerivationParameters = nativeChannelDerivationParametersImport;
794 /// The parameters required to derive a channel signer via [`SignerProvider`].
797 pub struct ChannelDerivationParameters {
798 /// A pointer to the opaque Rust object.
800 /// Nearly everywhere, inner must be non-null, however in places where
801 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
802 pub inner: *mut nativeChannelDerivationParameters,
803 /// Indicates that this is the only struct which contains the same pointer.
805 /// Rust functions which take ownership of an object provided via an argument require
806 /// this to be true and invalidate the object pointed to by inner.
810 impl Drop for ChannelDerivationParameters {
812 if self.is_owned && !<*mut nativeChannelDerivationParameters>::is_null(self.inner) {
813 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
817 /// Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL.
819 pub extern "C" fn ChannelDerivationParameters_free(this_obj: ChannelDerivationParameters) { }
821 /// Used only if an object of this type is returned as a trait impl by a method
822 pub(crate) extern "C" fn ChannelDerivationParameters_free_void(this_ptr: *mut c_void) {
823 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDerivationParameters) };
826 impl ChannelDerivationParameters {
827 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDerivationParameters {
828 unsafe { &*ObjOps::untweak_ptr(self.inner) }
830 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDerivationParameters {
831 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
833 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
834 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDerivationParameters {
835 assert!(self.is_owned);
836 let ret = ObjOps::untweak_ptr(self.inner);
837 self.inner = core::ptr::null_mut();
841 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
843 pub extern "C" fn ChannelDerivationParameters_get_value_satoshis(this_ptr: &ChannelDerivationParameters) -> u64 {
844 let mut inner_val = &mut this_ptr.get_native_mut_ref().value_satoshis;
847 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
849 pub extern "C" fn ChannelDerivationParameters_set_value_satoshis(this_ptr: &mut ChannelDerivationParameters, mut val: u64) {
850 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.value_satoshis = val;
852 /// The unique identifier to re-derive the signer for the associated channel.
854 pub extern "C" fn ChannelDerivationParameters_get_keys_id(this_ptr: &ChannelDerivationParameters) -> *const [u8; 32] {
855 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_id;
858 /// The unique identifier to re-derive the signer for the associated channel.
860 pub extern "C" fn ChannelDerivationParameters_set_keys_id(this_ptr: &mut ChannelDerivationParameters, mut val: crate::c_types::ThirtyTwoBytes) {
861 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_id = val.data;
863 /// The necessary channel parameters that need to be provided to the re-derived signer through
864 /// [`ChannelSigner::provide_channel_parameters`].
866 pub extern "C" fn ChannelDerivationParameters_get_transaction_parameters(this_ptr: &ChannelDerivationParameters) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
867 let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_parameters;
868 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 }
870 /// The necessary channel parameters that need to be provided to the re-derived signer through
871 /// [`ChannelSigner::provide_channel_parameters`].
873 pub extern "C" fn ChannelDerivationParameters_set_transaction_parameters(this_ptr: &mut ChannelDerivationParameters, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
874 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_parameters = *unsafe { Box::from_raw(val.take_inner()) };
876 /// Constructs a new ChannelDerivationParameters given each field
879 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 {
880 ChannelDerivationParameters { inner: ObjOps::heap_alloc(nativeChannelDerivationParameters {
881 value_satoshis: value_satoshis_arg,
882 keys_id: keys_id_arg.data,
883 transaction_parameters: *unsafe { Box::from_raw(transaction_parameters_arg.take_inner()) },
886 impl Clone for ChannelDerivationParameters {
887 fn clone(&self) -> Self {
889 inner: if <*mut nativeChannelDerivationParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
890 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
896 /// Used only if an object of this type is returned as a trait impl by a method
897 pub(crate) extern "C" fn ChannelDerivationParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
898 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelDerivationParameters)).clone() })) as *mut c_void
901 /// Creates a copy of the ChannelDerivationParameters
902 pub extern "C" fn ChannelDerivationParameters_clone(orig: &ChannelDerivationParameters) -> ChannelDerivationParameters {
905 /// Get a string which allows debug introspection of a ChannelDerivationParameters object
906 pub extern "C" fn ChannelDerivationParameters_debug_str_void(o: *const c_void) -> Str {
907 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::ChannelDerivationParameters }).into()}
908 /// Checks if two ChannelDerivationParameterss contain equal inner contents.
909 /// This ignores pointers and is_owned flags and looks at the values in fields.
910 /// Two objects with NULL inner values will be considered "equal" here.
912 pub extern "C" fn ChannelDerivationParameters_eq(a: &ChannelDerivationParameters, b: &ChannelDerivationParameters) -> bool {
913 if a.inner == b.inner { return true; }
914 if a.inner.is_null() || b.inner.is_null() { return false; }
915 if a.get_native_ref() == b.get_native_ref() { true } else { false }
918 /// Serialize the ChannelDerivationParameters object into a byte array which can be read by ChannelDerivationParameters_read
919 pub extern "C" fn ChannelDerivationParameters_write(obj: &crate::lightning::sign::ChannelDerivationParameters) -> crate::c_types::derived::CVec_u8Z {
920 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
923 pub(crate) extern "C" fn ChannelDerivationParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
924 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDerivationParameters) })
927 /// Read a ChannelDerivationParameters from a byte array, created by ChannelDerivationParameters_write
928 pub extern "C" fn ChannelDerivationParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDerivationParametersDecodeErrorZ {
929 let res: Result<lightning::sign::ChannelDerivationParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
930 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::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() };
934 use lightning::sign::HTLCDescriptor as nativeHTLCDescriptorImport;
935 pub(crate) type nativeHTLCDescriptor = nativeHTLCDescriptorImport;
937 /// A descriptor used to sign for a commitment transaction's HTLC output.
940 pub struct HTLCDescriptor {
941 /// A pointer to the opaque Rust object.
943 /// Nearly everywhere, inner must be non-null, however in places where
944 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
945 pub inner: *mut nativeHTLCDescriptor,
946 /// Indicates that this is the only struct which contains the same pointer.
948 /// Rust functions which take ownership of an object provided via an argument require
949 /// this to be true and invalidate the object pointed to by inner.
953 impl Drop for HTLCDescriptor {
955 if self.is_owned && !<*mut nativeHTLCDescriptor>::is_null(self.inner) {
956 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
960 /// Frees any resources used by the HTLCDescriptor, if is_owned is set and inner is non-NULL.
962 pub extern "C" fn HTLCDescriptor_free(this_obj: HTLCDescriptor) { }
964 /// Used only if an object of this type is returned as a trait impl by a method
965 pub(crate) extern "C" fn HTLCDescriptor_free_void(this_ptr: *mut c_void) {
966 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCDescriptor) };
969 impl HTLCDescriptor {
970 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCDescriptor {
971 unsafe { &*ObjOps::untweak_ptr(self.inner) }
973 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCDescriptor {
974 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
976 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
977 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCDescriptor {
978 assert!(self.is_owned);
979 let ret = ObjOps::untweak_ptr(self.inner);
980 self.inner = core::ptr::null_mut();
984 /// The parameters required to derive the signer for the HTLC input.
986 pub extern "C" fn HTLCDescriptor_get_channel_derivation_parameters(this_ptr: &HTLCDescriptor) -> crate::lightning::sign::ChannelDerivationParameters {
987 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters;
988 crate::lightning::sign::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::sign::ChannelDerivationParameters<>) as *mut _) }, is_owned: false }
990 /// The parameters required to derive the signer for the HTLC input.
992 pub extern "C" fn HTLCDescriptor_set_channel_derivation_parameters(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::sign::ChannelDerivationParameters) {
993 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) };
995 /// The txid of the commitment transaction in which the HTLC output lives.
997 pub extern "C" fn HTLCDescriptor_get_commitment_txid(this_ptr: &HTLCDescriptor) -> *const [u8; 32] {
998 let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_txid;
1001 /// The txid of the commitment transaction in which the HTLC output lives.
1003 pub extern "C" fn HTLCDescriptor_set_commitment_txid(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
1004 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap();
1006 /// The number of the commitment transaction in which the HTLC output lives.
1008 pub extern "C" fn HTLCDescriptor_get_per_commitment_number(this_ptr: &HTLCDescriptor) -> u64 {
1009 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_number;
1012 /// The number of the commitment transaction in which the HTLC output lives.
1014 pub extern "C" fn HTLCDescriptor_set_per_commitment_number(this_ptr: &mut HTLCDescriptor, mut val: u64) {
1015 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_number = val;
1017 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
1018 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
1019 /// arrive at unique keys per commitment.
1021 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
1023 pub extern "C" fn HTLCDescriptor_get_per_commitment_point(this_ptr: &HTLCDescriptor) -> crate::c_types::PublicKey {
1024 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
1025 crate::c_types::PublicKey::from_rust(&inner_val)
1027 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
1028 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
1029 /// arrive at unique keys per commitment.
1031 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
1033 pub extern "C" fn HTLCDescriptor_set_per_commitment_point(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::PublicKey) {
1034 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
1036 /// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
1037 /// originating from a channel supporting anchor outputs, otherwise it is the channel's
1038 /// negotiated feerate at the time the commitment transaction was built.
1040 pub extern "C" fn HTLCDescriptor_get_feerate_per_kw(this_ptr: &HTLCDescriptor) -> u32 {
1041 let mut inner_val = &mut this_ptr.get_native_mut_ref().feerate_per_kw;
1044 /// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
1045 /// originating from a channel supporting anchor outputs, otherwise it is the channel's
1046 /// negotiated feerate at the time the commitment transaction was built.
1048 pub extern "C" fn HTLCDescriptor_set_feerate_per_kw(this_ptr: &mut HTLCDescriptor, mut val: u32) {
1049 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.feerate_per_kw = val;
1051 /// The details of the HTLC as it appears in the commitment transaction.
1053 pub extern "C" fn HTLCDescriptor_get_htlc(this_ptr: &HTLCDescriptor) -> crate::lightning::ln::chan_utils::HTLCOutputInCommitment {
1054 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc;
1055 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 }
1057 /// The details of the HTLC as it appears in the commitment transaction.
1059 pub extern "C" fn HTLCDescriptor_set_htlc(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::ln::chan_utils::HTLCOutputInCommitment) {
1060 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc = *unsafe { Box::from_raw(val.take_inner()) };
1062 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
1065 pub extern "C" fn HTLCDescriptor_get_preimage(this_ptr: &HTLCDescriptor) -> crate::c_types::derived::COption_ThirtyTwoBytesZ {
1066 let mut inner_val = &mut this_ptr.get_native_mut_ref().preimage;
1067 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 } }) };
1070 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
1073 pub extern "C" fn HTLCDescriptor_set_preimage(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::derived::COption_ThirtyTwoBytesZ) {
1074 let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::lightning::ln::types::PaymentPreimage({ val_opt.take() }.data) }})} };
1075 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.preimage = local_val;
1077 /// The counterparty's signature required to spend the HTLC output.
1079 pub extern "C" fn HTLCDescriptor_get_counterparty_sig(this_ptr: &HTLCDescriptor) -> crate::c_types::ECDSASignature {
1080 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig;
1081 crate::c_types::ECDSASignature::from_rust(&inner_val)
1083 /// The counterparty's signature required to spend the HTLC output.
1085 pub extern "C" fn HTLCDescriptor_set_counterparty_sig(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::ECDSASignature) {
1086 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust();
1088 /// Constructs a new HTLCDescriptor given each field
1091 pub extern "C" fn HTLCDescriptor_new(mut channel_derivation_parameters_arg: crate::lightning::sign::ChannelDerivationParameters, mut commitment_txid_arg: crate::c_types::ThirtyTwoBytes, mut per_commitment_number_arg: u64, mut per_commitment_point_arg: crate::c_types::PublicKey, mut feerate_per_kw_arg: u32, mut htlc_arg: crate::lightning::ln::chan_utils::HTLCOutputInCommitment, mut preimage_arg: crate::c_types::derived::COption_ThirtyTwoBytesZ, mut counterparty_sig_arg: crate::c_types::ECDSASignature) -> HTLCDescriptor {
1092 let mut local_preimage_arg = { /*preimage_arg*/ let preimage_arg_opt = preimage_arg; if preimage_arg_opt.is_none() { None } else { Some({ { ::lightning::ln::types::PaymentPreimage({ preimage_arg_opt.take() }.data) }})} };
1093 HTLCDescriptor { inner: ObjOps::heap_alloc(nativeHTLCDescriptor {
1094 channel_derivation_parameters: *unsafe { Box::from_raw(channel_derivation_parameters_arg.take_inner()) },
1095 commitment_txid: ::bitcoin::hash_types::Txid::from_slice(&commitment_txid_arg.data[..]).unwrap(),
1096 per_commitment_number: per_commitment_number_arg,
1097 per_commitment_point: per_commitment_point_arg.into_rust(),
1098 feerate_per_kw: feerate_per_kw_arg,
1099 htlc: *unsafe { Box::from_raw(htlc_arg.take_inner()) },
1100 preimage: local_preimage_arg,
1101 counterparty_sig: counterparty_sig_arg.into_rust(),
1102 }), is_owned: true }
1104 impl Clone for HTLCDescriptor {
1105 fn clone(&self) -> Self {
1107 inner: if <*mut nativeHTLCDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
1108 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1114 /// Used only if an object of this type is returned as a trait impl by a method
1115 pub(crate) extern "C" fn HTLCDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
1116 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHTLCDescriptor)).clone() })) as *mut c_void
1119 /// Creates a copy of the HTLCDescriptor
1120 pub extern "C" fn HTLCDescriptor_clone(orig: &HTLCDescriptor) -> HTLCDescriptor {
1123 /// Get a string which allows debug introspection of a HTLCDescriptor object
1124 pub extern "C" fn HTLCDescriptor_debug_str_void(o: *const c_void) -> Str {
1125 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::HTLCDescriptor }).into()}
1126 /// Checks if two HTLCDescriptors contain equal inner contents.
1127 /// This ignores pointers and is_owned flags and looks at the values in fields.
1128 /// Two objects with NULL inner values will be considered "equal" here.
1130 pub extern "C" fn HTLCDescriptor_eq(a: &HTLCDescriptor, b: &HTLCDescriptor) -> bool {
1131 if a.inner == b.inner { return true; }
1132 if a.inner.is_null() || b.inner.is_null() { return false; }
1133 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1136 /// Serialize the HTLCDescriptor object into a byte array which can be read by HTLCDescriptor_read
1137 pub extern "C" fn HTLCDescriptor_write(obj: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z {
1138 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1141 pub(crate) extern "C" fn HTLCDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1142 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCDescriptor) })
1145 /// Read a HTLCDescriptor from a byte array, created by HTLCDescriptor_write
1146 pub extern "C" fn HTLCDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCDescriptorDecodeErrorZ {
1147 let res: Result<lightning::sign::HTLCDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1148 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::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() };
1151 /// Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint
1152 /// being spent by the HTLC input in the HTLC transaction.
1155 pub extern "C" fn HTLCDescriptor_outpoint(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::lightning::chain::transaction::OutPoint {
1156 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.outpoint();
1157 crate::c_types::bitcoin_to_C_outpoint(&ret)
1160 /// Returns the UTXO to be spent by the HTLC input, which can be obtained via
1161 /// [`Self::unsigned_tx_input`].
1164 pub extern "C" fn HTLCDescriptor_previous_utxo(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxOut {
1165 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo(secp256k1::global::SECP256K1);
1166 crate::c_types::TxOut::from_rust(&ret)
1169 /// Returns the unsigned transaction input spending the HTLC output in the commitment
1173 pub extern "C" fn HTLCDescriptor_unsigned_tx_input(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxIn {
1174 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input();
1175 crate::c_types::TxIn::from_rust(&ret)
1178 /// Returns the delayed output created as a result of spending the HTLC output in the commitment
1182 pub extern "C" fn HTLCDescriptor_tx_output(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxOut {
1183 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_output(secp256k1::global::SECP256K1);
1184 crate::c_types::TxOut::from_rust(&ret)
1187 /// Returns the witness script of the HTLC output in the commitment transaction.
1190 pub extern "C" fn HTLCDescriptor_witness_script(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z {
1191 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script(secp256k1::global::SECP256K1);
1192 ret.to_bytes().into()
1195 /// Returns the fully signed witness required to spend the HTLC output in the commitment
1199 pub extern "C" fn HTLCDescriptor_tx_input_witness(this_arg: &crate::lightning::sign::HTLCDescriptor, mut signature: crate::c_types::ECDSASignature, mut witness_script: crate::c_types::u8slice) -> crate::c_types::Witness {
1200 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_input_witness(&signature.into_rust(), ::bitcoin::blockdata::script::Script::from_bytes(witness_script.to_slice()));
1201 crate::c_types::Witness::from_bitcoin(&ret)
1204 /// Derives the channel signer required to sign the HTLC input.
1207 pub extern "C" fn HTLCDescriptor_derive_channel_signer(this_arg: &crate::lightning::sign::HTLCDescriptor, signer_provider: &crate::lightning::sign::SignerProvider) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
1208 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider);
1212 /// A trait to handle Lightning channel key material without concretizing the channel type or
1213 /// the signature mechanism.
1215 pub struct ChannelSigner {
1216 /// An opaque pointer which is passed to your function implementations as an argument.
1217 /// This has no meaning in the LDK, and can be NULL or any other value.
1218 pub this_arg: *mut c_void,
1219 /// Gets the per-commitment point for a specific commitment number
1221 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
1222 pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey,
1223 /// Gets the commitment secret for a specific commitment number as part of the revocation process
1225 /// An external signer implementation should error here if the commitment was already signed
1226 /// and should refuse to sign it in the future.
1228 /// May be called more than once for the same index.
1230 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
1231 pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes,
1232 /// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
1234 /// This is required in order for the signer to make sure that releasing a commitment
1235 /// secret won't leave us without a broadcastable holder transaction.
1236 /// Policy checks should be implemented in this function, including checking the amount
1237 /// sent to us and checking the HTLCs.
1239 /// The preimages of outbound HTLCs that were fulfilled since the last commitment are provided.
1240 /// A validating signer should ensure that an HTLC output is removed only when the matching
1241 /// preimage is provided, or when the value to holder is restored.
1243 /// Note that all the relevant preimages will be provided, but there may also be additional
1244 /// irrelevant or duplicate preimages.
1245 pub validate_holder_commitment: extern "C" fn (this_arg: *const c_void, holder_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction, outbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_NoneNoneZ,
1246 /// Validate the counterparty's revocation.
1248 /// This is required in order for the signer to make sure that the state has moved
1249 /// forward and it is safe to sign the next counterparty commitment.
1250 pub validate_counterparty_revocation: extern "C" fn (this_arg: *const c_void, idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ,
1251 /// Returns the holder's channel public keys and basepoints.
1252 pub pubkeys: core::cell::UnsafeCell<crate::lightning::ln::chan_utils::ChannelPublicKeys>,
1253 /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns
1254 /// Note that this takes a pointer to this object, not the this_ptr like other methods do
1255 /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
1256 pub set_pubkeys: Option<extern "C" fn(&ChannelSigner)>,
1257 /// Returns an arbitrary identifier describing the set of keys which are provided back to you in
1258 /// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
1259 /// [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
1260 pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1261 /// Set the counterparty static channel data, including basepoints,
1262 /// `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
1264 /// This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
1265 /// instance, LDK will call this method exactly once - either immediately after construction
1266 /// (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
1267 /// information has been generated.
1269 /// channel_parameters.is_populated() MUST be true.
1270 pub provide_channel_parameters: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters),
1271 /// Frees any resources associated with this object given its this_arg pointer.
1272 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1273 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1275 unsafe impl Send for ChannelSigner {}
1276 unsafe impl Sync for ChannelSigner {}
1278 pub(crate) fn ChannelSigner_clone_fields(orig: &ChannelSigner) -> ChannelSigner {
1280 this_arg: orig.this_arg,
1281 get_per_commitment_point: Clone::clone(&orig.get_per_commitment_point),
1282 release_commitment_secret: Clone::clone(&orig.release_commitment_secret),
1283 validate_holder_commitment: Clone::clone(&orig.validate_holder_commitment),
1284 validate_counterparty_revocation: Clone::clone(&orig.validate_counterparty_revocation),
1285 pubkeys: Clone::clone(unsafe { &*core::cell::UnsafeCell::get(&orig.pubkeys)}).into(),
1286 set_pubkeys: Clone::clone(&orig.set_pubkeys),
1287 channel_keys_id: Clone::clone(&orig.channel_keys_id),
1288 provide_channel_parameters: Clone::clone(&orig.provide_channel_parameters),
1289 free: Clone::clone(&orig.free),
1293 use lightning::sign::ChannelSigner as rustChannelSigner;
1294 impl rustChannelSigner for ChannelSigner {
1295 fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
1296 let mut ret = (self.get_per_commitment_point)(self.this_arg, idx);
1299 fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
1300 let mut ret = (self.release_commitment_secret)(self.this_arg, idx);
1303 fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut outbound_htlc_preimages: Vec<lightning::ln::types::PaymentPreimage>) -> Result<(), ()> {
1304 let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.drain(..) { local_outbound_htlc_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1305 let mut ret = (self.validate_holder_commitment)(self.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((holder_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false }, local_outbound_htlc_preimages.into());
1306 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1309 fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
1310 let mut ret = (self.validate_counterparty_revocation)(self.this_arg, idx, secret.as_ref());
1311 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1314 fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
1315 if let Some(f) = self.set_pubkeys {
1318 unsafe { &*self.pubkeys.get() }.get_native_ref()
1320 fn channel_keys_id(&self) -> [u8; 32] {
1321 let mut ret = (self.channel_keys_id)(self.this_arg);
1324 fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
1325 (self.provide_channel_parameters)(self.this_arg, &crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((channel_parameters as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false })
1329 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1330 // directly as a Deref trait in higher-level structs:
1331 impl core::ops::Deref for ChannelSigner {
1333 fn deref(&self) -> &Self {
1337 impl core::ops::DerefMut for ChannelSigner {
1338 fn deref_mut(&mut self) -> &mut Self {
1342 /// Calls the free function if one is set
1344 pub extern "C" fn ChannelSigner_free(this_ptr: ChannelSigner) { }
1345 impl Drop for ChannelSigner {
1346 fn drop(&mut self) {
1347 if let Some(f) = self.free {
1352 /// Specifies the recipient of an invoice.
1354 /// This indicates to [`NodeSigner::sign_invoice`] what node secret key should be used to sign
1359 pub enum Recipient {
1360 /// The invoice should be signed with the local node secret key.
1362 /// The invoice should be signed with the phantom node secret key. This secret key must be the
1363 /// same for all nodes participating in the [phantom node payment].
1365 /// [phantom node payment]: PhantomKeysManager
1368 use lightning::sign::Recipient as RecipientImport;
1369 pub(crate) type nativeRecipient = RecipientImport;
1373 pub(crate) fn to_native(&self) -> nativeRecipient {
1375 Recipient::Node => nativeRecipient::Node,
1376 Recipient::PhantomNode => nativeRecipient::PhantomNode,
1380 pub(crate) fn into_native(self) -> nativeRecipient {
1382 Recipient::Node => nativeRecipient::Node,
1383 Recipient::PhantomNode => nativeRecipient::PhantomNode,
1387 pub(crate) fn from_native(native: &RecipientImport) -> Self {
1388 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeRecipient) };
1390 nativeRecipient::Node => Recipient::Node,
1391 nativeRecipient::PhantomNode => Recipient::PhantomNode,
1395 pub(crate) fn native_into(native: nativeRecipient) -> Self {
1397 nativeRecipient::Node => Recipient::Node,
1398 nativeRecipient::PhantomNode => Recipient::PhantomNode,
1402 /// Creates a copy of the Recipient
1404 pub extern "C" fn Recipient_clone(orig: &Recipient) -> Recipient {
1408 /// Used only if an object of this type is returned as a trait impl by a method
1409 pub(crate) extern "C" fn Recipient_clone_void(this_ptr: *const c_void) -> *mut c_void {
1410 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Recipient)).clone() })) as *mut c_void
1413 /// Used only if an object of this type is returned as a trait impl by a method
1414 pub(crate) extern "C" fn Recipient_free_void(this_ptr: *mut c_void) {
1415 let _ = unsafe { Box::from_raw(this_ptr as *mut Recipient) };
1418 /// Utility method to constructs a new Node-variant Recipient
1419 pub extern "C" fn Recipient_node() -> Recipient {
1422 /// Utility method to constructs a new PhantomNode-variant Recipient
1423 pub extern "C" fn Recipient_phantom_node() -> Recipient {
1424 Recipient::PhantomNode}
1425 /// A trait that describes a source of entropy.
1427 pub struct EntropySource {
1428 /// An opaque pointer which is passed to your function implementations as an argument.
1429 /// This has no meaning in the LDK, and can be NULL or any other value.
1430 pub this_arg: *mut c_void,
1431 /// Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
1432 /// different value each time it is called.
1433 pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1434 /// Frees any resources associated with this object given its this_arg pointer.
1435 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1436 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1438 unsafe impl Send for EntropySource {}
1439 unsafe impl Sync for EntropySource {}
1441 pub(crate) fn EntropySource_clone_fields(orig: &EntropySource) -> EntropySource {
1443 this_arg: orig.this_arg,
1444 get_secure_random_bytes: Clone::clone(&orig.get_secure_random_bytes),
1445 free: Clone::clone(&orig.free),
1449 use lightning::sign::EntropySource as rustEntropySource;
1450 impl rustEntropySource for EntropySource {
1451 fn get_secure_random_bytes(&self) -> [u8; 32] {
1452 let mut ret = (self.get_secure_random_bytes)(self.this_arg);
1457 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1458 // directly as a Deref trait in higher-level structs:
1459 impl core::ops::Deref for EntropySource {
1461 fn deref(&self) -> &Self {
1465 impl core::ops::DerefMut for EntropySource {
1466 fn deref_mut(&mut self) -> &mut Self {
1470 /// Calls the free function if one is set
1472 pub extern "C" fn EntropySource_free(this_ptr: EntropySource) { }
1473 impl Drop for EntropySource {
1474 fn drop(&mut self) {
1475 if let Some(f) = self.free {
1480 /// A trait that can handle cryptographic operations at the scope level of a node.
1482 pub struct NodeSigner {
1483 /// An opaque pointer which is passed to your function implementations as an argument.
1484 /// This has no meaning in the LDK, and can be NULL or any other value.
1485 pub this_arg: *mut c_void,
1486 /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
1488 /// If the implementor of this trait supports [phantom node payments], then every node that is
1489 /// intended to be included in the phantom invoice route hints must return the same value from
1492 /// This method must return the same value each time it is called.
1494 /// [phantom node payments]: PhantomKeysManager
1495 pub get_inbound_payment_key_material: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1496 /// Get node id based on the provided [`Recipient`].
1498 /// This method must return the same value each time it is called with a given [`Recipient`]
1501 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1502 pub get_node_id: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ,
1503 /// Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
1504 /// one is provided. Note that this tweak can be applied to `other_key` instead of our node
1505 /// secret, though this is less efficient.
1507 /// Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
1508 /// should be resolved to allow LDK to resume forwarding HTLCs.
1510 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1511 pub ecdh: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::sign::Recipient, other_key: crate::c_types::PublicKey, tweak: crate::c_types::derived::COption_BigEndianScalarZ) -> crate::c_types::derived::CResult_ThirtyTwoBytesNoneZ,
1512 /// Sign an invoice.
1514 /// By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
1515 /// this trait to parse the invoice and make sure they're signing what they expect, rather than
1516 /// blindly signing the hash.
1518 /// The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
1520 /// The secret key used to sign the invoice is dependent on the [`Recipient`].
1522 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1523 pub sign_invoice: extern "C" fn (this_arg: *const c_void, hrp_bytes: crate::c_types::u8slice, invoice_data: crate::c_types::derived::CVec_U5Z, recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ,
1524 /// Signs the [`TaggedHash`] of a BOLT 12 invoice request.
1526 /// May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
1527 /// `invoice_request` is the callee.
1529 /// Implementors may check that the `invoice_request` is expected rather than blindly signing
1530 /// the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
1531 /// the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
1532 /// [`UnsignedInvoiceRequest::payer_id`].
1534 /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
1535 pub sign_bolt12_invoice_request: extern "C" fn (this_arg: *const c_void, invoice_request: &crate::lightning::offers::invoice_request::UnsignedInvoiceRequest) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ,
1536 /// Signs the [`TaggedHash`] of a BOLT 12 invoice.
1538 /// May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
1541 /// Implementors may check that the `invoice` is expected rather than blindly signing the tagged
1542 /// hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
1543 /// key or an ephemeral key to preserve privacy, whichever is associated with
1544 /// [`UnsignedBolt12Invoice::signing_pubkey`].
1546 /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
1547 pub sign_bolt12_invoice: extern "C" fn (this_arg: *const c_void, invoice: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ,
1548 /// Sign a gossip message.
1550 /// Note that if this fails, LDK may panic and the message will not be broadcast to the network
1551 /// or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
1552 /// message to be broadcast, as otherwise it may prevent one from receiving funds over the
1553 /// corresponding channel.
1554 pub sign_gossip_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
1555 /// Frees any resources associated with this object given its this_arg pointer.
1556 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1557 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1559 unsafe impl Send for NodeSigner {}
1560 unsafe impl Sync for NodeSigner {}
1562 pub(crate) fn NodeSigner_clone_fields(orig: &NodeSigner) -> NodeSigner {
1564 this_arg: orig.this_arg,
1565 get_inbound_payment_key_material: Clone::clone(&orig.get_inbound_payment_key_material),
1566 get_node_id: Clone::clone(&orig.get_node_id),
1567 ecdh: Clone::clone(&orig.ecdh),
1568 sign_invoice: Clone::clone(&orig.sign_invoice),
1569 sign_bolt12_invoice_request: Clone::clone(&orig.sign_bolt12_invoice_request),
1570 sign_bolt12_invoice: Clone::clone(&orig.sign_bolt12_invoice),
1571 sign_gossip_message: Clone::clone(&orig.sign_gossip_message),
1572 free: Clone::clone(&orig.free),
1576 use lightning::sign::NodeSigner as rustNodeSigner;
1577 impl rustNodeSigner for NodeSigner {
1578 fn get_inbound_payment_key_material(&self) -> lightning::sign::KeyMaterial {
1579 let mut ret = (self.get_inbound_payment_key_material)(self.this_arg);
1580 ::lightning::sign::KeyMaterial(ret.data)
1582 fn get_node_id(&self, mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::PublicKey, ()> {
1583 let mut ret = (self.get_node_id)(self.this_arg, crate::lightning::sign::Recipient::native_into(recipient));
1584 let mut local_ret = match ret.result_ok { true => Ok( { (*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)) })*/ })};
1587 fn ecdh(&self, mut recipient: lightning::sign::Recipient, mut other_key: &bitcoin::secp256k1::PublicKey, mut tweak: Option<&bitcoin::secp256k1::Scalar>) -> Result<bitcoin::secp256k1::ecdh::SharedSecret, ()> {
1588 let mut local_tweak = if tweak.is_none() { crate::c_types::derived::COption_BigEndianScalarZ::None } else { crate::c_types::derived::COption_BigEndianScalarZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::BigEndianScalar::from_rust(&(*tweak.as_ref().unwrap()).clone()) }) };
1589 let mut ret = (self.ecdh)(self.this_arg, crate::lightning::sign::Recipient::native_into(recipient), crate::c_types::PublicKey::from_rust(&other_key), local_tweak);
1590 let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::secp256k1::ecdh::SharedSecret::from_bytes((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).data) }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1593 fn sign_invoice(&self, mut hrp_bytes: &[u8], mut invoice_data: &[bitcoin::bech32::u5], mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
1594 let mut local_hrp_bytes = crate::c_types::u8slice::from_slice(hrp_bytes);
1595 let mut local_invoice_data_clone = Vec::new(); local_invoice_data_clone.extend_from_slice(invoice_data); let mut invoice_data = local_invoice_data_clone; let mut local_invoice_data = Vec::new(); for mut item in invoice_data.drain(..) { local_invoice_data.push( { item.into() }); };
1596 let mut ret = (self.sign_invoice)(self.this_arg, local_hrp_bytes, local_invoice_data.into(), crate::lightning::sign::Recipient::native_into(recipient));
1597 let mut local_ret = match ret.result_ok { true => Ok( { (*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)) })*/ })};
1600 fn sign_bolt12_invoice_request(&self, mut invoice_request: &lightning::offers::invoice_request::UnsignedInvoiceRequest) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
1601 let mut ret = (self.sign_bolt12_invoice_request)(self.this_arg, &crate::lightning::offers::invoice_request::UnsignedInvoiceRequest { inner: unsafe { ObjOps::nonnull_ptr_to_inner((invoice_request as *const lightning::offers::invoice_request::UnsignedInvoiceRequest<>) as *mut _) }, is_owned: false });
1602 let mut local_ret = match ret.result_ok { true => Ok( { (*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)) })*/ })};
1605 fn sign_bolt12_invoice(&self, mut invoice: &lightning::offers::invoice::UnsignedBolt12Invoice) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
1606 let mut ret = (self.sign_bolt12_invoice)(self.this_arg, &crate::lightning::offers::invoice::UnsignedBolt12Invoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((invoice as *const lightning::offers::invoice::UnsignedBolt12Invoice<>) as *mut _) }, is_owned: false });
1607 let mut local_ret = match ret.result_ok { true => Ok( { (*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)) })*/ })};
1610 fn sign_gossip_message(&self, mut msg: lightning::ln::msgs::UnsignedGossipMessage) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1611 let mut ret = (self.sign_gossip_message)(self.this_arg, crate::lightning::ln::msgs::UnsignedGossipMessage::native_into(msg));
1612 let mut local_ret = match ret.result_ok { true => Ok( { (*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)) })*/ })};
1617 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1618 // directly as a Deref trait in higher-level structs:
1619 impl core::ops::Deref for NodeSigner {
1621 fn deref(&self) -> &Self {
1625 impl core::ops::DerefMut for NodeSigner {
1626 fn deref_mut(&mut self) -> &mut Self {
1630 /// Calls the free function if one is set
1632 pub extern "C" fn NodeSigner_free(this_ptr: NodeSigner) { }
1633 impl Drop for NodeSigner {
1634 fn drop(&mut self) {
1635 if let Some(f) = self.free {
1640 /// A trait that describes a wallet capable of creating a spending [`Transaction`] from a set of
1641 /// [`SpendableOutputDescriptor`]s.
1643 pub struct OutputSpender {
1644 /// An opaque pointer which is passed to your function implementations as an argument.
1645 /// This has no meaning in the LDK, and can be NULL or any other value.
1646 pub this_arg: *mut c_void,
1647 /// Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
1648 /// output to the given change destination (if sufficient change value remains). The
1649 /// transaction will have a feerate, at least, of the given value.
1651 /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
1652 /// transaction will have a locktime of 0. It it recommended to set this to the current block
1653 /// height to avoid fee sniping, unless you have some specific reason to use a different
1656 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
1657 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
1658 /// does not match the one we can spend.
1659 pub spend_spendable_outputs: extern "C" fn (this_arg: *const c_void, descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, outputs: crate::c_types::derived::CVec_TxOutZ, change_destination_script: crate::c_types::derived::CVec_u8Z, feerate_sat_per_1000_weight: u32, locktime: crate::c_types::derived::COption_u32Z) -> crate::c_types::derived::CResult_TransactionNoneZ,
1660 /// Frees any resources associated with this object given its this_arg pointer.
1661 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1662 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1664 unsafe impl Send for OutputSpender {}
1665 unsafe impl Sync for OutputSpender {}
1667 pub(crate) fn OutputSpender_clone_fields(orig: &OutputSpender) -> OutputSpender {
1669 this_arg: orig.this_arg,
1670 spend_spendable_outputs: Clone::clone(&orig.spend_spendable_outputs),
1671 free: Clone::clone(&orig.free),
1675 use lightning::sign::OutputSpender as rustOutputSpender;
1676 impl rustOutputSpender for OutputSpender {
1677 fn spend_spendable_outputs<C:bitcoin::secp256k1::Signing>(&self, mut descriptors: &[&lightning::sign::SpendableOutputDescriptor], mut outputs: Vec<bitcoin::blockdata::transaction::TxOut>, mut change_destination_script: bitcoin::blockdata::script::ScriptBuf, mut feerate_sat_per_1000_weight: u32, mut locktime: Option<bitcoin::blockdata::locktime::absolute::LockTime>, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<C>) -> Result<bitcoin::blockdata::transaction::Transaction, ()> {
1678 let mut local_descriptors = Vec::new(); for item in descriptors.iter() { local_descriptors.push( { crate::lightning::sign::SpendableOutputDescriptor::from_native((*item)) }); };
1679 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::c_types::TxOut::from_rust(&item) }); };
1680 let mut local_locktime = if locktime.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { locktime.unwrap().to_consensus_u32() }) };
1681 let mut ret = (self.spend_spendable_outputs)(self.this_arg, local_descriptors.into(), local_outputs.into(), change_destination_script.to_bytes().into(), feerate_sat_per_1000_weight, local_locktime);
1682 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)) })*/ })};
1687 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1688 // directly as a Deref trait in higher-level structs:
1689 impl core::ops::Deref for OutputSpender {
1691 fn deref(&self) -> &Self {
1695 impl core::ops::DerefMut for OutputSpender {
1696 fn deref_mut(&mut self) -> &mut Self {
1700 /// Calls the free function if one is set
1702 pub extern "C" fn OutputSpender_free(this_ptr: OutputSpender) { }
1703 impl Drop for OutputSpender {
1704 fn drop(&mut self) {
1705 if let Some(f) = self.free {
1710 /// A trait that can return signer instances for individual channels.
1712 pub struct SignerProvider {
1713 /// An opaque pointer which is passed to your function implementations as an argument.
1714 /// This has no meaning in the LDK, and can be NULL or any other value.
1715 pub this_arg: *mut c_void,
1716 /// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::EcdsaSigner`] through
1717 /// [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
1718 /// implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
1719 /// `channel_keys_id`.
1721 /// This method must return a different value each time it is called.
1722 pub generate_channel_keys_id: extern "C" fn (this_arg: *const c_void, inbound: bool, channel_value_satoshis: u64, user_channel_id: crate::c_types::U128) -> crate::c_types::ThirtyTwoBytes,
1723 /// Derives the private key material backing a `Signer`.
1725 /// To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
1726 /// [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
1727 /// re-derived from its `channel_keys_id`, which can be obtained through its trait method
1728 /// [`ChannelSigner::channel_keys_id`].
1729 pub derive_channel_signer: extern "C" fn (this_arg: *const c_void, channel_value_satoshis: u64, channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner,
1730 /// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
1731 /// This is only called during deserialization of other objects which contain
1732 /// [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
1733 /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
1734 /// contain no versioning scheme. You may wish to include your own version prefix and ensure
1735 /// you've read all of the provided bytes to ensure no corruption occurred.
1737 /// This method is slowly being phased out -- it will only be called when reading objects
1738 /// written by LDK versions prior to 0.0.113.
1740 /// [`Signer`]: Self::EcdsaSigner
1741 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
1742 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1743 pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ,
1744 /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
1746 /// If this function returns an error, this will result in a channel failing to open.
1748 /// This method should return a different value each time it is called, to avoid linking
1749 /// on-chain funds across channels as controlled to the same user. `channel_keys_id` may be
1750 /// used to derive a unique value for each channel.
1751 pub get_destination_script: extern "C" fn (this_arg: *const c_void, channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ,
1752 /// Get a script pubkey which we will send funds to when closing a channel.
1754 /// If this function returns an error, this will result in a channel failing to open or close.
1755 /// In the event of a failure when the counterparty is initiating a close, this can result in a
1756 /// channel force close.
1758 /// This method should return a different value each time it is called, to avoid linking
1759 /// on-chain funds across channels as controlled to the same user.
1760 pub get_shutdown_scriptpubkey: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ,
1761 /// Frees any resources associated with this object given its this_arg pointer.
1762 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1763 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1765 unsafe impl Send for SignerProvider {}
1766 unsafe impl Sync for SignerProvider {}
1768 pub(crate) fn SignerProvider_clone_fields(orig: &SignerProvider) -> SignerProvider {
1770 this_arg: orig.this_arg,
1771 generate_channel_keys_id: Clone::clone(&orig.generate_channel_keys_id),
1772 derive_channel_signer: Clone::clone(&orig.derive_channel_signer),
1773 read_chan_signer: Clone::clone(&orig.read_chan_signer),
1774 get_destination_script: Clone::clone(&orig.get_destination_script),
1775 get_shutdown_scriptpubkey: Clone::clone(&orig.get_shutdown_scriptpubkey),
1776 free: Clone::clone(&orig.free),
1780 use lightning::sign::SignerProvider as rustSignerProvider;
1781 impl rustSignerProvider for SignerProvider {
1782 type EcdsaSigner = crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner;
1783 fn generate_channel_keys_id(&self, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: u128) -> [u8; 32] {
1784 let mut ret = (self.generate_channel_keys_id)(self.this_arg, inbound, channel_value_satoshis, user_channel_id.into());
1787 fn derive_channel_signer(&self, mut channel_value_satoshis: u64, mut channel_keys_id: [u8; 32]) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
1788 let mut ret = (self.derive_channel_signer)(self.this_arg, channel_value_satoshis, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
1791 fn read_chan_signer(&self, mut reader: &[u8]) -> Result<crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner, lightning::ln::msgs::DecodeError> {
1792 let mut local_reader = crate::c_types::u8slice::from_slice(reader);
1793 let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
1794 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
1797 fn get_destination_script(&self, mut channel_keys_id: [u8; 32]) -> Result<bitcoin::blockdata::script::ScriptBuf, ()> {
1798 let mut ret = (self.get_destination_script)(self.this_arg, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
1799 let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::blockdata::script::ScriptBuf::from((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust()) }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1802 fn get_shutdown_scriptpubkey(&self) -> Result<lightning::ln::script::ShutdownScript, ()> {
1803 let mut ret = (self.get_shutdown_scriptpubkey)(self.this_arg);
1804 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)) })*/ })};
1809 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1810 // directly as a Deref trait in higher-level structs:
1811 impl core::ops::Deref for SignerProvider {
1813 fn deref(&self) -> &Self {
1817 impl core::ops::DerefMut for SignerProvider {
1818 fn deref_mut(&mut self) -> &mut Self {
1822 /// Calls the free function if one is set
1824 pub extern "C" fn SignerProvider_free(this_ptr: SignerProvider) { }
1825 impl Drop for SignerProvider {
1826 fn drop(&mut self) {
1827 if let Some(f) = self.free {
1832 /// A helper trait that describes an on-chain wallet capable of returning a (change) destination
1835 pub struct ChangeDestinationSource {
1836 /// An opaque pointer which is passed to your function implementations as an argument.
1837 /// This has no meaning in the LDK, and can be NULL or any other value.
1838 pub this_arg: *mut c_void,
1839 /// Returns a script pubkey which can be used as a change destination for
1840 /// [`OutputSpender::spend_spendable_outputs`].
1842 /// This method should return a different value each time it is called, to avoid linking
1843 /// on-chain funds controlled to the same user.
1844 pub get_change_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ,
1845 /// Frees any resources associated with this object given its this_arg pointer.
1846 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1847 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1849 unsafe impl Send for ChangeDestinationSource {}
1850 unsafe impl Sync for ChangeDestinationSource {}
1852 pub(crate) fn ChangeDestinationSource_clone_fields(orig: &ChangeDestinationSource) -> ChangeDestinationSource {
1853 ChangeDestinationSource {
1854 this_arg: orig.this_arg,
1855 get_change_destination_script: Clone::clone(&orig.get_change_destination_script),
1856 free: Clone::clone(&orig.free),
1860 use lightning::sign::ChangeDestinationSource as rustChangeDestinationSource;
1861 impl rustChangeDestinationSource for ChangeDestinationSource {
1862 fn get_change_destination_script(&self) -> Result<bitcoin::blockdata::script::ScriptBuf, ()> {
1863 let mut ret = (self.get_change_destination_script)(self.this_arg);
1864 let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::blockdata::script::ScriptBuf::from((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust()) }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1869 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1870 // directly as a Deref trait in higher-level structs:
1871 impl core::ops::Deref for ChangeDestinationSource {
1873 fn deref(&self) -> &Self {
1877 impl core::ops::DerefMut for ChangeDestinationSource {
1878 fn deref_mut(&mut self) -> &mut Self {
1882 /// Calls the free function if one is set
1884 pub extern "C" fn ChangeDestinationSource_free(this_ptr: ChangeDestinationSource) { }
1885 impl Drop for ChangeDestinationSource {
1886 fn drop(&mut self) {
1887 if let Some(f) = self.free {
1893 use lightning::sign::InMemorySigner as nativeInMemorySignerImport;
1894 pub(crate) type nativeInMemorySigner = nativeInMemorySignerImport;
1896 /// A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
1898 /// This implementation performs no policy checks and is insufficient by itself as
1899 /// a secure external signer.
1902 pub struct InMemorySigner {
1903 /// A pointer to the opaque Rust object.
1905 /// Nearly everywhere, inner must be non-null, however in places where
1906 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1907 pub inner: *mut nativeInMemorySigner,
1908 /// Indicates that this is the only struct which contains the same pointer.
1910 /// Rust functions which take ownership of an object provided via an argument require
1911 /// this to be true and invalidate the object pointed to by inner.
1915 impl Drop for InMemorySigner {
1916 fn drop(&mut self) {
1917 if self.is_owned && !<*mut nativeInMemorySigner>::is_null(self.inner) {
1918 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1922 /// Frees any resources used by the InMemorySigner, if is_owned is set and inner is non-NULL.
1924 pub extern "C" fn InMemorySigner_free(this_obj: InMemorySigner) { }
1926 /// Used only if an object of this type is returned as a trait impl by a method
1927 pub(crate) extern "C" fn InMemorySigner_free_void(this_ptr: *mut c_void) {
1928 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInMemorySigner) };
1931 impl InMemorySigner {
1932 pub(crate) fn get_native_ref(&self) -> &'static nativeInMemorySigner {
1933 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1935 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInMemorySigner {
1936 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1938 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1939 pub(crate) fn take_inner(mut self) -> *mut nativeInMemorySigner {
1940 assert!(self.is_owned);
1941 let ret = ObjOps::untweak_ptr(self.inner);
1942 self.inner = core::ptr::null_mut();
1946 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1947 /// holder's anchor output in a commitment transaction, if one is present.
1949 pub extern "C" fn InMemorySigner_get_funding_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1950 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_key;
1953 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1954 /// holder's anchor output in a commitment transaction, if one is present.
1956 pub extern "C" fn InMemorySigner_set_funding_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1957 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_key = val.into_rust();
1959 /// Holder secret key for blinded revocation pubkey.
1961 pub extern "C" fn InMemorySigner_get_revocation_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1962 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_base_key;
1965 /// Holder secret key for blinded revocation pubkey.
1967 pub extern "C" fn InMemorySigner_set_revocation_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1968 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_base_key = val.into_rust();
1970 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1972 pub extern "C" fn InMemorySigner_get_payment_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1973 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_key;
1976 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1978 pub extern "C" fn InMemorySigner_set_payment_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1979 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_key = val.into_rust();
1981 /// Holder secret key used in an HTLC transaction.
1983 pub extern "C" fn InMemorySigner_get_delayed_payment_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1984 let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_base_key;
1987 /// Holder secret key used in an HTLC transaction.
1989 pub extern "C" fn InMemorySigner_set_delayed_payment_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1990 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_base_key = val.into_rust();
1992 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1994 pub extern "C" fn InMemorySigner_get_htlc_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1995 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_base_key;
1998 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
2000 pub extern "C" fn InMemorySigner_set_htlc_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
2001 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_base_key = val.into_rust();
2003 /// Commitment seed.
2005 pub extern "C" fn InMemorySigner_get_commitment_seed(this_ptr: &InMemorySigner) -> *const [u8; 32] {
2006 let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_seed;
2009 /// Commitment seed.
2011 pub extern "C" fn InMemorySigner_set_commitment_seed(this_ptr: &mut InMemorySigner, mut val: crate::c_types::ThirtyTwoBytes) {
2012 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_seed = val.data;
2014 /// Get a string which allows debug introspection of a InMemorySigner object
2015 pub extern "C" fn InMemorySigner_debug_str_void(o: *const c_void) -> Str {
2016 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::InMemorySigner }).into()}
2017 impl Clone for InMemorySigner {
2018 fn clone(&self) -> Self {
2020 inner: if <*mut nativeInMemorySigner>::is_null(self.inner) { core::ptr::null_mut() } else {
2021 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2027 /// Used only if an object of this type is returned as a trait impl by a method
2028 pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void {
2029 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInMemorySigner)).clone() })) as *mut c_void
2032 /// Creates a copy of the InMemorySigner
2033 pub extern "C" fn InMemorySigner_clone(orig: &InMemorySigner) -> InMemorySigner {
2036 /// Creates a new [`InMemorySigner`].
2039 pub extern "C" fn InMemorySigner_new(mut funding_key: crate::c_types::SecretKey, mut revocation_base_key: crate::c_types::SecretKey, mut payment_key: crate::c_types::SecretKey, mut delayed_payment_base_key: crate::c_types::SecretKey, mut htlc_base_key: crate::c_types::SecretKey, mut commitment_seed: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes, mut rand_bytes_unique_start: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::InMemorySigner {
2040 let mut ret = lightning::sign::InMemorySigner::new(secp256k1::global::SECP256K1, funding_key.into_rust(), revocation_base_key.into_rust(), payment_key.into_rust(), delayed_payment_base_key.into_rust(), htlc_base_key.into_rust(), commitment_seed.data, channel_value_satoshis, channel_keys_id.data, rand_bytes_unique_start.data);
2041 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2044 /// Returns the counterparty's pubkeys.
2046 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2047 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2049 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2052 pub extern "C" fn InMemorySigner_counterparty_pubkeys(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
2053 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_pubkeys();
2054 let mut local_ret = crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::chan_utils::ChannelPublicKeys<>) as *mut _ }, is_owned: false };
2058 /// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
2059 /// transactions, i.e., the amount of time that we have to wait to recover our funds if we
2060 /// broadcast a transaction.
2062 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2063 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2066 pub extern "C" fn InMemorySigner_counterparty_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_u16Z {
2067 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_selected_contest_delay();
2068 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u16Z::None } else { crate::c_types::derived::COption_u16Z::Some( { ret.unwrap() }) };
2072 /// Returns the `contest_delay` value specified by us and applied on transactions broadcastable
2073 /// by our counterparty, i.e., the amount of time that they have to wait to recover their funds
2074 /// if they broadcast a transaction.
2076 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2077 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2080 pub extern "C" fn InMemorySigner_holder_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_u16Z {
2081 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.holder_selected_contest_delay();
2082 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u16Z::None } else { crate::c_types::derived::COption_u16Z::Some( { ret.unwrap() }) };
2086 /// Returns whether the holder is the initiator.
2088 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2089 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2092 pub extern "C" fn InMemorySigner_is_outbound(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_boolZ {
2093 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
2094 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_boolZ::None } else { crate::c_types::derived::COption_boolZ::Some( { ret.unwrap() }) };
2098 /// Funding outpoint
2100 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2101 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2103 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2106 pub extern "C" fn InMemorySigner_funding_outpoint(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::chain::transaction::OutPoint {
2107 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
2108 let mut local_ret = crate::lightning::chain::transaction::OutPoint { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::chain::transaction::OutPoint<>) as *mut _ }, is_owned: false };
2112 /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
2113 /// building transactions.
2115 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2116 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2118 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2121 pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
2122 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_channel_parameters();
2123 let mut local_ret = crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _ }, is_owned: false };
2127 /// Returns the channel type features of the channel parameters. Should be helpful for
2128 /// determining a channel's category, i. e. legacy/anchors/taproot/etc.
2130 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2131 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2133 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2136 pub extern "C" fn InMemorySigner_channel_type_features(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::features::ChannelTypeFeatures {
2137 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_type_features();
2138 let mut local_ret = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false };
2142 /// Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
2143 /// by `descriptor`, returning the witness stack for the input.
2145 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
2146 /// is not spending the outpoint described by [`descriptor.outpoint`],
2147 /// or if an output descriptor `script_pubkey` does not match the one we can spend.
2149 /// [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
2152 pub extern "C" fn InMemorySigner_sign_counterparty_payment_input(this_arg: &crate::lightning::sign::InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CResult_WitnessNoneZ {
2153 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_counterparty_payment_input(&spend_tx.into_bitcoin(), input_idx, descriptor.get_native_ref(), secp256k1::global::SECP256K1);
2154 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Witness::from_bitcoin(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2158 /// Sign the single input of `spend_tx` at index `input_idx` which spends the output
2159 /// described by `descriptor`, returning the witness stack for the input.
2161 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
2162 /// is not spending the outpoint described by [`descriptor.outpoint`], does not have a
2163 /// sequence set to [`descriptor.to_self_delay`], or if an output descriptor
2164 /// `script_pubkey` does not match the one we can spend.
2166 /// [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
2167 /// [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
2170 pub extern "C" fn InMemorySigner_sign_dynamic_p2wsh_input(this_arg: &crate::lightning::sign::InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::lightning::sign::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CResult_WitnessNoneZ {
2171 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_dynamic_p2wsh_input(&spend_tx.into_bitcoin(), input_idx, descriptor.get_native_ref(), secp256k1::global::SECP256K1);
2172 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Witness::from_bitcoin(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2176 impl From<nativeInMemorySigner> for crate::lightning::sign::EntropySource {
2177 fn from(obj: nativeInMemorySigner) -> Self {
2178 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2179 let mut ret = InMemorySigner_as_EntropySource(&rust_obj);
2180 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2181 core::mem::forget(rust_obj);
2182 ret.free = Some(InMemorySigner_free_void);
2186 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2187 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2189 pub extern "C" fn InMemorySigner_as_EntropySource(this_arg: &InMemorySigner) -> crate::lightning::sign::EntropySource {
2190 crate::lightning::sign::EntropySource {
2191 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2193 get_secure_random_bytes: InMemorySigner_EntropySource_get_secure_random_bytes,
2198 extern "C" fn InMemorySigner_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2199 let mut ret = <nativeInMemorySigner as lightning::sign::EntropySource>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2200 crate::c_types::ThirtyTwoBytes { data: ret }
2203 impl From<nativeInMemorySigner> for crate::lightning::sign::ChannelSigner {
2204 fn from(obj: nativeInMemorySigner) -> Self {
2205 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2206 let mut ret = InMemorySigner_as_ChannelSigner(&rust_obj);
2207 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2208 core::mem::forget(rust_obj);
2209 ret.free = Some(InMemorySigner_free_void);
2213 /// Constructs a new ChannelSigner which calls the relevant methods on this_arg.
2214 /// This copies the `inner` pointer in this_arg and thus the returned ChannelSigner must be freed before this_arg is
2216 pub extern "C" fn InMemorySigner_as_ChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ChannelSigner {
2217 crate::lightning::sign::ChannelSigner {
2218 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2220 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2221 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2222 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2223 validate_counterparty_revocation: InMemorySigner_ChannelSigner_validate_counterparty_revocation,
2225 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2226 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2227 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2228 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2233 extern "C" fn InMemorySigner_ChannelSigner_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey {
2234 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::get_per_commitment_point(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, secp256k1::global::SECP256K1);
2235 crate::c_types::PublicKey::from_rust(&ret)
2238 extern "C" fn InMemorySigner_ChannelSigner_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
2239 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::release_commitment_secret(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx);
2240 crate::c_types::ThirtyTwoBytes { data: ret }
2243 extern "C" fn InMemorySigner_ChannelSigner_validate_holder_commitment(this_arg: *const c_void, holder_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction, mut outbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_NoneNoneZ {
2244 let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.into_rust().drain(..) { local_outbound_htlc_preimages.push( { ::lightning::ln::types::PaymentPreimage(item.data) }); };
2245 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::validate_holder_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, holder_tx.get_native_ref(), local_outbound_htlc_preimages);
2246 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2250 extern "C" fn InMemorySigner_ChannelSigner_validate_counterparty_revocation(this_arg: *const c_void, mut idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ {
2251 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::validate_counterparty_revocation(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *secret}[..]).unwrap());
2252 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2256 extern "C" fn InMemorySigner_ChannelSigner_pubkeys(this_arg: *const c_void) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
2257 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::pubkeys(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2258 crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::chan_utils::ChannelPublicKeys<>) as *mut _) }, is_owned: false }
2260 extern "C" fn InMemorySigner_ChannelSigner_set_pubkeys(trait_self_arg: &ChannelSigner) {
2261 // This is a bit race-y in the general case, but for our specific use-cases today, we're safe
2262 // Specifically, we must ensure that the first time we're called it can never be in parallel
2263 if unsafe { &*trait_self_arg.pubkeys.get() }.inner.is_null() {
2264 *unsafe { &mut *(&*(trait_self_arg as *const ChannelSigner)).pubkeys.get() } = InMemorySigner_ChannelSigner_pubkeys(trait_self_arg.this_arg).into();
2268 extern "C" fn InMemorySigner_ChannelSigner_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2269 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::channel_keys_id(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2270 crate::c_types::ThirtyTwoBytes { data: ret }
2272 extern "C" fn InMemorySigner_ChannelSigner_provide_channel_parameters(this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
2273 <nativeInMemorySigner as lightning::sign::ChannelSigner>::provide_channel_parameters(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, channel_parameters.get_native_ref())
2276 impl From<nativeInMemorySigner> for crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2277 fn from(obj: nativeInMemorySigner) -> Self {
2278 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2279 let mut ret = InMemorySigner_as_EcdsaChannelSigner(&rust_obj);
2280 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2281 core::mem::forget(rust_obj);
2282 ret.free = Some(InMemorySigner_free_void);
2286 /// Constructs a new EcdsaChannelSigner which calls the relevant methods on this_arg.
2287 /// This copies the `inner` pointer in this_arg and thus the returned EcdsaChannelSigner must be freed before this_arg is
2289 pub extern "C" fn InMemorySigner_as_EcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2290 crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2291 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2293 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
2294 sign_holder_commitment: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment,
2295 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
2296 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
2297 sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
2298 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
2299 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
2300 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
2301 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
2302 ChannelSigner: crate::lightning::sign::ChannelSigner {
2303 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2305 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2306 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2307 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2308 validate_counterparty_revocation: InMemorySigner_ChannelSigner_validate_counterparty_revocation,
2310 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2311 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2312 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2313 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2319 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::CommitmentTransaction, mut inbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ, mut outbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ {
2320 let mut local_inbound_htlc_preimages = Vec::new(); for mut item in inbound_htlc_preimages.into_rust().drain(..) { local_inbound_htlc_preimages.push( { ::lightning::ln::types::PaymentPreimage(item.data) }); };
2321 let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.into_rust().drain(..) { local_outbound_htlc_preimages.push( { ::lightning::ln::types::PaymentPreimage(item.data) }); };
2322 let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_counterparty_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), local_inbound_htlc_preimages, local_outbound_htlc_preimages, secp256k1::global::SECP256K1);
2323 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::ECDSASignature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::ECDSASignature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2327 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_commitment(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2328 let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_holder_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), secp256k1::global::SECP256K1);
2329 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2333 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output(this_arg: *const c_void, mut justice_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_key: *const [u8; 32]) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2334 let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_justice_revoked_output(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &justice_tx.into_bitcoin(), input, amount, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), secp256k1::global::SECP256K1);
2335 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2339 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc(this_arg: *const c_void, mut justice_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2340 let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_justice_revoked_htlc(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &justice_tx.into_bitcoin(), input, amount, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), htlc.get_native_ref(), secp256k1::global::SECP256K1);
2341 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2345 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, htlc_descriptor: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2346 let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_holder_htlc_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &htlc_tx.into_bitcoin(), input, htlc_descriptor.get_native_ref(), secp256k1::global::SECP256K1);
2347 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2351 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: crate::c_types::PublicKey, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2352 let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_counterparty_htlc_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &htlc_tx.into_bitcoin(), input, amount, &per_commitment_point.into_rust(), htlc.get_native_ref(), secp256k1::global::SECP256K1);
2353 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2357 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_closing_transaction(this_arg: *const c_void, closing_tx: &crate::lightning::ln::chan_utils::ClosingTransaction) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2358 let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_closing_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, closing_tx.get_native_ref(), secp256k1::global::SECP256K1);
2359 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2363 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input(this_arg: *const c_void, mut anchor_tx: crate::c_types::Transaction, mut input: usize) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2364 let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_holder_anchor_input(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &anchor_tx.into_bitcoin(), input, secp256k1::global::SECP256K1);
2365 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2369 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2370 let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_channel_announcement_with_funding_key(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, msg.get_native_ref(), secp256k1::global::SECP256K1);
2371 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2375 impl From<nativeInMemorySigner> for crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2376 fn from(obj: nativeInMemorySigner) -> Self {
2377 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2378 let mut ret = InMemorySigner_as_WriteableEcdsaChannelSigner(&rust_obj);
2379 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2380 core::mem::forget(rust_obj);
2381 ret.free = Some(InMemorySigner_free_void);
2385 /// Constructs a new WriteableEcdsaChannelSigner which calls the relevant methods on this_arg.
2386 /// This copies the `inner` pointer in this_arg and thus the returned WriteableEcdsaChannelSigner must be freed before this_arg is
2388 pub extern "C" fn InMemorySigner_as_WriteableEcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2389 crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2390 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2392 EcdsaChannelSigner: crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2393 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2395 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
2396 sign_holder_commitment: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment,
2397 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
2398 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
2399 sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
2400 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
2401 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
2402 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
2403 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
2404 ChannelSigner: crate::lightning::sign::ChannelSigner {
2405 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2407 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2408 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2409 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2410 validate_counterparty_revocation: InMemorySigner_ChannelSigner_validate_counterparty_revocation,
2412 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2413 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2414 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2415 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2418 write: InMemorySigner_write_void,
2419 cloned: Some(WriteableEcdsaChannelSigner_InMemorySigner_cloned),
2423 extern "C" fn WriteableEcdsaChannelSigner_InMemorySigner_cloned(new_obj: &mut crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner) {
2424 new_obj.this_arg = InMemorySigner_clone_void(new_obj.this_arg);
2425 new_obj.free = Some(InMemorySigner_free_void);
2426 new_obj.EcdsaChannelSigner.this_arg = new_obj.this_arg;
2427 new_obj.EcdsaChannelSigner.free = None;
2428 new_obj.EcdsaChannelSigner.ChannelSigner.this_arg = new_obj.this_arg;
2429 new_obj.EcdsaChannelSigner.ChannelSigner.free = None;
2433 /// Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
2434 pub extern "C" fn InMemorySigner_write(obj: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::CVec_u8Z {
2435 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2438 pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2439 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) })
2442 /// Read a InMemorySigner from a byte array, created by InMemorySigner_write
2443 pub extern "C" fn InMemorySigner_read(ser: crate::c_types::u8slice, arg: crate::lightning::sign::EntropySource) -> crate::c_types::derived::CResult_InMemorySignerDecodeErrorZ {
2445 let res: Result<lightning::sign::InMemorySigner, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
2446 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::InMemorySigner { 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() };
2450 use lightning::sign::KeysManager as nativeKeysManagerImport;
2451 pub(crate) type nativeKeysManager = nativeKeysManagerImport;
2453 /// Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a
2454 /// 32-byte seed for use as a BIP 32 extended key and derives keys from that.
2456 /// Your `node_id` is seed/0'.
2457 /// Unilateral closes may use seed/1'.
2458 /// Cooperative closes may use seed/2'.
2459 /// The two close keys may be needed to claim on-chain funds!
2461 /// This struct cannot be used for nodes that wish to support receiving phantom payments;
2462 /// [`PhantomKeysManager`] must be used instead.
2464 /// Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
2465 /// previously issued invoices and attempts to pay previous invoices will fail.
2468 pub struct KeysManager {
2469 /// A pointer to the opaque Rust object.
2471 /// Nearly everywhere, inner must be non-null, however in places where
2472 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2473 pub inner: *mut nativeKeysManager,
2474 /// Indicates that this is the only struct which contains the same pointer.
2476 /// Rust functions which take ownership of an object provided via an argument require
2477 /// this to be true and invalidate the object pointed to by inner.
2481 impl Drop for KeysManager {
2482 fn drop(&mut self) {
2483 if self.is_owned && !<*mut nativeKeysManager>::is_null(self.inner) {
2484 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2488 /// Frees any resources used by the KeysManager, if is_owned is set and inner is non-NULL.
2490 pub extern "C" fn KeysManager_free(this_obj: KeysManager) { }
2492 /// Used only if an object of this type is returned as a trait impl by a method
2493 pub(crate) extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) {
2494 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeKeysManager) };
2498 pub(crate) fn get_native_ref(&self) -> &'static nativeKeysManager {
2499 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2501 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeKeysManager {
2502 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2504 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2505 pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager {
2506 assert!(self.is_owned);
2507 let ret = ObjOps::untweak_ptr(self.inner);
2508 self.inner = core::ptr::null_mut();
2512 /// Constructs a [`KeysManager`] from a 32-byte seed. If the seed is in some way biased (e.g.,
2513 /// your CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
2514 /// `starting_time` isn't strictly required to actually be a time, but it must absolutely,
2515 /// without a doubt, be unique to this instance. ie if you start multiple times with the same
2516 /// `seed`, `starting_time` must be unique to each run. Thus, the easiest way to achieve this
2517 /// is to simply use the current time (with very high precision).
2519 /// The `seed` MUST be backed up safely prior to use so that the keys can be re-created, however,
2520 /// obviously, `starting_time` should be unique every time you reload the library - it is only
2521 /// used to generate new ephemeral key data (which will be stored by the individual channel if
2524 /// Note that the seed is required to recover certain on-chain funds independent of
2525 /// [`ChannelMonitor`] data, though a current copy of [`ChannelMonitor`] data is also required
2526 /// for any channel, and some on-chain during-closing funds.
2528 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
2531 pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32) -> crate::lightning::sign::KeysManager {
2532 let mut ret = lightning::sign::KeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos);
2533 crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2536 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2539 pub extern "C" fn KeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::KeysManager) -> crate::c_types::SecretKey {
2540 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2541 crate::c_types::SecretKey::from_rust(ret)
2544 /// Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
2547 pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &crate::lightning::sign::KeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::lightning::sign::InMemorySigner {
2548 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2549 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2552 /// Signs the given [`PartiallySignedTransaction`] which spends the given [`SpendableOutputDescriptor`]s.
2553 /// The resulting inputs will be finalized and the PSBT will be ready for broadcast if there
2554 /// are no other inputs that need signing.
2556 /// Returns `Err(())` if the PSBT is missing a descriptor or if we fail to sign.
2558 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
2559 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2562 pub extern "C" fn KeysManager_sign_spendable_outputs_psbt(this_arg: &crate::lightning::sign::KeysManager, mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut psbt: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ {
2563 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2564 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_spendable_outputs_psbt(&local_descriptors.iter().collect::<Vec<_>>()[..], ::bitcoin::psbt::PartiallySignedTransaction::deserialize(psbt.as_slice()).expect("Invalid PSBT format"), secp256k1::global::SECP256K1);
2565 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.serialize().into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2569 impl From<nativeKeysManager> for crate::lightning::sign::EntropySource {
2570 fn from(obj: nativeKeysManager) -> Self {
2571 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2572 let mut ret = KeysManager_as_EntropySource(&rust_obj);
2573 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2574 core::mem::forget(rust_obj);
2575 ret.free = Some(KeysManager_free_void);
2579 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2580 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2582 pub extern "C" fn KeysManager_as_EntropySource(this_arg: &KeysManager) -> crate::lightning::sign::EntropySource {
2583 crate::lightning::sign::EntropySource {
2584 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2586 get_secure_random_bytes: KeysManager_EntropySource_get_secure_random_bytes,
2591 extern "C" fn KeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2592 let mut ret = <nativeKeysManager as lightning::sign::EntropySource>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2593 crate::c_types::ThirtyTwoBytes { data: ret }
2596 impl From<nativeKeysManager> for crate::lightning::sign::NodeSigner {
2597 fn from(obj: nativeKeysManager) -> Self {
2598 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2599 let mut ret = KeysManager_as_NodeSigner(&rust_obj);
2600 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2601 core::mem::forget(rust_obj);
2602 ret.free = Some(KeysManager_free_void);
2606 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2607 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2609 pub extern "C" fn KeysManager_as_NodeSigner(this_arg: &KeysManager) -> crate::lightning::sign::NodeSigner {
2610 crate::lightning::sign::NodeSigner {
2611 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2613 get_inbound_payment_key_material: KeysManager_NodeSigner_get_inbound_payment_key_material,
2614 get_node_id: KeysManager_NodeSigner_get_node_id,
2615 ecdh: KeysManager_NodeSigner_ecdh,
2616 sign_invoice: KeysManager_NodeSigner_sign_invoice,
2617 sign_bolt12_invoice_request: KeysManager_NodeSigner_sign_bolt12_invoice_request,
2618 sign_bolt12_invoice: KeysManager_NodeSigner_sign_bolt12_invoice,
2619 sign_gossip_message: KeysManager_NodeSigner_sign_gossip_message,
2624 extern "C" fn KeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2625 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2626 crate::c_types::ThirtyTwoBytes { data: ret.0 }
2629 extern "C" fn KeysManager_NodeSigner_get_node_id(this_arg: *const c_void, mut recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ {
2630 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::get_node_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native());
2631 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2635 extern "C" fn KeysManager_NodeSigner_ecdh(this_arg: *const c_void, mut recipient: crate::lightning::sign::Recipient, mut other_key: crate::c_types::PublicKey, mut tweak: crate::c_types::derived::COption_BigEndianScalarZ) -> crate::c_types::derived::CResult_ThirtyTwoBytesNoneZ {
2636 let mut local_tweak_base = { /*tweak*/ let tweak_opt = tweak; if tweak_opt.is_none() { None } else { Some({ { { tweak_opt.take() }.into_rust() }})} }; let mut local_tweak = local_tweak_base.as_ref();
2637 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::ecdh(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native(), &other_key.into_rust(), local_tweak);
2638 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.secret_bytes() } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2642 extern "C" fn KeysManager_NodeSigner_sign_invoice(this_arg: *const c_void, mut hrp_bytes: crate::c_types::u8slice, mut invoice_data: crate::c_types::derived::CVec_U5Z, mut recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ {
2643 let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2644 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::sign_invoice(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, hrp_bytes.to_slice(), &local_invoice_data[..], recipient.into_native());
2645 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::RecoverableSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2649 extern "C" fn KeysManager_NodeSigner_sign_bolt12_invoice_request(this_arg: *const c_void, invoice_request: &crate::lightning::offers::invoice_request::UnsignedInvoiceRequest) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ {
2650 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::sign_bolt12_invoice_request(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, invoice_request.get_native_ref());
2651 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SchnorrSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2655 extern "C" fn KeysManager_NodeSigner_sign_bolt12_invoice(this_arg: *const c_void, invoice: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ {
2656 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::sign_bolt12_invoice(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, invoice.get_native_ref());
2657 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SchnorrSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2661 extern "C" fn KeysManager_NodeSigner_sign_gossip_message(this_arg: *const c_void, mut msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2662 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, msg.into_native());
2663 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2667 impl From<nativeKeysManager> for crate::lightning::sign::OutputSpender {
2668 fn from(obj: nativeKeysManager) -> Self {
2669 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2670 let mut ret = KeysManager_as_OutputSpender(&rust_obj);
2671 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2672 core::mem::forget(rust_obj);
2673 ret.free = Some(KeysManager_free_void);
2677 /// Constructs a new OutputSpender which calls the relevant methods on this_arg.
2678 /// This copies the `inner` pointer in this_arg and thus the returned OutputSpender must be freed before this_arg is
2680 pub extern "C" fn KeysManager_as_OutputSpender(this_arg: &KeysManager) -> crate::lightning::sign::OutputSpender {
2681 crate::lightning::sign::OutputSpender {
2682 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2684 spend_spendable_outputs: KeysManager_OutputSpender_spend_spendable_outputs,
2689 extern "C" fn KeysManager_OutputSpender_spend_spendable_outputs(this_arg: *const c_void, mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut outputs: crate::c_types::derived::CVec_TxOutZ, mut change_destination_script: crate::c_types::derived::CVec_u8Z, mut feerate_sat_per_1000_weight: u32, mut locktime: crate::c_types::derived::COption_u32Z) -> crate::c_types::derived::CResult_TransactionNoneZ {
2690 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2691 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2692 let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus({ locktime_opt.take() }) }})} };
2693 let mut ret = <nativeKeysManager as lightning::sign::OutputSpender>::spend_spendable_outputs(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, &local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::ScriptBuf::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime, secp256k1::global::SECP256K1);
2694 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() };
2698 impl From<nativeKeysManager> for crate::lightning::sign::SignerProvider {
2699 fn from(obj: nativeKeysManager) -> Self {
2700 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2701 let mut ret = KeysManager_as_SignerProvider(&rust_obj);
2702 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2703 core::mem::forget(rust_obj);
2704 ret.free = Some(KeysManager_free_void);
2708 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2709 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2711 pub extern "C" fn KeysManager_as_SignerProvider(this_arg: &KeysManager) -> crate::lightning::sign::SignerProvider {
2712 crate::lightning::sign::SignerProvider {
2713 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2715 generate_channel_keys_id: KeysManager_SignerProvider_generate_channel_keys_id,
2716 derive_channel_signer: KeysManager_SignerProvider_derive_channel_signer,
2717 read_chan_signer: KeysManager_SignerProvider_read_chan_signer,
2718 get_destination_script: KeysManager_SignerProvider_get_destination_script,
2719 get_shutdown_scriptpubkey: KeysManager_SignerProvider_get_shutdown_scriptpubkey,
2724 extern "C" fn KeysManager_SignerProvider_generate_channel_keys_id(this_arg: *const c_void, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: crate::c_types::U128) -> crate::c_types::ThirtyTwoBytes {
2725 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::generate_channel_keys_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, inbound, channel_value_satoshis, user_channel_id.into());
2726 crate::c_types::ThirtyTwoBytes { data: ret }
2729 extern "C" fn KeysManager_SignerProvider_derive_channel_signer(this_arg: *const c_void, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2730 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::derive_channel_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, channel_value_satoshis, channel_keys_id.data);
2734 extern "C" fn KeysManager_SignerProvider_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ {
2735 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, reader.to_slice());
2736 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { Into::into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2740 extern "C" fn KeysManager_SignerProvider_get_destination_script(this_arg: *const c_void, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ {
2741 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, channel_keys_id.data);
2742 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.to_bytes().into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2746 extern "C" fn KeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2747 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2748 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2753 use lightning::sign::PhantomKeysManager as nativePhantomKeysManagerImport;
2754 pub(crate) type nativePhantomKeysManager = nativePhantomKeysManagerImport;
2756 /// Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
2759 /// A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
2760 /// paid to one of multiple nodes. This works because we encode the invoice route hints such that
2761 /// LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
2762 /// itself without ever needing to forward to this fake node.
2764 /// Phantom node payments are useful for load balancing between multiple LDK nodes. They also
2765 /// provide some fault tolerance, because payers will automatically retry paying other provided
2766 /// nodes in the case that one node goes down.
2768 /// Note that multi-path payments are not supported in phantom invoices for security reasons.
2769 /// Switching between this struct and [`KeysManager`] will invalidate any previously issued
2770 /// invoices and attempts to pay previous invoices will fail.
2773 pub struct PhantomKeysManager {
2774 /// A pointer to the opaque Rust object.
2776 /// Nearly everywhere, inner must be non-null, however in places where
2777 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2778 pub inner: *mut nativePhantomKeysManager,
2779 /// Indicates that this is the only struct which contains the same pointer.
2781 /// Rust functions which take ownership of an object provided via an argument require
2782 /// this to be true and invalidate the object pointed to by inner.
2786 impl Drop for PhantomKeysManager {
2787 fn drop(&mut self) {
2788 if self.is_owned && !<*mut nativePhantomKeysManager>::is_null(self.inner) {
2789 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2793 /// Frees any resources used by the PhantomKeysManager, if is_owned is set and inner is non-NULL.
2795 pub extern "C" fn PhantomKeysManager_free(this_obj: PhantomKeysManager) { }
2797 /// Used only if an object of this type is returned as a trait impl by a method
2798 pub(crate) extern "C" fn PhantomKeysManager_free_void(this_ptr: *mut c_void) {
2799 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomKeysManager) };
2802 impl PhantomKeysManager {
2803 pub(crate) fn get_native_ref(&self) -> &'static nativePhantomKeysManager {
2804 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2806 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomKeysManager {
2807 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2809 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2810 pub(crate) fn take_inner(mut self) -> *mut nativePhantomKeysManager {
2811 assert!(self.is_owned);
2812 let ret = ObjOps::untweak_ptr(self.inner);
2813 self.inner = core::ptr::null_mut();
2817 impl From<nativePhantomKeysManager> for crate::lightning::sign::EntropySource {
2818 fn from(obj: nativePhantomKeysManager) -> Self {
2819 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2820 let mut ret = PhantomKeysManager_as_EntropySource(&rust_obj);
2821 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2822 core::mem::forget(rust_obj);
2823 ret.free = Some(PhantomKeysManager_free_void);
2827 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2828 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2830 pub extern "C" fn PhantomKeysManager_as_EntropySource(this_arg: &PhantomKeysManager) -> crate::lightning::sign::EntropySource {
2831 crate::lightning::sign::EntropySource {
2832 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2834 get_secure_random_bytes: PhantomKeysManager_EntropySource_get_secure_random_bytes,
2839 extern "C" fn PhantomKeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2840 let mut ret = <nativePhantomKeysManager as lightning::sign::EntropySource>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2841 crate::c_types::ThirtyTwoBytes { data: ret }
2844 impl From<nativePhantomKeysManager> for crate::lightning::sign::NodeSigner {
2845 fn from(obj: nativePhantomKeysManager) -> Self {
2846 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2847 let mut ret = PhantomKeysManager_as_NodeSigner(&rust_obj);
2848 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2849 core::mem::forget(rust_obj);
2850 ret.free = Some(PhantomKeysManager_free_void);
2854 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2855 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2857 pub extern "C" fn PhantomKeysManager_as_NodeSigner(this_arg: &PhantomKeysManager) -> crate::lightning::sign::NodeSigner {
2858 crate::lightning::sign::NodeSigner {
2859 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2861 get_inbound_payment_key_material: PhantomKeysManager_NodeSigner_get_inbound_payment_key_material,
2862 get_node_id: PhantomKeysManager_NodeSigner_get_node_id,
2863 ecdh: PhantomKeysManager_NodeSigner_ecdh,
2864 sign_invoice: PhantomKeysManager_NodeSigner_sign_invoice,
2865 sign_bolt12_invoice_request: PhantomKeysManager_NodeSigner_sign_bolt12_invoice_request,
2866 sign_bolt12_invoice: PhantomKeysManager_NodeSigner_sign_bolt12_invoice,
2867 sign_gossip_message: PhantomKeysManager_NodeSigner_sign_gossip_message,
2872 extern "C" fn PhantomKeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2873 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2874 crate::c_types::ThirtyTwoBytes { data: ret.0 }
2877 extern "C" fn PhantomKeysManager_NodeSigner_get_node_id(this_arg: *const c_void, mut recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ {
2878 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::get_node_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native());
2879 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2883 extern "C" fn PhantomKeysManager_NodeSigner_ecdh(this_arg: *const c_void, mut recipient: crate::lightning::sign::Recipient, mut other_key: crate::c_types::PublicKey, mut tweak: crate::c_types::derived::COption_BigEndianScalarZ) -> crate::c_types::derived::CResult_ThirtyTwoBytesNoneZ {
2884 let mut local_tweak_base = { /*tweak*/ let tweak_opt = tweak; if tweak_opt.is_none() { None } else { Some({ { { tweak_opt.take() }.into_rust() }})} }; let mut local_tweak = local_tweak_base.as_ref();
2885 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::ecdh(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native(), &other_key.into_rust(), local_tweak);
2886 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.secret_bytes() } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2890 extern "C" fn PhantomKeysManager_NodeSigner_sign_invoice(this_arg: *const c_void, mut hrp_bytes: crate::c_types::u8slice, mut invoice_data: crate::c_types::derived::CVec_U5Z, mut recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ {
2891 let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2892 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::sign_invoice(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, hrp_bytes.to_slice(), &local_invoice_data[..], recipient.into_native());
2893 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::RecoverableSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2897 extern "C" fn PhantomKeysManager_NodeSigner_sign_bolt12_invoice_request(this_arg: *const c_void, invoice_request: &crate::lightning::offers::invoice_request::UnsignedInvoiceRequest) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ {
2898 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::sign_bolt12_invoice_request(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, invoice_request.get_native_ref());
2899 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SchnorrSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2903 extern "C" fn PhantomKeysManager_NodeSigner_sign_bolt12_invoice(this_arg: *const c_void, invoice: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ {
2904 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::sign_bolt12_invoice(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, invoice.get_native_ref());
2905 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SchnorrSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2909 extern "C" fn PhantomKeysManager_NodeSigner_sign_gossip_message(this_arg: *const c_void, mut msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2910 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, msg.into_native());
2911 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2915 impl From<nativePhantomKeysManager> for crate::lightning::sign::OutputSpender {
2916 fn from(obj: nativePhantomKeysManager) -> Self {
2917 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2918 let mut ret = PhantomKeysManager_as_OutputSpender(&rust_obj);
2919 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2920 core::mem::forget(rust_obj);
2921 ret.free = Some(PhantomKeysManager_free_void);
2925 /// Constructs a new OutputSpender which calls the relevant methods on this_arg.
2926 /// This copies the `inner` pointer in this_arg and thus the returned OutputSpender must be freed before this_arg is
2928 pub extern "C" fn PhantomKeysManager_as_OutputSpender(this_arg: &PhantomKeysManager) -> crate::lightning::sign::OutputSpender {
2929 crate::lightning::sign::OutputSpender {
2930 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2932 spend_spendable_outputs: PhantomKeysManager_OutputSpender_spend_spendable_outputs,
2937 extern "C" fn PhantomKeysManager_OutputSpender_spend_spendable_outputs(this_arg: *const c_void, mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut outputs: crate::c_types::derived::CVec_TxOutZ, mut change_destination_script: crate::c_types::derived::CVec_u8Z, mut feerate_sat_per_1000_weight: u32, mut locktime: crate::c_types::derived::COption_u32Z) -> crate::c_types::derived::CResult_TransactionNoneZ {
2938 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2939 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2940 let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus({ locktime_opt.take() }) }})} };
2941 let mut ret = <nativePhantomKeysManager as lightning::sign::OutputSpender>::spend_spendable_outputs(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, &local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::ScriptBuf::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime, secp256k1::global::SECP256K1);
2942 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() };
2946 impl From<nativePhantomKeysManager> for crate::lightning::sign::SignerProvider {
2947 fn from(obj: nativePhantomKeysManager) -> Self {
2948 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2949 let mut ret = PhantomKeysManager_as_SignerProvider(&rust_obj);
2950 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2951 core::mem::forget(rust_obj);
2952 ret.free = Some(PhantomKeysManager_free_void);
2956 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2957 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2959 pub extern "C" fn PhantomKeysManager_as_SignerProvider(this_arg: &PhantomKeysManager) -> crate::lightning::sign::SignerProvider {
2960 crate::lightning::sign::SignerProvider {
2961 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2963 generate_channel_keys_id: PhantomKeysManager_SignerProvider_generate_channel_keys_id,
2964 derive_channel_signer: PhantomKeysManager_SignerProvider_derive_channel_signer,
2965 read_chan_signer: PhantomKeysManager_SignerProvider_read_chan_signer,
2966 get_destination_script: PhantomKeysManager_SignerProvider_get_destination_script,
2967 get_shutdown_scriptpubkey: PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey,
2972 extern "C" fn PhantomKeysManager_SignerProvider_generate_channel_keys_id(this_arg: *const c_void, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: crate::c_types::U128) -> crate::c_types::ThirtyTwoBytes {
2973 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::generate_channel_keys_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, inbound, channel_value_satoshis, user_channel_id.into());
2974 crate::c_types::ThirtyTwoBytes { data: ret }
2977 extern "C" fn PhantomKeysManager_SignerProvider_derive_channel_signer(this_arg: *const c_void, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2978 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::derive_channel_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, channel_value_satoshis, channel_keys_id.data);
2982 extern "C" fn PhantomKeysManager_SignerProvider_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ {
2983 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, reader.to_slice());
2984 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { Into::into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2988 extern "C" fn PhantomKeysManager_SignerProvider_get_destination_script(this_arg: *const c_void, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ {
2989 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::get_destination_script(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, channel_keys_id.data);
2990 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.to_bytes().into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2994 extern "C" fn PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2995 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2996 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
3000 /// Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
3001 /// that is shared across all nodes that intend to participate in [phantom node payments]
3004 /// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
3005 /// `starting_time_nanos`.
3007 /// `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
3008 /// same across restarts, or else inbound payments may fail.
3010 /// [phantom node payments]: PhantomKeysManager
3013 pub extern "C" fn PhantomKeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32, cross_node_seed: *const [u8; 32]) -> crate::lightning::sign::PhantomKeysManager {
3014 let mut ret = lightning::sign::PhantomKeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos, unsafe { &*cross_node_seed});
3015 crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
3018 /// See [`KeysManager::derive_channel_keys`] for documentation on this method.
3021 pub extern "C" fn PhantomKeysManager_derive_channel_keys(this_arg: &crate::lightning::sign::PhantomKeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::lightning::sign::InMemorySigner {
3022 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
3023 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
3026 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
3029 pub extern "C" fn PhantomKeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
3030 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
3031 crate::c_types::SecretKey::from_rust(ret)
3034 /// Gets the \"node_id\" secret key of the phantom node used to sign invoices, decode the
3035 /// last-hop onion data, etc.
3038 pub extern "C" fn PhantomKeysManager_get_phantom_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
3039 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_node_secret_key();
3040 crate::c_types::SecretKey::from_rust(ret)
3044 use lightning::sign::RandomBytes as nativeRandomBytesImport;
3045 pub(crate) type nativeRandomBytes = nativeRandomBytesImport;
3047 /// An implementation of [`EntropySource`] using ChaCha20.
3050 pub struct RandomBytes {
3051 /// A pointer to the opaque Rust object.
3053 /// Nearly everywhere, inner must be non-null, however in places where
3054 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
3055 pub inner: *mut nativeRandomBytes,
3056 /// Indicates that this is the only struct which contains the same pointer.
3058 /// Rust functions which take ownership of an object provided via an argument require
3059 /// this to be true and invalidate the object pointed to by inner.
3063 impl Drop for RandomBytes {
3064 fn drop(&mut self) {
3065 if self.is_owned && !<*mut nativeRandomBytes>::is_null(self.inner) {
3066 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
3070 /// Frees any resources used by the RandomBytes, if is_owned is set and inner is non-NULL.
3072 pub extern "C" fn RandomBytes_free(this_obj: RandomBytes) { }
3074 /// Used only if an object of this type is returned as a trait impl by a method
3075 pub(crate) extern "C" fn RandomBytes_free_void(this_ptr: *mut c_void) {
3076 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRandomBytes) };
3080 pub(crate) fn get_native_ref(&self) -> &'static nativeRandomBytes {
3081 unsafe { &*ObjOps::untweak_ptr(self.inner) }
3083 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRandomBytes {
3084 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
3086 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
3087 pub(crate) fn take_inner(mut self) -> *mut nativeRandomBytes {
3088 assert!(self.is_owned);
3089 let ret = ObjOps::untweak_ptr(self.inner);
3090 self.inner = core::ptr::null_mut();
3094 /// Get a string which allows debug introspection of a RandomBytes object
3095 pub extern "C" fn RandomBytes_debug_str_void(o: *const c_void) -> Str {
3096 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::RandomBytes }).into()}
3097 /// Creates a new instance using the given seed.
3100 pub extern "C" fn RandomBytes_new(mut seed: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::RandomBytes {
3101 let mut ret = lightning::sign::RandomBytes::new(seed.data);
3102 crate::lightning::sign::RandomBytes { inner: ObjOps::heap_alloc(ret), is_owned: true }
3105 impl From<nativeRandomBytes> for crate::lightning::sign::EntropySource {
3106 fn from(obj: nativeRandomBytes) -> Self {
3107 let rust_obj = crate::lightning::sign::RandomBytes { inner: ObjOps::heap_alloc(obj), is_owned: true };
3108 let mut ret = RandomBytes_as_EntropySource(&rust_obj);
3109 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
3110 core::mem::forget(rust_obj);
3111 ret.free = Some(RandomBytes_free_void);
3115 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
3116 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
3118 pub extern "C" fn RandomBytes_as_EntropySource(this_arg: &RandomBytes) -> crate::lightning::sign::EntropySource {
3119 crate::lightning::sign::EntropySource {
3120 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
3122 get_secure_random_bytes: RandomBytes_EntropySource_get_secure_random_bytes,
3127 extern "C" fn RandomBytes_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
3128 let mut ret = <nativeRandomBytes as lightning::sign::EntropySource>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeRandomBytes) }, );
3129 crate::c_types::ThirtyTwoBytes { data: ret }