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 /// Constructs a new DelayedPaymentOutputDescriptor given each field
175 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) -> DelayedPaymentOutputDescriptor {
176 DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeDelayedPaymentOutputDescriptor {
177 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
178 per_commitment_point: per_commitment_point_arg.into_rust(),
179 to_self_delay: to_self_delay_arg,
180 output: output_arg.into_rust(),
181 revocation_pubkey: *unsafe { Box::from_raw(revocation_pubkey_arg.take_inner()) },
182 channel_keys_id: channel_keys_id_arg.data,
183 channel_value_satoshis: channel_value_satoshis_arg,
186 impl Clone for DelayedPaymentOutputDescriptor {
187 fn clone(&self) -> Self {
189 inner: if <*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
190 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
196 /// Used only if an object of this type is returned as a trait impl by a method
197 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
198 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void
201 /// Creates a copy of the DelayedPaymentOutputDescriptor
202 pub extern "C" fn DelayedPaymentOutputDescriptor_clone(orig: &DelayedPaymentOutputDescriptor) -> DelayedPaymentOutputDescriptor {
205 /// Get a string which allows debug introspection of a DelayedPaymentOutputDescriptor object
206 pub extern "C" fn DelayedPaymentOutputDescriptor_debug_str_void(o: *const c_void) -> Str {
207 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::DelayedPaymentOutputDescriptor }).into()}
208 /// Generates a non-cryptographic 64-bit hash of the DelayedPaymentOutputDescriptor.
210 pub extern "C" fn DelayedPaymentOutputDescriptor_hash(o: &DelayedPaymentOutputDescriptor) -> u64 {
211 if o.inner.is_null() { return 0; }
212 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
214 let mut hasher = core::hash::SipHasher::new();
215 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
216 core::hash::Hasher::finish(&hasher)
218 /// Checks if two DelayedPaymentOutputDescriptors contain equal inner contents.
219 /// This ignores pointers and is_owned flags and looks at the values in fields.
220 /// Two objects with NULL inner values will be considered "equal" here.
222 pub extern "C" fn DelayedPaymentOutputDescriptor_eq(a: &DelayedPaymentOutputDescriptor, b: &DelayedPaymentOutputDescriptor) -> bool {
223 if a.inner == b.inner { return true; }
224 if a.inner.is_null() || b.inner.is_null() { return false; }
225 if a.get_native_ref() == b.get_native_ref() { true } else { false }
228 /// Serialize the DelayedPaymentOutputDescriptor object into a byte array which can be read by DelayedPaymentOutputDescriptor_read
229 pub extern "C" fn DelayedPaymentOutputDescriptor_write(obj: &crate::lightning::sign::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
230 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
233 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
234 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentOutputDescriptor) })
237 /// Read a DelayedPaymentOutputDescriptor from a byte array, created by DelayedPaymentOutputDescriptor_write
238 pub extern "C" fn DelayedPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentOutputDescriptorDecodeErrorZ {
239 let res: Result<lightning::sign::DelayedPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
240 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() };
244 use lightning::sign::StaticPaymentOutputDescriptor as nativeStaticPaymentOutputDescriptorImport;
245 pub(crate) type nativeStaticPaymentOutputDescriptor = nativeStaticPaymentOutputDescriptorImport;
247 /// Information about a spendable output to our \"payment key\".
249 /// See [`SpendableOutputDescriptor::StaticPaymentOutput`] for more details on how to spend this.
252 pub struct StaticPaymentOutputDescriptor {
253 /// A pointer to the opaque Rust object.
255 /// Nearly everywhere, inner must be non-null, however in places where
256 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
257 pub inner: *mut nativeStaticPaymentOutputDescriptor,
258 /// Indicates that this is the only struct which contains the same pointer.
260 /// Rust functions which take ownership of an object provided via an argument require
261 /// this to be true and invalidate the object pointed to by inner.
265 impl Drop for StaticPaymentOutputDescriptor {
267 if self.is_owned && !<*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) {
268 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
272 /// Frees any resources used by the StaticPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
274 pub extern "C" fn StaticPaymentOutputDescriptor_free(this_obj: StaticPaymentOutputDescriptor) { }
276 /// Used only if an object of this type is returned as a trait impl by a method
277 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
278 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeStaticPaymentOutputDescriptor) };
281 impl StaticPaymentOutputDescriptor {
282 pub(crate) fn get_native_ref(&self) -> &'static nativeStaticPaymentOutputDescriptor {
283 unsafe { &*ObjOps::untweak_ptr(self.inner) }
285 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeStaticPaymentOutputDescriptor {
286 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
288 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
289 pub(crate) fn take_inner(mut self) -> *mut nativeStaticPaymentOutputDescriptor {
290 assert!(self.is_owned);
291 let ret = ObjOps::untweak_ptr(self.inner);
292 self.inner = core::ptr::null_mut();
296 /// The outpoint which is spendable.
298 pub extern "C" fn StaticPaymentOutputDescriptor_get_outpoint(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
299 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
300 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 }
302 /// The outpoint which is spendable.
304 pub extern "C" fn StaticPaymentOutputDescriptor_set_outpoint(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
305 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
307 /// The output which is referenced by the given outpoint.
309 pub extern "C" fn StaticPaymentOutputDescriptor_get_output(this_ptr: &StaticPaymentOutputDescriptor) -> crate::c_types::TxOut {
310 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
311 crate::c_types::TxOut::from_rust(inner_val)
313 /// The output which is referenced by the given outpoint.
315 pub extern "C" fn StaticPaymentOutputDescriptor_set_output(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
316 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
318 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
319 /// This may be useful in re-deriving keys used in the channel to spend the output.
321 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &StaticPaymentOutputDescriptor) -> *const [u8; 32] {
322 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
325 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
326 /// This may be useful in re-deriving keys used in the channel to spend the output.
328 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
329 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
331 /// The value of the channel which this transactions spends.
333 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &StaticPaymentOutputDescriptor) -> u64 {
334 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
337 /// The value of the channel which this transactions spends.
339 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: u64) {
340 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
342 /// The necessary channel parameters that need to be provided to the re-derived signer through
343 /// [`ChannelSigner::provide_channel_parameters`].
345 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
347 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
349 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_transaction_parameters(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
350 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_transaction_parameters;
351 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 };
354 /// The necessary channel parameters that need to be provided to the re-derived signer through
355 /// [`ChannelSigner::provide_channel_parameters`].
357 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
359 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
361 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_transaction_parameters(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
362 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
363 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_transaction_parameters = local_val;
365 /// Constructs a new StaticPaymentOutputDescriptor given each field
367 /// Note that channel_transaction_parameters_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
370 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 {
371 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()) } }) };
372 StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeStaticPaymentOutputDescriptor {
373 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
374 output: output_arg.into_rust(),
375 channel_keys_id: channel_keys_id_arg.data,
376 channel_value_satoshis: channel_value_satoshis_arg,
377 channel_transaction_parameters: local_channel_transaction_parameters_arg,
380 impl Clone for StaticPaymentOutputDescriptor {
381 fn clone(&self) -> Self {
383 inner: if <*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
384 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
390 /// Used only if an object of this type is returned as a trait impl by a method
391 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
392 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void
395 /// Creates a copy of the StaticPaymentOutputDescriptor
396 pub extern "C" fn StaticPaymentOutputDescriptor_clone(orig: &StaticPaymentOutputDescriptor) -> StaticPaymentOutputDescriptor {
399 /// Get a string which allows debug introspection of a StaticPaymentOutputDescriptor object
400 pub extern "C" fn StaticPaymentOutputDescriptor_debug_str_void(o: *const c_void) -> Str {
401 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::StaticPaymentOutputDescriptor }).into()}
402 /// Generates a non-cryptographic 64-bit hash of the StaticPaymentOutputDescriptor.
404 pub extern "C" fn StaticPaymentOutputDescriptor_hash(o: &StaticPaymentOutputDescriptor) -> u64 {
405 if o.inner.is_null() { return 0; }
406 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
408 let mut hasher = core::hash::SipHasher::new();
409 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
410 core::hash::Hasher::finish(&hasher)
412 /// Checks if two StaticPaymentOutputDescriptors contain equal inner contents.
413 /// This ignores pointers and is_owned flags and looks at the values in fields.
414 /// Two objects with NULL inner values will be considered "equal" here.
416 pub extern "C" fn StaticPaymentOutputDescriptor_eq(a: &StaticPaymentOutputDescriptor, b: &StaticPaymentOutputDescriptor) -> bool {
417 if a.inner == b.inner { return true; }
418 if a.inner.is_null() || b.inner.is_null() { return false; }
419 if a.get_native_ref() == b.get_native_ref() { true } else { false }
421 /// Returns the `witness_script` of the spendable output.
423 /// Note that this will only return `Some` for [`StaticPaymentOutputDescriptor`]s that
424 /// originated from an anchor outputs channel, as they take the form of a P2WSH script.
427 pub extern "C" fn StaticPaymentOutputDescriptor_witness_script(this_arg: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::COption_CVec_u8ZZ {
428 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script();
429 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() }) };
433 /// The maximum length a well-formed witness spending one of these should have.
434 /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
438 pub extern "C" fn StaticPaymentOutputDescriptor_max_witness_length(this_arg: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> u64 {
439 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.max_witness_length();
444 /// Serialize the StaticPaymentOutputDescriptor object into a byte array which can be read by StaticPaymentOutputDescriptor_read
445 pub extern "C" fn StaticPaymentOutputDescriptor_write(obj: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
446 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
449 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
450 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeStaticPaymentOutputDescriptor) })
453 /// Read a StaticPaymentOutputDescriptor from a byte array, created by StaticPaymentOutputDescriptor_write
454 pub extern "C" fn StaticPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_StaticPaymentOutputDescriptorDecodeErrorZ {
455 let res: Result<lightning::sign::StaticPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
456 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() };
459 /// Describes the necessary information to spend a spendable output.
461 /// When on-chain outputs are created by LDK (which our counterparty is not able to claim at any
462 /// point in the future) a [`SpendableOutputs`] event is generated which you must track and be able
463 /// to spend on-chain. The information needed to do this is provided in this enum, including the
464 /// outpoint describing which `txid` and output `index` is available, the full output which exists
465 /// at that `txid`/`index`, and any keys or other information required to sign.
467 /// [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
471 pub enum SpendableOutputDescriptor {
472 /// An output to a script which was provided via [`SignerProvider`] directly, either from
473 /// [`get_destination_script`] or [`get_shutdown_scriptpubkey`], thus you should already
474 /// know how to spend it. No secret keys are provided as LDK was never given any key.
475 /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
476 /// on-chain using the payment preimage or after it has timed out.
478 /// [`get_shutdown_scriptpubkey`]: SignerProvider::get_shutdown_scriptpubkey
479 /// [`get_destination_script`]: SignerProvider::get_shutdown_scriptpubkey
481 /// The outpoint which is spendable.
482 outpoint: crate::lightning::chain::transaction::OutPoint,
483 /// The output which is referenced by the given outpoint.
484 output: crate::c_types::TxOut,
485 /// The `channel_keys_id` for the channel which this output came from.
487 /// For channels which were generated on LDK 0.0.119 or later, this is the value which was
488 /// passed to the [`SignerProvider::get_destination_script`] call which provided this
491 /// For channels which were generated prior to LDK 0.0.119, no such argument existed,
492 /// however this field may still be filled in if such data is available.
494 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
495 channel_keys_id: crate::c_types::ThirtyTwoBytes,
497 /// An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
500 /// The witness in the spending input should be:
502 /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
505 /// Note that the `nSequence` field in the spending input must be set to
506 /// [`DelayedPaymentOutputDescriptor::to_self_delay`] (which means the transaction is not
507 /// broadcastable until at least [`DelayedPaymentOutputDescriptor::to_self_delay`] blocks after
508 /// the outpoint confirms, see [BIP
509 /// 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)). Also note that LDK
510 /// won't generate a [`SpendableOutputDescriptor`] until the corresponding block height
513 /// These are generally the result of a \"revocable\" output to us, spendable only by us unless
514 /// it is an output from an old state which we broadcast (which should never happen).
516 /// To derive the delayed payment key which is used to sign this input, you must pass the
517 /// holder [`InMemorySigner::delayed_payment_base_key`] (i.e., the private key which corresponds to the
518 /// [`ChannelPublicKeys::delayed_payment_basepoint`] in [`ChannelSigner::pubkeys`]) and the provided
519 /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to [`chan_utils::derive_private_key`]. The DelayedPaymentKey can be
520 /// generated without the secret key using [`DelayedPaymentKey::from_basepoint`] and only the
521 /// [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`ChannelSigner::pubkeys`].
523 /// To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
524 /// used in the witness script generation), you must pass the counterparty
525 /// [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
526 /// [`ChannelSigner::provide_channel_parameters`]) and the provided
527 /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
528 /// [`RevocationKey`].
530 /// The witness script which is hashed and included in the output `script_pubkey` may be
531 /// regenerated by passing the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] (derived
532 /// as explained above), our delayed payment pubkey (derived as explained above), and the
533 /// [`DelayedPaymentOutputDescriptor::to_self_delay`] contained here to
534 /// [`chan_utils::get_revokeable_redeemscript`].
535 DelayedPaymentOutput(
536 crate::lightning::sign::DelayedPaymentOutputDescriptor),
537 /// An output spendable exclusively by our payment key (i.e., the private key that corresponds
538 /// to the `payment_point` in [`ChannelSigner::pubkeys`]). The output type depends on the
539 /// channel type negotiated.
541 /// On an anchor outputs channel, the witness in the spending input is:
543 /// <BIP 143 signature> <witness script>
546 /// Otherwise, it is:
548 /// <BIP 143 signature> <payment key>
551 /// These are generally the result of our counterparty having broadcast the current state,
552 /// allowing us to claim the non-HTLC-encumbered outputs immediately, or after one confirmation
553 /// in the case of anchor outputs channels.
555 crate::lightning::sign::StaticPaymentOutputDescriptor),
557 use lightning::sign::SpendableOutputDescriptor as SpendableOutputDescriptorImport;
558 pub(crate) type nativeSpendableOutputDescriptor = SpendableOutputDescriptorImport;
560 impl SpendableOutputDescriptor {
562 pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor {
564 SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, ref channel_keys_id, } => {
565 let mut outpoint_nonref = Clone::clone(outpoint);
566 let mut output_nonref = Clone::clone(output);
567 let mut channel_keys_id_nonref = Clone::clone(channel_keys_id);
568 let mut local_channel_keys_id_nonref = if channel_keys_id_nonref.data == [0; 32] { None } else { Some( { channel_keys_id_nonref.data }) };
569 nativeSpendableOutputDescriptor::StaticOutput {
570 outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
571 output: output_nonref.into_rust(),
572 channel_keys_id: local_channel_keys_id_nonref,
575 SpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
576 let mut a_nonref = Clone::clone(a);
577 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
578 *unsafe { Box::from_raw(a_nonref.take_inner()) },
581 SpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
582 let mut a_nonref = Clone::clone(a);
583 nativeSpendableOutputDescriptor::StaticPaymentOutput (
584 *unsafe { Box::from_raw(a_nonref.take_inner()) },
590 pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor {
592 SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, mut channel_keys_id, } => {
593 let mut local_channel_keys_id = if channel_keys_id.data == [0; 32] { None } else { Some( { channel_keys_id.data }) };
594 nativeSpendableOutputDescriptor::StaticOutput {
595 outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
596 output: output.into_rust(),
597 channel_keys_id: local_channel_keys_id,
600 SpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
601 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
602 *unsafe { Box::from_raw(a.take_inner()) },
605 SpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
606 nativeSpendableOutputDescriptor::StaticPaymentOutput (
607 *unsafe { Box::from_raw(a.take_inner()) },
613 pub(crate) fn from_native(native: &SpendableOutputDescriptorImport) -> Self {
614 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSpendableOutputDescriptor) };
616 nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, ref channel_keys_id, } => {
617 let mut outpoint_nonref = Clone::clone(outpoint);
618 let mut output_nonref = Clone::clone(output);
619 let mut channel_keys_id_nonref = Clone::clone(channel_keys_id);
620 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()) } } };
621 SpendableOutputDescriptor::StaticOutput {
622 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true },
623 output: crate::c_types::TxOut::from_rust(&output_nonref),
624 channel_keys_id: local_channel_keys_id_nonref,
627 nativeSpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
628 let mut a_nonref = Clone::clone(a);
629 SpendableOutputDescriptor::DelayedPaymentOutput (
630 crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
633 nativeSpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
634 let mut a_nonref = Clone::clone(a);
635 SpendableOutputDescriptor::StaticPaymentOutput (
636 crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
642 pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self {
644 nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, mut channel_keys_id, } => {
645 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()) } } };
646 SpendableOutputDescriptor::StaticOutput {
647 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true },
648 output: crate::c_types::TxOut::from_rust(&output),
649 channel_keys_id: local_channel_keys_id,
652 nativeSpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
653 SpendableOutputDescriptor::DelayedPaymentOutput (
654 crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
657 nativeSpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
658 SpendableOutputDescriptor::StaticPaymentOutput (
659 crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
665 /// Frees any resources used by the SpendableOutputDescriptor
667 pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { }
668 /// Creates a copy of the SpendableOutputDescriptor
670 pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor {
674 /// Used only if an object of this type is returned as a trait impl by a method
675 pub(crate) extern "C" fn SpendableOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
676 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SpendableOutputDescriptor)).clone() })) as *mut c_void
679 /// Used only if an object of this type is returned as a trait impl by a method
680 pub(crate) extern "C" fn SpendableOutputDescriptor_free_void(this_ptr: *mut c_void) {
681 let _ = unsafe { Box::from_raw(this_ptr as *mut SpendableOutputDescriptor) };
684 /// Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
685 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 {
686 SpendableOutputDescriptor::StaticOutput {
693 /// Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
694 pub extern "C" fn SpendableOutputDescriptor_delayed_payment_output(a: crate::lightning::sign::DelayedPaymentOutputDescriptor) -> SpendableOutputDescriptor {
695 SpendableOutputDescriptor::DelayedPaymentOutput(a, )
698 /// Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
699 pub extern "C" fn SpendableOutputDescriptor_static_payment_output(a: crate::lightning::sign::StaticPaymentOutputDescriptor) -> SpendableOutputDescriptor {
700 SpendableOutputDescriptor::StaticPaymentOutput(a, )
702 /// Get a string which allows debug introspection of a SpendableOutputDescriptor object
703 pub extern "C" fn SpendableOutputDescriptor_debug_str_void(o: *const c_void) -> Str {
704 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::SpendableOutputDescriptor }).into()}
705 /// Generates a non-cryptographic 64-bit hash of the SpendableOutputDescriptor.
707 pub extern "C" fn SpendableOutputDescriptor_hash(o: &SpendableOutputDescriptor) -> u64 {
708 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
710 let mut hasher = core::hash::SipHasher::new();
711 core::hash::Hash::hash(&o.to_native(), &mut hasher);
712 core::hash::Hasher::finish(&hasher)
714 /// Checks if two SpendableOutputDescriptors contain equal inner contents.
715 /// This ignores pointers and is_owned flags and looks at the values in fields.
717 pub extern "C" fn SpendableOutputDescriptor_eq(a: &SpendableOutputDescriptor, b: &SpendableOutputDescriptor) -> bool {
718 if &a.to_native() == &b.to_native() { true } else { false }
721 /// Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
722 pub extern "C" fn SpendableOutputDescriptor_write(obj: &crate::lightning::sign::SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
723 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
726 pub(crate) extern "C" fn SpendableOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
727 SpendableOutputDescriptor_write(unsafe { &*(obj as *const SpendableOutputDescriptor) })
730 /// Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
731 pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
732 let res: Result<lightning::sign::SpendableOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
733 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() };
736 /// Creates an unsigned [`PartiallySignedTransaction`] which spends the given descriptors to
737 /// the given outputs, plus an output to the given change destination (if sufficient
738 /// change value remains). The PSBT will have a feerate, at least, of the given value.
740 /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
741 /// transaction will have a locktime of 0. It it recommended to set this to the current block
742 /// height to avoid fee sniping, unless you have some specific reason to use a different
745 /// Returns the PSBT and expected max transaction weight.
747 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
748 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
749 /// does not match the one we can spend.
751 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
754 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 {
755 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
756 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
757 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() }) }})} };
758 let mut ret = lightning::sign::SpendableOutputDescriptor::create_spendable_outputs_psbt(&local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::ScriptBuf::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime);
759 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() };
764 use lightning::sign::ChannelDerivationParameters as nativeChannelDerivationParametersImport;
765 pub(crate) type nativeChannelDerivationParameters = nativeChannelDerivationParametersImport;
767 /// The parameters required to derive a channel signer via [`SignerProvider`].
770 pub struct ChannelDerivationParameters {
771 /// A pointer to the opaque Rust object.
773 /// Nearly everywhere, inner must be non-null, however in places where
774 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
775 pub inner: *mut nativeChannelDerivationParameters,
776 /// Indicates that this is the only struct which contains the same pointer.
778 /// Rust functions which take ownership of an object provided via an argument require
779 /// this to be true and invalidate the object pointed to by inner.
783 impl Drop for ChannelDerivationParameters {
785 if self.is_owned && !<*mut nativeChannelDerivationParameters>::is_null(self.inner) {
786 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
790 /// Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL.
792 pub extern "C" fn ChannelDerivationParameters_free(this_obj: ChannelDerivationParameters) { }
794 /// Used only if an object of this type is returned as a trait impl by a method
795 pub(crate) extern "C" fn ChannelDerivationParameters_free_void(this_ptr: *mut c_void) {
796 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDerivationParameters) };
799 impl ChannelDerivationParameters {
800 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDerivationParameters {
801 unsafe { &*ObjOps::untweak_ptr(self.inner) }
803 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDerivationParameters {
804 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
806 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
807 pub(crate) fn take_inner(mut self) -> *mut nativeChannelDerivationParameters {
808 assert!(self.is_owned);
809 let ret = ObjOps::untweak_ptr(self.inner);
810 self.inner = core::ptr::null_mut();
814 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
816 pub extern "C" fn ChannelDerivationParameters_get_value_satoshis(this_ptr: &ChannelDerivationParameters) -> u64 {
817 let mut inner_val = &mut this_ptr.get_native_mut_ref().value_satoshis;
820 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
822 pub extern "C" fn ChannelDerivationParameters_set_value_satoshis(this_ptr: &mut ChannelDerivationParameters, mut val: u64) {
823 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.value_satoshis = val;
825 /// The unique identifier to re-derive the signer for the associated channel.
827 pub extern "C" fn ChannelDerivationParameters_get_keys_id(this_ptr: &ChannelDerivationParameters) -> *const [u8; 32] {
828 let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_id;
831 /// The unique identifier to re-derive the signer for the associated channel.
833 pub extern "C" fn ChannelDerivationParameters_set_keys_id(this_ptr: &mut ChannelDerivationParameters, mut val: crate::c_types::ThirtyTwoBytes) {
834 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_id = val.data;
836 /// The necessary channel parameters that need to be provided to the re-derived signer through
837 /// [`ChannelSigner::provide_channel_parameters`].
839 pub extern "C" fn ChannelDerivationParameters_get_transaction_parameters(this_ptr: &ChannelDerivationParameters) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
840 let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_parameters;
841 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 }
843 /// The necessary channel parameters that need to be provided to the re-derived signer through
844 /// [`ChannelSigner::provide_channel_parameters`].
846 pub extern "C" fn ChannelDerivationParameters_set_transaction_parameters(this_ptr: &mut ChannelDerivationParameters, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
847 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_parameters = *unsafe { Box::from_raw(val.take_inner()) };
849 /// Constructs a new ChannelDerivationParameters given each field
852 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 {
853 ChannelDerivationParameters { inner: ObjOps::heap_alloc(nativeChannelDerivationParameters {
854 value_satoshis: value_satoshis_arg,
855 keys_id: keys_id_arg.data,
856 transaction_parameters: *unsafe { Box::from_raw(transaction_parameters_arg.take_inner()) },
859 impl Clone for ChannelDerivationParameters {
860 fn clone(&self) -> Self {
862 inner: if <*mut nativeChannelDerivationParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
863 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
869 /// Used only if an object of this type is returned as a trait impl by a method
870 pub(crate) extern "C" fn ChannelDerivationParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
871 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelDerivationParameters)).clone() })) as *mut c_void
874 /// Creates a copy of the ChannelDerivationParameters
875 pub extern "C" fn ChannelDerivationParameters_clone(orig: &ChannelDerivationParameters) -> ChannelDerivationParameters {
878 /// Get a string which allows debug introspection of a ChannelDerivationParameters object
879 pub extern "C" fn ChannelDerivationParameters_debug_str_void(o: *const c_void) -> Str {
880 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::ChannelDerivationParameters }).into()}
881 /// Checks if two ChannelDerivationParameterss contain equal inner contents.
882 /// This ignores pointers and is_owned flags and looks at the values in fields.
883 /// Two objects with NULL inner values will be considered "equal" here.
885 pub extern "C" fn ChannelDerivationParameters_eq(a: &ChannelDerivationParameters, b: &ChannelDerivationParameters) -> bool {
886 if a.inner == b.inner { return true; }
887 if a.inner.is_null() || b.inner.is_null() { return false; }
888 if a.get_native_ref() == b.get_native_ref() { true } else { false }
891 /// Serialize the ChannelDerivationParameters object into a byte array which can be read by ChannelDerivationParameters_read
892 pub extern "C" fn ChannelDerivationParameters_write(obj: &crate::lightning::sign::ChannelDerivationParameters) -> crate::c_types::derived::CVec_u8Z {
893 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
896 pub(crate) extern "C" fn ChannelDerivationParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
897 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDerivationParameters) })
900 /// Read a ChannelDerivationParameters from a byte array, created by ChannelDerivationParameters_write
901 pub extern "C" fn ChannelDerivationParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDerivationParametersDecodeErrorZ {
902 let res: Result<lightning::sign::ChannelDerivationParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
903 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() };
907 use lightning::sign::HTLCDescriptor as nativeHTLCDescriptorImport;
908 pub(crate) type nativeHTLCDescriptor = nativeHTLCDescriptorImport;
910 /// A descriptor used to sign for a commitment transaction's HTLC output.
913 pub struct HTLCDescriptor {
914 /// A pointer to the opaque Rust object.
916 /// Nearly everywhere, inner must be non-null, however in places where
917 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
918 pub inner: *mut nativeHTLCDescriptor,
919 /// Indicates that this is the only struct which contains the same pointer.
921 /// Rust functions which take ownership of an object provided via an argument require
922 /// this to be true and invalidate the object pointed to by inner.
926 impl Drop for HTLCDescriptor {
928 if self.is_owned && !<*mut nativeHTLCDescriptor>::is_null(self.inner) {
929 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
933 /// Frees any resources used by the HTLCDescriptor, if is_owned is set and inner is non-NULL.
935 pub extern "C" fn HTLCDescriptor_free(this_obj: HTLCDescriptor) { }
937 /// Used only if an object of this type is returned as a trait impl by a method
938 pub(crate) extern "C" fn HTLCDescriptor_free_void(this_ptr: *mut c_void) {
939 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCDescriptor) };
942 impl HTLCDescriptor {
943 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCDescriptor {
944 unsafe { &*ObjOps::untweak_ptr(self.inner) }
946 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCDescriptor {
947 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
949 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
950 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCDescriptor {
951 assert!(self.is_owned);
952 let ret = ObjOps::untweak_ptr(self.inner);
953 self.inner = core::ptr::null_mut();
957 /// The parameters required to derive the signer for the HTLC input.
959 pub extern "C" fn HTLCDescriptor_get_channel_derivation_parameters(this_ptr: &HTLCDescriptor) -> crate::lightning::sign::ChannelDerivationParameters {
960 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters;
961 crate::lightning::sign::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::sign::ChannelDerivationParameters<>) as *mut _) }, is_owned: false }
963 /// The parameters required to derive the signer for the HTLC input.
965 pub extern "C" fn HTLCDescriptor_set_channel_derivation_parameters(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::sign::ChannelDerivationParameters) {
966 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) };
968 /// The number of the commitment transaction in which the HTLC output lives.
970 pub extern "C" fn HTLCDescriptor_get_per_commitment_number(this_ptr: &HTLCDescriptor) -> u64 {
971 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_number;
974 /// The number of the commitment transaction in which the HTLC output lives.
976 pub extern "C" fn HTLCDescriptor_set_per_commitment_number(this_ptr: &mut HTLCDescriptor, mut val: u64) {
977 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_number = val;
979 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
980 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
981 /// arrive at unique keys per commitment.
983 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
985 pub extern "C" fn HTLCDescriptor_get_per_commitment_point(this_ptr: &HTLCDescriptor) -> crate::c_types::PublicKey {
986 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
987 crate::c_types::PublicKey::from_rust(&inner_val)
989 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
990 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
991 /// arrive at unique keys per commitment.
993 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
995 pub extern "C" fn HTLCDescriptor_set_per_commitment_point(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::PublicKey) {
996 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
998 /// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
999 /// originating from a channel supporting anchor outputs, otherwise it is the channel's
1000 /// negotiated feerate at the time the commitment transaction was built.
1002 pub extern "C" fn HTLCDescriptor_get_feerate_per_kw(this_ptr: &HTLCDescriptor) -> u32 {
1003 let mut inner_val = &mut this_ptr.get_native_mut_ref().feerate_per_kw;
1006 /// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
1007 /// originating from a channel supporting anchor outputs, otherwise it is the channel's
1008 /// negotiated feerate at the time the commitment transaction was built.
1010 pub extern "C" fn HTLCDescriptor_set_feerate_per_kw(this_ptr: &mut HTLCDescriptor, mut val: u32) {
1011 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.feerate_per_kw = val;
1013 /// The details of the HTLC as it appears in the commitment transaction.
1015 pub extern "C" fn HTLCDescriptor_get_htlc(this_ptr: &HTLCDescriptor) -> crate::lightning::ln::chan_utils::HTLCOutputInCommitment {
1016 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc;
1017 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 }
1019 /// The details of the HTLC as it appears in the commitment transaction.
1021 pub extern "C" fn HTLCDescriptor_set_htlc(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::ln::chan_utils::HTLCOutputInCommitment) {
1022 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc = *unsafe { Box::from_raw(val.take_inner()) };
1024 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
1027 pub extern "C" fn HTLCDescriptor_get_preimage(this_ptr: &HTLCDescriptor) -> crate::c_types::derived::COption_ThirtyTwoBytesZ {
1028 let mut inner_val = &mut this_ptr.get_native_mut_ref().preimage;
1029 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 } }) };
1032 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
1035 pub extern "C" fn HTLCDescriptor_set_preimage(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::derived::COption_ThirtyTwoBytesZ) {
1036 let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::lightning::ln::PaymentPreimage({ val_opt.take() }.data) }})} };
1037 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.preimage = local_val;
1039 /// The counterparty's signature required to spend the HTLC output.
1041 pub extern "C" fn HTLCDescriptor_get_counterparty_sig(this_ptr: &HTLCDescriptor) -> crate::c_types::ECDSASignature {
1042 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig;
1043 crate::c_types::ECDSASignature::from_rust(&inner_val)
1045 /// The counterparty's signature required to spend the HTLC output.
1047 pub extern "C" fn HTLCDescriptor_set_counterparty_sig(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::ECDSASignature) {
1048 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust();
1050 impl Clone for HTLCDescriptor {
1051 fn clone(&self) -> Self {
1053 inner: if <*mut nativeHTLCDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
1054 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1060 /// Used only if an object of this type is returned as a trait impl by a method
1061 pub(crate) extern "C" fn HTLCDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
1062 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHTLCDescriptor)).clone() })) as *mut c_void
1065 /// Creates a copy of the HTLCDescriptor
1066 pub extern "C" fn HTLCDescriptor_clone(orig: &HTLCDescriptor) -> HTLCDescriptor {
1069 /// Get a string which allows debug introspection of a HTLCDescriptor object
1070 pub extern "C" fn HTLCDescriptor_debug_str_void(o: *const c_void) -> Str {
1071 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::HTLCDescriptor }).into()}
1072 /// Checks if two HTLCDescriptors contain equal inner contents.
1073 /// This ignores pointers and is_owned flags and looks at the values in fields.
1074 /// Two objects with NULL inner values will be considered "equal" here.
1076 pub extern "C" fn HTLCDescriptor_eq(a: &HTLCDescriptor, b: &HTLCDescriptor) -> bool {
1077 if a.inner == b.inner { return true; }
1078 if a.inner.is_null() || b.inner.is_null() { return false; }
1079 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1082 /// Serialize the HTLCDescriptor object into a byte array which can be read by HTLCDescriptor_read
1083 pub extern "C" fn HTLCDescriptor_write(obj: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z {
1084 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1087 pub(crate) extern "C" fn HTLCDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1088 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCDescriptor) })
1091 /// Read a HTLCDescriptor from a byte array, created by HTLCDescriptor_write
1092 pub extern "C" fn HTLCDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCDescriptorDecodeErrorZ {
1093 let res: Result<lightning::sign::HTLCDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1094 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() };
1097 /// Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint
1098 /// being spent by the HTLC input in the HTLC transaction.
1101 pub extern "C" fn HTLCDescriptor_outpoint(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::lightning::chain::transaction::OutPoint {
1102 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.outpoint();
1103 crate::c_types::bitcoin_to_C_outpoint(&ret)
1106 /// Returns the UTXO to be spent by the HTLC input, which can be obtained via
1107 /// [`Self::unsigned_tx_input`].
1110 pub extern "C" fn HTLCDescriptor_previous_utxo(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxOut {
1111 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo(secp256k1::global::SECP256K1);
1112 crate::c_types::TxOut::from_rust(&ret)
1115 /// Returns the unsigned transaction input spending the HTLC output in the commitment
1119 pub extern "C" fn HTLCDescriptor_unsigned_tx_input(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxIn {
1120 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input();
1121 crate::c_types::TxIn::from_rust(&ret)
1124 /// Returns the delayed output created as a result of spending the HTLC output in the commitment
1128 pub extern "C" fn HTLCDescriptor_tx_output(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxOut {
1129 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_output(secp256k1::global::SECP256K1);
1130 crate::c_types::TxOut::from_rust(&ret)
1133 /// Returns the witness script of the HTLC output in the commitment transaction.
1136 pub extern "C" fn HTLCDescriptor_witness_script(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z {
1137 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script(secp256k1::global::SECP256K1);
1138 ret.to_bytes().into()
1141 /// Returns the fully signed witness required to spend the HTLC output in the commitment
1145 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 {
1146 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()));
1147 crate::c_types::Witness::from_bitcoin(&ret)
1150 /// Derives the channel signer required to sign the HTLC input.
1153 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 {
1154 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider);
1158 /// A trait to handle Lightning channel key material without concretizing the channel type or
1159 /// the signature mechanism.
1161 pub struct ChannelSigner {
1162 /// An opaque pointer which is passed to your function implementations as an argument.
1163 /// This has no meaning in the LDK, and can be NULL or any other value.
1164 pub this_arg: *mut c_void,
1165 /// Gets the per-commitment point for a specific commitment number
1167 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
1168 pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey,
1169 /// Gets the commitment secret for a specific commitment number as part of the revocation process
1171 /// An external signer implementation should error here if the commitment was already signed
1172 /// and should refuse to sign it in the future.
1174 /// May be called more than once for the same index.
1176 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
1177 pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes,
1178 /// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
1180 /// This is required in order for the signer to make sure that releasing a commitment
1181 /// secret won't leave us without a broadcastable holder transaction.
1182 /// Policy checks should be implemented in this function, including checking the amount
1183 /// sent to us and checking the HTLCs.
1185 /// The preimages of outbound HTLCs that were fulfilled since the last commitment are provided.
1186 /// A validating signer should ensure that an HTLC output is removed only when the matching
1187 /// preimage is provided, or when the value to holder is restored.
1189 /// Note that all the relevant preimages will be provided, but there may also be additional
1190 /// irrelevant or duplicate preimages.
1191 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,
1192 /// Validate the counterparty's revocation.
1194 /// This is required in order for the signer to make sure that the state has moved
1195 /// forward and it is safe to sign the next counterparty commitment.
1196 pub validate_counterparty_revocation: extern "C" fn (this_arg: *const c_void, idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ,
1197 /// Returns the holder's channel public keys and basepoints.
1198 pub pubkeys: core::cell::UnsafeCell<crate::lightning::ln::chan_utils::ChannelPublicKeys>,
1199 /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns
1200 /// Note that this takes a pointer to this object, not the this_ptr like other methods do
1201 /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
1202 pub set_pubkeys: Option<extern "C" fn(&ChannelSigner)>,
1203 /// Returns an arbitrary identifier describing the set of keys which are provided back to you in
1204 /// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
1205 /// [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
1206 pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1207 /// Set the counterparty static channel data, including basepoints,
1208 /// `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
1210 /// This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
1211 /// instance, LDK will call this method exactly once - either immediately after construction
1212 /// (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
1213 /// information has been generated.
1215 /// channel_parameters.is_populated() MUST be true.
1216 pub provide_channel_parameters: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters),
1217 /// Frees any resources associated with this object given its this_arg pointer.
1218 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1219 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1221 unsafe impl Send for ChannelSigner {}
1222 unsafe impl Sync for ChannelSigner {}
1224 pub(crate) fn ChannelSigner_clone_fields(orig: &ChannelSigner) -> ChannelSigner {
1226 this_arg: orig.this_arg,
1227 get_per_commitment_point: Clone::clone(&orig.get_per_commitment_point),
1228 release_commitment_secret: Clone::clone(&orig.release_commitment_secret),
1229 validate_holder_commitment: Clone::clone(&orig.validate_holder_commitment),
1230 validate_counterparty_revocation: Clone::clone(&orig.validate_counterparty_revocation),
1231 pubkeys: Clone::clone(unsafe { &*core::cell::UnsafeCell::get(&orig.pubkeys)}).into(),
1232 set_pubkeys: Clone::clone(&orig.set_pubkeys),
1233 channel_keys_id: Clone::clone(&orig.channel_keys_id),
1234 provide_channel_parameters: Clone::clone(&orig.provide_channel_parameters),
1235 free: Clone::clone(&orig.free),
1239 use lightning::sign::ChannelSigner as rustChannelSigner;
1240 impl rustChannelSigner for ChannelSigner {
1241 fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
1242 let mut ret = (self.get_per_commitment_point)(self.this_arg, idx);
1245 fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
1246 let mut ret = (self.release_commitment_secret)(self.this_arg, idx);
1249 fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut outbound_htlc_preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
1250 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 } }); };
1251 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());
1252 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)) })*/ })};
1255 fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
1256 let mut ret = (self.validate_counterparty_revocation)(self.this_arg, idx, secret.as_ref());
1257 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)) })*/ })};
1260 fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
1261 if let Some(f) = self.set_pubkeys {
1264 unsafe { &*self.pubkeys.get() }.get_native_ref()
1266 fn channel_keys_id(&self) -> [u8; 32] {
1267 let mut ret = (self.channel_keys_id)(self.this_arg);
1270 fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
1271 (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 })
1275 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1276 // directly as a Deref trait in higher-level structs:
1277 impl core::ops::Deref for ChannelSigner {
1279 fn deref(&self) -> &Self {
1283 impl core::ops::DerefMut for ChannelSigner {
1284 fn deref_mut(&mut self) -> &mut Self {
1288 /// Calls the free function if one is set
1290 pub extern "C" fn ChannelSigner_free(this_ptr: ChannelSigner) { }
1291 impl Drop for ChannelSigner {
1292 fn drop(&mut self) {
1293 if let Some(f) = self.free {
1298 /// Specifies the recipient of an invoice.
1300 /// This indicates to [`NodeSigner::sign_invoice`] what node secret key should be used to sign
1305 pub enum Recipient {
1306 /// The invoice should be signed with the local node secret key.
1308 /// The invoice should be signed with the phantom node secret key. This secret key must be the
1309 /// same for all nodes participating in the [phantom node payment].
1311 /// [phantom node payment]: PhantomKeysManager
1314 use lightning::sign::Recipient as RecipientImport;
1315 pub(crate) type nativeRecipient = RecipientImport;
1319 pub(crate) fn to_native(&self) -> nativeRecipient {
1321 Recipient::Node => nativeRecipient::Node,
1322 Recipient::PhantomNode => nativeRecipient::PhantomNode,
1326 pub(crate) fn into_native(self) -> nativeRecipient {
1328 Recipient::Node => nativeRecipient::Node,
1329 Recipient::PhantomNode => nativeRecipient::PhantomNode,
1333 pub(crate) fn from_native(native: &RecipientImport) -> Self {
1334 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeRecipient) };
1336 nativeRecipient::Node => Recipient::Node,
1337 nativeRecipient::PhantomNode => Recipient::PhantomNode,
1341 pub(crate) fn native_into(native: nativeRecipient) -> Self {
1343 nativeRecipient::Node => Recipient::Node,
1344 nativeRecipient::PhantomNode => Recipient::PhantomNode,
1348 /// Creates a copy of the Recipient
1350 pub extern "C" fn Recipient_clone(orig: &Recipient) -> Recipient {
1354 /// Used only if an object of this type is returned as a trait impl by a method
1355 pub(crate) extern "C" fn Recipient_clone_void(this_ptr: *const c_void) -> *mut c_void {
1356 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Recipient)).clone() })) as *mut c_void
1359 /// Used only if an object of this type is returned as a trait impl by a method
1360 pub(crate) extern "C" fn Recipient_free_void(this_ptr: *mut c_void) {
1361 let _ = unsafe { Box::from_raw(this_ptr as *mut Recipient) };
1364 /// Utility method to constructs a new Node-variant Recipient
1365 pub extern "C" fn Recipient_node() -> Recipient {
1368 /// Utility method to constructs a new PhantomNode-variant Recipient
1369 pub extern "C" fn Recipient_phantom_node() -> Recipient {
1370 Recipient::PhantomNode}
1371 /// A trait that describes a source of entropy.
1373 pub struct EntropySource {
1374 /// An opaque pointer which is passed to your function implementations as an argument.
1375 /// This has no meaning in the LDK, and can be NULL or any other value.
1376 pub this_arg: *mut c_void,
1377 /// Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
1378 /// different value each time it is called.
1379 pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1380 /// Frees any resources associated with this object given its this_arg pointer.
1381 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1382 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1384 unsafe impl Send for EntropySource {}
1385 unsafe impl Sync for EntropySource {}
1387 pub(crate) fn EntropySource_clone_fields(orig: &EntropySource) -> EntropySource {
1389 this_arg: orig.this_arg,
1390 get_secure_random_bytes: Clone::clone(&orig.get_secure_random_bytes),
1391 free: Clone::clone(&orig.free),
1395 use lightning::sign::EntropySource as rustEntropySource;
1396 impl rustEntropySource for EntropySource {
1397 fn get_secure_random_bytes(&self) -> [u8; 32] {
1398 let mut ret = (self.get_secure_random_bytes)(self.this_arg);
1403 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1404 // directly as a Deref trait in higher-level structs:
1405 impl core::ops::Deref for EntropySource {
1407 fn deref(&self) -> &Self {
1411 impl core::ops::DerefMut for EntropySource {
1412 fn deref_mut(&mut self) -> &mut Self {
1416 /// Calls the free function if one is set
1418 pub extern "C" fn EntropySource_free(this_ptr: EntropySource) { }
1419 impl Drop for EntropySource {
1420 fn drop(&mut self) {
1421 if let Some(f) = self.free {
1426 /// A trait that can handle cryptographic operations at the scope level of a node.
1428 pub struct NodeSigner {
1429 /// An opaque pointer which is passed to your function implementations as an argument.
1430 /// This has no meaning in the LDK, and can be NULL or any other value.
1431 pub this_arg: *mut c_void,
1432 /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
1434 /// If the implementor of this trait supports [phantom node payments], then every node that is
1435 /// intended to be included in the phantom invoice route hints must return the same value from
1438 /// This method must return the same value each time it is called.
1440 /// [phantom node payments]: PhantomKeysManager
1441 pub get_inbound_payment_key_material: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1442 /// Get node id based on the provided [`Recipient`].
1444 /// This method must return the same value each time it is called with a given [`Recipient`]
1447 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1448 pub get_node_id: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ,
1449 /// Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
1450 /// one is provided. Note that this tweak can be applied to `other_key` instead of our node
1451 /// secret, though this is less efficient.
1453 /// Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
1454 /// should be resolved to allow LDK to resume forwarding HTLCs.
1456 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1457 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,
1458 /// Sign an invoice.
1460 /// By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
1461 /// this trait to parse the invoice and make sure they're signing what they expect, rather than
1462 /// blindly signing the hash.
1464 /// The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
1466 /// The secret key used to sign the invoice is dependent on the [`Recipient`].
1468 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1469 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,
1470 /// Signs the [`TaggedHash`] of a BOLT 12 invoice request.
1472 /// May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
1473 /// `invoice_request` is the callee.
1475 /// Implementors may check that the `invoice_request` is expected rather than blindly signing
1476 /// the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
1477 /// the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
1478 /// [`UnsignedInvoiceRequest::payer_id`].
1480 /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
1481 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,
1482 /// Signs the [`TaggedHash`] of a BOLT 12 invoice.
1484 /// May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
1487 /// Implementors may check that the `invoice` is expected rather than blindly signing the tagged
1488 /// hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
1489 /// key or an ephemeral key to preserve privacy, whichever is associated with
1490 /// [`UnsignedBolt12Invoice::signing_pubkey`].
1492 /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
1493 pub sign_bolt12_invoice: extern "C" fn (this_arg: *const c_void, invoice: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ,
1494 /// Sign a gossip message.
1496 /// Note that if this fails, LDK may panic and the message will not be broadcast to the network
1497 /// or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
1498 /// message to be broadcast, as otherwise it may prevent one from receiving funds over the
1499 /// corresponding channel.
1500 pub sign_gossip_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
1501 /// Frees any resources associated with this object given its this_arg pointer.
1502 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1503 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1505 unsafe impl Send for NodeSigner {}
1506 unsafe impl Sync for NodeSigner {}
1508 pub(crate) fn NodeSigner_clone_fields(orig: &NodeSigner) -> NodeSigner {
1510 this_arg: orig.this_arg,
1511 get_inbound_payment_key_material: Clone::clone(&orig.get_inbound_payment_key_material),
1512 get_node_id: Clone::clone(&orig.get_node_id),
1513 ecdh: Clone::clone(&orig.ecdh),
1514 sign_invoice: Clone::clone(&orig.sign_invoice),
1515 sign_bolt12_invoice_request: Clone::clone(&orig.sign_bolt12_invoice_request),
1516 sign_bolt12_invoice: Clone::clone(&orig.sign_bolt12_invoice),
1517 sign_gossip_message: Clone::clone(&orig.sign_gossip_message),
1518 free: Clone::clone(&orig.free),
1522 use lightning::sign::NodeSigner as rustNodeSigner;
1523 impl rustNodeSigner for NodeSigner {
1524 fn get_inbound_payment_key_material(&self) -> lightning::sign::KeyMaterial {
1525 let mut ret = (self.get_inbound_payment_key_material)(self.this_arg);
1526 ::lightning::sign::KeyMaterial(ret.data)
1528 fn get_node_id(&self, mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::PublicKey, ()> {
1529 let mut ret = (self.get_node_id)(self.this_arg, crate::lightning::sign::Recipient::native_into(recipient));
1530 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)) })*/ })};
1533 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, ()> {
1534 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()) }) };
1535 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);
1536 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)) })*/ })};
1539 fn sign_invoice(&self, mut hrp_bytes: &[u8], mut invoice_data: &[bitcoin::bech32::u5], mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
1540 let mut local_hrp_bytes = crate::c_types::u8slice::from_slice(hrp_bytes);
1541 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() }); };
1542 let mut ret = (self.sign_invoice)(self.this_arg, local_hrp_bytes, local_invoice_data.into(), crate::lightning::sign::Recipient::native_into(recipient));
1543 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)) })*/ })};
1546 fn sign_bolt12_invoice_request(&self, mut invoice_request: &lightning::offers::invoice_request::UnsignedInvoiceRequest) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
1547 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 });
1548 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)) })*/ })};
1551 fn sign_bolt12_invoice(&self, mut invoice: &lightning::offers::invoice::UnsignedBolt12Invoice) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
1552 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 });
1553 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)) })*/ })};
1556 fn sign_gossip_message(&self, mut msg: lightning::ln::msgs::UnsignedGossipMessage) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1557 let mut ret = (self.sign_gossip_message)(self.this_arg, crate::lightning::ln::msgs::UnsignedGossipMessage::native_into(msg));
1558 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)) })*/ })};
1563 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1564 // directly as a Deref trait in higher-level structs:
1565 impl core::ops::Deref for NodeSigner {
1567 fn deref(&self) -> &Self {
1571 impl core::ops::DerefMut for NodeSigner {
1572 fn deref_mut(&mut self) -> &mut Self {
1576 /// Calls the free function if one is set
1578 pub extern "C" fn NodeSigner_free(this_ptr: NodeSigner) { }
1579 impl Drop for NodeSigner {
1580 fn drop(&mut self) {
1581 if let Some(f) = self.free {
1586 /// A trait that can return signer instances for individual channels.
1588 pub struct SignerProvider {
1589 /// An opaque pointer which is passed to your function implementations as an argument.
1590 /// This has no meaning in the LDK, and can be NULL or any other value.
1591 pub this_arg: *mut c_void,
1592 /// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::EcdsaSigner`] through
1593 /// [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
1594 /// implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
1595 /// `channel_keys_id`.
1597 /// This method must return a different value each time it is called.
1598 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,
1599 /// Derives the private key material backing a `Signer`.
1601 /// To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
1602 /// [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
1603 /// re-derived from its `channel_keys_id`, which can be obtained through its trait method
1604 /// [`ChannelSigner::channel_keys_id`].
1605 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,
1606 /// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
1607 /// This is only called during deserialization of other objects which contain
1608 /// [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
1609 /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
1610 /// contain no versioning scheme. You may wish to include your own version prefix and ensure
1611 /// you've read all of the provided bytes to ensure no corruption occurred.
1613 /// This method is slowly being phased out -- it will only be called when reading objects
1614 /// written by LDK versions prior to 0.0.113.
1616 /// [`Signer`]: Self::EcdsaSigner
1617 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
1618 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1619 pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ,
1620 /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
1622 /// If this function returns an error, this will result in a channel failing to open.
1624 /// This method should return a different value each time it is called, to avoid linking
1625 /// on-chain funds across channels as controlled to the same user. `channel_keys_id` may be
1626 /// used to derive a unique value for each channel.
1627 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,
1628 /// Get a script pubkey which we will send funds to when closing a channel.
1630 /// If this function returns an error, this will result in a channel failing to open or close.
1631 /// In the event of a failure when the counterparty is initiating a close, this can result in a
1632 /// channel force close.
1634 /// This method should return a different value each time it is called, to avoid linking
1635 /// on-chain funds across channels as controlled to the same user.
1636 pub get_shutdown_scriptpubkey: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ,
1637 /// Frees any resources associated with this object given its this_arg pointer.
1638 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1639 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1641 unsafe impl Send for SignerProvider {}
1642 unsafe impl Sync for SignerProvider {}
1644 pub(crate) fn SignerProvider_clone_fields(orig: &SignerProvider) -> SignerProvider {
1646 this_arg: orig.this_arg,
1647 generate_channel_keys_id: Clone::clone(&orig.generate_channel_keys_id),
1648 derive_channel_signer: Clone::clone(&orig.derive_channel_signer),
1649 read_chan_signer: Clone::clone(&orig.read_chan_signer),
1650 get_destination_script: Clone::clone(&orig.get_destination_script),
1651 get_shutdown_scriptpubkey: Clone::clone(&orig.get_shutdown_scriptpubkey),
1652 free: Clone::clone(&orig.free),
1656 use lightning::sign::SignerProvider as rustSignerProvider;
1657 impl rustSignerProvider for SignerProvider {
1658 type EcdsaSigner = crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner;
1659 fn generate_channel_keys_id(&self, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: u128) -> [u8; 32] {
1660 let mut ret = (self.generate_channel_keys_id)(self.this_arg, inbound, channel_value_satoshis, user_channel_id.into());
1663 fn derive_channel_signer(&self, mut channel_value_satoshis: u64, mut channel_keys_id: [u8; 32]) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
1664 let mut ret = (self.derive_channel_signer)(self.this_arg, channel_value_satoshis, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
1667 fn read_chan_signer(&self, mut reader: &[u8]) -> Result<crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner, lightning::ln::msgs::DecodeError> {
1668 let mut local_reader = crate::c_types::u8slice::from_slice(reader);
1669 let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
1670 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() })};
1673 fn get_destination_script(&self, mut channel_keys_id: [u8; 32]) -> Result<bitcoin::blockdata::script::ScriptBuf, ()> {
1674 let mut ret = (self.get_destination_script)(self.this_arg, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
1675 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)) })*/ })};
1678 fn get_shutdown_scriptpubkey(&self) -> Result<lightning::ln::script::ShutdownScript, ()> {
1679 let mut ret = (self.get_shutdown_scriptpubkey)(self.this_arg);
1680 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)) })*/ })};
1685 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1686 // directly as a Deref trait in higher-level structs:
1687 impl core::ops::Deref for SignerProvider {
1689 fn deref(&self) -> &Self {
1693 impl core::ops::DerefMut for SignerProvider {
1694 fn deref_mut(&mut self) -> &mut Self {
1698 /// Calls the free function if one is set
1700 pub extern "C" fn SignerProvider_free(this_ptr: SignerProvider) { }
1701 impl Drop for SignerProvider {
1702 fn drop(&mut self) {
1703 if let Some(f) = self.free {
1709 use lightning::sign::InMemorySigner as nativeInMemorySignerImport;
1710 pub(crate) type nativeInMemorySigner = nativeInMemorySignerImport;
1712 /// A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
1714 /// This implementation performs no policy checks and is insufficient by itself as
1715 /// a secure external signer.
1718 pub struct InMemorySigner {
1719 /// A pointer to the opaque Rust object.
1721 /// Nearly everywhere, inner must be non-null, however in places where
1722 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1723 pub inner: *mut nativeInMemorySigner,
1724 /// Indicates that this is the only struct which contains the same pointer.
1726 /// Rust functions which take ownership of an object provided via an argument require
1727 /// this to be true and invalidate the object pointed to by inner.
1731 impl Drop for InMemorySigner {
1732 fn drop(&mut self) {
1733 if self.is_owned && !<*mut nativeInMemorySigner>::is_null(self.inner) {
1734 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1738 /// Frees any resources used by the InMemorySigner, if is_owned is set and inner is non-NULL.
1740 pub extern "C" fn InMemorySigner_free(this_obj: InMemorySigner) { }
1742 /// Used only if an object of this type is returned as a trait impl by a method
1743 pub(crate) extern "C" fn InMemorySigner_free_void(this_ptr: *mut c_void) {
1744 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInMemorySigner) };
1747 impl InMemorySigner {
1748 pub(crate) fn get_native_ref(&self) -> &'static nativeInMemorySigner {
1749 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1751 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInMemorySigner {
1752 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1754 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1755 pub(crate) fn take_inner(mut self) -> *mut nativeInMemorySigner {
1756 assert!(self.is_owned);
1757 let ret = ObjOps::untweak_ptr(self.inner);
1758 self.inner = core::ptr::null_mut();
1762 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1763 /// holder's anchor output in a commitment transaction, if one is present.
1765 pub extern "C" fn InMemorySigner_get_funding_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1766 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_key;
1769 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1770 /// holder's anchor output in a commitment transaction, if one is present.
1772 pub extern "C" fn InMemorySigner_set_funding_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1773 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_key = val.into_rust();
1775 /// Holder secret key for blinded revocation pubkey.
1777 pub extern "C" fn InMemorySigner_get_revocation_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1778 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_base_key;
1781 /// Holder secret key for blinded revocation pubkey.
1783 pub extern "C" fn InMemorySigner_set_revocation_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1784 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_base_key = val.into_rust();
1786 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1788 pub extern "C" fn InMemorySigner_get_payment_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1789 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_key;
1792 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1794 pub extern "C" fn InMemorySigner_set_payment_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1795 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_key = val.into_rust();
1797 /// Holder secret key used in an HTLC transaction.
1799 pub extern "C" fn InMemorySigner_get_delayed_payment_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1800 let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_base_key;
1803 /// Holder secret key used in an HTLC transaction.
1805 pub extern "C" fn InMemorySigner_set_delayed_payment_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1806 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_base_key = val.into_rust();
1808 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1810 pub extern "C" fn InMemorySigner_get_htlc_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1811 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_base_key;
1814 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1816 pub extern "C" fn InMemorySigner_set_htlc_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1817 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_base_key = val.into_rust();
1819 /// Commitment seed.
1821 pub extern "C" fn InMemorySigner_get_commitment_seed(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1822 let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_seed;
1825 /// Commitment seed.
1827 pub extern "C" fn InMemorySigner_set_commitment_seed(this_ptr: &mut InMemorySigner, mut val: crate::c_types::ThirtyTwoBytes) {
1828 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_seed = val.data;
1830 /// Get a string which allows debug introspection of a InMemorySigner object
1831 pub extern "C" fn InMemorySigner_debug_str_void(o: *const c_void) -> Str {
1832 alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::InMemorySigner }).into()}
1833 impl Clone for InMemorySigner {
1834 fn clone(&self) -> Self {
1836 inner: if <*mut nativeInMemorySigner>::is_null(self.inner) { core::ptr::null_mut() } else {
1837 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1843 /// Used only if an object of this type is returned as a trait impl by a method
1844 pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void {
1845 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInMemorySigner)).clone() })) as *mut c_void
1848 /// Creates a copy of the InMemorySigner
1849 pub extern "C" fn InMemorySigner_clone(orig: &InMemorySigner) -> InMemorySigner {
1852 /// Creates a new [`InMemorySigner`].
1855 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 {
1856 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);
1857 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
1860 /// Returns the counterparty's pubkeys.
1862 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1863 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1865 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1868 pub extern "C" fn InMemorySigner_counterparty_pubkeys(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1869 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_pubkeys();
1870 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 };
1874 /// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
1875 /// transactions, i.e., the amount of time that we have to wait to recover our funds if we
1876 /// broadcast a transaction.
1878 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1879 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1882 pub extern "C" fn InMemorySigner_counterparty_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_u16Z {
1883 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_selected_contest_delay();
1884 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() }) };
1888 /// Returns the `contest_delay` value specified by us and applied on transactions broadcastable
1889 /// by our counterparty, i.e., the amount of time that they have to wait to recover their funds
1890 /// if they broadcast a transaction.
1892 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1893 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1896 pub extern "C" fn InMemorySigner_holder_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_u16Z {
1897 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.holder_selected_contest_delay();
1898 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() }) };
1902 /// Returns whether the holder is the initiator.
1904 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1905 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1908 pub extern "C" fn InMemorySigner_is_outbound(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_boolZ {
1909 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
1910 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() }) };
1914 /// Funding outpoint
1916 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1917 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1919 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1922 pub extern "C" fn InMemorySigner_funding_outpoint(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::chain::transaction::OutPoint {
1923 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
1924 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 };
1928 /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
1929 /// building transactions.
1931 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1932 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1934 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1937 pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
1938 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_channel_parameters();
1939 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 };
1943 /// Returns the channel type features of the channel parameters. Should be helpful for
1944 /// determining a channel's category, i. e. legacy/anchors/taproot/etc.
1946 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1947 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1949 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1952 pub extern "C" fn InMemorySigner_channel_type_features(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::features::ChannelTypeFeatures {
1953 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_type_features();
1954 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 };
1958 /// Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
1959 /// by `descriptor`, returning the witness stack for the input.
1961 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
1962 /// is not spending the outpoint described by [`descriptor.outpoint`],
1963 /// or if an output descriptor `script_pubkey` does not match the one we can spend.
1965 /// [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
1968 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 {
1969 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);
1970 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() };
1974 /// Sign the single input of `spend_tx` at index `input_idx` which spends the output
1975 /// described by `descriptor`, returning the witness stack for the input.
1977 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
1978 /// is not spending the outpoint described by [`descriptor.outpoint`], does not have a
1979 /// sequence set to [`descriptor.to_self_delay`], or if an output descriptor
1980 /// `script_pubkey` does not match the one we can spend.
1982 /// [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
1983 /// [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
1986 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 {
1987 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);
1988 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() };
1992 impl From<nativeInMemorySigner> for crate::lightning::sign::EntropySource {
1993 fn from(obj: nativeInMemorySigner) -> Self {
1994 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1995 let mut ret = InMemorySigner_as_EntropySource(&rust_obj);
1996 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
1997 core::mem::forget(rust_obj);
1998 ret.free = Some(InMemorySigner_free_void);
2002 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2003 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2005 pub extern "C" fn InMemorySigner_as_EntropySource(this_arg: &InMemorySigner) -> crate::lightning::sign::EntropySource {
2006 crate::lightning::sign::EntropySource {
2007 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2009 get_secure_random_bytes: InMemorySigner_EntropySource_get_secure_random_bytes,
2014 extern "C" fn InMemorySigner_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2015 let mut ret = <nativeInMemorySigner as lightning::sign::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2016 crate::c_types::ThirtyTwoBytes { data: ret }
2019 impl From<nativeInMemorySigner> for crate::lightning::sign::ChannelSigner {
2020 fn from(obj: nativeInMemorySigner) -> Self {
2021 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2022 let mut ret = InMemorySigner_as_ChannelSigner(&rust_obj);
2023 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2024 core::mem::forget(rust_obj);
2025 ret.free = Some(InMemorySigner_free_void);
2029 /// Constructs a new ChannelSigner which calls the relevant methods on this_arg.
2030 /// This copies the `inner` pointer in this_arg and thus the returned ChannelSigner must be freed before this_arg is
2032 pub extern "C" fn InMemorySigner_as_ChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ChannelSigner {
2033 crate::lightning::sign::ChannelSigner {
2034 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2036 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2037 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2038 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2039 validate_counterparty_revocation: InMemorySigner_ChannelSigner_validate_counterparty_revocation,
2041 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2042 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2043 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2044 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2049 extern "C" fn InMemorySigner_ChannelSigner_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey {
2050 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::get_per_commitment_point(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, secp256k1::global::SECP256K1);
2051 crate::c_types::PublicKey::from_rust(&ret)
2054 extern "C" fn InMemorySigner_ChannelSigner_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
2055 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::release_commitment_secret(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx);
2056 crate::c_types::ThirtyTwoBytes { data: ret }
2059 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 {
2060 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::PaymentPreimage(item.data) }); };
2061 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);
2062 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() };
2066 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 {
2067 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());
2068 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() };
2072 extern "C" fn InMemorySigner_ChannelSigner_pubkeys(this_arg: *const c_void) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
2073 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::pubkeys(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2074 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 }
2076 extern "C" fn InMemorySigner_ChannelSigner_set_pubkeys(trait_self_arg: &ChannelSigner) {
2077 // This is a bit race-y in the general case, but for our specific use-cases today, we're safe
2078 // Specifically, we must ensure that the first time we're called it can never be in parallel
2079 if unsafe { &*trait_self_arg.pubkeys.get() }.inner.is_null() {
2080 *unsafe { &mut *(&*(trait_self_arg as *const ChannelSigner)).pubkeys.get() } = InMemorySigner_ChannelSigner_pubkeys(trait_self_arg.this_arg).into();
2084 extern "C" fn InMemorySigner_ChannelSigner_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2085 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::channel_keys_id(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2086 crate::c_types::ThirtyTwoBytes { data: ret }
2088 extern "C" fn InMemorySigner_ChannelSigner_provide_channel_parameters(this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
2089 <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::provide_channel_parameters(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, channel_parameters.get_native_ref())
2092 impl From<nativeInMemorySigner> for crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2093 fn from(obj: nativeInMemorySigner) -> Self {
2094 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2095 let mut ret = InMemorySigner_as_EcdsaChannelSigner(&rust_obj);
2096 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2097 core::mem::forget(rust_obj);
2098 ret.free = Some(InMemorySigner_free_void);
2102 /// Constructs a new EcdsaChannelSigner which calls the relevant methods on this_arg.
2103 /// This copies the `inner` pointer in this_arg and thus the returned EcdsaChannelSigner must be freed before this_arg is
2105 pub extern "C" fn InMemorySigner_as_EcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2106 crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2107 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2109 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
2110 sign_holder_commitment: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment,
2111 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
2112 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
2113 sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
2114 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
2115 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
2116 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
2117 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
2118 ChannelSigner: crate::lightning::sign::ChannelSigner {
2119 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2121 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2122 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2123 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2124 validate_counterparty_revocation: InMemorySigner_ChannelSigner_validate_counterparty_revocation,
2126 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2127 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2128 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2129 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2135 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 {
2136 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::PaymentPreimage(item.data) }); };
2137 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::PaymentPreimage(item.data) }); };
2138 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);
2139 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() };
2143 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 {
2144 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);
2145 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() };
2149 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 {
2150 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);
2151 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() };
2155 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 {
2156 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);
2157 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() };
2161 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 {
2162 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);
2163 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() };
2167 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 {
2168 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);
2169 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() };
2173 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 {
2174 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);
2175 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() };
2179 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 {
2180 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);
2181 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() };
2185 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 {
2186 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);
2187 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() };
2191 impl From<nativeInMemorySigner> for crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2192 fn from(obj: nativeInMemorySigner) -> Self {
2193 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2194 let mut ret = InMemorySigner_as_WriteableEcdsaChannelSigner(&rust_obj);
2195 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2196 core::mem::forget(rust_obj);
2197 ret.free = Some(InMemorySigner_free_void);
2201 /// Constructs a new WriteableEcdsaChannelSigner which calls the relevant methods on this_arg.
2202 /// This copies the `inner` pointer in this_arg and thus the returned WriteableEcdsaChannelSigner must be freed before this_arg is
2204 pub extern "C" fn InMemorySigner_as_WriteableEcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2205 crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2206 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2208 EcdsaChannelSigner: crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2209 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2211 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
2212 sign_holder_commitment: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment,
2213 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
2214 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
2215 sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
2216 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
2217 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
2218 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
2219 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
2220 ChannelSigner: crate::lightning::sign::ChannelSigner {
2221 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2223 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2224 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2225 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2226 validate_counterparty_revocation: InMemorySigner_ChannelSigner_validate_counterparty_revocation,
2228 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2229 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2230 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2231 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2234 write: InMemorySigner_write_void,
2235 cloned: Some(WriteableEcdsaChannelSigner_InMemorySigner_cloned),
2239 extern "C" fn WriteableEcdsaChannelSigner_InMemorySigner_cloned(new_obj: &mut crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner) {
2240 new_obj.this_arg = InMemorySigner_clone_void(new_obj.this_arg);
2241 new_obj.free = Some(InMemorySigner_free_void);
2242 new_obj.EcdsaChannelSigner.this_arg = new_obj.this_arg;
2243 new_obj.EcdsaChannelSigner.free = None;
2244 new_obj.EcdsaChannelSigner.ChannelSigner.this_arg = new_obj.this_arg;
2245 new_obj.EcdsaChannelSigner.ChannelSigner.free = None;
2249 /// Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
2250 pub extern "C" fn InMemorySigner_write(obj: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::CVec_u8Z {
2251 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2254 pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2255 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) })
2258 /// Read a InMemorySigner from a byte array, created by InMemorySigner_write
2259 pub extern "C" fn InMemorySigner_read(ser: crate::c_types::u8slice, arg: crate::lightning::sign::EntropySource) -> crate::c_types::derived::CResult_InMemorySignerDecodeErrorZ {
2261 let res: Result<lightning::sign::InMemorySigner, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
2262 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() };
2266 use lightning::sign::KeysManager as nativeKeysManagerImport;
2267 pub(crate) type nativeKeysManager = nativeKeysManagerImport;
2269 /// Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a
2270 /// 32-byte seed for use as a BIP 32 extended key and derives keys from that.
2272 /// Your `node_id` is seed/0'.
2273 /// Unilateral closes may use seed/1'.
2274 /// Cooperative closes may use seed/2'.
2275 /// The two close keys may be needed to claim on-chain funds!
2277 /// This struct cannot be used for nodes that wish to support receiving phantom payments;
2278 /// [`PhantomKeysManager`] must be used instead.
2280 /// Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
2281 /// previously issued invoices and attempts to pay previous invoices will fail.
2284 pub struct KeysManager {
2285 /// A pointer to the opaque Rust object.
2287 /// Nearly everywhere, inner must be non-null, however in places where
2288 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2289 pub inner: *mut nativeKeysManager,
2290 /// Indicates that this is the only struct which contains the same pointer.
2292 /// Rust functions which take ownership of an object provided via an argument require
2293 /// this to be true and invalidate the object pointed to by inner.
2297 impl Drop for KeysManager {
2298 fn drop(&mut self) {
2299 if self.is_owned && !<*mut nativeKeysManager>::is_null(self.inner) {
2300 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2304 /// Frees any resources used by the KeysManager, if is_owned is set and inner is non-NULL.
2306 pub extern "C" fn KeysManager_free(this_obj: KeysManager) { }
2308 /// Used only if an object of this type is returned as a trait impl by a method
2309 pub(crate) extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) {
2310 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeKeysManager) };
2314 pub(crate) fn get_native_ref(&self) -> &'static nativeKeysManager {
2315 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2317 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeKeysManager {
2318 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2320 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2321 pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager {
2322 assert!(self.is_owned);
2323 let ret = ObjOps::untweak_ptr(self.inner);
2324 self.inner = core::ptr::null_mut();
2328 /// Constructs a [`KeysManager`] from a 32-byte seed. If the seed is in some way biased (e.g.,
2329 /// your CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
2330 /// `starting_time` isn't strictly required to actually be a time, but it must absolutely,
2331 /// without a doubt, be unique to this instance. ie if you start multiple times with the same
2332 /// `seed`, `starting_time` must be unique to each run. Thus, the easiest way to achieve this
2333 /// is to simply use the current time (with very high precision).
2335 /// The `seed` MUST be backed up safely prior to use so that the keys can be re-created, however,
2336 /// obviously, `starting_time` should be unique every time you reload the library - it is only
2337 /// used to generate new ephemeral key data (which will be stored by the individual channel if
2340 /// Note that the seed is required to recover certain on-chain funds independent of
2341 /// [`ChannelMonitor`] data, though a current copy of [`ChannelMonitor`] data is also required
2342 /// for any channel, and some on-chain during-closing funds.
2344 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
2347 pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32) -> crate::lightning::sign::KeysManager {
2348 let mut ret = lightning::sign::KeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos);
2349 crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2352 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2355 pub extern "C" fn KeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::KeysManager) -> crate::c_types::SecretKey {
2356 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2357 crate::c_types::SecretKey::from_rust(ret)
2360 /// Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
2363 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 {
2364 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2365 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2368 /// Signs the given [`PartiallySignedTransaction`] which spends the given [`SpendableOutputDescriptor`]s.
2369 /// The resulting inputs will be finalized and the PSBT will be ready for broadcast if there
2370 /// are no other inputs that need signing.
2372 /// Returns `Err(())` if the PSBT is missing a descriptor or if we fail to sign.
2374 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
2375 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2378 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 {
2379 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2380 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);
2381 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() };
2385 /// Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
2386 /// output to the given change destination (if sufficient change value remains). The
2387 /// transaction will have a feerate, at least, of the given value.
2389 /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
2390 /// transaction will have a locktime of 0. It it recommended to set this to the current block
2391 /// height to avoid fee sniping, unless you have some specific reason to use a different
2394 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
2395 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
2396 /// does not match the one we can spend.
2398 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
2400 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
2401 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2404 pub extern "C" fn KeysManager_spend_spendable_outputs(this_arg: &crate::lightning::sign::KeysManager, 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 {
2405 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2406 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2407 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() }) }})} };
2408 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.spend_spendable_outputs(&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);
2409 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() };
2413 impl From<nativeKeysManager> for crate::lightning::sign::EntropySource {
2414 fn from(obj: nativeKeysManager) -> Self {
2415 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2416 let mut ret = KeysManager_as_EntropySource(&rust_obj);
2417 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2418 core::mem::forget(rust_obj);
2419 ret.free = Some(KeysManager_free_void);
2423 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2424 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2426 pub extern "C" fn KeysManager_as_EntropySource(this_arg: &KeysManager) -> crate::lightning::sign::EntropySource {
2427 crate::lightning::sign::EntropySource {
2428 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2430 get_secure_random_bytes: KeysManager_EntropySource_get_secure_random_bytes,
2435 extern "C" fn KeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2436 let mut ret = <nativeKeysManager as lightning::sign::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2437 crate::c_types::ThirtyTwoBytes { data: ret }
2440 impl From<nativeKeysManager> for crate::lightning::sign::NodeSigner {
2441 fn from(obj: nativeKeysManager) -> Self {
2442 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2443 let mut ret = KeysManager_as_NodeSigner(&rust_obj);
2444 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2445 core::mem::forget(rust_obj);
2446 ret.free = Some(KeysManager_free_void);
2450 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2451 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2453 pub extern "C" fn KeysManager_as_NodeSigner(this_arg: &KeysManager) -> crate::lightning::sign::NodeSigner {
2454 crate::lightning::sign::NodeSigner {
2455 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2457 get_inbound_payment_key_material: KeysManager_NodeSigner_get_inbound_payment_key_material,
2458 get_node_id: KeysManager_NodeSigner_get_node_id,
2459 ecdh: KeysManager_NodeSigner_ecdh,
2460 sign_invoice: KeysManager_NodeSigner_sign_invoice,
2461 sign_bolt12_invoice_request: KeysManager_NodeSigner_sign_bolt12_invoice_request,
2462 sign_bolt12_invoice: KeysManager_NodeSigner_sign_bolt12_invoice,
2463 sign_gossip_message: KeysManager_NodeSigner_sign_gossip_message,
2468 extern "C" fn KeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2469 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2470 crate::c_types::ThirtyTwoBytes { data: ret.0 }
2473 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 {
2474 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native());
2475 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() };
2479 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 {
2480 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();
2481 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);
2482 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() };
2486 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 {
2487 let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2488 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());
2489 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() };
2493 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 {
2494 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::sign_bolt12_invoice_request(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, invoice_request.get_native_ref());
2495 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() };
2499 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 {
2500 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::sign_bolt12_invoice(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, invoice.get_native_ref());
2501 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() };
2505 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 {
2506 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, msg.into_native());
2507 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() };
2511 impl From<nativeKeysManager> for crate::lightning::sign::SignerProvider {
2512 fn from(obj: nativeKeysManager) -> Self {
2513 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2514 let mut ret = KeysManager_as_SignerProvider(&rust_obj);
2515 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2516 core::mem::forget(rust_obj);
2517 ret.free = Some(KeysManager_free_void);
2521 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2522 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2524 pub extern "C" fn KeysManager_as_SignerProvider(this_arg: &KeysManager) -> crate::lightning::sign::SignerProvider {
2525 crate::lightning::sign::SignerProvider {
2526 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2528 generate_channel_keys_id: KeysManager_SignerProvider_generate_channel_keys_id,
2529 derive_channel_signer: KeysManager_SignerProvider_derive_channel_signer,
2530 read_chan_signer: KeysManager_SignerProvider_read_chan_signer,
2531 get_destination_script: KeysManager_SignerProvider_get_destination_script,
2532 get_shutdown_scriptpubkey: KeysManager_SignerProvider_get_shutdown_scriptpubkey,
2537 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 {
2538 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());
2539 crate::c_types::ThirtyTwoBytes { data: ret }
2542 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 {
2543 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);
2547 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 {
2548 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, reader.to_slice());
2549 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() };
2553 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 {
2554 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, channel_keys_id.data);
2555 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() };
2559 extern "C" fn KeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2560 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2561 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() };
2566 use lightning::sign::PhantomKeysManager as nativePhantomKeysManagerImport;
2567 pub(crate) type nativePhantomKeysManager = nativePhantomKeysManagerImport;
2569 /// Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
2572 /// A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
2573 /// paid to one of multiple nodes. This works because we encode the invoice route hints such that
2574 /// LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
2575 /// itself without ever needing to forward to this fake node.
2577 /// Phantom node payments are useful for load balancing between multiple LDK nodes. They also
2578 /// provide some fault tolerance, because payers will automatically retry paying other provided
2579 /// nodes in the case that one node goes down.
2581 /// Note that multi-path payments are not supported in phantom invoices for security reasons.
2582 /// Switching between this struct and [`KeysManager`] will invalidate any previously issued
2583 /// invoices and attempts to pay previous invoices will fail.
2586 pub struct PhantomKeysManager {
2587 /// A pointer to the opaque Rust object.
2589 /// Nearly everywhere, inner must be non-null, however in places where
2590 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2591 pub inner: *mut nativePhantomKeysManager,
2592 /// Indicates that this is the only struct which contains the same pointer.
2594 /// Rust functions which take ownership of an object provided via an argument require
2595 /// this to be true and invalidate the object pointed to by inner.
2599 impl Drop for PhantomKeysManager {
2600 fn drop(&mut self) {
2601 if self.is_owned && !<*mut nativePhantomKeysManager>::is_null(self.inner) {
2602 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2606 /// Frees any resources used by the PhantomKeysManager, if is_owned is set and inner is non-NULL.
2608 pub extern "C" fn PhantomKeysManager_free(this_obj: PhantomKeysManager) { }
2610 /// Used only if an object of this type is returned as a trait impl by a method
2611 pub(crate) extern "C" fn PhantomKeysManager_free_void(this_ptr: *mut c_void) {
2612 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomKeysManager) };
2615 impl PhantomKeysManager {
2616 pub(crate) fn get_native_ref(&self) -> &'static nativePhantomKeysManager {
2617 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2619 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomKeysManager {
2620 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2622 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2623 pub(crate) fn take_inner(mut self) -> *mut nativePhantomKeysManager {
2624 assert!(self.is_owned);
2625 let ret = ObjOps::untweak_ptr(self.inner);
2626 self.inner = core::ptr::null_mut();
2630 impl From<nativePhantomKeysManager> for crate::lightning::sign::EntropySource {
2631 fn from(obj: nativePhantomKeysManager) -> Self {
2632 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2633 let mut ret = PhantomKeysManager_as_EntropySource(&rust_obj);
2634 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2635 core::mem::forget(rust_obj);
2636 ret.free = Some(PhantomKeysManager_free_void);
2640 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2641 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2643 pub extern "C" fn PhantomKeysManager_as_EntropySource(this_arg: &PhantomKeysManager) -> crate::lightning::sign::EntropySource {
2644 crate::lightning::sign::EntropySource {
2645 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2647 get_secure_random_bytes: PhantomKeysManager_EntropySource_get_secure_random_bytes,
2652 extern "C" fn PhantomKeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2653 let mut ret = <nativePhantomKeysManager as lightning::sign::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2654 crate::c_types::ThirtyTwoBytes { data: ret }
2657 impl From<nativePhantomKeysManager> for crate::lightning::sign::NodeSigner {
2658 fn from(obj: nativePhantomKeysManager) -> Self {
2659 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2660 let mut ret = PhantomKeysManager_as_NodeSigner(&rust_obj);
2661 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2662 core::mem::forget(rust_obj);
2663 ret.free = Some(PhantomKeysManager_free_void);
2667 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2668 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2670 pub extern "C" fn PhantomKeysManager_as_NodeSigner(this_arg: &PhantomKeysManager) -> crate::lightning::sign::NodeSigner {
2671 crate::lightning::sign::NodeSigner {
2672 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2674 get_inbound_payment_key_material: PhantomKeysManager_NodeSigner_get_inbound_payment_key_material,
2675 get_node_id: PhantomKeysManager_NodeSigner_get_node_id,
2676 ecdh: PhantomKeysManager_NodeSigner_ecdh,
2677 sign_invoice: PhantomKeysManager_NodeSigner_sign_invoice,
2678 sign_bolt12_invoice_request: PhantomKeysManager_NodeSigner_sign_bolt12_invoice_request,
2679 sign_bolt12_invoice: PhantomKeysManager_NodeSigner_sign_bolt12_invoice,
2680 sign_gossip_message: PhantomKeysManager_NodeSigner_sign_gossip_message,
2685 extern "C" fn PhantomKeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2686 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2687 crate::c_types::ThirtyTwoBytes { data: ret.0 }
2690 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 {
2691 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native());
2692 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() };
2696 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 {
2697 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();
2698 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);
2699 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() };
2703 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 {
2704 let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2705 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());
2706 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() };
2710 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 {
2711 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::sign_bolt12_invoice_request(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, invoice_request.get_native_ref());
2712 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() };
2716 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 {
2717 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::sign_bolt12_invoice(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, invoice.get_native_ref());
2718 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() };
2722 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 {
2723 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, msg.into_native());
2724 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() };
2728 impl From<nativePhantomKeysManager> for crate::lightning::sign::SignerProvider {
2729 fn from(obj: nativePhantomKeysManager) -> Self {
2730 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2731 let mut ret = PhantomKeysManager_as_SignerProvider(&rust_obj);
2732 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2733 core::mem::forget(rust_obj);
2734 ret.free = Some(PhantomKeysManager_free_void);
2738 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2739 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2741 pub extern "C" fn PhantomKeysManager_as_SignerProvider(this_arg: &PhantomKeysManager) -> crate::lightning::sign::SignerProvider {
2742 crate::lightning::sign::SignerProvider {
2743 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2745 generate_channel_keys_id: PhantomKeysManager_SignerProvider_generate_channel_keys_id,
2746 derive_channel_signer: PhantomKeysManager_SignerProvider_derive_channel_signer,
2747 read_chan_signer: PhantomKeysManager_SignerProvider_read_chan_signer,
2748 get_destination_script: PhantomKeysManager_SignerProvider_get_destination_script,
2749 get_shutdown_scriptpubkey: PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey,
2754 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 {
2755 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());
2756 crate::c_types::ThirtyTwoBytes { data: ret }
2759 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 {
2760 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);
2764 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 {
2765 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, reader.to_slice());
2766 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() };
2770 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 {
2771 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, channel_keys_id.data);
2772 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() };
2776 extern "C" fn PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2777 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2778 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() };
2782 /// Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
2783 /// that is shared across all nodes that intend to participate in [phantom node payments]
2786 /// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
2787 /// `starting_time_nanos`.
2789 /// `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
2790 /// same across restarts, or else inbound payments may fail.
2792 /// [phantom node payments]: PhantomKeysManager
2795 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 {
2796 let mut ret = lightning::sign::PhantomKeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos, unsafe { &*cross_node_seed});
2797 crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2800 /// See [`KeysManager::spend_spendable_outputs`] for documentation on this method.
2803 pub extern "C" fn PhantomKeysManager_spend_spendable_outputs(this_arg: &crate::lightning::sign::PhantomKeysManager, 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 {
2804 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2805 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2806 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() }) }})} };
2807 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.spend_spendable_outputs(&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);
2808 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() };
2812 /// See [`KeysManager::derive_channel_keys`] for documentation on this method.
2815 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 {
2816 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2817 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2820 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2823 pub extern "C" fn PhantomKeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
2824 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2825 crate::c_types::SecretKey::from_rust(ret)
2828 /// Gets the \"node_id\" secret key of the phantom node used to sign invoices, decode the
2829 /// last-hop onion data, etc.
2832 pub extern "C" fn PhantomKeysManager_get_phantom_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
2833 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_node_secret_key();
2834 crate::c_types::SecretKey::from_rust(ret)