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 core::ffi::c_void;
16 use core::convert::Infallible;
17 use bitcoin::hashes::Hash;
18 use crate::c_types::*;
19 #[cfg(feature="no-std")]
20 use alloc::{vec::Vec, boxed::Box};
23 use lightning::sign::DelayedPaymentOutputDescriptor as nativeDelayedPaymentOutputDescriptorImport;
24 pub(crate) type nativeDelayedPaymentOutputDescriptor = nativeDelayedPaymentOutputDescriptorImport;
26 /// Information about a spendable output to a P2WSH script.
28 /// See [`SpendableOutputDescriptor::DelayedPaymentOutput`] for more details on how to spend this.
31 pub struct DelayedPaymentOutputDescriptor {
32 /// A pointer to the opaque Rust object.
34 /// Nearly everywhere, inner must be non-null, however in places where
35 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
36 pub inner: *mut nativeDelayedPaymentOutputDescriptor,
37 /// Indicates that this is the only struct which contains the same pointer.
39 /// Rust functions which take ownership of an object provided via an argument require
40 /// this to be true and invalidate the object pointed to by inner.
44 impl Drop for DelayedPaymentOutputDescriptor {
46 if self.is_owned && !<*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) {
47 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
51 /// Frees any resources used by the DelayedPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
53 pub extern "C" fn DelayedPaymentOutputDescriptor_free(this_obj: DelayedPaymentOutputDescriptor) { }
55 /// Used only if an object of this type is returned as a trait impl by a method
56 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
57 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDelayedPaymentOutputDescriptor) };
60 impl DelayedPaymentOutputDescriptor {
61 pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentOutputDescriptor {
62 unsafe { &*ObjOps::untweak_ptr(self.inner) }
64 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentOutputDescriptor {
65 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
67 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
68 pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentOutputDescriptor {
69 assert!(self.is_owned);
70 let ret = ObjOps::untweak_ptr(self.inner);
71 self.inner = core::ptr::null_mut();
75 /// The outpoint which is spendable.
77 pub extern "C" fn DelayedPaymentOutputDescriptor_get_outpoint(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
78 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
79 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 }
81 /// The outpoint which is spendable.
83 pub extern "C" fn DelayedPaymentOutputDescriptor_set_outpoint(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
84 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
86 /// Per commitment point to derive the delayed payment key by key holder.
88 pub extern "C" fn DelayedPaymentOutputDescriptor_get_per_commitment_point(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
89 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
90 crate::c_types::PublicKey::from_rust(&inner_val)
92 /// Per commitment point to derive the delayed payment key by key holder.
94 pub extern "C" fn DelayedPaymentOutputDescriptor_set_per_commitment_point(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
95 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
97 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
98 /// the witness_script.
100 pub extern "C" fn DelayedPaymentOutputDescriptor_get_to_self_delay(this_ptr: &DelayedPaymentOutputDescriptor) -> u16 {
101 let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay;
104 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
105 /// the witness_script.
107 pub extern "C" fn DelayedPaymentOutputDescriptor_set_to_self_delay(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u16) {
108 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val;
110 /// The output which is referenced by the given outpoint.
112 pub extern "C" fn DelayedPaymentOutputDescriptor_get_output(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::TxOut {
113 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
114 crate::c_types::TxOut::from_rust(inner_val)
116 /// The output which is referenced by the given outpoint.
118 pub extern "C" fn DelayedPaymentOutputDescriptor_set_output(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
119 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
121 /// The revocation point specific to the commitment transaction which was broadcast. Used to
122 /// derive the witnessScript for this output.
124 pub extern "C" fn DelayedPaymentOutputDescriptor_get_revocation_pubkey(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
125 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_pubkey;
126 crate::c_types::PublicKey::from_rust(&inner_val)
128 /// The revocation point specific to the commitment transaction which was broadcast. Used to
129 /// derive the witnessScript for this output.
131 pub extern "C" fn DelayedPaymentOutputDescriptor_set_revocation_pubkey(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
132 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_pubkey = val.into_rust();
134 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
135 /// This may be useful in re-deriving keys used in the channel to spend the output.
137 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &DelayedPaymentOutputDescriptor) -> *const [u8; 32] {
138 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
141 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
142 /// This may be useful in re-deriving keys used in the channel to spend the output.
144 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
145 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
147 /// The value of the channel which this output originated from, possibly indirectly.
149 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &DelayedPaymentOutputDescriptor) -> u64 {
150 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
153 /// The value of the channel which this output originated from, possibly indirectly.
155 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u64) {
156 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
158 /// Constructs a new DelayedPaymentOutputDescriptor given each field
161 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 {
162 DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeDelayedPaymentOutputDescriptor {
163 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
164 per_commitment_point: per_commitment_point_arg.into_rust(),
165 to_self_delay: to_self_delay_arg,
166 output: output_arg.into_rust(),
167 revocation_pubkey: revocation_pubkey_arg.into_rust(),
168 channel_keys_id: channel_keys_id_arg.data,
169 channel_value_satoshis: channel_value_satoshis_arg,
172 impl Clone for DelayedPaymentOutputDescriptor {
173 fn clone(&self) -> Self {
175 inner: if <*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
176 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
182 /// Used only if an object of this type is returned as a trait impl by a method
183 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
184 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void
187 /// Creates a copy of the DelayedPaymentOutputDescriptor
188 pub extern "C" fn DelayedPaymentOutputDescriptor_clone(orig: &DelayedPaymentOutputDescriptor) -> DelayedPaymentOutputDescriptor {
191 /// Checks if two DelayedPaymentOutputDescriptors contain equal inner contents.
192 /// This ignores pointers and is_owned flags and looks at the values in fields.
193 /// Two objects with NULL inner values will be considered "equal" here.
195 pub extern "C" fn DelayedPaymentOutputDescriptor_eq(a: &DelayedPaymentOutputDescriptor, b: &DelayedPaymentOutputDescriptor) -> bool {
196 if a.inner == b.inner { return true; }
197 if a.inner.is_null() || b.inner.is_null() { return false; }
198 if a.get_native_ref() == b.get_native_ref() { true } else { false }
201 /// Serialize the DelayedPaymentOutputDescriptor object into a byte array which can be read by DelayedPaymentOutputDescriptor_read
202 pub extern "C" fn DelayedPaymentOutputDescriptor_write(obj: &crate::lightning::sign::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
203 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
206 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
207 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentOutputDescriptor) })
210 /// Read a DelayedPaymentOutputDescriptor from a byte array, created by DelayedPaymentOutputDescriptor_write
211 pub extern "C" fn DelayedPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentOutputDescriptorDecodeErrorZ {
212 let res: Result<lightning::sign::DelayedPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
213 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() };
217 use lightning::sign::StaticPaymentOutputDescriptor as nativeStaticPaymentOutputDescriptorImport;
218 pub(crate) type nativeStaticPaymentOutputDescriptor = nativeStaticPaymentOutputDescriptorImport;
220 /// Information about a spendable output to our \"payment key\".
222 /// See [`SpendableOutputDescriptor::StaticPaymentOutput`] for more details on how to spend this.
225 pub struct StaticPaymentOutputDescriptor {
226 /// A pointer to the opaque Rust object.
228 /// Nearly everywhere, inner must be non-null, however in places where
229 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
230 pub inner: *mut nativeStaticPaymentOutputDescriptor,
231 /// Indicates that this is the only struct which contains the same pointer.
233 /// Rust functions which take ownership of an object provided via an argument require
234 /// this to be true and invalidate the object pointed to by inner.
238 impl Drop for StaticPaymentOutputDescriptor {
240 if self.is_owned && !<*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) {
241 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
245 /// Frees any resources used by the StaticPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
247 pub extern "C" fn StaticPaymentOutputDescriptor_free(this_obj: StaticPaymentOutputDescriptor) { }
249 /// Used only if an object of this type is returned as a trait impl by a method
250 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
251 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeStaticPaymentOutputDescriptor) };
254 impl StaticPaymentOutputDescriptor {
255 pub(crate) fn get_native_ref(&self) -> &'static nativeStaticPaymentOutputDescriptor {
256 unsafe { &*ObjOps::untweak_ptr(self.inner) }
258 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeStaticPaymentOutputDescriptor {
259 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
261 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
262 pub(crate) fn take_inner(mut self) -> *mut nativeStaticPaymentOutputDescriptor {
263 assert!(self.is_owned);
264 let ret = ObjOps::untweak_ptr(self.inner);
265 self.inner = core::ptr::null_mut();
269 /// The outpoint which is spendable.
271 pub extern "C" fn StaticPaymentOutputDescriptor_get_outpoint(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
272 let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
273 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 }
275 /// The outpoint which is spendable.
277 pub extern "C" fn StaticPaymentOutputDescriptor_set_outpoint(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
278 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
280 /// The output which is referenced by the given outpoint.
282 pub extern "C" fn StaticPaymentOutputDescriptor_get_output(this_ptr: &StaticPaymentOutputDescriptor) -> crate::c_types::TxOut {
283 let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
284 crate::c_types::TxOut::from_rust(inner_val)
286 /// The output which is referenced by the given outpoint.
288 pub extern "C" fn StaticPaymentOutputDescriptor_set_output(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
289 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
291 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
292 /// This may be useful in re-deriving keys used in the channel to spend the output.
294 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &StaticPaymentOutputDescriptor) -> *const [u8; 32] {
295 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
298 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
299 /// This may be useful in re-deriving keys used in the channel to spend the output.
301 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
302 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
304 /// The value of the channel which this transactions spends.
306 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &StaticPaymentOutputDescriptor) -> u64 {
307 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
310 /// The value of the channel which this transactions spends.
312 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: u64) {
313 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
315 /// Constructs a new StaticPaymentOutputDescriptor given each field
318 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) -> StaticPaymentOutputDescriptor {
319 StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeStaticPaymentOutputDescriptor {
320 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
321 output: output_arg.into_rust(),
322 channel_keys_id: channel_keys_id_arg.data,
323 channel_value_satoshis: channel_value_satoshis_arg,
326 impl Clone for StaticPaymentOutputDescriptor {
327 fn clone(&self) -> Self {
329 inner: if <*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
330 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
336 /// Used only if an object of this type is returned as a trait impl by a method
337 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
338 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void
341 /// Creates a copy of the StaticPaymentOutputDescriptor
342 pub extern "C" fn StaticPaymentOutputDescriptor_clone(orig: &StaticPaymentOutputDescriptor) -> StaticPaymentOutputDescriptor {
345 /// Checks if two StaticPaymentOutputDescriptors contain equal inner contents.
346 /// This ignores pointers and is_owned flags and looks at the values in fields.
347 /// Two objects with NULL inner values will be considered "equal" here.
349 pub extern "C" fn StaticPaymentOutputDescriptor_eq(a: &StaticPaymentOutputDescriptor, b: &StaticPaymentOutputDescriptor) -> bool {
350 if a.inner == b.inner { return true; }
351 if a.inner.is_null() || b.inner.is_null() { return false; }
352 if a.get_native_ref() == b.get_native_ref() { true } else { false }
355 /// Serialize the StaticPaymentOutputDescriptor object into a byte array which can be read by StaticPaymentOutputDescriptor_read
356 pub extern "C" fn StaticPaymentOutputDescriptor_write(obj: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
357 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
360 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
361 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeStaticPaymentOutputDescriptor) })
364 /// Read a StaticPaymentOutputDescriptor from a byte array, created by StaticPaymentOutputDescriptor_write
365 pub extern "C" fn StaticPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_StaticPaymentOutputDescriptorDecodeErrorZ {
366 let res: Result<lightning::sign::StaticPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
367 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() };
370 /// Describes the necessary information to spend a spendable output.
372 /// When on-chain outputs are created by LDK (which our counterparty is not able to claim at any
373 /// point in the future) a [`SpendableOutputs`] event is generated which you must track and be able
374 /// to spend on-chain. The information needed to do this is provided in this enum, including the
375 /// outpoint describing which `txid` and output `index` is available, the full output which exists
376 /// at that `txid`/`index`, and any keys or other information required to sign.
378 /// [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
382 pub enum SpendableOutputDescriptor {
383 /// An output to a script which was provided via [`SignerProvider`] directly, either from
384 /// [`get_destination_script`] or [`get_shutdown_scriptpubkey`], thus you should already
385 /// know how to spend it. No secret keys are provided as LDK was never given any key.
386 /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
387 /// on-chain using the payment preimage or after it has timed out.
389 /// [`get_shutdown_scriptpubkey`]: SignerProvider::get_shutdown_scriptpubkey
390 /// [`get_destination_script`]: SignerProvider::get_shutdown_scriptpubkey
392 /// The outpoint which is spendable.
393 outpoint: crate::lightning::chain::transaction::OutPoint,
394 /// The output which is referenced by the given outpoint.
395 output: crate::c_types::TxOut,
397 /// An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
400 /// The witness in the spending input should be:
402 /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
405 /// Note that the `nSequence` field in the spending input must be set to
406 /// [`DelayedPaymentOutputDescriptor::to_self_delay`] (which means the transaction is not
407 /// broadcastable until at least [`DelayedPaymentOutputDescriptor::to_self_delay`] blocks after
408 /// the outpoint confirms, see [BIP
409 /// 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)). Also note that LDK
410 /// won't generate a [`SpendableOutputDescriptor`] until the corresponding block height
413 /// These are generally the result of a \"revocable\" output to us, spendable only by us unless
414 /// it is an output from an old state which we broadcast (which should never happen).
416 /// To derive the delayed payment key which is used to sign this input, you must pass the
417 /// holder [`InMemorySigner::delayed_payment_base_key`] (i.e., the private key which corresponds to the
418 /// [`ChannelPublicKeys::delayed_payment_basepoint`] in [`ChannelSigner::pubkeys`]) and the provided
419 /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to [`chan_utils::derive_private_key`]. The public key can be
420 /// generated without the secret key using [`chan_utils::derive_public_key`] and only the
421 /// [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`ChannelSigner::pubkeys`].
423 /// To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
424 /// used in the witness script generation), you must pass the counterparty
425 /// [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
426 /// [`ChannelSigner::provide_channel_parameters`]) and the provided
427 /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
428 /// [`chan_utils::derive_public_revocation_key`].
430 /// The witness script which is hashed and included in the output `script_pubkey` may be
431 /// regenerated by passing the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] (derived
432 /// as explained above), our delayed payment pubkey (derived as explained above), and the
433 /// [`DelayedPaymentOutputDescriptor::to_self_delay`] contained here to
434 /// [`chan_utils::get_revokeable_redeemscript`].
435 DelayedPaymentOutput(
436 crate::lightning::sign::DelayedPaymentOutputDescriptor),
437 /// An output to a P2WPKH, spendable exclusively by our payment key (i.e., the private key
438 /// which corresponds to the `payment_point` in [`ChannelSigner::pubkeys`]). The witness
439 /// in the spending input is, thus, simply:
441 /// <BIP 143 signature> <payment key>
444 /// These are generally the result of our counterparty having broadcast the current state,
445 /// allowing us to claim the non-HTLC-encumbered outputs immediately.
447 crate::lightning::sign::StaticPaymentOutputDescriptor),
449 use lightning::sign::SpendableOutputDescriptor as SpendableOutputDescriptorImport;
450 pub(crate) type nativeSpendableOutputDescriptor = SpendableOutputDescriptorImport;
452 impl SpendableOutputDescriptor {
454 pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor {
456 SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
457 let mut outpoint_nonref = Clone::clone(outpoint);
458 let mut output_nonref = Clone::clone(output);
459 nativeSpendableOutputDescriptor::StaticOutput {
460 outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
461 output: output_nonref.into_rust(),
464 SpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
465 let mut a_nonref = Clone::clone(a);
466 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
467 *unsafe { Box::from_raw(a_nonref.take_inner()) },
470 SpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
471 let mut a_nonref = Clone::clone(a);
472 nativeSpendableOutputDescriptor::StaticPaymentOutput (
473 *unsafe { Box::from_raw(a_nonref.take_inner()) },
479 pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor {
481 SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
482 nativeSpendableOutputDescriptor::StaticOutput {
483 outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
484 output: output.into_rust(),
487 SpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
488 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
489 *unsafe { Box::from_raw(a.take_inner()) },
492 SpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
493 nativeSpendableOutputDescriptor::StaticPaymentOutput (
494 *unsafe { Box::from_raw(a.take_inner()) },
500 pub(crate) fn from_native(native: &nativeSpendableOutputDescriptor) -> Self {
502 nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
503 let mut outpoint_nonref = Clone::clone(outpoint);
504 let mut output_nonref = Clone::clone(output);
505 SpendableOutputDescriptor::StaticOutput {
506 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true },
507 output: crate::c_types::TxOut::from_rust(&output_nonref),
510 nativeSpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
511 let mut a_nonref = Clone::clone(a);
512 SpendableOutputDescriptor::DelayedPaymentOutput (
513 crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
516 nativeSpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
517 let mut a_nonref = Clone::clone(a);
518 SpendableOutputDescriptor::StaticPaymentOutput (
519 crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
525 pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self {
527 nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
528 SpendableOutputDescriptor::StaticOutput {
529 outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true },
530 output: crate::c_types::TxOut::from_rust(&output),
533 nativeSpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
534 SpendableOutputDescriptor::DelayedPaymentOutput (
535 crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
538 nativeSpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
539 SpendableOutputDescriptor::StaticPaymentOutput (
540 crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
546 /// Frees any resources used by the SpendableOutputDescriptor
548 pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { }
549 /// Creates a copy of the SpendableOutputDescriptor
551 pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor {
555 /// Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
556 pub extern "C" fn SpendableOutputDescriptor_static_output(outpoint: crate::lightning::chain::transaction::OutPoint, output: crate::c_types::TxOut) -> SpendableOutputDescriptor {
557 SpendableOutputDescriptor::StaticOutput {
563 /// Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
564 pub extern "C" fn SpendableOutputDescriptor_delayed_payment_output(a: crate::lightning::sign::DelayedPaymentOutputDescriptor) -> SpendableOutputDescriptor {
565 SpendableOutputDescriptor::DelayedPaymentOutput(a, )
568 /// Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
569 pub extern "C" fn SpendableOutputDescriptor_static_payment_output(a: crate::lightning::sign::StaticPaymentOutputDescriptor) -> SpendableOutputDescriptor {
570 SpendableOutputDescriptor::StaticPaymentOutput(a, )
572 /// Checks if two SpendableOutputDescriptors contain equal inner contents.
573 /// This ignores pointers and is_owned flags and looks at the values in fields.
575 pub extern "C" fn SpendableOutputDescriptor_eq(a: &SpendableOutputDescriptor, b: &SpendableOutputDescriptor) -> bool {
576 if &a.to_native() == &b.to_native() { true } else { false }
579 /// Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
580 pub extern "C" fn SpendableOutputDescriptor_write(obj: &crate::lightning::sign::SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
581 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
584 /// Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
585 pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
586 let res: Result<lightning::sign::SpendableOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
587 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() };
590 /// Creates an unsigned [`PartiallySignedTransaction`] which spends the given descriptors to
591 /// the given outputs, plus an output to the given change destination (if sufficient
592 /// change value remains). The PSBT will have a feerate, at least, of the given value.
594 /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
595 /// transaction will have a locktime of 0. It it recommended to set this to the current block
596 /// height to avoid fee sniping, unless you have some specific reason to use a different
599 /// Returns the PSBT and expected max transaction weight.
601 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
602 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
603 /// does not match the one we can spend.
605 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
608 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_PackedLockTimeZ) -> crate::c_types::derived::CResult_C2Tuple_PartiallySignedTransactionusizeZNoneZ {
609 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
610 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
611 let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::PackedLockTime({ locktime_opt.take() }) }})} };
612 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);
613 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() };
617 /// A trait to handle Lightning channel key material without concretizing the channel type or
618 /// the signature mechanism.
620 pub struct ChannelSigner {
621 /// An opaque pointer which is passed to your function implementations as an argument.
622 /// This has no meaning in the LDK, and can be NULL or any other value.
623 pub this_arg: *mut c_void,
624 /// Gets the per-commitment point for a specific commitment number
626 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
627 pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey,
628 /// Gets the commitment secret for a specific commitment number as part of the revocation process
630 /// An external signer implementation should error here if the commitment was already signed
631 /// and should refuse to sign it in the future.
633 /// May be called more than once for the same index.
635 /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
636 pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes,
637 /// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
639 /// This is required in order for the signer to make sure that releasing a commitment
640 /// secret won't leave us without a broadcastable holder transaction.
641 /// Policy checks should be implemented in this function, including checking the amount
642 /// sent to us and checking the HTLCs.
644 /// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
645 /// A validating signer should ensure that an HTLC output is removed only when the matching
646 /// preimage is provided, or when the value to holder is restored.
648 /// Note that all the relevant preimages will be provided, but there may also be additional
649 /// irrelevant or duplicate preimages.
650 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_PaymentPreimageZ) -> crate::c_types::derived::CResult_NoneNoneZ,
651 /// Returns the holder's channel public keys and basepoints.
652 pub pubkeys: core::cell::UnsafeCell<crate::lightning::ln::chan_utils::ChannelPublicKeys>,
653 /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns
654 /// Note that this takes a pointer to this object, not the this_ptr like other methods do
655 /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
656 pub set_pubkeys: Option<extern "C" fn(&ChannelSigner)>,
657 /// Returns an arbitrary identifier describing the set of keys which are provided back to you in
658 /// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
659 /// [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
660 pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
661 /// Set the counterparty static channel data, including basepoints,
662 /// `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
664 /// This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
665 /// instance, LDK will call this method exactly once - either immediately after construction
666 /// (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
667 /// information has been generated.
669 /// channel_parameters.is_populated() MUST be true.
670 pub provide_channel_parameters: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters),
671 /// Frees any resources associated with this object given its this_arg pointer.
672 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
673 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
675 unsafe impl Send for ChannelSigner {}
676 unsafe impl Sync for ChannelSigner {}
678 pub(crate) extern "C" fn ChannelSigner_clone_fields(orig: &ChannelSigner) -> ChannelSigner {
680 this_arg: orig.this_arg,
681 get_per_commitment_point: Clone::clone(&orig.get_per_commitment_point),
682 release_commitment_secret: Clone::clone(&orig.release_commitment_secret),
683 validate_holder_commitment: Clone::clone(&orig.validate_holder_commitment),
684 pubkeys: Clone::clone(unsafe { &*core::cell::UnsafeCell::get(&orig.pubkeys)}).into(),
685 set_pubkeys: Clone::clone(&orig.set_pubkeys),
686 channel_keys_id: Clone::clone(&orig.channel_keys_id),
687 provide_channel_parameters: Clone::clone(&orig.provide_channel_parameters),
688 free: Clone::clone(&orig.free),
692 use lightning::sign::ChannelSigner as rustChannelSigner;
693 impl rustChannelSigner for ChannelSigner {
694 fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
695 let mut ret = (self.get_per_commitment_point)(self.this_arg, idx);
698 fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
699 let mut ret = (self.release_commitment_secret)(self.this_arg, idx);
702 fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
703 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
704 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());
705 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)) })*/ })};
708 fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
709 if let Some(f) = self.set_pubkeys {
712 unsafe { &*self.pubkeys.get() }.get_native_ref()
714 fn channel_keys_id(&self) -> [u8; 32] {
715 let mut ret = (self.channel_keys_id)(self.this_arg);
718 fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
719 (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 })
723 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
724 // directly as a Deref trait in higher-level structs:
725 impl core::ops::Deref for ChannelSigner {
727 fn deref(&self) -> &Self {
731 /// Calls the free function if one is set
733 pub extern "C" fn ChannelSigner_free(this_ptr: ChannelSigner) { }
734 impl Drop for ChannelSigner {
736 if let Some(f) = self.free {
741 /// A trait to sign Lightning channel transactions as described in
742 /// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
744 /// Signing services could be implemented on a hardware wallet and should implement signing
745 /// policies in order to be secure. Please refer to the [VLS Policy
746 /// Controls](https://gitlab.com/lightning-signer/validating-lightning-signer/-/blob/main/docs/policy-controls.md)
747 /// for an example of such policies.
749 pub struct EcdsaChannelSigner {
750 /// An opaque pointer which is passed to your function implementations as an argument.
751 /// This has no meaning in the LDK, and can be NULL or any other value.
752 pub this_arg: *mut c_void,
753 /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
755 /// Note that if signing fails or is rejected, the channel will be force-closed.
757 /// Policy checks should be implemented in this function, including checking the amount
758 /// sent to us and checking the HTLCs.
760 /// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
761 /// A validating signer should ensure that an HTLC output is removed only when the matching
762 /// preimage is provided, or when the value to holder is restored.
764 /// Note that all the relevant preimages will be provided, but there may also be additional
765 /// irrelevant or duplicate preimages.
766 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_PaymentPreimageZ) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ,
767 /// Validate the counterparty's revocation.
769 /// This is required in order for the signer to make sure that the state has moved
770 /// forward and it is safe to sign the next counterparty commitment.
771 pub validate_counterparty_revocation: extern "C" fn (this_arg: *const c_void, idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ,
772 /// Creates a signature for a holder's commitment transaction and its claiming HTLC transactions.
774 /// This will be called
775 /// - with a non-revoked `commitment_tx`.
776 /// - with the latest `commitment_tx` when we initiate a force-close.
777 /// - with the previous `commitment_tx`, just to get claiming HTLC
778 /// signatures, if we are reacting to a [`ChannelMonitor`]
779 /// [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas)
780 /// that decided to broadcast before it had been updated to the latest `commitment_tx`.
782 /// This may be called multiple times for the same transaction.
784 /// An external signer implementation should check that the commitment has not been revoked.
786 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
787 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_SignatureCVec_SignatureZZNoneZ,
788 /// Create a signature for the given input in a transaction spending an HTLC transaction output
789 /// or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
791 /// A justice transaction may claim multiple outputs at the same time if timelocks are
792 /// similar, but only a signature for the input at index `input` should be signed for here.
793 /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
794 /// to an upcoming timelock expiration.
796 /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
798 /// `per_commitment_key` is revocation secret which was provided by our counterparty when they
799 /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
800 /// not allow the spending of any funds by itself (you need our holder `revocation_secret` to do
802 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_SignatureNoneZ,
803 /// Create a signature for the given input in a transaction spending a commitment transaction
804 /// HTLC output when our counterparty broadcasts an old state.
806 /// A justice transaction may claim multiple outputs at the same time if timelocks are
807 /// similar, but only a signature for the input at index `input` should be signed for here.
808 /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
809 /// to an upcoming timelock expiration.
811 /// `amount` is the value of the output spent by this input, committed to in the BIP 143
814 /// `per_commitment_key` is revocation secret which was provided by our counterparty when they
815 /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
816 /// not allow the spending of any funds by itself (you need our holder revocation_secret to do
819 /// `htlc` holds HTLC elements (hash, timelock), thus changing the format of the witness script
820 /// (which is committed to in the BIP 143 signatures).
821 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_SignatureNoneZ,
822 /// Computes the signature for a commitment transaction's HTLC output used as an input within
823 /// `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned
824 /// must be be computed using [`EcdsaSighashType::All`]. Note that this should only be used to
825 /// sign HTLC transactions from channels supporting anchor outputs after all additional
826 /// inputs/outputs have been added to the transaction.
828 /// [`EcdsaSighashType::All`]: bitcoin::blockdata::transaction::EcdsaSighashType::All
829 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_SignatureNoneZ,
830 /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
831 /// transaction, either offered or received.
833 /// Such a transaction may claim multiples offered outputs at same time if we know the
834 /// preimage for each when we create it, but only the input at index `input` should be
835 /// signed for here. It may be called multiple times for same output(s) if a fee-bump is
836 /// needed with regards to an upcoming timelock expiration.
838 /// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
841 /// `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
843 /// `per_commitment_point` is the dynamic point corresponding to the channel state
844 /// detected onchain. It has been generated by our counterparty and is used to derive
845 /// channel state keys, which are then included in the witness script and committed to in the
846 /// BIP 143 signature.
847 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_SignatureNoneZ,
848 /// Create a signature for a (proposed) closing transaction.
850 /// Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
851 /// chosen to forgo their output as dust.
852 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_SignatureNoneZ,
853 /// Computes the signature for a commitment transaction's anchor output used as an
854 /// input within `anchor_tx`, which spends the commitment transaction, at index `input`.
855 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_SignatureNoneZ,
856 /// Signs a channel announcement message with our funding key proving it comes from one of the
857 /// channel participants.
859 /// Channel announcements also require a signature from each node's network key. Our node
860 /// signature is computed through [`NodeSigner::sign_gossip_message`].
862 /// Note that if this fails or is rejected, the channel will not be publicly announced and
863 /// our counterparty may (though likely will not) close the channel on us for violating the
865 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_SignatureNoneZ,
866 /// Implementation of ChannelSigner for this object.
867 pub ChannelSigner: crate::lightning::sign::ChannelSigner,
868 /// Frees any resources associated with this object given its this_arg pointer.
869 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
870 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
872 unsafe impl Send for EcdsaChannelSigner {}
873 unsafe impl Sync for EcdsaChannelSigner {}
875 pub(crate) extern "C" fn EcdsaChannelSigner_clone_fields(orig: &EcdsaChannelSigner) -> EcdsaChannelSigner {
877 this_arg: orig.this_arg,
878 sign_counterparty_commitment: Clone::clone(&orig.sign_counterparty_commitment),
879 validate_counterparty_revocation: Clone::clone(&orig.validate_counterparty_revocation),
880 sign_holder_commitment_and_htlcs: Clone::clone(&orig.sign_holder_commitment_and_htlcs),
881 sign_justice_revoked_output: Clone::clone(&orig.sign_justice_revoked_output),
882 sign_justice_revoked_htlc: Clone::clone(&orig.sign_justice_revoked_htlc),
883 sign_holder_htlc_transaction: Clone::clone(&orig.sign_holder_htlc_transaction),
884 sign_counterparty_htlc_transaction: Clone::clone(&orig.sign_counterparty_htlc_transaction),
885 sign_closing_transaction: Clone::clone(&orig.sign_closing_transaction),
886 sign_holder_anchor_input: Clone::clone(&orig.sign_holder_anchor_input),
887 sign_channel_announcement_with_funding_key: Clone::clone(&orig.sign_channel_announcement_with_funding_key),
888 ChannelSigner: crate::lightning::sign::ChannelSigner_clone_fields(&orig.ChannelSigner),
889 free: Clone::clone(&orig.free),
892 impl lightning::sign::ChannelSigner for EcdsaChannelSigner {
893 fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
894 let mut ret = (self.ChannelSigner.get_per_commitment_point)(self.ChannelSigner.this_arg, idx);
897 fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
898 let mut ret = (self.ChannelSigner.release_commitment_secret)(self.ChannelSigner.this_arg, idx);
901 fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
902 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
903 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());
904 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)) })*/ })};
907 fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
908 if let Some(f) = self.ChannelSigner.set_pubkeys {
909 (f)(&self.ChannelSigner);
911 unsafe { &*self.ChannelSigner.pubkeys.get() }.get_native_ref()
913 fn channel_keys_id(&self) -> [u8; 32] {
914 let mut ret = (self.ChannelSigner.channel_keys_id)(self.ChannelSigner.this_arg);
917 fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
918 (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 })
922 use lightning::sign::EcdsaChannelSigner as rustEcdsaChannelSigner;
923 impl rustEcdsaChannelSigner for EcdsaChannelSigner {
924 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>), ()> {
925 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
926 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());
927 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)) })*/ })};
930 fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
931 let mut ret = (self.validate_counterparty_revocation)(self.this_arg, idx, secret.as_ref());
932 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)) })*/ })};
935 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>), ()> {
936 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 });
937 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)) })*/ })};
940 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, ()> {
941 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());
942 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)) })*/ })};
945 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, ()> {
946 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 });
947 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)) })*/ })};
950 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, ()> {
951 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 });
952 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)) })*/ })};
955 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, ()> {
956 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 });
957 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)) })*/ })};
960 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, ()> {
961 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 });
962 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)) })*/ })};
965 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, ()> {
966 let mut ret = (self.sign_holder_anchor_input)(self.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
967 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)) })*/ })};
970 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, ()> {
971 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 });
972 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)) })*/ })};
977 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
978 // directly as a Deref trait in higher-level structs:
979 impl core::ops::Deref for EcdsaChannelSigner {
981 fn deref(&self) -> &Self {
985 /// Calls the free function if one is set
987 pub extern "C" fn EcdsaChannelSigner_free(this_ptr: EcdsaChannelSigner) { }
988 impl Drop for EcdsaChannelSigner {
990 if let Some(f) = self.free {
995 /// A writeable signer.
997 /// There will always be two instances of a signer per channel, one occupied by the
998 /// [`ChannelManager`] and another by the channel's [`ChannelMonitor`].
1000 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1001 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
1003 pub struct WriteableEcdsaChannelSigner {
1004 /// An opaque pointer which is passed to your function implementations as an argument.
1005 /// This has no meaning in the LDK, and can be NULL or any other value.
1006 pub this_arg: *mut c_void,
1007 /// Implementation of EcdsaChannelSigner for this object.
1008 pub EcdsaChannelSigner: crate::lightning::sign::EcdsaChannelSigner,
1009 /// Serialize the object into a byte array
1010 pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
1011 /// Frees any resources associated with this object given its this_arg pointer.
1012 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1013 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1015 unsafe impl Send for WriteableEcdsaChannelSigner {}
1016 unsafe impl Sync for WriteableEcdsaChannelSigner {}
1018 pub(crate) extern "C" fn WriteableEcdsaChannelSigner_clone_fields(orig: &WriteableEcdsaChannelSigner) -> WriteableEcdsaChannelSigner {
1019 WriteableEcdsaChannelSigner {
1020 this_arg: orig.this_arg,
1021 EcdsaChannelSigner: crate::lightning::sign::EcdsaChannelSigner_clone_fields(&orig.EcdsaChannelSigner),
1022 write: Clone::clone(&orig.write),
1023 free: Clone::clone(&orig.free),
1026 impl lightning::sign::EcdsaChannelSigner for WriteableEcdsaChannelSigner {
1027 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>), ()> {
1028 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1029 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());
1030 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)) })*/ })};
1033 fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
1034 let mut ret = (self.EcdsaChannelSigner.validate_counterparty_revocation)(self.EcdsaChannelSigner.this_arg, idx, secret.as_ref());
1035 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)) })*/ })};
1038 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>), ()> {
1039 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 });
1040 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)) })*/ })};
1043 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, ()> {
1044 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());
1045 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)) })*/ })};
1048 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, ()> {
1049 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 });
1050 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)) })*/ })};
1053 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, ()> {
1054 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 });
1055 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)) })*/ })};
1058 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, ()> {
1059 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 });
1060 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)) })*/ })};
1063 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, ()> {
1064 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 });
1065 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)) })*/ })};
1068 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, ()> {
1069 let mut ret = (self.EcdsaChannelSigner.sign_holder_anchor_input)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
1070 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)) })*/ })};
1073 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, ()> {
1074 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 });
1075 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 impl lightning::sign::ChannelSigner for WriteableEcdsaChannelSigner {
1080 fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
1081 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.get_per_commitment_point)(self.EcdsaChannelSigner.ChannelSigner.this_arg, idx);
1084 fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
1085 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.release_commitment_secret)(self.EcdsaChannelSigner.ChannelSigner.this_arg, idx);
1088 fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
1089 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1090 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());
1091 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)) })*/ })};
1094 fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
1095 if let Some(f) = self.EcdsaChannelSigner.ChannelSigner.set_pubkeys {
1096 (f)(&self.EcdsaChannelSigner.ChannelSigner);
1098 unsafe { &*self.EcdsaChannelSigner.ChannelSigner.pubkeys.get() }.get_native_ref()
1100 fn channel_keys_id(&self) -> [u8; 32] {
1101 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.channel_keys_id)(self.EcdsaChannelSigner.ChannelSigner.this_arg);
1104 fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
1105 (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 })
1108 impl lightning::util::ser::Writeable for WriteableEcdsaChannelSigner {
1109 fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
1110 let vec = (self.write)(self.this_arg);
1111 w.write_all(vec.as_slice())
1115 use lightning::sign::WriteableEcdsaChannelSigner as rustWriteableEcdsaChannelSigner;
1116 impl rustWriteableEcdsaChannelSigner for WriteableEcdsaChannelSigner {
1119 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1120 // directly as a Deref trait in higher-level structs:
1121 impl core::ops::Deref for WriteableEcdsaChannelSigner {
1123 fn deref(&self) -> &Self {
1127 /// Calls the free function if one is set
1129 pub extern "C" fn WriteableEcdsaChannelSigner_free(this_ptr: WriteableEcdsaChannelSigner) { }
1130 impl Drop for WriteableEcdsaChannelSigner {
1131 fn drop(&mut self) {
1132 if let Some(f) = self.free {
1137 /// Specifies the recipient of an invoice.
1139 /// This indicates to [`NodeSigner::sign_invoice`] what node secret key should be used to sign
1144 pub enum Recipient {
1145 /// The invoice should be signed with the local node secret key.
1147 /// The invoice should be signed with the phantom node secret key. This secret key must be the
1148 /// same for all nodes participating in the [phantom node payment].
1150 /// [phantom node payment]: PhantomKeysManager
1153 use lightning::sign::Recipient as RecipientImport;
1154 pub(crate) type nativeRecipient = RecipientImport;
1158 pub(crate) fn to_native(&self) -> nativeRecipient {
1160 Recipient::Node => nativeRecipient::Node,
1161 Recipient::PhantomNode => nativeRecipient::PhantomNode,
1165 pub(crate) fn into_native(self) -> nativeRecipient {
1167 Recipient::Node => nativeRecipient::Node,
1168 Recipient::PhantomNode => nativeRecipient::PhantomNode,
1172 pub(crate) fn from_native(native: &nativeRecipient) -> Self {
1174 nativeRecipient::Node => Recipient::Node,
1175 nativeRecipient::PhantomNode => Recipient::PhantomNode,
1179 pub(crate) fn native_into(native: nativeRecipient) -> Self {
1181 nativeRecipient::Node => Recipient::Node,
1182 nativeRecipient::PhantomNode => Recipient::PhantomNode,
1186 /// Creates a copy of the Recipient
1188 pub extern "C" fn Recipient_clone(orig: &Recipient) -> Recipient {
1192 /// Utility method to constructs a new Node-variant Recipient
1193 pub extern "C" fn Recipient_node() -> Recipient {
1196 /// Utility method to constructs a new PhantomNode-variant Recipient
1197 pub extern "C" fn Recipient_phantom_node() -> Recipient {
1198 Recipient::PhantomNode}
1199 /// A trait that describes a source of entropy.
1201 pub struct EntropySource {
1202 /// An opaque pointer which is passed to your function implementations as an argument.
1203 /// This has no meaning in the LDK, and can be NULL or any other value.
1204 pub this_arg: *mut c_void,
1205 /// Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
1206 /// different value each time it is called.
1207 pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1208 /// Frees any resources associated with this object given its this_arg pointer.
1209 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1210 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1212 unsafe impl Send for EntropySource {}
1213 unsafe impl Sync for EntropySource {}
1215 pub(crate) extern "C" fn EntropySource_clone_fields(orig: &EntropySource) -> EntropySource {
1217 this_arg: orig.this_arg,
1218 get_secure_random_bytes: Clone::clone(&orig.get_secure_random_bytes),
1219 free: Clone::clone(&orig.free),
1223 use lightning::sign::EntropySource as rustEntropySource;
1224 impl rustEntropySource for EntropySource {
1225 fn get_secure_random_bytes(&self) -> [u8; 32] {
1226 let mut ret = (self.get_secure_random_bytes)(self.this_arg);
1231 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1232 // directly as a Deref trait in higher-level structs:
1233 impl core::ops::Deref for EntropySource {
1235 fn deref(&self) -> &Self {
1239 /// Calls the free function if one is set
1241 pub extern "C" fn EntropySource_free(this_ptr: EntropySource) { }
1242 impl Drop for EntropySource {
1243 fn drop(&mut self) {
1244 if let Some(f) = self.free {
1249 /// A trait that can handle cryptographic operations at the scope level of a node.
1251 pub struct NodeSigner {
1252 /// An opaque pointer which is passed to your function implementations as an argument.
1253 /// This has no meaning in the LDK, and can be NULL or any other value.
1254 pub this_arg: *mut c_void,
1255 /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
1257 /// If the implementor of this trait supports [phantom node payments], then every node that is
1258 /// intended to be included in the phantom invoice route hints must return the same value from
1261 /// This method must return the same value each time it is called.
1263 /// [phantom node payments]: PhantomKeysManager
1264 pub get_inbound_payment_key_material: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1265 /// Get node id based on the provided [`Recipient`].
1267 /// This method must return the same value each time it is called with a given [`Recipient`]
1270 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1271 pub get_node_id: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ,
1272 /// Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
1273 /// one is provided. Note that this tweak can be applied to `other_key` instead of our node
1274 /// secret, though this is less efficient.
1276 /// Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
1277 /// should be resolved to allow LDK to resume forwarding HTLCs.
1279 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1280 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_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ,
1281 /// Sign an invoice.
1283 /// By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
1284 /// this trait to parse the invoice and make sure they're signing what they expect, rather than
1285 /// blindly signing the hash.
1287 /// The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
1289 /// The secret key used to sign the invoice is dependent on the [`Recipient`].
1291 /// Errors if the [`Recipient`] variant is not supported by the implementation.
1292 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,
1293 /// Sign a gossip message.
1295 /// Note that if this fails, LDK may panic and the message will not be broadcast to the network
1296 /// or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
1297 /// message to be broadcast, as otherwise it may prevent one from receiving funds over the
1298 /// corresponding channel.
1299 pub sign_gossip_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_SignatureNoneZ,
1300 /// Frees any resources associated with this object given its this_arg pointer.
1301 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1302 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1304 unsafe impl Send for NodeSigner {}
1305 unsafe impl Sync for NodeSigner {}
1307 pub(crate) extern "C" fn NodeSigner_clone_fields(orig: &NodeSigner) -> NodeSigner {
1309 this_arg: orig.this_arg,
1310 get_inbound_payment_key_material: Clone::clone(&orig.get_inbound_payment_key_material),
1311 get_node_id: Clone::clone(&orig.get_node_id),
1312 ecdh: Clone::clone(&orig.ecdh),
1313 sign_invoice: Clone::clone(&orig.sign_invoice),
1314 sign_gossip_message: Clone::clone(&orig.sign_gossip_message),
1315 free: Clone::clone(&orig.free),
1319 use lightning::sign::NodeSigner as rustNodeSigner;
1320 impl rustNodeSigner for NodeSigner {
1321 fn get_inbound_payment_key_material(&self) -> lightning::sign::KeyMaterial {
1322 let mut ret = (self.get_inbound_payment_key_material)(self.this_arg);
1323 ::lightning::sign::KeyMaterial(ret.data)
1325 fn get_node_id(&self, mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::PublicKey, ()> {
1326 let mut ret = (self.get_node_id)(self.this_arg, crate::lightning::sign::Recipient::native_into(recipient));
1327 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)) })*/ })};
1330 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, ()> {
1331 let mut local_tweak = if tweak.is_none() { crate::c_types::derived::COption_ScalarZ::None } else { crate::c_types::derived::COption_ScalarZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::BigEndianScalar::from_rust(&(*tweak.as_ref().unwrap()).clone()) }) };
1332 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);
1333 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)) })*/ })};
1336 fn sign_invoice(&self, mut hrp_bytes: &[u8], mut invoice_data: &[bitcoin::bech32::u5], mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
1337 let mut local_hrp_bytes = crate::c_types::u8slice::from_slice(hrp_bytes);
1338 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() }); };
1339 let mut ret = (self.sign_invoice)(self.this_arg, local_hrp_bytes, local_invoice_data.into(), crate::lightning::sign::Recipient::native_into(recipient));
1340 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)) })*/ })};
1343 fn sign_gossip_message(&self, mut msg: lightning::ln::msgs::UnsignedGossipMessage) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1344 let mut ret = (self.sign_gossip_message)(self.this_arg, crate::lightning::ln::msgs::UnsignedGossipMessage::native_into(msg));
1345 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)) })*/ })};
1350 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1351 // directly as a Deref trait in higher-level structs:
1352 impl core::ops::Deref for NodeSigner {
1354 fn deref(&self) -> &Self {
1358 /// Calls the free function if one is set
1360 pub extern "C" fn NodeSigner_free(this_ptr: NodeSigner) { }
1361 impl Drop for NodeSigner {
1362 fn drop(&mut self) {
1363 if let Some(f) = self.free {
1368 /// A trait that can return signer instances for individual channels.
1370 pub struct SignerProvider {
1371 /// An opaque pointer which is passed to your function implementations as an argument.
1372 /// This has no meaning in the LDK, and can be NULL or any other value.
1373 pub this_arg: *mut c_void,
1374 /// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
1375 /// [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
1376 /// implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
1377 /// `channel_keys_id`.
1379 /// This method must return a different value each time it is called.
1380 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,
1381 /// Derives the private key material backing a `Signer`.
1383 /// To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
1384 /// [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
1385 /// re-derived from its `channel_keys_id`, which can be obtained through its trait method
1386 /// [`ChannelSigner::channel_keys_id`].
1387 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,
1388 /// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
1389 /// This is only called during deserialization of other objects which contain
1390 /// [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
1391 /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
1392 /// contain no versioning scheme. You may wish to include your own version prefix and ensure
1393 /// you've read all of the provided bytes to ensure no corruption occurred.
1395 /// This method is slowly being phased out -- it will only be called when reading objects
1396 /// written by LDK versions prior to 0.0.113.
1398 /// [`Signer`]: Self::Signer
1399 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
1400 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1401 pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ,
1402 /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
1404 /// If this function returns an error, this will result in a channel failing to open.
1406 /// This method should return a different value each time it is called, to avoid linking
1407 /// on-chain funds across channels as controlled to the same user.
1408 pub get_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_ScriptNoneZ,
1409 /// Get a script pubkey which we will send funds to when closing a channel.
1411 /// If this function returns an error, this will result in a channel failing to open or close.
1412 /// In the event of a failure when the counterparty is initiating a close, this can result in a
1413 /// channel force close.
1415 /// This method should return a different value each time it is called, to avoid linking
1416 /// on-chain funds across channels as controlled to the same user.
1417 pub get_shutdown_scriptpubkey: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ,
1418 /// Frees any resources associated with this object given its this_arg pointer.
1419 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1420 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1422 unsafe impl Send for SignerProvider {}
1423 unsafe impl Sync for SignerProvider {}
1425 pub(crate) extern "C" fn SignerProvider_clone_fields(orig: &SignerProvider) -> SignerProvider {
1427 this_arg: orig.this_arg,
1428 generate_channel_keys_id: Clone::clone(&orig.generate_channel_keys_id),
1429 derive_channel_signer: Clone::clone(&orig.derive_channel_signer),
1430 read_chan_signer: Clone::clone(&orig.read_chan_signer),
1431 get_destination_script: Clone::clone(&orig.get_destination_script),
1432 get_shutdown_scriptpubkey: Clone::clone(&orig.get_shutdown_scriptpubkey),
1433 free: Clone::clone(&orig.free),
1437 use lightning::sign::SignerProvider as rustSignerProvider;
1438 impl rustSignerProvider for SignerProvider {
1439 type Signer = crate::lightning::sign::WriteableEcdsaChannelSigner;
1440 fn generate_channel_keys_id(&self, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: u128) -> [u8; 32] {
1441 let mut ret = (self.generate_channel_keys_id)(self.this_arg, inbound, channel_value_satoshis, user_channel_id.into());
1444 fn derive_channel_signer(&self, mut channel_value_satoshis: u64, mut channel_keys_id: [u8; 32]) -> crate::lightning::sign::WriteableEcdsaChannelSigner {
1445 let mut ret = (self.derive_channel_signer)(self.this_arg, channel_value_satoshis, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
1448 fn read_chan_signer(&self, mut reader: &[u8]) -> Result<crate::lightning::sign::WriteableEcdsaChannelSigner, lightning::ln::msgs::DecodeError> {
1449 let mut local_reader = crate::c_types::u8slice::from_slice(reader);
1450 let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
1451 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() })};
1454 fn get_destination_script(&self) -> Result<bitcoin::blockdata::script::Script, ()> {
1455 let mut ret = (self.get_destination_script)(self.this_arg);
1456 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)) })*/ })};
1459 fn get_shutdown_scriptpubkey(&self) -> Result<lightning::ln::script::ShutdownScript, ()> {
1460 let mut ret = (self.get_shutdown_scriptpubkey)(self.this_arg);
1461 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)) })*/ })};
1466 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1467 // directly as a Deref trait in higher-level structs:
1468 impl core::ops::Deref for SignerProvider {
1470 fn deref(&self) -> &Self {
1474 /// Calls the free function if one is set
1476 pub extern "C" fn SignerProvider_free(this_ptr: SignerProvider) { }
1477 impl Drop for SignerProvider {
1478 fn drop(&mut self) {
1479 if let Some(f) = self.free {
1485 use lightning::sign::InMemorySigner as nativeInMemorySignerImport;
1486 pub(crate) type nativeInMemorySigner = nativeInMemorySignerImport;
1488 /// A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
1490 /// This implementation performs no policy checks and is insufficient by itself as
1491 /// a secure external signer.
1494 pub struct InMemorySigner {
1495 /// A pointer to the opaque Rust object.
1497 /// Nearly everywhere, inner must be non-null, however in places where
1498 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1499 pub inner: *mut nativeInMemorySigner,
1500 /// Indicates that this is the only struct which contains the same pointer.
1502 /// Rust functions which take ownership of an object provided via an argument require
1503 /// this to be true and invalidate the object pointed to by inner.
1507 impl Drop for InMemorySigner {
1508 fn drop(&mut self) {
1509 if self.is_owned && !<*mut nativeInMemorySigner>::is_null(self.inner) {
1510 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1514 /// Frees any resources used by the InMemorySigner, if is_owned is set and inner is non-NULL.
1516 pub extern "C" fn InMemorySigner_free(this_obj: InMemorySigner) { }
1518 /// Used only if an object of this type is returned as a trait impl by a method
1519 pub(crate) extern "C" fn InMemorySigner_free_void(this_ptr: *mut c_void) {
1520 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInMemorySigner) };
1523 impl InMemorySigner {
1524 pub(crate) fn get_native_ref(&self) -> &'static nativeInMemorySigner {
1525 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1527 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInMemorySigner {
1528 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1530 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1531 pub(crate) fn take_inner(mut self) -> *mut nativeInMemorySigner {
1532 assert!(self.is_owned);
1533 let ret = ObjOps::untweak_ptr(self.inner);
1534 self.inner = core::ptr::null_mut();
1538 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1539 /// holder's anchor output in a commitment transaction, if one is present.
1541 pub extern "C" fn InMemorySigner_get_funding_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1542 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_key;
1545 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1546 /// holder's anchor output in a commitment transaction, if one is present.
1548 pub extern "C" fn InMemorySigner_set_funding_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1549 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_key = val.into_rust();
1551 /// Holder secret key for blinded revocation pubkey.
1553 pub extern "C" fn InMemorySigner_get_revocation_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1554 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_base_key;
1557 /// Holder secret key for blinded revocation pubkey.
1559 pub extern "C" fn InMemorySigner_set_revocation_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1560 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_base_key = val.into_rust();
1562 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1564 pub extern "C" fn InMemorySigner_get_payment_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1565 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_key;
1568 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1570 pub extern "C" fn InMemorySigner_set_payment_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1571 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_key = val.into_rust();
1573 /// Holder secret key used in an HTLC transaction.
1575 pub extern "C" fn InMemorySigner_get_delayed_payment_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1576 let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_base_key;
1579 /// Holder secret key used in an HTLC transaction.
1581 pub extern "C" fn InMemorySigner_set_delayed_payment_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1582 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_base_key = val.into_rust();
1584 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1586 pub extern "C" fn InMemorySigner_get_htlc_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1587 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_base_key;
1590 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1592 pub extern "C" fn InMemorySigner_set_htlc_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1593 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_base_key = val.into_rust();
1595 /// Commitment seed.
1597 pub extern "C" fn InMemorySigner_get_commitment_seed(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1598 let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_seed;
1601 /// Commitment seed.
1603 pub extern "C" fn InMemorySigner_set_commitment_seed(this_ptr: &mut InMemorySigner, mut val: crate::c_types::ThirtyTwoBytes) {
1604 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_seed = val.data;
1606 impl Clone for InMemorySigner {
1607 fn clone(&self) -> Self {
1609 inner: if <*mut nativeInMemorySigner>::is_null(self.inner) { core::ptr::null_mut() } else {
1610 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1616 /// Used only if an object of this type is returned as a trait impl by a method
1617 pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void {
1618 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInMemorySigner)).clone() })) as *mut c_void
1621 /// Creates a copy of the InMemorySigner
1622 pub extern "C" fn InMemorySigner_clone(orig: &InMemorySigner) -> InMemorySigner {
1625 /// Creates a new [`InMemorySigner`].
1628 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 {
1629 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);
1630 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
1633 /// Returns the counterparty's pubkeys.
1635 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1638 pub extern "C" fn InMemorySigner_counterparty_pubkeys(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1639 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_pubkeys();
1640 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 }
1643 /// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
1644 /// transactions, i.e., the amount of time that we have to wait to recover our funds if we
1645 /// broadcast a transaction.
1647 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1650 pub extern "C" fn InMemorySigner_counterparty_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> u16 {
1651 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_selected_contest_delay();
1655 /// Returns the `contest_delay` value specified by us and applied on transactions broadcastable
1656 /// by our counterparty, i.e., the amount of time that they have to wait to recover their funds
1657 /// if they broadcast a transaction.
1659 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1662 pub extern "C" fn InMemorySigner_holder_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> u16 {
1663 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.holder_selected_contest_delay();
1667 /// Returns whether the holder is the initiator.
1669 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1672 pub extern "C" fn InMemorySigner_is_outbound(this_arg: &crate::lightning::sign::InMemorySigner) -> bool {
1673 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
1677 /// Funding outpoint
1679 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1682 pub extern "C" fn InMemorySigner_funding_outpoint(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::chain::transaction::OutPoint {
1683 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
1684 crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::chain::transaction::OutPoint<>) as *mut _) }, is_owned: false }
1687 /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
1688 /// building transactions.
1690 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1693 pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
1694 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_channel_parameters();
1695 crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false }
1698 /// Returns the channel type features of the channel parameters. Should be helpful for
1699 /// determining a channel's category, i. e. legacy/anchors/taproot/etc.
1701 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1704 pub extern "C" fn InMemorySigner_channel_type_features(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::features::ChannelTypeFeatures {
1705 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_type_features();
1706 crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _) }, is_owned: false }
1709 /// Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
1710 /// by `descriptor`, returning the witness stack for the input.
1712 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
1713 /// is not spending the outpoint described by [`descriptor.outpoint`],
1714 /// or if an output descriptor `script_pubkey` does not match the one we can spend.
1716 /// [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
1719 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 {
1720 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);
1721 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() };
1725 /// Sign the single input of `spend_tx` at index `input_idx` which spends the output
1726 /// described by `descriptor`, returning the witness stack for the input.
1728 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
1729 /// is not spending the outpoint described by [`descriptor.outpoint`], does not have a
1730 /// sequence set to [`descriptor.to_self_delay`], or if an output descriptor
1731 /// `script_pubkey` does not match the one we can spend.
1733 /// [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
1734 /// [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
1737 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 {
1738 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);
1739 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() };
1743 impl From<nativeInMemorySigner> for crate::lightning::sign::EntropySource {
1744 fn from(obj: nativeInMemorySigner) -> Self {
1745 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1746 let mut ret = InMemorySigner_as_EntropySource(&rust_obj);
1747 // 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
1748 rust_obj.inner = core::ptr::null_mut();
1749 ret.free = Some(InMemorySigner_free_void);
1753 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
1754 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
1756 pub extern "C" fn InMemorySigner_as_EntropySource(this_arg: &InMemorySigner) -> crate::lightning::sign::EntropySource {
1757 crate::lightning::sign::EntropySource {
1758 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1760 get_secure_random_bytes: InMemorySigner_EntropySource_get_secure_random_bytes,
1765 extern "C" fn InMemorySigner_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1766 let mut ret = <nativeInMemorySigner as lightning::sign::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1767 crate::c_types::ThirtyTwoBytes { data: ret }
1770 impl From<nativeInMemorySigner> for crate::lightning::sign::ChannelSigner {
1771 fn from(obj: nativeInMemorySigner) -> Self {
1772 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1773 let mut ret = InMemorySigner_as_ChannelSigner(&rust_obj);
1774 // 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
1775 rust_obj.inner = core::ptr::null_mut();
1776 ret.free = Some(InMemorySigner_free_void);
1780 /// Constructs a new ChannelSigner which calls the relevant methods on this_arg.
1781 /// This copies the `inner` pointer in this_arg and thus the returned ChannelSigner must be freed before this_arg is
1783 pub extern "C" fn InMemorySigner_as_ChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ChannelSigner {
1784 crate::lightning::sign::ChannelSigner {
1785 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1787 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
1788 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
1789 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
1791 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
1792 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
1793 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
1794 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
1799 extern "C" fn InMemorySigner_ChannelSigner_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey {
1800 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::get_per_commitment_point(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, secp256k1::global::SECP256K1);
1801 crate::c_types::PublicKey::from_rust(&ret)
1804 extern "C" fn InMemorySigner_ChannelSigner_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
1805 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::release_commitment_secret(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx);
1806 crate::c_types::ThirtyTwoBytes { data: ret }
1809 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_PaymentPreimageZ) -> crate::c_types::derived::CResult_NoneNoneZ {
1810 let mut local_preimages = Vec::new(); for mut item in preimages.into_rust().drain(..) { local_preimages.push( { ::lightning::ln::PaymentPreimage(item.data) }); };
1811 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);
1812 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() };
1816 extern "C" fn InMemorySigner_ChannelSigner_pubkeys(this_arg: *const c_void) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1817 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::pubkeys(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1818 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 }
1820 extern "C" fn InMemorySigner_ChannelSigner_set_pubkeys(trait_self_arg: &ChannelSigner) {
1821 // This is a bit race-y in the general case, but for our specific use-cases today, we're safe
1822 // Specifically, we must ensure that the first time we're called it can never be in parallel
1823 if unsafe { &*trait_self_arg.pubkeys.get() }.inner.is_null() {
1824 *unsafe { &mut *(&*(trait_self_arg as *const ChannelSigner)).pubkeys.get() } = InMemorySigner_ChannelSigner_pubkeys(trait_self_arg.this_arg).into();
1828 extern "C" fn InMemorySigner_ChannelSigner_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1829 let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::channel_keys_id(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1830 crate::c_types::ThirtyTwoBytes { data: ret }
1832 extern "C" fn InMemorySigner_ChannelSigner_provide_channel_parameters(this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
1833 <nativeInMemorySigner as lightning::sign::ChannelSigner<>>::provide_channel_parameters(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, channel_parameters.get_native_ref())
1836 impl From<nativeInMemorySigner> for crate::lightning::sign::EcdsaChannelSigner {
1837 fn from(obj: nativeInMemorySigner) -> Self {
1838 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1839 let mut ret = InMemorySigner_as_EcdsaChannelSigner(&rust_obj);
1840 // 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
1841 rust_obj.inner = core::ptr::null_mut();
1842 ret.free = Some(InMemorySigner_free_void);
1846 /// Constructs a new EcdsaChannelSigner which calls the relevant methods on this_arg.
1847 /// This copies the `inner` pointer in this_arg and thus the returned EcdsaChannelSigner must be freed before this_arg is
1849 pub extern "C" fn InMemorySigner_as_EcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::EcdsaChannelSigner {
1850 crate::lightning::sign::EcdsaChannelSigner {
1851 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1853 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
1854 validate_counterparty_revocation: InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation,
1855 sign_holder_commitment_and_htlcs: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs,
1856 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
1857 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
1858 sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
1859 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
1860 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
1861 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
1862 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
1863 ChannelSigner: crate::lightning::sign::ChannelSigner {
1864 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1866 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
1867 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
1868 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
1870 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
1871 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
1872 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
1873 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
1879 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_PaymentPreimageZ) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ {
1880 let mut local_preimages = Vec::new(); for mut item in preimages.into_rust().drain(..) { local_preimages.push( { ::lightning::ln::PaymentPreimage(item.data) }); };
1881 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);
1882 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::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::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() };
1886 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 {
1887 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());
1888 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() };
1892 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_SignatureCVec_SignatureZZNoneZ {
1893 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);
1894 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::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::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() };
1898 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_SignatureNoneZ {
1899 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);
1900 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1904 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_SignatureNoneZ {
1905 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);
1906 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1910 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_SignatureNoneZ {
1911 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);
1912 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1916 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_SignatureNoneZ {
1917 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);
1918 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1922 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_SignatureNoneZ {
1923 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);
1924 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1928 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_SignatureNoneZ {
1929 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);
1930 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1934 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_SignatureNoneZ {
1935 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);
1936 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1940 impl From<nativeInMemorySigner> for crate::lightning::sign::WriteableEcdsaChannelSigner {
1941 fn from(obj: nativeInMemorySigner) -> Self {
1942 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1943 let mut ret = InMemorySigner_as_WriteableEcdsaChannelSigner(&rust_obj);
1944 // 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
1945 rust_obj.inner = core::ptr::null_mut();
1946 ret.free = Some(InMemorySigner_free_void);
1950 /// Constructs a new WriteableEcdsaChannelSigner which calls the relevant methods on this_arg.
1951 /// This copies the `inner` pointer in this_arg and thus the returned WriteableEcdsaChannelSigner must be freed before this_arg is
1953 pub extern "C" fn InMemorySigner_as_WriteableEcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::WriteableEcdsaChannelSigner {
1954 crate::lightning::sign::WriteableEcdsaChannelSigner {
1955 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1957 EcdsaChannelSigner: crate::lightning::sign::EcdsaChannelSigner {
1958 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1960 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
1961 validate_counterparty_revocation: InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation,
1962 sign_holder_commitment_and_htlcs: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs,
1963 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
1964 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
1965 sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
1966 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
1967 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
1968 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
1969 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
1970 ChannelSigner: crate::lightning::sign::ChannelSigner {
1971 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1973 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
1974 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
1975 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
1977 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
1978 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
1979 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
1980 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
1983 write: InMemorySigner_write_void,
1989 /// Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
1990 pub extern "C" fn InMemorySigner_write(obj: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::CVec_u8Z {
1991 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1994 pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1995 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) })
1998 /// Read a InMemorySigner from a byte array, created by InMemorySigner_write
1999 pub extern "C" fn InMemorySigner_read(ser: crate::c_types::u8slice, arg: crate::lightning::sign::EntropySource) -> crate::c_types::derived::CResult_InMemorySignerDecodeErrorZ {
2001 let res: Result<lightning::sign::InMemorySigner, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
2002 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() };
2006 use lightning::sign::KeysManager as nativeKeysManagerImport;
2007 pub(crate) type nativeKeysManager = nativeKeysManagerImport;
2009 /// Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a
2010 /// 32-byte seed for use as a BIP 32 extended key and derives keys from that.
2012 /// Your `node_id` is seed/0'.
2013 /// Unilateral closes may use seed/1'.
2014 /// Cooperative closes may use seed/2'.
2015 /// The two close keys may be needed to claim on-chain funds!
2017 /// This struct cannot be used for nodes that wish to support receiving phantom payments;
2018 /// [`PhantomKeysManager`] must be used instead.
2020 /// Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
2021 /// previously issued invoices and attempts to pay previous invoices will fail.
2024 pub struct KeysManager {
2025 /// A pointer to the opaque Rust object.
2027 /// Nearly everywhere, inner must be non-null, however in places where
2028 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2029 pub inner: *mut nativeKeysManager,
2030 /// Indicates that this is the only struct which contains the same pointer.
2032 /// Rust functions which take ownership of an object provided via an argument require
2033 /// this to be true and invalidate the object pointed to by inner.
2037 impl Drop for KeysManager {
2038 fn drop(&mut self) {
2039 if self.is_owned && !<*mut nativeKeysManager>::is_null(self.inner) {
2040 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2044 /// Frees any resources used by the KeysManager, if is_owned is set and inner is non-NULL.
2046 pub extern "C" fn KeysManager_free(this_obj: KeysManager) { }
2048 /// Used only if an object of this type is returned as a trait impl by a method
2049 pub(crate) extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) {
2050 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeKeysManager) };
2054 pub(crate) fn get_native_ref(&self) -> &'static nativeKeysManager {
2055 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2057 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeKeysManager {
2058 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2060 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2061 pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager {
2062 assert!(self.is_owned);
2063 let ret = ObjOps::untweak_ptr(self.inner);
2064 self.inner = core::ptr::null_mut();
2068 /// Constructs a [`KeysManager`] from a 32-byte seed. If the seed is in some way biased (e.g.,
2069 /// your CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
2070 /// `starting_time` isn't strictly required to actually be a time, but it must absolutely,
2071 /// without a doubt, be unique to this instance. ie if you start multiple times with the same
2072 /// `seed`, `starting_time` must be unique to each run. Thus, the easiest way to achieve this
2073 /// is to simply use the current time (with very high precision).
2075 /// The `seed` MUST be backed up safely prior to use so that the keys can be re-created, however,
2076 /// obviously, `starting_time` should be unique every time you reload the library - it is only
2077 /// used to generate new ephemeral key data (which will be stored by the individual channel if
2080 /// Note that the seed is required to recover certain on-chain funds independent of
2081 /// [`ChannelMonitor`] data, though a current copy of [`ChannelMonitor`] data is also required
2082 /// for any channel, and some on-chain during-closing funds.
2084 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
2087 pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32) -> crate::lightning::sign::KeysManager {
2088 let mut ret = lightning::sign::KeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos);
2089 crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2092 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2095 pub extern "C" fn KeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::KeysManager) -> crate::c_types::SecretKey {
2096 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2097 crate::c_types::SecretKey::from_rust(ret)
2100 /// Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
2103 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 {
2104 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2105 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2108 /// Signs the given [`PartiallySignedTransaction`] which spends the given [`SpendableOutputDescriptor`]s.
2109 /// The resulting inputs will be finalized and the PSBT will be ready for broadcast if there
2110 /// are no other inputs that need signing.
2112 /// Returns `Err(())` if the PSBT is missing a descriptor or if we fail to sign.
2114 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
2115 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2118 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_PartiallySignedTransactionNoneZ {
2119 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2120 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);
2121 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() };
2125 /// Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
2126 /// output to the given change destination (if sufficient change value remains). The
2127 /// transaction will have a feerate, at least, of the given value.
2129 /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
2130 /// transaction will have a locktime of 0. It it recommended to set this to the current block
2131 /// height to avoid fee sniping, unless you have some specific reason to use a different
2134 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
2135 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
2136 /// does not match the one we can spend.
2138 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
2140 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
2141 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2144 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_PackedLockTimeZ) -> crate::c_types::derived::CResult_TransactionNoneZ {
2145 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2146 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2147 let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::PackedLockTime({ locktime_opt.take() }) }})} };
2148 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);
2149 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() };
2153 impl From<nativeKeysManager> for crate::lightning::sign::EntropySource {
2154 fn from(obj: nativeKeysManager) -> Self {
2155 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2156 let mut ret = KeysManager_as_EntropySource(&rust_obj);
2157 // 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
2158 rust_obj.inner = core::ptr::null_mut();
2159 ret.free = Some(KeysManager_free_void);
2163 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2164 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2166 pub extern "C" fn KeysManager_as_EntropySource(this_arg: &KeysManager) -> crate::lightning::sign::EntropySource {
2167 crate::lightning::sign::EntropySource {
2168 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2170 get_secure_random_bytes: KeysManager_EntropySource_get_secure_random_bytes,
2175 extern "C" fn KeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2176 let mut ret = <nativeKeysManager as lightning::sign::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2177 crate::c_types::ThirtyTwoBytes { data: ret }
2180 impl From<nativeKeysManager> for crate::lightning::sign::NodeSigner {
2181 fn from(obj: nativeKeysManager) -> Self {
2182 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2183 let mut ret = KeysManager_as_NodeSigner(&rust_obj);
2184 // 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
2185 rust_obj.inner = core::ptr::null_mut();
2186 ret.free = Some(KeysManager_free_void);
2190 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2191 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2193 pub extern "C" fn KeysManager_as_NodeSigner(this_arg: &KeysManager) -> crate::lightning::sign::NodeSigner {
2194 crate::lightning::sign::NodeSigner {
2195 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2197 get_inbound_payment_key_material: KeysManager_NodeSigner_get_inbound_payment_key_material,
2198 get_node_id: KeysManager_NodeSigner_get_node_id,
2199 ecdh: KeysManager_NodeSigner_ecdh,
2200 sign_invoice: KeysManager_NodeSigner_sign_invoice,
2201 sign_gossip_message: KeysManager_NodeSigner_sign_gossip_message,
2206 extern "C" fn KeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2207 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2208 crate::c_types::ThirtyTwoBytes { data: ret.0 }
2211 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 {
2212 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native());
2213 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() };
2217 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_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ {
2218 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();
2219 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);
2220 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() };
2224 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 {
2225 let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2226 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());
2227 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() };
2231 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_SignatureNoneZ {
2232 let mut ret = <nativeKeysManager as lightning::sign::NodeSigner<>>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, msg.into_native());
2233 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2237 impl From<nativeKeysManager> for crate::lightning::sign::SignerProvider {
2238 fn from(obj: nativeKeysManager) -> Self {
2239 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2240 let mut ret = KeysManager_as_SignerProvider(&rust_obj);
2241 // 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
2242 rust_obj.inner = core::ptr::null_mut();
2243 ret.free = Some(KeysManager_free_void);
2247 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2248 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2250 pub extern "C" fn KeysManager_as_SignerProvider(this_arg: &KeysManager) -> crate::lightning::sign::SignerProvider {
2251 crate::lightning::sign::SignerProvider {
2252 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2254 generate_channel_keys_id: KeysManager_SignerProvider_generate_channel_keys_id,
2255 derive_channel_signer: KeysManager_SignerProvider_derive_channel_signer,
2256 read_chan_signer: KeysManager_SignerProvider_read_chan_signer,
2257 get_destination_script: KeysManager_SignerProvider_get_destination_script,
2258 get_shutdown_scriptpubkey: KeysManager_SignerProvider_get_shutdown_scriptpubkey,
2263 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 {
2264 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());
2265 crate::c_types::ThirtyTwoBytes { data: ret }
2268 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 {
2269 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);
2273 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 {
2274 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, reader.to_slice());
2275 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() };
2279 extern "C" fn KeysManager_SignerProvider_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CResult_ScriptNoneZ {
2280 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2281 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() };
2285 extern "C" fn KeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2286 let mut ret = <nativeKeysManager as lightning::sign::SignerProvider<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2287 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() };
2292 use lightning::sign::PhantomKeysManager as nativePhantomKeysManagerImport;
2293 pub(crate) type nativePhantomKeysManager = nativePhantomKeysManagerImport;
2295 /// Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
2298 /// A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
2299 /// paid to one of multiple nodes. This works because we encode the invoice route hints such that
2300 /// LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
2301 /// itself without ever needing to forward to this fake node.
2303 /// Phantom node payments are useful for load balancing between multiple LDK nodes. They also
2304 /// provide some fault tolerance, because payers will automatically retry paying other provided
2305 /// nodes in the case that one node goes down.
2307 /// Note that multi-path payments are not supported in phantom invoices for security reasons.
2308 /// Switching between this struct and [`KeysManager`] will invalidate any previously issued
2309 /// invoices and attempts to pay previous invoices will fail.
2312 pub struct PhantomKeysManager {
2313 /// A pointer to the opaque Rust object.
2315 /// Nearly everywhere, inner must be non-null, however in places where
2316 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2317 pub inner: *mut nativePhantomKeysManager,
2318 /// Indicates that this is the only struct which contains the same pointer.
2320 /// Rust functions which take ownership of an object provided via an argument require
2321 /// this to be true and invalidate the object pointed to by inner.
2325 impl Drop for PhantomKeysManager {
2326 fn drop(&mut self) {
2327 if self.is_owned && !<*mut nativePhantomKeysManager>::is_null(self.inner) {
2328 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2332 /// Frees any resources used by the PhantomKeysManager, if is_owned is set and inner is non-NULL.
2334 pub extern "C" fn PhantomKeysManager_free(this_obj: PhantomKeysManager) { }
2336 /// Used only if an object of this type is returned as a trait impl by a method
2337 pub(crate) extern "C" fn PhantomKeysManager_free_void(this_ptr: *mut c_void) {
2338 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomKeysManager) };
2341 impl PhantomKeysManager {
2342 pub(crate) fn get_native_ref(&self) -> &'static nativePhantomKeysManager {
2343 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2345 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomKeysManager {
2346 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2348 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2349 pub(crate) fn take_inner(mut self) -> *mut nativePhantomKeysManager {
2350 assert!(self.is_owned);
2351 let ret = ObjOps::untweak_ptr(self.inner);
2352 self.inner = core::ptr::null_mut();
2356 impl From<nativePhantomKeysManager> for crate::lightning::sign::EntropySource {
2357 fn from(obj: nativePhantomKeysManager) -> Self {
2358 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2359 let mut ret = PhantomKeysManager_as_EntropySource(&rust_obj);
2360 // 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
2361 rust_obj.inner = core::ptr::null_mut();
2362 ret.free = Some(PhantomKeysManager_free_void);
2366 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2367 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2369 pub extern "C" fn PhantomKeysManager_as_EntropySource(this_arg: &PhantomKeysManager) -> crate::lightning::sign::EntropySource {
2370 crate::lightning::sign::EntropySource {
2371 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2373 get_secure_random_bytes: PhantomKeysManager_EntropySource_get_secure_random_bytes,
2378 extern "C" fn PhantomKeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2379 let mut ret = <nativePhantomKeysManager as lightning::sign::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2380 crate::c_types::ThirtyTwoBytes { data: ret }
2383 impl From<nativePhantomKeysManager> for crate::lightning::sign::NodeSigner {
2384 fn from(obj: nativePhantomKeysManager) -> Self {
2385 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2386 let mut ret = PhantomKeysManager_as_NodeSigner(&rust_obj);
2387 // 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
2388 rust_obj.inner = core::ptr::null_mut();
2389 ret.free = Some(PhantomKeysManager_free_void);
2393 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2394 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2396 pub extern "C" fn PhantomKeysManager_as_NodeSigner(this_arg: &PhantomKeysManager) -> crate::lightning::sign::NodeSigner {
2397 crate::lightning::sign::NodeSigner {
2398 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2400 get_inbound_payment_key_material: PhantomKeysManager_NodeSigner_get_inbound_payment_key_material,
2401 get_node_id: PhantomKeysManager_NodeSigner_get_node_id,
2402 ecdh: PhantomKeysManager_NodeSigner_ecdh,
2403 sign_invoice: PhantomKeysManager_NodeSigner_sign_invoice,
2404 sign_gossip_message: PhantomKeysManager_NodeSigner_sign_gossip_message,
2409 extern "C" fn PhantomKeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2410 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2411 crate::c_types::ThirtyTwoBytes { data: ret.0 }
2414 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 {
2415 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native());
2416 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() };
2420 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_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ {
2421 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();
2422 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);
2423 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() };
2427 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 {
2428 let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2429 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());
2430 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() };
2434 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_SignatureNoneZ {
2435 let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner<>>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, msg.into_native());
2436 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2440 impl From<nativePhantomKeysManager> for crate::lightning::sign::SignerProvider {
2441 fn from(obj: nativePhantomKeysManager) -> Self {
2442 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2443 let mut ret = PhantomKeysManager_as_SignerProvider(&rust_obj);
2444 // 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
2445 rust_obj.inner = core::ptr::null_mut();
2446 ret.free = Some(PhantomKeysManager_free_void);
2450 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2451 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2453 pub extern "C" fn PhantomKeysManager_as_SignerProvider(this_arg: &PhantomKeysManager) -> crate::lightning::sign::SignerProvider {
2454 crate::lightning::sign::SignerProvider {
2455 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2457 generate_channel_keys_id: PhantomKeysManager_SignerProvider_generate_channel_keys_id,
2458 derive_channel_signer: PhantomKeysManager_SignerProvider_derive_channel_signer,
2459 read_chan_signer: PhantomKeysManager_SignerProvider_read_chan_signer,
2460 get_destination_script: PhantomKeysManager_SignerProvider_get_destination_script,
2461 get_shutdown_scriptpubkey: PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey,
2466 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 {
2467 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());
2468 crate::c_types::ThirtyTwoBytes { data: ret }
2471 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 {
2472 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);
2476 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 {
2477 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, reader.to_slice());
2478 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() };
2482 extern "C" fn PhantomKeysManager_SignerProvider_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CResult_ScriptNoneZ {
2483 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2484 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() };
2488 extern "C" fn PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2489 let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2490 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() };
2494 /// Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
2495 /// that is shared across all nodes that intend to participate in [phantom node payments]
2498 /// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
2499 /// `starting_time_nanos`.
2501 /// `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
2502 /// same across restarts, or else inbound payments may fail.
2504 /// [phantom node payments]: PhantomKeysManager
2507 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 {
2508 let mut ret = lightning::sign::PhantomKeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos, unsafe { &*cross_node_seed});
2509 crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2512 /// See [`KeysManager::spend_spendable_outputs`] for documentation on this method.
2515 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_PackedLockTimeZ) -> crate::c_types::derived::CResult_TransactionNoneZ {
2516 let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2517 let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2518 let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::PackedLockTime({ locktime_opt.take() }) }})} };
2519 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);
2520 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() };
2524 /// See [`KeysManager::derive_channel_keys`] for documentation on this method.
2527 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 {
2528 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2529 crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2532 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2535 pub extern "C" fn PhantomKeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
2536 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2537 crate::c_types::SecretKey::from_rust(ret)
2540 /// Gets the \"node_id\" secret key of the phantom node used to sign invoices, decode the
2541 /// last-hop onion data, etc.
2544 pub extern "C" fn PhantomKeysManager_get_phantom_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
2545 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_node_secret_key();
2546 crate::c_types::SecretKey::from_rust(ret)