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};
25 use alloc::str::FromStr;
26 use alloc::string::String;
27 use core::ffi::c_void;
28 use core::convert::Infallible;
29 use bitcoin::hashes::Hash;
30 use crate::c_types::*;
31 #[cfg(feature="no-std")]
32 use alloc::{vec::Vec, boxed::Box};
36 use lightning::sign::DelayedPaymentOutputDescriptor as nativeDelayedPaymentOutputDescriptorImport;
37 pub(crate) type nativeDelayedPaymentOutputDescriptor = nativeDelayedPaymentOutputDescriptorImport;
39 /// Information about a spendable output to a P2WSH script.
41 /// See [`SpendableOutputDescriptor::DelayedPaymentOutput`] for more details on how to spend this.
44 pub struct DelayedPaymentOutputDescriptor {
45 /// A pointer to the opaque Rust object.
47 /// Nearly everywhere, inner must be non-null, however in places where
48 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
49 pub inner: *mut nativeDelayedPaymentOutputDescriptor,
50 /// Indicates that this is the only struct which contains the same pointer.
52 /// Rust functions which take ownership of an object provided via an argument require
53 /// this to be true and invalidate the object pointed to by inner.
57 impl Drop for DelayedPaymentOutputDescriptor {
59 if self.is_owned && !<*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) {
60 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
64 /// Frees any resources used by the DelayedPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
66 pub extern "C" fn DelayedPaymentOutputDescriptor_free(this_obj: DelayedPaymentOutputDescriptor) { }
68 /// Used only if an object of this type is returned as a trait impl by a method
69 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
70 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDelayedPaymentOutputDescriptor) };
73 impl DelayedPaymentOutputDescriptor {
74 pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentOutputDescriptor {
75 unsafe { &*ObjOps::untweak_ptr(self.inner) }
77 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentOutputDescriptor {
78 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
80 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
81 pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentOutputDescriptor {
82 assert!(self.is_owned);
83 let ret = ObjOps::untweak_ptr(self.inner);
84 self.inner = core::ptr::null_mut();
88 /// The outpoint which is spendable.
90 pub extern "C" fn DelayedPaymentOutputDescriptor_get_outpoint(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
91 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
92 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 }
94 /// The outpoint which is spendable.
96 pub extern "C" fn DelayedPaymentOutputDescriptor_set_outpoint(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
97 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
99 /// Per commitment point to derive the delayed payment key by key holder.
101 pub extern "C" fn DelayedPaymentOutputDescriptor_get_per_commitment_point(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
102 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
103 crate::c_types::PublicKey::from_rust(&inner_val)
105 /// Per commitment point to derive the delayed payment key by key holder.
107 pub extern "C" fn DelayedPaymentOutputDescriptor_set_per_commitment_point(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
108 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
110 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
111 /// the witness_script.
113 pub extern "C" fn DelayedPaymentOutputDescriptor_get_to_self_delay(this_ptr: &DelayedPaymentOutputDescriptor) -> u16 {
114 let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay;
117 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
118 /// the witness_script.
120 pub extern "C" fn DelayedPaymentOutputDescriptor_set_to_self_delay(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u16) {
121 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val;
123 /// The output which is referenced by the given outpoint.
125 pub extern "C" fn DelayedPaymentOutputDescriptor_get_output(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::TxOut {
126 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
127 crate::c_types::TxOut::from_rust(inner_val)
129 /// The output which is referenced by the given outpoint.
131 pub extern "C" fn DelayedPaymentOutputDescriptor_set_output(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
132 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
134 /// The revocation point specific to the commitment transaction which was broadcast. Used to
135 /// derive the witnessScript for this output.
137 pub extern "C" fn DelayedPaymentOutputDescriptor_get_revocation_pubkey(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
138 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_pubkey;
139 crate::c_types::PublicKey::from_rust(&inner_val)
141 /// The revocation point specific to the commitment transaction which was broadcast. Used to
142 /// derive the witnessScript for this output.
144 pub extern "C" fn DelayedPaymentOutputDescriptor_set_revocation_pubkey(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
145 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_pubkey = val.into_rust();
147 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
148 /// This may be useful in re-deriving keys used in the channel to spend the output.
150 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &DelayedPaymentOutputDescriptor) -> *const [u8; 32] {
151 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
154 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
155 /// This may be useful in re-deriving keys used in the channel to spend the output.
157 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
158 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
160 /// The value of the channel which this output originated from, possibly indirectly.
162 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &DelayedPaymentOutputDescriptor) -> u64 {
163 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
166 /// The value of the channel which this output originated from, possibly indirectly.
168 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u64) {
169 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
171 /// Constructs a new DelayedPaymentOutputDescriptor given each field
174 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::c_types::PublicKey, mut channel_keys_id_arg: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis_arg: u64) -> DelayedPaymentOutputDescriptor {
175 DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeDelayedPaymentOutputDescriptor {
176 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
177 per_commitment_point: per_commitment_point_arg.into_rust(),
178 to_self_delay: to_self_delay_arg,
179 output: output_arg.into_rust(),
180 revocation_pubkey: revocation_pubkey_arg.into_rust(),
181 channel_keys_id: channel_keys_id_arg.data,
182 channel_value_satoshis: channel_value_satoshis_arg,
185 impl Clone for DelayedPaymentOutputDescriptor {
186 fn clone(&self) -> Self {
188 inner: if <*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
189 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
195 /// Used only if an object of this type is returned as a trait impl by a method
196 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
197 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void
200 /// Creates a copy of the DelayedPaymentOutputDescriptor
201 pub extern "C" fn DelayedPaymentOutputDescriptor_clone(orig: &DelayedPaymentOutputDescriptor) -> DelayedPaymentOutputDescriptor {
204 /// Generates a non-cryptographic 64-bit hash of the DelayedPaymentOutputDescriptor.
206 pub extern "C" fn DelayedPaymentOutputDescriptor_hash(o: &DelayedPaymentOutputDescriptor) -> u64 {
207 if o.inner.is_null() { return 0; }
208 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
210 let mut hasher = core::hash::SipHasher::new();
211 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
212 core::hash::Hasher::finish(&hasher)
214 /// Checks if two DelayedPaymentOutputDescriptors contain equal inner contents.
215 /// This ignores pointers and is_owned flags and looks at the values in fields.
216 /// Two objects with NULL inner values will be considered "equal" here.
218 pub extern "C" fn DelayedPaymentOutputDescriptor_eq(a: &DelayedPaymentOutputDescriptor, b: &DelayedPaymentOutputDescriptor) -> bool {
219 if a.inner == b.inner { return true; }
220 if a.inner.is_null() || b.inner.is_null() { return false; }
221 if a.get_native_ref() == b.get_native_ref() { true } else { false }
224 /// Serialize the DelayedPaymentOutputDescriptor object into a byte array which can be read by DelayedPaymentOutputDescriptor_read
225 pub extern "C" fn DelayedPaymentOutputDescriptor_write(obj: &crate::lightning::sign::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
226 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
229 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
230 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentOutputDescriptor) })
233 /// Read a DelayedPaymentOutputDescriptor from a byte array, created by DelayedPaymentOutputDescriptor_write
234 pub extern "C" fn DelayedPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentOutputDescriptorDecodeErrorZ {
235 let res: Result<lightning::sign::DelayedPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
236 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() };
240 use lightning::sign::StaticPaymentOutputDescriptor as nativeStaticPaymentOutputDescriptorImport;
241 pub(crate) type nativeStaticPaymentOutputDescriptor = nativeStaticPaymentOutputDescriptorImport;
243 /// Information about a spendable output to our \"payment key\".
245 /// See [`SpendableOutputDescriptor::StaticPaymentOutput`] for more details on how to spend this.
248 pub struct StaticPaymentOutputDescriptor {
249 /// A pointer to the opaque Rust object.
251 /// Nearly everywhere, inner must be non-null, however in places where
252 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
253 pub inner: *mut nativeStaticPaymentOutputDescriptor,
254 /// Indicates that this is the only struct which contains the same pointer.
256 /// Rust functions which take ownership of an object provided via an argument require
257 /// this to be true and invalidate the object pointed to by inner.
261 impl Drop for StaticPaymentOutputDescriptor {
263 if self.is_owned && !<*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) {
264 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
268 /// Frees any resources used by the StaticPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
270 pub extern "C" fn StaticPaymentOutputDescriptor_free(this_obj: StaticPaymentOutputDescriptor) { }
272 /// Used only if an object of this type is returned as a trait impl by a method
273 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
274 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeStaticPaymentOutputDescriptor) };
277 impl StaticPaymentOutputDescriptor {
278 pub(crate) fn get_native_ref(&self) -> &'static nativeStaticPaymentOutputDescriptor {
279 unsafe { &*ObjOps::untweak_ptr(self.inner) }
281 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeStaticPaymentOutputDescriptor {
282 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
284 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
285 pub(crate) fn take_inner(mut self) -> *mut nativeStaticPaymentOutputDescriptor {
286 assert!(self.is_owned);
287 let ret = ObjOps::untweak_ptr(self.inner);
288 self.inner = core::ptr::null_mut();
292 /// The outpoint which is spendable.
294 pub extern "C" fn StaticPaymentOutputDescriptor_get_outpoint(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
295 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
296 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 }
298 /// The outpoint which is spendable.
300 pub extern "C" fn StaticPaymentOutputDescriptor_set_outpoint(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
301 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
303 /// The output which is referenced by the given outpoint.
305 pub extern "C" fn StaticPaymentOutputDescriptor_get_output(this_ptr: &StaticPaymentOutputDescriptor) -> crate::c_types::TxOut {
306 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
307 crate::c_types::TxOut::from_rust(inner_val)
309 /// The output which is referenced by the given outpoint.
311 pub extern "C" fn StaticPaymentOutputDescriptor_set_output(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
312 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
314 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
315 /// This may be useful in re-deriving keys used in the channel to spend the output.
317 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &StaticPaymentOutputDescriptor) -> *const [u8; 32] {
318 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
321 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
322 /// This may be useful in re-deriving keys used in the channel to spend the output.
324 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
325 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
327 /// The value of the channel which this transactions spends.
329 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &StaticPaymentOutputDescriptor) -> u64 {
330 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
333 /// The value of the channel which this transactions spends.
335 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: u64) {
336 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
338 /// The necessary channel parameters that need to be provided to the re-derived signer through
339 /// [`ChannelSigner::provide_channel_parameters`].
341 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
343 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
345 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_transaction_parameters(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
346 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_transaction_parameters;
347 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 };
350 /// The necessary channel parameters that need to be provided to the re-derived signer through
351 /// [`ChannelSigner::provide_channel_parameters`].
353 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
355 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
357 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_transaction_parameters(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
358 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
359 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_transaction_parameters = local_val;
361 /// Constructs a new StaticPaymentOutputDescriptor given each field
363 /// Note that channel_transaction_parameters_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
366 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 {
367 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()) } }) };
368 StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeStaticPaymentOutputDescriptor {
369 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
370 output: output_arg.into_rust(),
371 channel_keys_id: channel_keys_id_arg.data,
372 channel_value_satoshis: channel_value_satoshis_arg,
373 channel_transaction_parameters: local_channel_transaction_parameters_arg,
376 impl Clone for StaticPaymentOutputDescriptor {
377 fn clone(&self) -> Self {
379 inner: if <*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
380 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
386 /// Used only if an object of this type is returned as a trait impl by a method
387 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
388 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void
391 /// Creates a copy of the StaticPaymentOutputDescriptor
392 pub extern "C" fn StaticPaymentOutputDescriptor_clone(orig: &StaticPaymentOutputDescriptor) -> StaticPaymentOutputDescriptor {
395 /// Generates a non-cryptographic 64-bit hash of the StaticPaymentOutputDescriptor.
397 pub extern "C" fn StaticPaymentOutputDescriptor_hash(o: &StaticPaymentOutputDescriptor) -> u64 {
398 if o.inner.is_null() { return 0; }
399 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
401 let mut hasher = core::hash::SipHasher::new();
402 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
403 core::hash::Hasher::finish(&hasher)
405 /// Checks if two StaticPaymentOutputDescriptors contain equal inner contents.
406 /// This ignores pointers and is_owned flags and looks at the values in fields.
407 /// Two objects with NULL inner values will be considered "equal" here.
409 pub extern "C" fn StaticPaymentOutputDescriptor_eq(a: &StaticPaymentOutputDescriptor, b: &StaticPaymentOutputDescriptor) -> bool {
410 if a.inner == b.inner { return true; }
411 if a.inner.is_null() || b.inner.is_null() { return false; }
412 if a.get_native_ref() == b.get_native_ref() { true } else { false }
414 /// Returns the `witness_script` of the spendable output.
416 /// Note that this will only return `Some` for [`StaticPaymentOutputDescriptor`]s that
417 /// originated from an anchor outputs channel, as they take the form of a P2WSH script.
420 pub extern "C" fn StaticPaymentOutputDescriptor_witness_script(this_arg: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::COption_CVec_u8ZZ {
421 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script();
422 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().into_bytes().into() }) };
426 /// The maximum length a well-formed witness spending one of these should have.
427 /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
431 pub extern "C" fn StaticPaymentOutputDescriptor_max_witness_length(this_arg: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> usize {
432 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.max_witness_length();
437 /// Serialize the StaticPaymentOutputDescriptor object into a byte array which can be read by StaticPaymentOutputDescriptor_read
438 pub extern "C" fn StaticPaymentOutputDescriptor_write(obj: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
439 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
442 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
443 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeStaticPaymentOutputDescriptor) })
446 /// Read a StaticPaymentOutputDescriptor from a byte array, created by StaticPaymentOutputDescriptor_write
447 pub extern "C" fn StaticPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_StaticPaymentOutputDescriptorDecodeErrorZ {
448 let res: Result<lightning::sign::StaticPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
449 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() };
452 /// Describes the necessary information to spend a spendable output.
454 /// When on-chain outputs are created by LDK (which our counterparty is not able to claim at any
455 /// point in the future) a [`SpendableOutputs`] event is generated which you must track and be able
456 /// to spend on-chain. The information needed to do this is provided in this enum, including the
457 /// outpoint describing which `txid` and output `index` is available, the full output which exists
458 /// at that `txid`/`index`, and any keys or other information required to sign.
460 /// [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
464 pub enum SpendableOutputDescriptor {
465 /// An output to a script which was provided via [`SignerProvider`] directly, either from
466 /// [`get_destination_script`] or [`get_shutdown_scriptpubkey`], thus you should already
467 /// know how to spend it. No secret keys are provided as LDK was never given any key.
468 /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
469 /// on-chain using the payment preimage or after it has timed out.
471 /// [`get_shutdown_scriptpubkey`]: SignerProvider::get_shutdown_scriptpubkey
472 /// [`get_destination_script`]: SignerProvider::get_shutdown_scriptpubkey
474 /// The outpoint which is spendable.
475 outpoint: crate::lightning::chain::transaction::OutPoint,
476 /// The output which is referenced by the given outpoint.
477 output: crate::c_types::TxOut,
479 /// An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
482 /// The witness in the spending input should be:
484 /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
487 /// Note that the `nSequence` field in the spending input must be set to
488 /// [`DelayedPaymentOutputDescriptor::to_self_delay`] (which means the transaction is not
489 /// broadcastable until at least [`DelayedPaymentOutputDescriptor::to_self_delay`] blocks after
490 /// the outpoint confirms, see [BIP
491 /// 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)). Also note that LDK
492 /// won't generate a [`SpendableOutputDescriptor`] until the corresponding block height
495 /// These are generally the result of a \"revocable\" output to us, spendable only by us unless
496 /// it is an output from an old state which we broadcast (which should never happen).
498 /// To derive the delayed payment key which is used to sign this input, you must pass the
499 /// holder [`InMemorySigner::delayed_payment_base_key`] (i.e., the private key which corresponds to the
500 /// [`ChannelPublicKeys::delayed_payment_basepoint`] in [`ChannelSigner::pubkeys`]) and the provided
501 /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to [`chan_utils::derive_private_key`]. The public key can be
502 /// generated without the secret key using [`chan_utils::derive_public_key`] and only the
503 /// [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`ChannelSigner::pubkeys`].
505 /// To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
506 /// used in the witness script generation), you must pass the counterparty
507 /// [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
508 /// [`ChannelSigner::provide_channel_parameters`]) and the provided
509 /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
510 /// [`chan_utils::derive_public_revocation_key`].
512 /// The witness script which is hashed and included in the output `script_pubkey` may be
513 /// regenerated by passing the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] (derived
514 /// as explained above), our delayed payment pubkey (derived as explained above), and the
515 /// [`DelayedPaymentOutputDescriptor::to_self_delay`] contained here to
516 /// [`chan_utils::get_revokeable_redeemscript`].
517 DelayedPaymentOutput(
518 crate::lightning::sign::DelayedPaymentOutputDescriptor),
519 /// An output spendable exclusively by our payment key (i.e., the private key that corresponds
520 /// to the `payment_point` in [`ChannelSigner::pubkeys`]). The output type depends on the
521 /// channel type negotiated.
523 /// On an anchor outputs channel, the witness in the spending input is:
525 /// <BIP 143 signature> <witness script>
528 /// Otherwise, it is:
530 /// <BIP 143 signature> <payment key>
533 /// These are generally the result of our counterparty having broadcast the current state,
534 /// allowing us to claim the non-HTLC-encumbered outputs immediately, or after one confirmation
535 /// in the case of anchor outputs channels.
537 crate::lightning::sign::StaticPaymentOutputDescriptor),
539 use lightning::sign::SpendableOutputDescriptor as SpendableOutputDescriptorImport;
540 pub(crate) type nativeSpendableOutputDescriptor = SpendableOutputDescriptorImport;
542 impl SpendableOutputDescriptor {
544 pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor {
546 SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
547 let mut outpoint_nonref = Clone::clone(outpoint);
548 let mut output_nonref = Clone::clone(output);
549 nativeSpendableOutputDescriptor::StaticOutput {
550 outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
551 output: output_nonref.into_rust(),
554 SpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
555 let mut a_nonref = Clone::clone(a);
556 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
557 *unsafe { Box::from_raw(a_nonref.take_inner()) },
560 SpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
561 let mut a_nonref = Clone::clone(a);
562 nativeSpendableOutputDescriptor::StaticPaymentOutput (
563 *unsafe { Box::from_raw(a_nonref.take_inner()) },
569 pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor {
571 SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
572 nativeSpendableOutputDescriptor::StaticOutput {
573 outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
574 output: output.into_rust(),
577 SpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
578 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
579 *unsafe { Box::from_raw(a.take_inner()) },
582 SpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
583 nativeSpendableOutputDescriptor::StaticPaymentOutput (
584 *unsafe { Box::from_raw(a.take_inner()) },
590 pub(crate) fn from_native(native: &nativeSpendableOutputDescriptor) -> Self {
592 nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
593 let mut outpoint_nonref = Clone::clone(outpoint);
594 let mut output_nonref = Clone::clone(output);
595 SpendableOutputDescriptor::StaticOutput {
596 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true },
597 output: crate::c_types::TxOut::from_rust(&output_nonref),
600 nativeSpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
601 let mut a_nonref = Clone::clone(a);
602 SpendableOutputDescriptor::DelayedPaymentOutput (
603 crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
606 nativeSpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
607 let mut a_nonref = Clone::clone(a);
608 SpendableOutputDescriptor::StaticPaymentOutput (
609 crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
615 pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self {
617 nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
618 SpendableOutputDescriptor::StaticOutput {
619 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true },
620 output: crate::c_types::TxOut::from_rust(&output),
623 nativeSpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
624 SpendableOutputDescriptor::DelayedPaymentOutput (
625 crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
628 nativeSpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
629 SpendableOutputDescriptor::StaticPaymentOutput (
630 crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
636 /// Frees any resources used by the SpendableOutputDescriptor
638 pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { }
639 /// Creates a copy of the SpendableOutputDescriptor
641 pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor {
645 /// Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
646 pub extern "C" fn SpendableOutputDescriptor_static_output(outpoint: crate::lightning::chain::transaction::OutPoint, output: crate::c_types::TxOut) -> SpendableOutputDescriptor {
647 SpendableOutputDescriptor::StaticOutput {
653 /// Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
654 pub extern "C" fn SpendableOutputDescriptor_delayed_payment_output(a: crate::lightning::sign::DelayedPaymentOutputDescriptor) -> SpendableOutputDescriptor {
655 SpendableOutputDescriptor::DelayedPaymentOutput(a, )
658 /// Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
659 pub extern "C" fn SpendableOutputDescriptor_static_payment_output(a: crate::lightning::sign::StaticPaymentOutputDescriptor) -> SpendableOutputDescriptor {
660 SpendableOutputDescriptor::StaticPaymentOutput(a, )
662 /// Generates a non-cryptographic 64-bit hash of the SpendableOutputDescriptor.
664 pub extern "C" fn SpendableOutputDescriptor_hash(o: &SpendableOutputDescriptor) -> u64 {
665 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
667 let mut hasher = core::hash::SipHasher::new();
668 core::hash::Hash::hash(&o.to_native(), &mut hasher);
669 core::hash::Hasher::finish(&hasher)
671 /// Checks if two SpendableOutputDescriptors contain equal inner contents.
672 /// This ignores pointers and is_owned flags and looks at the values in fields.
674 pub extern "C" fn SpendableOutputDescriptor_eq(a: &SpendableOutputDescriptor, b: &SpendableOutputDescriptor) -> bool {
675 if &a.to_native() == &b.to_native() { true } else { false }
678 /// Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
679 pub extern "C" fn SpendableOutputDescriptor_write(obj: &crate::lightning::sign::SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
680 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
683 /// Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
684 pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
685 let res: Result<lightning::sign::SpendableOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
686 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() };
689 /// Creates an unsigned [`PartiallySignedTransaction`] which spends the given descriptors to
690 /// the given outputs, plus an output to the given change destination (if sufficient
691 /// change value remains). The PSBT will have a feerate, at least, of the given value.
693 /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
694 /// transaction will have a locktime of 0. It it recommended to set this to the current block
695 /// height to avoid fee sniping, unless you have some specific reason to use a different
698 /// Returns the PSBT and expected max transaction weight.
700 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
701 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
702 /// does not match the one we can spend.
704 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
707 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_u8ZusizeZNoneZ {
708 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
709 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
710 let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::PackedLockTime({ locktime_opt.take() }) }})} };
711 let mut ret = lightning::sign::SpendableOutputDescriptor::create_spendable_outputs_psbt(&local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::Script::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime);
712 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 = (::bitcoin::consensus::encode::serialize(&orig_ret_0_0).into(), orig_ret_0_1).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
716 /// A trait to handle Lightning channel key material without concretizing the channel type or
717 /// the signature mechanism.
719 pub struct ChannelSigner {
720 /// An opaque pointer which is passed to your function implementations as an argument.
721 /// This has no meaning in the LDK, and can be NULL or any other value.
722 pub this_arg: *mut c_void,
723 /// Gets the per-commitment point for a specific commitment number
725 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
726 pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey,
727 /// Gets the commitment secret for a specific commitment number as part of the revocation process
729 /// An external signer implementation should error here if the commitment was already signed
730 /// and should refuse to sign it in the future.
732 /// May be called more than once for the same index.
734 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
735 pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes,
736 /// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
738 /// This is required in order for the signer to make sure that releasing a commitment
739 /// secret won't leave us without a broadcastable holder transaction.
740 /// Policy checks should be implemented in this function, including checking the amount
741 /// sent to us and checking the HTLCs.
743 /// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
744 /// A validating signer should ensure that an HTLC output is removed only when the matching
745 /// preimage is provided, or when the value to holder is restored.
747 /// Note that all the relevant preimages will be provided, but there may also be additional
748 /// irrelevant or duplicate preimages.
749 pub validate_holder_commitment: extern "C" fn (this_arg: *const c_void, holder_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction, preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_NoneNoneZ,
750 /// Returns the holder's channel public keys and basepoints.
751 pub pubkeys: core::cell::UnsafeCell<crate::lightning::ln::chan_utils::ChannelPublicKeys>,
752 /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns
753 /// Note that this takes a pointer to this object, not the this_ptr like other methods do
754 /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
755 pub set_pubkeys: Option<extern "C" fn(&ChannelSigner)>,
756 /// Returns an arbitrary identifier describing the set of keys which are provided back to you in
757 /// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
758 /// [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
759 pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
760 /// Set the counterparty static channel data, including basepoints,
761 /// `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
763 /// This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
764 /// instance, LDK will call this method exactly once - either immediately after construction
765 /// (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
766 /// information has been generated.
768 /// channel_parameters.is_populated() MUST be true.
769 pub provide_channel_parameters: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters),
770 /// Frees any resources associated with this object given its this_arg pointer.
771 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
772 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
774 unsafe impl Send for ChannelSigner {}
775 unsafe impl Sync for ChannelSigner {}
776 pub(crate) fn ChannelSigner_clone_fields(orig: &ChannelSigner) -> ChannelSigner {
778 this_arg: orig.this_arg,
779 get_per_commitment_point: Clone::clone(&orig.get_per_commitment_point),
780 release_commitment_secret: Clone::clone(&orig.release_commitment_secret),
781 validate_holder_commitment: Clone::clone(&orig.validate_holder_commitment),
782 pubkeys: Clone::clone(unsafe { &*core::cell::UnsafeCell::get(&orig.pubkeys)}).into(),
783 set_pubkeys: Clone::clone(&orig.set_pubkeys),
784 channel_keys_id: Clone::clone(&orig.channel_keys_id),
785 provide_channel_parameters: Clone::clone(&orig.provide_channel_parameters),
786 free: Clone::clone(&orig.free),
790 use lightning::sign::ChannelSigner as rustChannelSigner;
791 impl rustChannelSigner for ChannelSigner {
792 fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
793 let mut ret = (self.get_per_commitment_point)(self.this_arg, idx);
796 fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
797 let mut ret = (self.release_commitment_secret)(self.this_arg, idx);
800 fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
801 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
802 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_preimages.into());
803 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)) })*/ })};
806 fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
807 if let Some(f) = self.set_pubkeys {
810 unsafe { &*self.pubkeys.get() }.get_native_ref()
812 fn channel_keys_id(&self) -> [u8; 32] {
813 let mut ret = (self.channel_keys_id)(self.this_arg);
816 fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
817 (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 })
821 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
822 // directly as a Deref trait in higher-level structs:
823 impl core::ops::Deref for ChannelSigner {
825 fn deref(&self) -> &Self {
829 impl core::ops::DerefMut for ChannelSigner {
830 fn deref_mut(&mut self) -> &mut Self {
834 /// Calls the free function if one is set
836 pub extern "C" fn ChannelSigner_free(this_ptr: ChannelSigner) { }
837 impl Drop for ChannelSigner {
839 if let Some(f) = self.free {
844 /// A trait to sign Lightning channel transactions as described in
845 /// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
847 /// Signing services could be implemented on a hardware wallet and should implement signing
848 /// policies in order to be secure. Please refer to the [VLS Policy
849 /// Controls](https://gitlab.com/lightning-signer/validating-lightning-signer/-/blob/main/docs/policy-controls.md)
850 /// for an example of such policies.
852 pub struct EcdsaChannelSigner {
853 /// An opaque pointer which is passed to your function implementations as an argument.
854 /// This has no meaning in the LDK, and can be NULL or any other value.
855 pub this_arg: *mut c_void,
856 /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
858 /// Note that if signing fails or is rejected, the channel will be force-closed.
860 /// Policy checks should be implemented in this function, including checking the amount
861 /// sent to us and checking the HTLCs.
863 /// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
864 /// A validating signer should ensure that an HTLC output is removed only when the matching
865 /// preimage is provided, or when the value to holder is restored.
867 /// Note that all the relevant preimages will be provided, but there may also be additional
868 /// irrelevant or duplicate preimages.
869 pub sign_counterparty_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::CommitmentTransaction, preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ,
870 /// Validate the counterparty's revocation.
872 /// This is required in order for the signer to make sure that the state has moved
873 /// forward and it is safe to sign the next counterparty commitment.
874 pub validate_counterparty_revocation: extern "C" fn (this_arg: *const c_void, idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ,
875 /// Creates a signature for a holder's commitment transaction and its claiming HTLC transactions.
877 /// This will be called
878 /// - with a non-revoked `commitment_tx`.
879 /// - with the latest `commitment_tx` when we initiate a force-close.
880 /// - with the previous `commitment_tx`, just to get claiming HTLC
881 /// signatures, if we are reacting to a [`ChannelMonitor`]
882 /// [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas)
883 /// that decided to broadcast before it had been updated to the latest `commitment_tx`.
885 /// This may be called multiple times for the same transaction.
887 /// An external signer implementation should check that the commitment has not been revoked.
889 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
890 pub sign_holder_commitment_and_htlcs: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ,
891 /// Create a signature for the given input in a transaction spending an HTLC transaction output
892 /// or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
894 /// A justice transaction may claim multiple outputs at the same time if timelocks are
895 /// similar, but only a signature for the input at index `input` should be signed for here.
896 /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
897 /// to an upcoming timelock expiration.
899 /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
901 /// `per_commitment_key` is revocation secret which was provided by our counterparty when they
902 /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
903 /// not allow the spending of any funds by itself (you need our holder `revocation_secret` to do
905 pub sign_justice_revoked_output: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32]) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
906 /// Create a signature for the given input in a transaction spending a commitment transaction
907 /// HTLC output when our counterparty broadcasts an old state.
909 /// A justice transaction may claim multiple outputs at the same time if timelocks are
910 /// similar, but only a signature for the input at index `input` should be signed for here.
911 /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
912 /// to an upcoming timelock expiration.
914 /// `amount` is the value of the output spent by this input, committed to in the BIP 143
917 /// `per_commitment_key` is revocation secret which was provided by our counterparty when they
918 /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
919 /// not allow the spending of any funds by itself (you need our holder revocation_secret to do
922 /// `htlc` holds HTLC elements (hash, timelock), thus changing the format of the witness script
923 /// (which is committed to in the BIP 143 signatures).
924 pub sign_justice_revoked_htlc: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
925 /// Computes the signature for a commitment transaction's HTLC output used as an input within
926 /// `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned
927 /// must be be computed using [`EcdsaSighashType::All`]. Note that this should only be used to
928 /// sign HTLC transactions from channels supporting anchor outputs after all additional
929 /// inputs/outputs have been added to the transaction.
931 /// [`EcdsaSighashType::All`]: bitcoin::blockdata::transaction::EcdsaSighashType::All
932 pub sign_holder_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, htlc_descriptor: &crate::lightning::events::bump_transaction::HTLCDescriptor) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
933 /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
934 /// transaction, either offered or received.
936 /// Such a transaction may claim multiples offered outputs at same time if we know the
937 /// preimage for each when we create it, but only the input at index `input` should be
938 /// signed for here. It may be called multiple times for same output(s) if a fee-bump is
939 /// needed with regards to an upcoming timelock expiration.
941 /// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
944 /// `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
946 /// `per_commitment_point` is the dynamic point corresponding to the channel state
947 /// detected onchain. It has been generated by our counterparty and is used to derive
948 /// channel state keys, which are then included in the witness script and committed to in the
949 /// BIP 143 signature.
950 pub sign_counterparty_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_point: crate::c_types::PublicKey, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
951 /// Create a signature for a (proposed) closing transaction.
953 /// Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
954 /// chosen to forgo their output as dust.
955 pub sign_closing_transaction: extern "C" fn (this_arg: *const c_void, closing_tx: &crate::lightning::ln::chan_utils::ClosingTransaction) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
956 /// Computes the signature for a commitment transaction's anchor output used as an
957 /// input within `anchor_tx`, which spends the commitment transaction, at index `input`.
958 pub sign_holder_anchor_input: extern "C" fn (this_arg: *const c_void, anchor_tx: crate::c_types::Transaction, input: usize) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
959 /// Signs a channel announcement message with our funding key proving it comes from one of the
960 /// channel participants.
962 /// Channel announcements also require a signature from each node's network key. Our node
963 /// signature is computed through [`NodeSigner::sign_gossip_message`].
965 /// Note that if this fails or is rejected, the channel will not be publicly announced and
966 /// our counterparty may (though likely will not) close the channel on us for violating the
968 pub sign_channel_announcement_with_funding_key: extern "C" fn (this_arg: *const c_void, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
969 /// Implementation of ChannelSigner for this object.
970 pub ChannelSigner: crate::lightning::sign::ChannelSigner,
971 /// Frees any resources associated with this object given its this_arg pointer.
972 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
973 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
975 unsafe impl Send for EcdsaChannelSigner {}
976 unsafe impl Sync for EcdsaChannelSigner {}
977 pub(crate) fn EcdsaChannelSigner_clone_fields(orig: &EcdsaChannelSigner) -> EcdsaChannelSigner {
979 this_arg: orig.this_arg,
980 sign_counterparty_commitment: Clone::clone(&orig.sign_counterparty_commitment),
981 validate_counterparty_revocation: Clone::clone(&orig.validate_counterparty_revocation),
982 sign_holder_commitment_and_htlcs: Clone::clone(&orig.sign_holder_commitment_and_htlcs),
983 sign_justice_revoked_output: Clone::clone(&orig.sign_justice_revoked_output),
984 sign_justice_revoked_htlc: Clone::clone(&orig.sign_justice_revoked_htlc),
985 sign_holder_htlc_transaction: Clone::clone(&orig.sign_holder_htlc_transaction),
986 sign_counterparty_htlc_transaction: Clone::clone(&orig.sign_counterparty_htlc_transaction),
987 sign_closing_transaction: Clone::clone(&orig.sign_closing_transaction),
988 sign_holder_anchor_input: Clone::clone(&orig.sign_holder_anchor_input),
989 sign_channel_announcement_with_funding_key: Clone::clone(&orig.sign_channel_announcement_with_funding_key),
990 ChannelSigner: crate::lightning::sign::ChannelSigner_clone_fields(&orig.ChannelSigner),
991 free: Clone::clone(&orig.free),
994 impl lightning::sign::ChannelSigner for EcdsaChannelSigner {
995 fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
996 let mut ret = (self.ChannelSigner.get_per_commitment_point)(self.ChannelSigner.this_arg, idx);
999 fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
1000 let mut ret = (self.ChannelSigner.release_commitment_secret)(self.ChannelSigner.this_arg, idx);
1003 fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
1004 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1005 let mut ret = (self.ChannelSigner.validate_holder_commitment)(self.ChannelSigner.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_preimages.into());
1006 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)) })*/ })};
1009 fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
1010 if let Some(f) = self.ChannelSigner.set_pubkeys {
1011 (f)(&self.ChannelSigner);
1013 unsafe { &*self.ChannelSigner.pubkeys.get() }.get_native_ref()
1015 fn channel_keys_id(&self) -> [u8; 32] {
1016 let mut ret = (self.ChannelSigner.channel_keys_id)(self.ChannelSigner.this_arg);
1019 fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
1020 (self.ChannelSigner.provide_channel_parameters)(self.ChannelSigner.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 })
1024 use lightning::sign::EcdsaChannelSigner as rustEcdsaChannelSigner;
1025 impl rustEcdsaChannelSigner for EcdsaChannelSigner {
1026 fn sign_counterparty_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec<bitcoin::secp256k1::ecdsa::Signature>), ()> {
1027 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1028 let mut ret = (self.sign_counterparty_commitment)(self.this_arg, &crate::lightning::ln::chan_utils::CommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::CommitmentTransaction<>) as *mut _) }, is_owned: false }, local_preimages.into());
1029 let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1032 fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
1033 let mut ret = (self.validate_counterparty_revocation)(self.this_arg, idx, secret.as_ref());
1034 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)) })*/ })};
1037 fn sign_holder_commitment_and_htlcs(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec<bitcoin::secp256k1::ecdsa::Signature>), ()> {
1038 let mut ret = (self.sign_holder_commitment_and_htlcs)(self.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false });
1039 let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1042 fn sign_justice_revoked_output(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1043 let mut ret = (self.sign_justice_revoked_output)(self.this_arg, crate::c_types::Transaction::from_bitcoin(justice_tx), input, amount, per_commitment_key.as_ref());
1044 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)) })*/ })};
1047 fn sign_justice_revoked_htlc(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1048 let mut ret = (self.sign_justice_revoked_htlc)(self.this_arg, crate::c_types::Transaction::from_bitcoin(justice_tx), input, amount, per_commitment_key.as_ref(), &crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false });
1049 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)) })*/ })};
1052 fn sign_holder_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut htlc_descriptor: &lightning::events::bump_transaction::HTLCDescriptor, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1053 let mut ret = (self.sign_holder_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, &crate::lightning::events::bump_transaction::HTLCDescriptor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc_descriptor as *const lightning::events::bump_transaction::HTLCDescriptor<>) as *mut _) }, is_owned: false });
1054 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)) })*/ })};
1057 fn sign_counterparty_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: &bitcoin::secp256k1::PublicKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1058 let mut ret = (self.sign_counterparty_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, amount, crate::c_types::PublicKey::from_rust(&per_commitment_point), &crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false });
1059 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)) })*/ })};
1062 fn sign_closing_transaction(&self, mut closing_tx: &lightning::ln::chan_utils::ClosingTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1063 let mut ret = (self.sign_closing_transaction)(self.this_arg, &crate::lightning::ln::chan_utils::ClosingTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((closing_tx as *const lightning::ln::chan_utils::ClosingTransaction<>) as *mut _) }, is_owned: false });
1064 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)) })*/ })};
1067 fn sign_holder_anchor_input(&self, mut anchor_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1068 let mut ret = (self.sign_holder_anchor_input)(self.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
1069 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)) })*/ })};
1072 fn sign_channel_announcement_with_funding_key(&self, mut msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1073 let mut ret = (self.sign_channel_announcement_with_funding_key)(self.this_arg, &crate::lightning::ln::msgs::UnsignedChannelAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::UnsignedChannelAnnouncement<>) as *mut _) }, is_owned: false });
1074 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)) })*/ })};
1079 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1080 // directly as a Deref trait in higher-level structs:
1081 impl core::ops::Deref for EcdsaChannelSigner {
1083 fn deref(&self) -> &Self {
1087 impl core::ops::DerefMut for EcdsaChannelSigner {
1088 fn deref_mut(&mut self) -> &mut Self {
1092 /// Calls the free function if one is set
1094 pub extern "C" fn EcdsaChannelSigner_free(this_ptr: EcdsaChannelSigner) { }
1095 impl Drop for EcdsaChannelSigner {
1096 fn drop(&mut self) {
1097 if let Some(f) = self.free {
1102 /// A writeable signer.
1104 /// There will always be two instances of a signer per channel, one occupied by the
1105 /// [`ChannelManager`] and another by the channel's [`ChannelMonitor`].
1107 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1108 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
1110 pub struct WriteableEcdsaChannelSigner {
1111 /// An opaque pointer which is passed to your function implementations as an argument.
1112 /// This has no meaning in the LDK, and can be NULL or any other value.
1113 pub this_arg: *mut c_void,
1114 /// Implementation of EcdsaChannelSigner for this object.
1115 pub EcdsaChannelSigner: crate::lightning::sign::EcdsaChannelSigner,
1116 /// Serialize the object into a byte array
1117 pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
1118 /// Called, if set, after this WriteableEcdsaChannelSigner has been cloned into a duplicate object.
1119 /// The new WriteableEcdsaChannelSigner is provided, and should be mutated as needed to perform a
1120 /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
1121 pub cloned: Option<extern "C" fn (new_WriteableEcdsaChannelSigner: &mut WriteableEcdsaChannelSigner)>,
1122 /// Frees any resources associated with this object given its this_arg pointer.
1123 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1124 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1126 unsafe impl Send for WriteableEcdsaChannelSigner {}
1127 unsafe impl Sync for WriteableEcdsaChannelSigner {}
1128 pub(crate) fn WriteableEcdsaChannelSigner_clone_fields(orig: &WriteableEcdsaChannelSigner) -> WriteableEcdsaChannelSigner {
1129 WriteableEcdsaChannelSigner {
1130 this_arg: orig.this_arg,
1131 EcdsaChannelSigner: crate::lightning::sign::EcdsaChannelSigner_clone_fields(&orig.EcdsaChannelSigner),
1132 write: Clone::clone(&orig.write),
1133 cloned: Clone::clone(&orig.cloned),
1134 free: Clone::clone(&orig.free),
1137 impl lightning::sign::EcdsaChannelSigner for WriteableEcdsaChannelSigner {
1138 fn sign_counterparty_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec<bitcoin::secp256k1::ecdsa::Signature>), ()> {
1139 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1140 let mut ret = (self.EcdsaChannelSigner.sign_counterparty_commitment)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::chan_utils::CommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::CommitmentTransaction<>) as *mut _) }, is_owned: false }, local_preimages.into());
1141 let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1144 fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
1145 let mut ret = (self.EcdsaChannelSigner.validate_counterparty_revocation)(self.EcdsaChannelSigner.this_arg, idx, secret.as_ref());
1146 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)) })*/ })};
1149 fn sign_holder_commitment_and_htlcs(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec<bitcoin::secp256k1::ecdsa::Signature>), ()> {
1150 let mut ret = (self.EcdsaChannelSigner.sign_holder_commitment_and_htlcs)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false });
1151 let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1154 fn sign_justice_revoked_output(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1155 let mut ret = (self.EcdsaChannelSigner.sign_justice_revoked_output)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(justice_tx), input, amount, per_commitment_key.as_ref());
1156 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)) })*/ })};
1159 fn sign_justice_revoked_htlc(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1160 let mut ret = (self.EcdsaChannelSigner.sign_justice_revoked_htlc)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(justice_tx), input, amount, per_commitment_key.as_ref(), &crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false });
1161 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)) })*/ })};
1164 fn sign_holder_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut htlc_descriptor: &lightning::events::bump_transaction::HTLCDescriptor, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1165 let mut ret = (self.EcdsaChannelSigner.sign_holder_htlc_transaction)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, &crate::lightning::events::bump_transaction::HTLCDescriptor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc_descriptor as *const lightning::events::bump_transaction::HTLCDescriptor<>) as *mut _) }, is_owned: false });
1166 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)) })*/ })};
1169 fn sign_counterparty_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: &bitcoin::secp256k1::PublicKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1170 let mut ret = (self.EcdsaChannelSigner.sign_counterparty_htlc_transaction)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, amount, crate::c_types::PublicKey::from_rust(&per_commitment_point), &crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false });
1171 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)) })*/ })};
1174 fn sign_closing_transaction(&self, mut closing_tx: &lightning::ln::chan_utils::ClosingTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1175 let mut ret = (self.EcdsaChannelSigner.sign_closing_transaction)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::chan_utils::ClosingTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((closing_tx as *const lightning::ln::chan_utils::ClosingTransaction<>) as *mut _) }, is_owned: false });
1176 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)) })*/ })};
1179 fn sign_holder_anchor_input(&self, mut anchor_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1180 let mut ret = (self.EcdsaChannelSigner.sign_holder_anchor_input)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
1181 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)) })*/ })};
1184 fn sign_channel_announcement_with_funding_key(&self, mut msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1185 let mut ret = (self.EcdsaChannelSigner.sign_channel_announcement_with_funding_key)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::msgs::UnsignedChannelAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::UnsignedChannelAnnouncement<>) as *mut _) }, is_owned: false });
1186 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)) })*/ })};
1190 impl lightning::sign::ChannelSigner for WriteableEcdsaChannelSigner {
1191 fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
1192 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.get_per_commitment_point)(self.EcdsaChannelSigner.ChannelSigner.this_arg, idx);
1195 fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
1196 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.release_commitment_secret)(self.EcdsaChannelSigner.ChannelSigner.this_arg, idx);
1199 fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
1200 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1201 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.validate_holder_commitment)(self.EcdsaChannelSigner.ChannelSigner.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_preimages.into());
1202 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)) })*/ })};
1205 fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
1206 if let Some(f) = self.EcdsaChannelSigner.ChannelSigner.set_pubkeys {
1207 (f)(&self.EcdsaChannelSigner.ChannelSigner);
1209 unsafe { &*self.EcdsaChannelSigner.ChannelSigner.pubkeys.get() }.get_native_ref()
1211 fn channel_keys_id(&self) -> [u8; 32] {
1212 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.channel_keys_id)(self.EcdsaChannelSigner.ChannelSigner.this_arg);
1215 fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
1216 (self.EcdsaChannelSigner.ChannelSigner.provide_channel_parameters)(self.EcdsaChannelSigner.ChannelSigner.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 })
1219 impl lightning::util::ser::Writeable for WriteableEcdsaChannelSigner {
1220 fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
1221 let vec = (self.write)(self.this_arg);
1222 w.write_all(vec.as_slice())
1226 /// Creates a copy of a WriteableEcdsaChannelSigner
1227 pub extern "C" fn WriteableEcdsaChannelSigner_clone(orig: &WriteableEcdsaChannelSigner) -> WriteableEcdsaChannelSigner {
1228 let mut res = WriteableEcdsaChannelSigner_clone_fields(orig);
1229 if let Some(f) = orig.cloned { (f)(&mut res) };
1232 impl Clone for WriteableEcdsaChannelSigner {
1233 fn clone(&self) -> Self {
1234 WriteableEcdsaChannelSigner_clone(self)
1238 use lightning::sign::WriteableEcdsaChannelSigner as rustWriteableEcdsaChannelSigner;
1239 impl rustWriteableEcdsaChannelSigner for WriteableEcdsaChannelSigner {
1242 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1243 // directly as a Deref trait in higher-level structs:
1244 impl core::ops::Deref for WriteableEcdsaChannelSigner {
1246 fn deref(&self) -> &Self {
1250 impl core::ops::DerefMut for WriteableEcdsaChannelSigner {
1251 fn deref_mut(&mut self) -> &mut Self {
1255 /// Calls the free function if one is set
1257 pub extern "C" fn WriteableEcdsaChannelSigner_free(this_ptr: WriteableEcdsaChannelSigner) { }
1258 impl Drop for WriteableEcdsaChannelSigner {
1259 fn drop(&mut self) {
1260 if let Some(f) = self.free {
1265 /// Specifies the recipient of an invoice.
1267 /// This indicates to [`NodeSigner::sign_invoice`] what node secret key should be used to sign
1272 pub enum Recipient {
1273 /// The invoice should be signed with the local node secret key.
1275 /// The invoice should be signed with the phantom node secret key. This secret key must be the
1276 /// same for all nodes participating in the [phantom node payment].
1278 /// [phantom node payment]: PhantomKeysManager
1281 use lightning::sign::Recipient as RecipientImport;
1282 pub(crate) type nativeRecipient = RecipientImport;
1286 pub(crate) fn to_native(&self) -> nativeRecipient {
1288 Recipient::Node => nativeRecipient::Node,
1289 Recipient::PhantomNode => nativeRecipient::PhantomNode,
1293 pub(crate) fn into_native(self) -> nativeRecipient {
1295 Recipient::Node => nativeRecipient::Node,
1296 Recipient::PhantomNode => nativeRecipient::PhantomNode,
1300 pub(crate) fn from_native(native: &nativeRecipient) -> Self {
1302 nativeRecipient::Node => Recipient::Node,
1303 nativeRecipient::PhantomNode => Recipient::PhantomNode,
1307 pub(crate) fn native_into(native: nativeRecipient) -> Self {
1309 nativeRecipient::Node => Recipient::Node,
1310 nativeRecipient::PhantomNode => Recipient::PhantomNode,
1314 /// Creates a copy of the Recipient
1316 pub extern "C" fn Recipient_clone(orig: &Recipient) -> Recipient {
1320 /// Utility method to constructs a new Node-variant Recipient
1321 pub extern "C" fn Recipient_node() -> Recipient {
1324 /// Utility method to constructs a new PhantomNode-variant Recipient
1325 pub extern "C" fn Recipient_phantom_node() -> Recipient {
1326 Recipient::PhantomNode}
1327 /// A trait that describes a source of entropy.
1329 pub struct EntropySource {
1330 /// An opaque pointer which is passed to your function implementations as an argument.
1331 /// This has no meaning in the LDK, and can be NULL or any other value.
1332 pub this_arg: *mut c_void,
1333 /// Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
1334 /// different value each time it is called.
1335 pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1336 /// Frees any resources associated with this object given its this_arg pointer.
1337 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1338 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1340 unsafe impl Send for EntropySource {}
1341 unsafe impl Sync for EntropySource {}
1342 pub(crate) fn EntropySource_clone_fields(orig: &EntropySource) -> EntropySource {
1344 this_arg: orig.this_arg,
1345 get_secure_random_bytes: Clone::clone(&orig.get_secure_random_bytes),
1346 free: Clone::clone(&orig.free),
1350 use lightning::sign::EntropySource as rustEntropySource;
1351 impl rustEntropySource for EntropySource {
1352 fn get_secure_random_bytes(&self) -> [u8; 32] {
1353 let mut ret = (self.get_secure_random_bytes)(self.this_arg);
1358 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1359 // directly as a Deref trait in higher-level structs:
1360 impl core::ops::Deref for EntropySource {
1362 fn deref(&self) -> &Self {
1366 impl core::ops::DerefMut for EntropySource {
1367 fn deref_mut(&mut self) -> &mut Self {
1371 /// Calls the free function if one is set
1373 pub extern "C" fn EntropySource_free(this_ptr: EntropySource) { }
1374 impl Drop for EntropySource {
1375 fn drop(&mut self) {
1376 if let Some(f) = self.free {
1381 /// A trait that can handle cryptographic operations at the scope level of a node.
1383 pub struct NodeSigner {
1384 /// An opaque pointer which is passed to your function implementations as an argument.
1385 /// This has no meaning in the LDK, and can be NULL or any other value.
1386 pub this_arg: *mut c_void,
1387 /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
1389 /// If the implementor of this trait supports [phantom node payments], then every node that is
1390 /// intended to be included in the phantom invoice route hints must return the same value from
1393 /// This method must return the same value each time it is called.
1395 /// [phantom node payments]: PhantomKeysManager
1396 pub get_inbound_payment_key_material: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1397 /// Get node id based on the provided [`Recipient`].
1399 /// This method must return the same value each time it is called with a given [`Recipient`]
1402 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1403 pub get_node_id: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ,
1404 /// Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
1405 /// one is provided. Note that this tweak can be applied to `other_key` instead of our node
1406 /// secret, though this is less efficient.
1408 /// Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
1409 /// should be resolved to allow LDK to resume forwarding HTLCs.
1411 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1412 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,
1413 /// Sign an invoice.
1415 /// By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
1416 /// this trait to parse the invoice and make sure they're signing what they expect, rather than
1417 /// blindly signing the hash.
1419 /// The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
1421 /// The secret key used to sign the invoice is dependent on the [`Recipient`].
1423 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1424 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,
1425 /// Signs the [`TaggedHash`] of a BOLT 12 invoice request.
1427 /// May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
1428 /// `invoice_request` is the callee.
1430 /// Implementors may check that the `invoice_request` is expected rather than blindly signing
1431 /// the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
1432 /// the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
1433 /// [`UnsignedInvoiceRequest::payer_id`].
1435 /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
1436 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,
1437 /// Signs the [`TaggedHash`] of a BOLT 12 invoice.
1439 /// May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
1442 /// Implementors may check that the `invoice` is expected rather than blindly signing the tagged
1443 /// hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
1444 /// key or an ephemeral key to preserve privacy, whichever is associated with
1445 /// [`UnsignedBolt12Invoice::signing_pubkey`].
1447 /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
1448 pub sign_bolt12_invoice: extern "C" fn (this_arg: *const c_void, invoice: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ,
1449 /// Sign a gossip message.
1451 /// Note that if this fails, LDK may panic and the message will not be broadcast to the network
1452 /// or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
1453 /// message to be broadcast, as otherwise it may prevent one from receiving funds over the
1454 /// corresponding channel.
1455 pub sign_gossip_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
1456 /// Frees any resources associated with this object given its this_arg pointer.
1457 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1458 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1460 unsafe impl Send for NodeSigner {}
1461 unsafe impl Sync for NodeSigner {}
1462 pub(crate) fn NodeSigner_clone_fields(orig: &NodeSigner) -> NodeSigner {
1464 this_arg: orig.this_arg,
1465 get_inbound_payment_key_material: Clone::clone(&orig.get_inbound_payment_key_material),
1466 get_node_id: Clone::clone(&orig.get_node_id),
1467 ecdh: Clone::clone(&orig.ecdh),
1468 sign_invoice: Clone::clone(&orig.sign_invoice),
1469 sign_bolt12_invoice_request: Clone::clone(&orig.sign_bolt12_invoice_request),
1470 sign_bolt12_invoice: Clone::clone(&orig.sign_bolt12_invoice),
1471 sign_gossip_message: Clone::clone(&orig.sign_gossip_message),
1472 free: Clone::clone(&orig.free),
1476 use lightning::sign::NodeSigner as rustNodeSigner;
1477 impl rustNodeSigner for NodeSigner {
1478 fn get_inbound_payment_key_material(&self) -> lightning::sign::KeyMaterial {
1479 let mut ret = (self.get_inbound_payment_key_material)(self.this_arg);
1480 ::lightning::sign::KeyMaterial(ret.data)
1482 fn get_node_id(&self, mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::PublicKey, ()> {
1483 let mut ret = (self.get_node_id)(self.this_arg, crate::lightning::sign::Recipient::native_into(recipient));
1484 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)) })*/ })};
1487 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, ()> {
1488 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()) }) };
1489 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);
1490 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)) })*/ })};
1493 fn sign_invoice(&self, mut hrp_bytes: &[u8], mut invoice_data: &[bitcoin::bech32::u5], mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
1494 let mut local_hrp_bytes = crate::c_types::u8slice::from_slice(hrp_bytes);
1495 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() }); };
1496 let mut ret = (self.sign_invoice)(self.this_arg, local_hrp_bytes, local_invoice_data.into(), crate::lightning::sign::Recipient::native_into(recipient));
1497 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)) })*/ })};
1500 fn sign_bolt12_invoice_request(&self, mut invoice_request: &lightning::offers::invoice_request::UnsignedInvoiceRequest) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
1501 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 });
1502 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)) })*/ })};
1505 fn sign_bolt12_invoice(&self, mut invoice: &lightning::offers::invoice::UnsignedBolt12Invoice) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
1506 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 });
1507 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)) })*/ })};
1510 fn sign_gossip_message(&self, mut msg: lightning::ln::msgs::UnsignedGossipMessage) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1511 let mut ret = (self.sign_gossip_message)(self.this_arg, crate::lightning::ln::msgs::UnsignedGossipMessage::native_into(msg));
1512 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)) })*/ })};
1517 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1518 // directly as a Deref trait in higher-level structs:
1519 impl core::ops::Deref for NodeSigner {
1521 fn deref(&self) -> &Self {
1525 impl core::ops::DerefMut for NodeSigner {
1526 fn deref_mut(&mut self) -> &mut Self {
1530 /// Calls the free function if one is set
1532 pub extern "C" fn NodeSigner_free(this_ptr: NodeSigner) { }
1533 impl Drop for NodeSigner {
1534 fn drop(&mut self) {
1535 if let Some(f) = self.free {
1540 /// A trait that can return signer instances for individual channels.
1542 pub struct SignerProvider {
1543 /// An opaque pointer which is passed to your function implementations as an argument.
1544 /// This has no meaning in the LDK, and can be NULL or any other value.
1545 pub this_arg: *mut c_void,
1546 /// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
1547 /// [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
1548 /// implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
1549 /// `channel_keys_id`.
1551 /// This method must return a different value each time it is called.
1552 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,
1553 /// Derives the private key material backing a `Signer`.
1555 /// To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
1556 /// [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
1557 /// re-derived from its `channel_keys_id`, which can be obtained through its trait method
1558 /// [`ChannelSigner::channel_keys_id`].
1559 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::WriteableEcdsaChannelSigner,
1560 /// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
1561 /// This is only called during deserialization of other objects which contain
1562 /// [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
1563 /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
1564 /// contain no versioning scheme. You may wish to include your own version prefix and ensure
1565 /// you've read all of the provided bytes to ensure no corruption occurred.
1567 /// This method is slowly being phased out -- it will only be called when reading objects
1568 /// written by LDK versions prior to 0.0.113.
1570 /// [`Signer`]: Self::Signer
1571 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
1572 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1573 pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ,
1574 /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
1576 /// If this function returns an error, this will result in a channel failing to open.
1578 /// This method should return a different value each time it is called, to avoid linking
1579 /// on-chain funds across channels as controlled to the same user.
1580 pub get_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ,
1581 /// Get a script pubkey which we will send funds to when closing a channel.
1583 /// If this function returns an error, this will result in a channel failing to open or close.
1584 /// In the event of a failure when the counterparty is initiating a close, this can result in a
1585 /// channel force close.
1587 /// This method should return a different value each time it is called, to avoid linking
1588 /// on-chain funds across channels as controlled to the same user.
1589 pub get_shutdown_scriptpubkey: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ,
1590 /// Frees any resources associated with this object given its this_arg pointer.
1591 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1592 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1594 unsafe impl Send for SignerProvider {}
1595 unsafe impl Sync for SignerProvider {}
1596 pub(crate) fn SignerProvider_clone_fields(orig: &SignerProvider) -> SignerProvider {
1598 this_arg: orig.this_arg,
1599 generate_channel_keys_id: Clone::clone(&orig.generate_channel_keys_id),
1600 derive_channel_signer: Clone::clone(&orig.derive_channel_signer),
1601 read_chan_signer: Clone::clone(&orig.read_chan_signer),
1602 get_destination_script: Clone::clone(&orig.get_destination_script),
1603 get_shutdown_scriptpubkey: Clone::clone(&orig.get_shutdown_scriptpubkey),
1604 free: Clone::clone(&orig.free),
1608 use lightning::sign::SignerProvider as rustSignerProvider;
1609 impl rustSignerProvider for SignerProvider {
1610 type Signer = crate::lightning::sign::WriteableEcdsaChannelSigner;
1611 fn generate_channel_keys_id(&self, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: u128) -> [u8; 32] {
1612 let mut ret = (self.generate_channel_keys_id)(self.this_arg, inbound, channel_value_satoshis, user_channel_id.into());
1615 fn derive_channel_signer(&self, mut channel_value_satoshis: u64, mut channel_keys_id: [u8; 32]) -> crate::lightning::sign::WriteableEcdsaChannelSigner {
1616 let mut ret = (self.derive_channel_signer)(self.this_arg, channel_value_satoshis, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
1619 fn read_chan_signer(&self, mut reader: &[u8]) -> Result<crate::lightning::sign::WriteableEcdsaChannelSigner, lightning::ln::msgs::DecodeError> {
1620 let mut local_reader = crate::c_types::u8slice::from_slice(reader);
1621 let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
1622 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() })};
1625 fn get_destination_script(&self) -> Result<bitcoin::blockdata::script::Script, ()> {
1626 let mut ret = (self.get_destination_script)(self.this_arg);
1627 let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::blockdata::script::Script::from((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust()) }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1630 fn get_shutdown_scriptpubkey(&self) -> Result<lightning::ln::script::ShutdownScript, ()> {
1631 let mut ret = (self.get_shutdown_scriptpubkey)(self.this_arg);
1632 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)) })*/ })};
1637 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1638 // directly as a Deref trait in higher-level structs:
1639 impl core::ops::Deref for SignerProvider {
1641 fn deref(&self) -> &Self {
1645 impl core::ops::DerefMut for SignerProvider {
1646 fn deref_mut(&mut self) -> &mut Self {
1650 /// Calls the free function if one is set
1652 pub extern "C" fn SignerProvider_free(this_ptr: SignerProvider) { }
1653 impl Drop for SignerProvider {
1654 fn drop(&mut self) {
1655 if let Some(f) = self.free {
1661 use lightning::sign::InMemorySigner as nativeInMemorySignerImport;
1662 pub(crate) type nativeInMemorySigner = nativeInMemorySignerImport;
1664 /// A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
1666 /// This implementation performs no policy checks and is insufficient by itself as
1667 /// a secure external signer.
1670 pub struct InMemorySigner {
1671 /// A pointer to the opaque Rust object.
1673 /// Nearly everywhere, inner must be non-null, however in places where
1674 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1675 pub inner: *mut nativeInMemorySigner,
1676 /// Indicates that this is the only struct which contains the same pointer.
1678 /// Rust functions which take ownership of an object provided via an argument require
1679 /// this to be true and invalidate the object pointed to by inner.
1683 impl Drop for InMemorySigner {
1684 fn drop(&mut self) {
1685 if self.is_owned && !<*mut nativeInMemorySigner>::is_null(self.inner) {
1686 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1690 /// Frees any resources used by the InMemorySigner, if is_owned is set and inner is non-NULL.
1692 pub extern "C" fn InMemorySigner_free(this_obj: InMemorySigner) { }
1694 /// Used only if an object of this type is returned as a trait impl by a method
1695 pub(crate) extern "C" fn InMemorySigner_free_void(this_ptr: *mut c_void) {
1696 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInMemorySigner) };
1699 impl InMemorySigner {
1700 pub(crate) fn get_native_ref(&self) -> &'static nativeInMemorySigner {
1701 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1703 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInMemorySigner {
1704 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1706 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1707 pub(crate) fn take_inner(mut self) -> *mut nativeInMemorySigner {
1708 assert!(self.is_owned);
1709 let ret = ObjOps::untweak_ptr(self.inner);
1710 self.inner = core::ptr::null_mut();
1714 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1715 /// holder's anchor output in a commitment transaction, if one is present.
1717 pub extern "C" fn InMemorySigner_get_funding_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1718 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_key;
1721 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1722 /// holder's anchor output in a commitment transaction, if one is present.
1724 pub extern "C" fn InMemorySigner_set_funding_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1725 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_key = val.into_rust();
1727 /// Holder secret key for blinded revocation pubkey.
1729 pub extern "C" fn InMemorySigner_get_revocation_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1730 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_base_key;
1733 /// Holder secret key for blinded revocation pubkey.
1735 pub extern "C" fn InMemorySigner_set_revocation_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1736 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_base_key = val.into_rust();
1738 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1740 pub extern "C" fn InMemorySigner_get_payment_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1741 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_key;
1744 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1746 pub extern "C" fn InMemorySigner_set_payment_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1747 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_key = val.into_rust();
1749 /// Holder secret key used in an HTLC transaction.
1751 pub extern "C" fn InMemorySigner_get_delayed_payment_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1752 let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_base_key;
1755 /// Holder secret key used in an HTLC transaction.
1757 pub extern "C" fn InMemorySigner_set_delayed_payment_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1758 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_base_key = val.into_rust();
1760 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1762 pub extern "C" fn InMemorySigner_get_htlc_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1763 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_base_key;
1766 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1768 pub extern "C" fn InMemorySigner_set_htlc_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1769 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_base_key = val.into_rust();
1771 /// Commitment seed.
1773 pub extern "C" fn InMemorySigner_get_commitment_seed(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1774 let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_seed;
1777 /// Commitment seed.
1779 pub extern "C" fn InMemorySigner_set_commitment_seed(this_ptr: &mut InMemorySigner, mut val: crate::c_types::ThirtyTwoBytes) {
1780 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_seed = val.data;
1782 impl Clone for InMemorySigner {
1783 fn clone(&self) -> Self {
1785 inner: if <*mut nativeInMemorySigner>::is_null(self.inner) { core::ptr::null_mut() } else {
1786 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1792 /// Used only if an object of this type is returned as a trait impl by a method
1793 pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void {
1794 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInMemorySigner)).clone() })) as *mut c_void
1797 /// Creates a copy of the InMemorySigner
1798 pub extern "C" fn InMemorySigner_clone(orig: &InMemorySigner) -> InMemorySigner {
1801 /// Creates a new [`InMemorySigner`].
1804 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 {
1805 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);
1806 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
1809 /// Returns the counterparty's pubkeys.
1811 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1812 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1814 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1817 pub extern "C" fn InMemorySigner_counterparty_pubkeys(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1818 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_pubkeys();
1819 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 };
1823 /// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
1824 /// transactions, i.e., the amount of time that we have to wait to recover our funds if we
1825 /// broadcast a transaction.
1827 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1828 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1831 pub extern "C" fn InMemorySigner_counterparty_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_u16Z {
1832 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_selected_contest_delay();
1833 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() }) };
1837 /// Returns the `contest_delay` value specified by us and applied on transactions broadcastable
1838 /// by our counterparty, i.e., the amount of time that they have to wait to recover their funds
1839 /// if they broadcast a transaction.
1841 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1842 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1845 pub extern "C" fn InMemorySigner_holder_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_u16Z {
1846 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.holder_selected_contest_delay();
1847 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() }) };
1851 /// Returns whether the holder is the initiator.
1853 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1854 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1857 pub extern "C" fn InMemorySigner_is_outbound(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_boolZ {
1858 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
1859 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() }) };
1863 /// Funding outpoint
1865 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1866 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1868 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1871 pub extern "C" fn InMemorySigner_funding_outpoint(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::chain::transaction::OutPoint {
1872 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
1873 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 };
1877 /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
1878 /// building transactions.
1880 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1881 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1883 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1886 pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
1887 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_channel_parameters();
1888 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 };
1892 /// Returns the channel type features of the channel parameters. Should be helpful for
1893 /// determining a channel's category, i. e. legacy/anchors/taproot/etc.
1895 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
1896 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
1898 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1901 pub extern "C" fn InMemorySigner_channel_type_features(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::features::ChannelTypeFeatures {
1902 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_type_features();
1903 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 };
1907 /// Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
1908 /// by `descriptor`, returning the witness stack for the input.
1910 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
1911 /// is not spending the outpoint described by [`descriptor.outpoint`],
1912 /// or if an output descriptor `script_pubkey` does not match the one we can spend.
1914 /// [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
1917 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_CVec_CVec_u8ZZNoneZ {
1918 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);
1919 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { let mut local_ret_0_0 = Vec::new(); for mut item in item.drain(..) { local_ret_0_0.push( { item }); }; local_ret_0_0.into() }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1923 /// Sign the single input of `spend_tx` at index `input_idx` which spends the output
1924 /// described by `descriptor`, returning the witness stack for the input.
1926 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
1927 /// is not spending the outpoint described by [`descriptor.outpoint`], does not have a
1928 /// sequence set to [`descriptor.to_self_delay`], or if an output descriptor
1929 /// `script_pubkey` does not match the one we can spend.
1931 /// [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
1932 /// [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
1935 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_CVec_CVec_u8ZZNoneZ {
1936 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);
1937 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { let mut local_ret_0_0 = Vec::new(); for mut item in item.drain(..) { local_ret_0_0.push( { item }); }; local_ret_0_0.into() }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1941 impl From<nativeInMemorySigner> for crate::lightning::sign::EntropySource {
1942 fn from(obj: nativeInMemorySigner) -> Self {
1943 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1944 let mut ret = InMemorySigner_as_EntropySource(&rust_obj);
1945 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1946 rust_obj.inner = core::ptr::null_mut();
1947 ret.free = Some(InMemorySigner_free_void);
1951 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
1952 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
1954 pub extern "C" fn InMemorySigner_as_EntropySource(this_arg: &InMemorySigner) -> crate::lightning::sign::EntropySource {
1955 crate::lightning::sign::EntropySource {
1956 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1958 get_secure_random_bytes: InMemorySigner_EntropySource_get_secure_random_bytes,
1963 extern "C" fn InMemorySigner_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1964 let mut ret = <nativeInMemorySigner as lightning::sign::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1965 crate::c_types::ThirtyTwoBytes { data: ret }
1968 impl From<nativeInMemorySigner> for crate::lightning::sign::ChannelSigner {
1969 fn from(obj: nativeInMemorySigner) -> Self {
1970 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1971 let mut ret = InMemorySigner_as_ChannelSigner(&rust_obj);
1972 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1973 rust_obj.inner = core::ptr::null_mut();
1974 ret.free = Some(InMemorySigner_free_void);
1978 /// Constructs a new ChannelSigner which calls the relevant methods on this_arg.
1979 /// This copies the `inner` pointer in this_arg and thus the returned ChannelSigner must be freed before this_arg is
1981 pub extern "C" fn InMemorySigner_as_ChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ChannelSigner {
1982 crate::lightning::sign::ChannelSigner {
1983 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1985 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
1986 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
1987 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
1989 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
1990 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
1991 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
1992 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
1997 extern "C" fn InMemorySigner_ChannelSigner_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey {
1998 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::get_per_commitment_point(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, secp256k1::global::SECP256K1);
1999 crate::c_types::PublicKey::from_rust(&ret)
2002 extern "C" fn InMemorySigner_ChannelSigner_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
2003 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::release_commitment_secret(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx);
2004 crate::c_types::ThirtyTwoBytes { data: ret }
2007 extern "C" fn InMemorySigner_ChannelSigner_validate_holder_commitment(this_arg: *const c_void, holder_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_NoneNoneZ {
2008 let mut local_preimages = Vec::new(); for mut item in preimages.into_rust().drain(..) { local_preimages.push( { ::lightning::ln::PaymentPreimage(item.data) }); };
2009 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::validate_holder_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, holder_tx.get_native_ref(), local_preimages);
2010 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() };
2014 extern "C" fn InMemorySigner_ChannelSigner_pubkeys(this_arg: *const c_void) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
2015 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::pubkeys(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2016 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 }
2018 extern "C" fn InMemorySigner_ChannelSigner_set_pubkeys(trait_self_arg: &ChannelSigner) {
2019 // This is a bit race-y in the general case, but for our specific use-cases today, we're safe
2020 // Specifically, we must ensure that the first time we're called it can never be in parallel
2021 if unsafe { &*trait_self_arg.pubkeys.get() }.inner.is_null() {
2022 *unsafe { &mut *(&*(trait_self_arg as *const ChannelSigner)).pubkeys.get() } = InMemorySigner_ChannelSigner_pubkeys(trait_self_arg.this_arg).into();
2026 extern "C" fn InMemorySigner_ChannelSigner_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2027 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::channel_keys_id(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2028 crate::c_types::ThirtyTwoBytes { data: ret }
2030 extern "C" fn InMemorySigner_ChannelSigner_provide_channel_parameters(this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
2031 <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::provide_channel_parameters(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, channel_parameters.get_native_ref())
2034 impl From<nativeInMemorySigner> for crate::lightning::sign::EcdsaChannelSigner {
2035 fn from(obj: nativeInMemorySigner) -> Self {
2036 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2037 let mut ret = InMemorySigner_as_EcdsaChannelSigner(&rust_obj);
2038 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2039 rust_obj.inner = core::ptr::null_mut();
2040 ret.free = Some(InMemorySigner_free_void);
2044 /// Constructs a new EcdsaChannelSigner which calls the relevant methods on this_arg.
2045 /// This copies the `inner` pointer in this_arg and thus the returned EcdsaChannelSigner must be freed before this_arg is
2047 pub extern "C" fn InMemorySigner_as_EcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::EcdsaChannelSigner {
2048 crate::lightning::sign::EcdsaChannelSigner {
2049 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2051 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
2052 validate_counterparty_revocation: InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation,
2053 sign_holder_commitment_and_htlcs: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs,
2054 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
2055 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
2056 sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
2057 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
2058 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
2059 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
2060 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
2061 ChannelSigner: crate::lightning::sign::ChannelSigner {
2062 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2064 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2065 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2066 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2068 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2069 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2070 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2071 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2077 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::CommitmentTransaction, mut preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ {
2078 let mut local_preimages = Vec::new(); for mut item in preimages.into_rust().drain(..) { local_preimages.push( { ::lightning::ln::PaymentPreimage(item.data) }); };
2079 let mut ret = <nativeInMemorySigner as lightning::sign::EcdsaChannelSigner<>>::sign_counterparty_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), local_preimages, secp256k1::global::SECP256K1);
2080 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() };
2084 extern "C" fn InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation(this_arg: *const c_void, mut idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ {
2085 let mut ret = <nativeInMemorySigner as lightning::sign::EcdsaChannelSigner<>>::validate_counterparty_revocation(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *secret}[..]).unwrap());
2086 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() };
2090 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ {
2091 let mut ret = <nativeInMemorySigner as lightning::sign::EcdsaChannelSigner<>>::sign_holder_commitment_and_htlcs(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), secp256k1::global::SECP256K1);
2092 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() };
2096 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 {
2097 let mut ret = <nativeInMemorySigner as lightning::sign::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);
2098 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() };
2102 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 {
2103 let mut ret = <nativeInMemorySigner as lightning::sign::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);
2104 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() };
2108 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::events::bump_transaction::HTLCDescriptor) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2109 let mut ret = <nativeInMemorySigner as lightning::sign::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);
2110 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() };
2114 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 {
2115 let mut ret = <nativeInMemorySigner as lightning::sign::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);
2116 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() };
2120 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 {
2121 let mut ret = <nativeInMemorySigner as lightning::sign::EcdsaChannelSigner<>>::sign_closing_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, closing_tx.get_native_ref(), secp256k1::global::SECP256K1);
2122 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() };
2126 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 {
2127 let mut ret = <nativeInMemorySigner as lightning::sign::EcdsaChannelSigner<>>::sign_holder_anchor_input(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &anchor_tx.into_bitcoin(), input, secp256k1::global::SECP256K1);
2128 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() };
2132 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 {
2133 let mut ret = <nativeInMemorySigner as lightning::sign::EcdsaChannelSigner<>>::sign_channel_announcement_with_funding_key(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, msg.get_native_ref(), secp256k1::global::SECP256K1);
2134 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() };
2138 impl From<nativeInMemorySigner> for crate::lightning::sign::WriteableEcdsaChannelSigner {
2139 fn from(obj: nativeInMemorySigner) -> Self {
2140 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2141 let mut ret = InMemorySigner_as_WriteableEcdsaChannelSigner(&rust_obj);
2142 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2143 rust_obj.inner = core::ptr::null_mut();
2144 ret.free = Some(InMemorySigner_free_void);
2148 /// Constructs a new WriteableEcdsaChannelSigner which calls the relevant methods on this_arg.
2149 /// This copies the `inner` pointer in this_arg and thus the returned WriteableEcdsaChannelSigner must be freed before this_arg is
2151 pub extern "C" fn InMemorySigner_as_WriteableEcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::WriteableEcdsaChannelSigner {
2152 crate::lightning::sign::WriteableEcdsaChannelSigner {
2153 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2155 EcdsaChannelSigner: crate::lightning::sign::EcdsaChannelSigner {
2156 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2158 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
2159 validate_counterparty_revocation: InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation,
2160 sign_holder_commitment_and_htlcs: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs,
2161 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
2162 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
2163 sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
2164 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
2165 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
2166 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
2167 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
2168 ChannelSigner: crate::lightning::sign::ChannelSigner {
2169 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2171 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2172 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2173 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2175 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2176 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2177 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2178 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2181 write: InMemorySigner_write_void,
2182 cloned: Some(WriteableEcdsaChannelSigner_InMemorySigner_cloned),
2186 extern "C" fn WriteableEcdsaChannelSigner_InMemorySigner_cloned(new_obj: &mut crate::lightning::sign::WriteableEcdsaChannelSigner) {
2187 new_obj.this_arg = InMemorySigner_clone_void(new_obj.this_arg);
2188 new_obj.free = Some(InMemorySigner_free_void);
2189 new_obj.EcdsaChannelSigner.this_arg = new_obj.this_arg;
2190 new_obj.EcdsaChannelSigner.free = None;
2191 new_obj.EcdsaChannelSigner.ChannelSigner.this_arg = new_obj.this_arg;
2192 new_obj.EcdsaChannelSigner.ChannelSigner.free = None;
2196 /// Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
2197 pub extern "C" fn InMemorySigner_write(obj: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::CVec_u8Z {
2198 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2201 pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2202 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) })
2205 /// Read a InMemorySigner from a byte array, created by InMemorySigner_write
2206 pub extern "C" fn InMemorySigner_read(ser: crate::c_types::u8slice, arg: crate::lightning::sign::EntropySource) -> crate::c_types::derived::CResult_InMemorySignerDecodeErrorZ {
2208 let res: Result<lightning::sign::InMemorySigner, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
2209 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() };
2213 use lightning::sign::KeysManager as nativeKeysManagerImport;
2214 pub(crate) type nativeKeysManager = nativeKeysManagerImport;
2216 /// Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a
2217 /// 32-byte seed for use as a BIP 32 extended key and derives keys from that.
2219 /// Your `node_id` is seed/0'.
2220 /// Unilateral closes may use seed/1'.
2221 /// Cooperative closes may use seed/2'.
2222 /// The two close keys may be needed to claim on-chain funds!
2224 /// This struct cannot be used for nodes that wish to support receiving phantom payments;
2225 /// [`PhantomKeysManager`] must be used instead.
2227 /// Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
2228 /// previously issued invoices and attempts to pay previous invoices will fail.
2231 pub struct KeysManager {
2232 /// A pointer to the opaque Rust object.
2234 /// Nearly everywhere, inner must be non-null, however in places where
2235 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2236 pub inner: *mut nativeKeysManager,
2237 /// Indicates that this is the only struct which contains the same pointer.
2239 /// Rust functions which take ownership of an object provided via an argument require
2240 /// this to be true and invalidate the object pointed to by inner.
2244 impl Drop for KeysManager {
2245 fn drop(&mut self) {
2246 if self.is_owned && !<*mut nativeKeysManager>::is_null(self.inner) {
2247 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2251 /// Frees any resources used by the KeysManager, if is_owned is set and inner is non-NULL.
2253 pub extern "C" fn KeysManager_free(this_obj: KeysManager) { }
2255 /// Used only if an object of this type is returned as a trait impl by a method
2256 pub(crate) extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) {
2257 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeKeysManager) };
2261 pub(crate) fn get_native_ref(&self) -> &'static nativeKeysManager {
2262 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2264 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeKeysManager {
2265 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2267 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2268 pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager {
2269 assert!(self.is_owned);
2270 let ret = ObjOps::untweak_ptr(self.inner);
2271 self.inner = core::ptr::null_mut();
2275 /// Constructs a [`KeysManager`] from a 32-byte seed. If the seed is in some way biased (e.g.,
2276 /// your CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
2277 /// `starting_time` isn't strictly required to actually be a time, but it must absolutely,
2278 /// without a doubt, be unique to this instance. ie if you start multiple times with the same
2279 /// `seed`, `starting_time` must be unique to each run. Thus, the easiest way to achieve this
2280 /// is to simply use the current time (with very high precision).
2282 /// The `seed` MUST be backed up safely prior to use so that the keys can be re-created, however,
2283 /// obviously, `starting_time` should be unique every time you reload the library - it is only
2284 /// used to generate new ephemeral key data (which will be stored by the individual channel if
2287 /// Note that the seed is required to recover certain on-chain funds independent of
2288 /// [`ChannelMonitor`] data, though a current copy of [`ChannelMonitor`] data is also required
2289 /// for any channel, and some on-chain during-closing funds.
2291 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
2294 pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32) -> crate::lightning::sign::KeysManager {
2295 let mut ret = lightning::sign::KeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos);
2296 crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2299 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2302 pub extern "C" fn KeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::KeysManager) -> crate::c_types::SecretKey {
2303 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2304 crate::c_types::SecretKey::from_rust(ret)
2307 /// Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
2310 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 {
2311 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2312 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2315 /// Signs the given [`PartiallySignedTransaction`] which spends the given [`SpendableOutputDescriptor`]s.
2316 /// The resulting inputs will be finalized and the PSBT will be ready for broadcast if there
2317 /// are no other inputs that need signing.
2319 /// Returns `Err(())` if the PSBT is missing a descriptor or if we fail to sign.
2321 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
2322 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2325 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 {
2326 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2327 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_spendable_outputs_psbt(&local_descriptors.iter().collect::<Vec<_>>()[..], ::bitcoin::consensus::encode::deserialize(psbt.as_slice()).expect("Invalid PSBT format"), secp256k1::global::SECP256K1);
2328 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { ::bitcoin::consensus::encode::serialize(&o).into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2332 /// Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
2333 /// output to the given change destination (if sufficient change value remains). The
2334 /// transaction will have a feerate, at least, of the given value.
2336 /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
2337 /// transaction will have a locktime of 0. It it recommended to set this to the current block
2338 /// height to avoid fee sniping, unless you have some specific reason to use a different
2341 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
2342 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
2343 /// does not match the one we can spend.
2345 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
2347 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
2348 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2351 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 {
2352 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2353 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2354 let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::PackedLockTime({ locktime_opt.take() }) }})} };
2355 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.spend_spendable_outputs(&local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::Script::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime, secp256k1::global::SECP256K1);
2356 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() };
2360 impl From<nativeKeysManager> for crate::lightning::sign::EntropySource {
2361 fn from(obj: nativeKeysManager) -> Self {
2362 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2363 let mut ret = KeysManager_as_EntropySource(&rust_obj);
2364 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2365 rust_obj.inner = core::ptr::null_mut();
2366 ret.free = Some(KeysManager_free_void);
2370 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2371 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2373 pub extern "C" fn KeysManager_as_EntropySource(this_arg: &KeysManager) -> crate::lightning::sign::EntropySource {
2374 crate::lightning::sign::EntropySource {
2375 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2377 get_secure_random_bytes: KeysManager_EntropySource_get_secure_random_bytes,
2382 extern "C" fn KeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2383 let mut ret = <nativeKeysManager as lightning::sign::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2384 crate::c_types::ThirtyTwoBytes { data: ret }
2387 impl From<nativeKeysManager> for crate::lightning::sign::NodeSigner {
2388 fn from(obj: nativeKeysManager) -> Self {
2389 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2390 let mut ret = KeysManager_as_NodeSigner(&rust_obj);
2391 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2392 rust_obj.inner = core::ptr::null_mut();
2393 ret.free = Some(KeysManager_free_void);
2397 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2398 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2400 pub extern "C" fn KeysManager_as_NodeSigner(this_arg: &KeysManager) -> crate::lightning::sign::NodeSigner {
2401 crate::lightning::sign::NodeSigner {
2402 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2404 get_inbound_payment_key_material: KeysManager_NodeSigner_get_inbound_payment_key_material,
2405 get_node_id: KeysManager_NodeSigner_get_node_id,
2406 ecdh: KeysManager_NodeSigner_ecdh,
2407 sign_invoice: KeysManager_NodeSigner_sign_invoice,
2408 sign_bolt12_invoice_request: KeysManager_NodeSigner_sign_bolt12_invoice_request,
2409 sign_bolt12_invoice: KeysManager_NodeSigner_sign_bolt12_invoice,
2410 sign_gossip_message: KeysManager_NodeSigner_sign_gossip_message,
2415 extern "C" fn KeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2416 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2417 crate::c_types::ThirtyTwoBytes { data: ret.0 }
2420 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 {
2421 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native());
2422 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() };
2426 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 {
2427 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();
2428 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);
2429 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() };
2433 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 {
2434 let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2435 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());
2436 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() };
2440 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 {
2441 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::sign_bolt12_invoice_request(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, invoice_request.get_native_ref());
2442 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() };
2446 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 {
2447 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::sign_bolt12_invoice(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, invoice.get_native_ref());
2448 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() };
2452 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 {
2453 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, msg.into_native());
2454 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() };
2458 impl From<nativeKeysManager> for crate::lightning::sign::SignerProvider {
2459 fn from(obj: nativeKeysManager) -> Self {
2460 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2461 let mut ret = KeysManager_as_SignerProvider(&rust_obj);
2462 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2463 rust_obj.inner = core::ptr::null_mut();
2464 ret.free = Some(KeysManager_free_void);
2468 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2469 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2471 pub extern "C" fn KeysManager_as_SignerProvider(this_arg: &KeysManager) -> crate::lightning::sign::SignerProvider {
2472 crate::lightning::sign::SignerProvider {
2473 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2475 generate_channel_keys_id: KeysManager_SignerProvider_generate_channel_keys_id,
2476 derive_channel_signer: KeysManager_SignerProvider_derive_channel_signer,
2477 read_chan_signer: KeysManager_SignerProvider_read_chan_signer,
2478 get_destination_script: KeysManager_SignerProvider_get_destination_script,
2479 get_shutdown_scriptpubkey: KeysManager_SignerProvider_get_shutdown_scriptpubkey,
2484 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 {
2485 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());
2486 crate::c_types::ThirtyTwoBytes { data: ret }
2489 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::WriteableEcdsaChannelSigner {
2490 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);
2494 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 {
2495 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, reader.to_slice());
2496 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() };
2500 extern "C" fn KeysManager_SignerProvider_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ {
2501 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2502 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.into_bytes().into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2506 extern "C" fn KeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2507 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2508 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() };
2513 use lightning::sign::PhantomKeysManager as nativePhantomKeysManagerImport;
2514 pub(crate) type nativePhantomKeysManager = nativePhantomKeysManagerImport;
2516 /// Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
2519 /// A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
2520 /// paid to one of multiple nodes. This works because we encode the invoice route hints such that
2521 /// LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
2522 /// itself without ever needing to forward to this fake node.
2524 /// Phantom node payments are useful for load balancing between multiple LDK nodes. They also
2525 /// provide some fault tolerance, because payers will automatically retry paying other provided
2526 /// nodes in the case that one node goes down.
2528 /// Note that multi-path payments are not supported in phantom invoices for security reasons.
2529 /// Switching between this struct and [`KeysManager`] will invalidate any previously issued
2530 /// invoices and attempts to pay previous invoices will fail.
2533 pub struct PhantomKeysManager {
2534 /// A pointer to the opaque Rust object.
2536 /// Nearly everywhere, inner must be non-null, however in places where
2537 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2538 pub inner: *mut nativePhantomKeysManager,
2539 /// Indicates that this is the only struct which contains the same pointer.
2541 /// Rust functions which take ownership of an object provided via an argument require
2542 /// this to be true and invalidate the object pointed to by inner.
2546 impl Drop for PhantomKeysManager {
2547 fn drop(&mut self) {
2548 if self.is_owned && !<*mut nativePhantomKeysManager>::is_null(self.inner) {
2549 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2553 /// Frees any resources used by the PhantomKeysManager, if is_owned is set and inner is non-NULL.
2555 pub extern "C" fn PhantomKeysManager_free(this_obj: PhantomKeysManager) { }
2557 /// Used only if an object of this type is returned as a trait impl by a method
2558 pub(crate) extern "C" fn PhantomKeysManager_free_void(this_ptr: *mut c_void) {
2559 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomKeysManager) };
2562 impl PhantomKeysManager {
2563 pub(crate) fn get_native_ref(&self) -> &'static nativePhantomKeysManager {
2564 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2566 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomKeysManager {
2567 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2569 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2570 pub(crate) fn take_inner(mut self) -> *mut nativePhantomKeysManager {
2571 assert!(self.is_owned);
2572 let ret = ObjOps::untweak_ptr(self.inner);
2573 self.inner = core::ptr::null_mut();
2577 impl From<nativePhantomKeysManager> for crate::lightning::sign::EntropySource {
2578 fn from(obj: nativePhantomKeysManager) -> Self {
2579 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2580 let mut ret = PhantomKeysManager_as_EntropySource(&rust_obj);
2581 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2582 rust_obj.inner = core::ptr::null_mut();
2583 ret.free = Some(PhantomKeysManager_free_void);
2587 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2588 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2590 pub extern "C" fn PhantomKeysManager_as_EntropySource(this_arg: &PhantomKeysManager) -> crate::lightning::sign::EntropySource {
2591 crate::lightning::sign::EntropySource {
2592 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2594 get_secure_random_bytes: PhantomKeysManager_EntropySource_get_secure_random_bytes,
2599 extern "C" fn PhantomKeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2600 let mut ret = <nativePhantomKeysManager as lightning::sign::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2601 crate::c_types::ThirtyTwoBytes { data: ret }
2604 impl From<nativePhantomKeysManager> for crate::lightning::sign::NodeSigner {
2605 fn from(obj: nativePhantomKeysManager) -> Self {
2606 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2607 let mut ret = PhantomKeysManager_as_NodeSigner(&rust_obj);
2608 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2609 rust_obj.inner = core::ptr::null_mut();
2610 ret.free = Some(PhantomKeysManager_free_void);
2614 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2615 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2617 pub extern "C" fn PhantomKeysManager_as_NodeSigner(this_arg: &PhantomKeysManager) -> crate::lightning::sign::NodeSigner {
2618 crate::lightning::sign::NodeSigner {
2619 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2621 get_inbound_payment_key_material: PhantomKeysManager_NodeSigner_get_inbound_payment_key_material,
2622 get_node_id: PhantomKeysManager_NodeSigner_get_node_id,
2623 ecdh: PhantomKeysManager_NodeSigner_ecdh,
2624 sign_invoice: PhantomKeysManager_NodeSigner_sign_invoice,
2625 sign_bolt12_invoice_request: PhantomKeysManager_NodeSigner_sign_bolt12_invoice_request,
2626 sign_bolt12_invoice: PhantomKeysManager_NodeSigner_sign_bolt12_invoice,
2627 sign_gossip_message: PhantomKeysManager_NodeSigner_sign_gossip_message,
2632 extern "C" fn PhantomKeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2633 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2634 crate::c_types::ThirtyTwoBytes { data: ret.0 }
2637 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 {
2638 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native());
2639 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() };
2643 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 {
2644 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();
2645 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);
2646 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() };
2650 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 {
2651 let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2652 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());
2653 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() };
2657 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 {
2658 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::sign_bolt12_invoice_request(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, invoice_request.get_native_ref());
2659 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() };
2663 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 {
2664 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::sign_bolt12_invoice(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, invoice.get_native_ref());
2665 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() };
2669 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 {
2670 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, msg.into_native());
2671 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() };
2675 impl From<nativePhantomKeysManager> for crate::lightning::sign::SignerProvider {
2676 fn from(obj: nativePhantomKeysManager) -> Self {
2677 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2678 let mut ret = PhantomKeysManager_as_SignerProvider(&rust_obj);
2679 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2680 rust_obj.inner = core::ptr::null_mut();
2681 ret.free = Some(PhantomKeysManager_free_void);
2685 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2686 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2688 pub extern "C" fn PhantomKeysManager_as_SignerProvider(this_arg: &PhantomKeysManager) -> crate::lightning::sign::SignerProvider {
2689 crate::lightning::sign::SignerProvider {
2690 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2692 generate_channel_keys_id: PhantomKeysManager_SignerProvider_generate_channel_keys_id,
2693 derive_channel_signer: PhantomKeysManager_SignerProvider_derive_channel_signer,
2694 read_chan_signer: PhantomKeysManager_SignerProvider_read_chan_signer,
2695 get_destination_script: PhantomKeysManager_SignerProvider_get_destination_script,
2696 get_shutdown_scriptpubkey: PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey,
2701 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 {
2702 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());
2703 crate::c_types::ThirtyTwoBytes { data: ret }
2706 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::WriteableEcdsaChannelSigner {
2707 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);
2711 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 {
2712 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, reader.to_slice());
2713 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() };
2717 extern "C" fn PhantomKeysManager_SignerProvider_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ {
2718 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2719 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.into_bytes().into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2723 extern "C" fn PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2724 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2725 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() };
2729 /// Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
2730 /// that is shared across all nodes that intend to participate in [phantom node payments]
2733 /// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
2734 /// `starting_time_nanos`.
2736 /// `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
2737 /// same across restarts, or else inbound payments may fail.
2739 /// [phantom node payments]: PhantomKeysManager
2742 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 {
2743 let mut ret = lightning::sign::PhantomKeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos, unsafe { &*cross_node_seed});
2744 crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2747 /// See [`KeysManager::spend_spendable_outputs`] for documentation on this method.
2750 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 {
2751 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2752 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2753 let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::PackedLockTime({ locktime_opt.take() }) }})} };
2754 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.spend_spendable_outputs(&local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::Script::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime, secp256k1::global::SECP256K1);
2755 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() };
2759 /// See [`KeysManager::derive_channel_keys`] for documentation on this method.
2762 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 {
2763 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2764 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2767 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2770 pub extern "C" fn PhantomKeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
2771 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2772 crate::c_types::SecretKey::from_rust(ret)
2775 /// Gets the \"node_id\" secret key of the phantom node used to sign invoices, decode the
2776 /// last-hop onion data, etc.
2779 pub extern "C" fn PhantomKeysManager_get_phantom_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
2780 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_node_secret_key();
2781 crate::c_types::SecretKey::from_rust(ret)