Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / keysinterface.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! Provides keys to LDK and defines some useful objects describing spendable on-chain outputs.
10 //!
11 //! The provided output descriptors follow a custom LDK data format and are currently not fully
12 //! compatible with Bitcoin Core output descriptors.
13
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};
21
22
23 use lightning::chain::keysinterface::DelayedPaymentOutputDescriptor as nativeDelayedPaymentOutputDescriptorImport;
24 pub(crate) type nativeDelayedPaymentOutputDescriptor = nativeDelayedPaymentOutputDescriptorImport;
25
26 /// Information about a spendable output to a P2WSH script.
27 ///
28 /// See [`SpendableOutputDescriptor::DelayedPaymentOutput`] for more details on how to spend this.
29 #[must_use]
30 #[repr(C)]
31 pub struct DelayedPaymentOutputDescriptor {
32         /// A pointer to the opaque Rust object.
33
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.
38
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.
41         pub is_owned: bool,
42 }
43
44 impl Drop for DelayedPaymentOutputDescriptor {
45         fn drop(&mut self) {
46                 if self.is_owned && !<*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) {
47                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
48                 }
49         }
50 }
51 /// Frees any resources used by the DelayedPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
52 #[no_mangle]
53 pub extern "C" fn DelayedPaymentOutputDescriptor_free(this_obj: DelayedPaymentOutputDescriptor) { }
54 #[allow(unused)]
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) };
58 }
59 #[allow(unused)]
60 impl DelayedPaymentOutputDescriptor {
61         pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentOutputDescriptor {
62                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
63         }
64         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentOutputDescriptor {
65                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
66         }
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();
72                 ret
73         }
74 }
75 /// The outpoint which is spendable.
76 #[no_mangle]
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 }
80 }
81 /// The outpoint which is spendable.
82 #[no_mangle]
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()) };
85 }
86 /// Per commitment point to derive the delayed payment key by key holder.
87 #[no_mangle]
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)
91 }
92 /// Per commitment point to derive the delayed payment key by key holder.
93 #[no_mangle]
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();
96 }
97 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
98 /// the witness_script.
99 #[no_mangle]
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;
102         *inner_val
103 }
104 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
105 /// the witness_script.
106 #[no_mangle]
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;
109 }
110 /// The output which is referenced by the given outpoint.
111 ///
112 /// Returns a copy of the field.
113 #[no_mangle]
114 pub extern "C" fn DelayedPaymentOutputDescriptor_get_output(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::TxOut {
115         let mut inner_val = this_ptr.get_native_mut_ref().output.clone();
116         crate::c_types::TxOut::from_rust(inner_val)
117 }
118 /// The output which is referenced by the given outpoint.
119 #[no_mangle]
120 pub extern "C" fn DelayedPaymentOutputDescriptor_set_output(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
121         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
122 }
123 /// The revocation point specific to the commitment transaction which was broadcast. Used to
124 /// derive the witnessScript for this output.
125 #[no_mangle]
126 pub extern "C" fn DelayedPaymentOutputDescriptor_get_revocation_pubkey(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
127         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_pubkey;
128         crate::c_types::PublicKey::from_rust(&inner_val)
129 }
130 /// The revocation point specific to the commitment transaction which was broadcast. Used to
131 /// derive the witnessScript for this output.
132 #[no_mangle]
133 pub extern "C" fn DelayedPaymentOutputDescriptor_set_revocation_pubkey(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
134         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_pubkey = val.into_rust();
135 }
136 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
137 /// This may be useful in re-deriving keys used in the channel to spend the output.
138 #[no_mangle]
139 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &DelayedPaymentOutputDescriptor) -> *const [u8; 32] {
140         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
141         inner_val
142 }
143 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
144 /// This may be useful in re-deriving keys used in the channel to spend the output.
145 #[no_mangle]
146 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
147         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
148 }
149 /// The value of the channel which this output originated from, possibly indirectly.
150 #[no_mangle]
151 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &DelayedPaymentOutputDescriptor) -> u64 {
152         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
153         *inner_val
154 }
155 /// The value of the channel which this output originated from, possibly indirectly.
156 #[no_mangle]
157 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u64) {
158         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
159 }
160 /// Constructs a new DelayedPaymentOutputDescriptor given each field
161 #[must_use]
162 #[no_mangle]
163 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 {
164         DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeDelayedPaymentOutputDescriptor {
165                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
166                 per_commitment_point: per_commitment_point_arg.into_rust(),
167                 to_self_delay: to_self_delay_arg,
168                 output: output_arg.into_rust(),
169                 revocation_pubkey: revocation_pubkey_arg.into_rust(),
170                 channel_keys_id: channel_keys_id_arg.data,
171                 channel_value_satoshis: channel_value_satoshis_arg,
172         }), is_owned: true }
173 }
174 impl Clone for DelayedPaymentOutputDescriptor {
175         fn clone(&self) -> Self {
176                 Self {
177                         inner: if <*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
178                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
179                         is_owned: true,
180                 }
181         }
182 }
183 #[allow(unused)]
184 /// Used only if an object of this type is returned as a trait impl by a method
185 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
186         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void
187 }
188 #[no_mangle]
189 /// Creates a copy of the DelayedPaymentOutputDescriptor
190 pub extern "C" fn DelayedPaymentOutputDescriptor_clone(orig: &DelayedPaymentOutputDescriptor) -> DelayedPaymentOutputDescriptor {
191         orig.clone()
192 }
193 /// Checks if two DelayedPaymentOutputDescriptors contain equal inner contents.
194 /// This ignores pointers and is_owned flags and looks at the values in fields.
195 /// Two objects with NULL inner values will be considered "equal" here.
196 #[no_mangle]
197 pub extern "C" fn DelayedPaymentOutputDescriptor_eq(a: &DelayedPaymentOutputDescriptor, b: &DelayedPaymentOutputDescriptor) -> bool {
198         if a.inner == b.inner { return true; }
199         if a.inner.is_null() || b.inner.is_null() { return false; }
200         if a.get_native_ref() == b.get_native_ref() { true } else { false }
201 }
202 #[no_mangle]
203 /// Serialize the DelayedPaymentOutputDescriptor object into a byte array which can be read by DelayedPaymentOutputDescriptor_read
204 pub extern "C" fn DelayedPaymentOutputDescriptor_write(obj: &crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
205         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
206 }
207 #[no_mangle]
208 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
209         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentOutputDescriptor) })
210 }
211 #[no_mangle]
212 /// Read a DelayedPaymentOutputDescriptor from a byte array, created by DelayedPaymentOutputDescriptor_write
213 pub extern "C" fn DelayedPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentOutputDescriptorDecodeErrorZ {
214         let res: Result<lightning::chain::keysinterface::DelayedPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
215         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::keysinterface::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() };
216         local_res
217 }
218
219 use lightning::chain::keysinterface::StaticPaymentOutputDescriptor as nativeStaticPaymentOutputDescriptorImport;
220 pub(crate) type nativeStaticPaymentOutputDescriptor = nativeStaticPaymentOutputDescriptorImport;
221
222 /// Information about a spendable output to our \"payment key\".
223 ///
224 /// See [`SpendableOutputDescriptor::StaticPaymentOutput`] for more details on how to spend this.
225 #[must_use]
226 #[repr(C)]
227 pub struct StaticPaymentOutputDescriptor {
228         /// A pointer to the opaque Rust object.
229
230         /// Nearly everywhere, inner must be non-null, however in places where
231         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
232         pub inner: *mut nativeStaticPaymentOutputDescriptor,
233         /// Indicates that this is the only struct which contains the same pointer.
234
235         /// Rust functions which take ownership of an object provided via an argument require
236         /// this to be true and invalidate the object pointed to by inner.
237         pub is_owned: bool,
238 }
239
240 impl Drop for StaticPaymentOutputDescriptor {
241         fn drop(&mut self) {
242                 if self.is_owned && !<*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) {
243                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
244                 }
245         }
246 }
247 /// Frees any resources used by the StaticPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
248 #[no_mangle]
249 pub extern "C" fn StaticPaymentOutputDescriptor_free(this_obj: StaticPaymentOutputDescriptor) { }
250 #[allow(unused)]
251 /// Used only if an object of this type is returned as a trait impl by a method
252 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
253         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeStaticPaymentOutputDescriptor) };
254 }
255 #[allow(unused)]
256 impl StaticPaymentOutputDescriptor {
257         pub(crate) fn get_native_ref(&self) -> &'static nativeStaticPaymentOutputDescriptor {
258                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
259         }
260         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeStaticPaymentOutputDescriptor {
261                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
262         }
263         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
264         pub(crate) fn take_inner(mut self) -> *mut nativeStaticPaymentOutputDescriptor {
265                 assert!(self.is_owned);
266                 let ret = ObjOps::untweak_ptr(self.inner);
267                 self.inner = core::ptr::null_mut();
268                 ret
269         }
270 }
271 /// The outpoint which is spendable.
272 #[no_mangle]
273 pub extern "C" fn StaticPaymentOutputDescriptor_get_outpoint(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
274         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
275         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 }
276 }
277 /// The outpoint which is spendable.
278 #[no_mangle]
279 pub extern "C" fn StaticPaymentOutputDescriptor_set_outpoint(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
280         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
281 }
282 /// The output which is referenced by the given outpoint.
283 ///
284 /// Returns a copy of the field.
285 #[no_mangle]
286 pub extern "C" fn StaticPaymentOutputDescriptor_get_output(this_ptr: &StaticPaymentOutputDescriptor) -> crate::c_types::TxOut {
287         let mut inner_val = this_ptr.get_native_mut_ref().output.clone();
288         crate::c_types::TxOut::from_rust(inner_val)
289 }
290 /// The output which is referenced by the given outpoint.
291 #[no_mangle]
292 pub extern "C" fn StaticPaymentOutputDescriptor_set_output(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
293         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
294 }
295 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
296 /// This may be useful in re-deriving keys used in the channel to spend the output.
297 #[no_mangle]
298 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &StaticPaymentOutputDescriptor) -> *const [u8; 32] {
299         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
300         inner_val
301 }
302 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
303 /// This may be useful in re-deriving keys used in the channel to spend the output.
304 #[no_mangle]
305 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
306         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
307 }
308 /// The value of the channel which this transactions spends.
309 #[no_mangle]
310 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &StaticPaymentOutputDescriptor) -> u64 {
311         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
312         *inner_val
313 }
314 /// The value of the channel which this transactions spends.
315 #[no_mangle]
316 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: u64) {
317         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
318 }
319 /// Constructs a new StaticPaymentOutputDescriptor given each field
320 #[must_use]
321 #[no_mangle]
322 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 {
323         StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeStaticPaymentOutputDescriptor {
324                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
325                 output: output_arg.into_rust(),
326                 channel_keys_id: channel_keys_id_arg.data,
327                 channel_value_satoshis: channel_value_satoshis_arg,
328         }), is_owned: true }
329 }
330 impl Clone for StaticPaymentOutputDescriptor {
331         fn clone(&self) -> Self {
332                 Self {
333                         inner: if <*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
334                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
335                         is_owned: true,
336                 }
337         }
338 }
339 #[allow(unused)]
340 /// Used only if an object of this type is returned as a trait impl by a method
341 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
342         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void
343 }
344 #[no_mangle]
345 /// Creates a copy of the StaticPaymentOutputDescriptor
346 pub extern "C" fn StaticPaymentOutputDescriptor_clone(orig: &StaticPaymentOutputDescriptor) -> StaticPaymentOutputDescriptor {
347         orig.clone()
348 }
349 /// Checks if two StaticPaymentOutputDescriptors contain equal inner contents.
350 /// This ignores pointers and is_owned flags and looks at the values in fields.
351 /// Two objects with NULL inner values will be considered "equal" here.
352 #[no_mangle]
353 pub extern "C" fn StaticPaymentOutputDescriptor_eq(a: &StaticPaymentOutputDescriptor, b: &StaticPaymentOutputDescriptor) -> bool {
354         if a.inner == b.inner { return true; }
355         if a.inner.is_null() || b.inner.is_null() { return false; }
356         if a.get_native_ref() == b.get_native_ref() { true } else { false }
357 }
358 #[no_mangle]
359 /// Serialize the StaticPaymentOutputDescriptor object into a byte array which can be read by StaticPaymentOutputDescriptor_read
360 pub extern "C" fn StaticPaymentOutputDescriptor_write(obj: &crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
361         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
362 }
363 #[no_mangle]
364 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
365         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeStaticPaymentOutputDescriptor) })
366 }
367 #[no_mangle]
368 /// Read a StaticPaymentOutputDescriptor from a byte array, created by StaticPaymentOutputDescriptor_write
369 pub extern "C" fn StaticPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_StaticPaymentOutputDescriptorDecodeErrorZ {
370         let res: Result<lightning::chain::keysinterface::StaticPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
371         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::keysinterface::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() };
372         local_res
373 }
374 /// Describes the necessary information to spend a spendable output.
375 ///
376 /// When on-chain outputs are created by LDK (which our counterparty is not able to claim at any
377 /// point in the future) a [`SpendableOutputs`] event is generated which you must track and be able
378 /// to spend on-chain. The information needed to do this is provided in this enum, including the
379 /// outpoint describing which `txid` and output `index` is available, the full output which exists
380 /// at that `txid`/`index`, and any keys or other information required to sign.
381 ///
382 /// [`SpendableOutputs`]: crate::util::events::Event::SpendableOutputs
383 #[derive(Clone)]
384 #[must_use]
385 #[repr(C)]
386 pub enum SpendableOutputDescriptor {
387         /// An output to a script which was provided via [`SignerProvider`] directly, either from
388         /// [`get_destination_script`] or [`get_shutdown_scriptpubkey`], thus you should already
389         /// know how to spend it. No secret keys are provided as LDK was never given any key.
390         /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
391         /// on-chain using the payment preimage or after it has timed out.
392         ///
393         /// [`get_shutdown_scriptpubkey`]: SignerProvider::get_shutdown_scriptpubkey
394         /// [`get_destination_script`]: SignerProvider::get_shutdown_scriptpubkey
395         StaticOutput {
396                 /// The outpoint which is spendable.
397                 outpoint: crate::lightning::chain::transaction::OutPoint,
398                 /// The output which is referenced by the given outpoint.
399                 output: crate::c_types::TxOut,
400         },
401         /// An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
402         /// delay.
403         ///
404         /// The witness in the spending input should be:
405         /// ```bitcoin
406         /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
407         /// ```
408         ///
409         /// Note that the `nSequence` field in the spending input must be set to
410         /// [`DelayedPaymentOutputDescriptor::to_self_delay`] (which means the transaction is not
411         /// broadcastable until at least [`DelayedPaymentOutputDescriptor::to_self_delay`] blocks after
412         /// the outpoint confirms, see [BIP
413         /// 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)). Also note that LDK
414         /// won't generate a [`SpendableOutputDescriptor`] until the corresponding block height
415         /// is reached.
416         ///
417         /// These are generally the result of a \"revocable\" output to us, spendable only by us unless
418         /// it is an output from an old state which we broadcast (which should never happen).
419         ///
420         /// To derive the delayed payment key which is used to sign this input, you must pass the
421         /// holder [`InMemorySigner::delayed_payment_base_key`] (i.e., the private key which corresponds to the
422         /// [`ChannelPublicKeys::delayed_payment_basepoint`] in [`ChannelSigner::pubkeys`]) and the provided
423         /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to [`chan_utils::derive_private_key`]. The public key can be
424         /// generated without the secret key using [`chan_utils::derive_public_key`] and only the
425         /// [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`ChannelSigner::pubkeys`].
426         ///
427         /// To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
428         /// used in the witness script generation), you must pass the counterparty
429         /// [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
430         /// [`ChannelSigner::provide_channel_parameters`]) and the provided
431         /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
432         /// [`chan_utils::derive_public_revocation_key`].
433         ///
434         /// The witness script which is hashed and included in the output `script_pubkey` may be
435         /// regenerated by passing the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] (derived
436         /// as explained above), our delayed payment pubkey (derived as explained above), and the
437         /// [`DelayedPaymentOutputDescriptor::to_self_delay`] contained here to
438         /// [`chan_utils::get_revokeable_redeemscript`].
439         DelayedPaymentOutput(
440                 crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor),
441         /// An output to a P2WPKH, spendable exclusively by our payment key (i.e., the private key
442         /// which corresponds to the `payment_point` in [`ChannelSigner::pubkeys`]). The witness
443         /// in the spending input is, thus, simply:
444         /// ```bitcoin
445         /// <BIP 143 signature> <payment key>
446         /// ```
447         ///
448         /// These are generally the result of our counterparty having broadcast the current state,
449         /// allowing us to claim the non-HTLC-encumbered outputs immediately.
450         StaticPaymentOutput(
451                 crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor),
452 }
453 use lightning::chain::keysinterface::SpendableOutputDescriptor as SpendableOutputDescriptorImport;
454 pub(crate) type nativeSpendableOutputDescriptor = SpendableOutputDescriptorImport;
455
456 impl SpendableOutputDescriptor {
457         #[allow(unused)]
458         pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor {
459                 match self {
460                         SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
461                                 let mut outpoint_nonref = Clone::clone(outpoint);
462                                 let mut output_nonref = Clone::clone(output);
463                                 nativeSpendableOutputDescriptor::StaticOutput {
464                                         outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
465                                         output: output_nonref.into_rust(),
466                                 }
467                         },
468                         SpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
469                                 let mut a_nonref = Clone::clone(a);
470                                 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
471                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
472                                 )
473                         },
474                         SpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
475                                 let mut a_nonref = Clone::clone(a);
476                                 nativeSpendableOutputDescriptor::StaticPaymentOutput (
477                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
478                                 )
479                         },
480                 }
481         }
482         #[allow(unused)]
483         pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor {
484                 match self {
485                         SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
486                                 nativeSpendableOutputDescriptor::StaticOutput {
487                                         outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
488                                         output: output.into_rust(),
489                                 }
490                         },
491                         SpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
492                                 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
493                                         *unsafe { Box::from_raw(a.take_inner()) },
494                                 )
495                         },
496                         SpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
497                                 nativeSpendableOutputDescriptor::StaticPaymentOutput (
498                                         *unsafe { Box::from_raw(a.take_inner()) },
499                                 )
500                         },
501                 }
502         }
503         #[allow(unused)]
504         pub(crate) fn from_native(native: &nativeSpendableOutputDescriptor) -> Self {
505                 match native {
506                         nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
507                                 let mut outpoint_nonref = Clone::clone(outpoint);
508                                 let mut output_nonref = Clone::clone(output);
509                                 SpendableOutputDescriptor::StaticOutput {
510                                         outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true },
511                                         output: crate::c_types::TxOut::from_rust(output_nonref),
512                                 }
513                         },
514                         nativeSpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
515                                 let mut a_nonref = Clone::clone(a);
516                                 SpendableOutputDescriptor::DelayedPaymentOutput (
517                                         crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
518                                 )
519                         },
520                         nativeSpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
521                                 let mut a_nonref = Clone::clone(a);
522                                 SpendableOutputDescriptor::StaticPaymentOutput (
523                                         crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
524                                 )
525                         },
526                 }
527         }
528         #[allow(unused)]
529         pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self {
530                 match native {
531                         nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
532                                 SpendableOutputDescriptor::StaticOutput {
533                                         outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true },
534                                         output: crate::c_types::TxOut::from_rust(output),
535                                 }
536                         },
537                         nativeSpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
538                                 SpendableOutputDescriptor::DelayedPaymentOutput (
539                                         crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
540                                 )
541                         },
542                         nativeSpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
543                                 SpendableOutputDescriptor::StaticPaymentOutput (
544                                         crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
545                                 )
546                         },
547                 }
548         }
549 }
550 /// Frees any resources used by the SpendableOutputDescriptor
551 #[no_mangle]
552 pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { }
553 /// Creates a copy of the SpendableOutputDescriptor
554 #[no_mangle]
555 pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor {
556         orig.clone()
557 }
558 #[no_mangle]
559 /// Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
560 pub extern "C" fn SpendableOutputDescriptor_static_output(outpoint: crate::lightning::chain::transaction::OutPoint, output: crate::c_types::TxOut) -> SpendableOutputDescriptor {
561         SpendableOutputDescriptor::StaticOutput {
562                 outpoint,
563                 output,
564         }
565 }
566 #[no_mangle]
567 /// Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
568 pub extern "C" fn SpendableOutputDescriptor_delayed_payment_output(a: crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor) -> SpendableOutputDescriptor {
569         SpendableOutputDescriptor::DelayedPaymentOutput(a, )
570 }
571 #[no_mangle]
572 /// Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
573 pub extern "C" fn SpendableOutputDescriptor_static_payment_output(a: crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor) -> SpendableOutputDescriptor {
574         SpendableOutputDescriptor::StaticPaymentOutput(a, )
575 }
576 /// Checks if two SpendableOutputDescriptors contain equal inner contents.
577 /// This ignores pointers and is_owned flags and looks at the values in fields.
578 #[no_mangle]
579 pub extern "C" fn SpendableOutputDescriptor_eq(a: &SpendableOutputDescriptor, b: &SpendableOutputDescriptor) -> bool {
580         if &a.to_native() == &b.to_native() { true } else { false }
581 }
582 #[no_mangle]
583 /// Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
584 pub extern "C" fn SpendableOutputDescriptor_write(obj: &crate::lightning::chain::keysinterface::SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
585         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
586 }
587 #[no_mangle]
588 /// Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
589 pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
590         let res: Result<lightning::chain::keysinterface::SpendableOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
591         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
592         local_res
593 }
594 /// A trait to handle Lightning channel key material without concretizing the channel type or
595 /// the signature mechanism.
596 #[repr(C)]
597 pub struct ChannelSigner {
598         /// An opaque pointer which is passed to your function implementations as an argument.
599         /// This has no meaning in the LDK, and can be NULL or any other value.
600         pub this_arg: *mut c_void,
601         /// Gets the per-commitment point for a specific commitment number
602         ///
603         /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
604         #[must_use]
605         pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey,
606         /// Gets the commitment secret for a specific commitment number as part of the revocation process
607         ///
608         /// An external signer implementation should error here if the commitment was already signed
609         /// and should refuse to sign it in the future.
610         ///
611         /// May be called more than once for the same index.
612         ///
613         /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
614         #[must_use]
615         pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes,
616         /// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
617         ///
618         /// This is required in order for the signer to make sure that releasing a commitment
619         /// secret won't leave us without a broadcastable holder transaction.
620         /// Policy checks should be implemented in this function, including checking the amount
621         /// sent to us and checking the HTLCs.
622         ///
623         /// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
624         /// A validating signer should ensure that an HTLC output is removed only when the matching
625         /// preimage is provided, or when the value to holder is restored.
626         ///
627         /// Note that all the relevant preimages will be provided, but there may also be additional
628         /// irrelevant or duplicate preimages.
629         #[must_use]
630         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,
631         /// Returns the holder's channel public keys and basepoints.
632         pub pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys,
633         /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns
634         /// Note that this takes a pointer to this object, not the this_ptr like other methods do
635         /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
636         pub set_pubkeys: Option<extern "C" fn(&ChannelSigner)>,
637         /// Returns an arbitrary identifier describing the set of keys which are provided back to you in
638         /// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
639         /// [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
640         #[must_use]
641         pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
642         /// Set the counterparty static channel data, including basepoints,
643         /// `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
644         ///
645         /// This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
646         /// instance, LDK will call this method exactly once - either immediately after construction
647         /// (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
648         /// information has been generated.
649         ///
650         /// channel_parameters.is_populated() MUST be true.
651         pub provide_channel_parameters: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters),
652         /// Frees any resources associated with this object given its this_arg pointer.
653         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
654         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
655 }
656 unsafe impl Send for ChannelSigner {}
657 unsafe impl Sync for ChannelSigner {}
658 #[no_mangle]
659 pub(crate) extern "C" fn ChannelSigner_clone_fields(orig: &ChannelSigner) -> ChannelSigner {
660         ChannelSigner {
661                 this_arg: orig.this_arg,
662                 get_per_commitment_point: Clone::clone(&orig.get_per_commitment_point),
663                 release_commitment_secret: Clone::clone(&orig.release_commitment_secret),
664                 validate_holder_commitment: Clone::clone(&orig.validate_holder_commitment),
665                 pubkeys: Clone::clone(&orig.pubkeys),
666                 set_pubkeys: Clone::clone(&orig.set_pubkeys),
667                 channel_keys_id: Clone::clone(&orig.channel_keys_id),
668                 provide_channel_parameters: Clone::clone(&orig.provide_channel_parameters),
669                 free: Clone::clone(&orig.free),
670         }
671 }
672
673 use lightning::chain::keysinterface::ChannelSigner as rustChannelSigner;
674 impl rustChannelSigner for ChannelSigner {
675         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
676                 let mut ret = (self.get_per_commitment_point)(self.this_arg, idx);
677                 ret.into_rust()
678         }
679         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
680                 let mut ret = (self.release_commitment_secret)(self.this_arg, idx);
681                 ret.data
682         }
683         fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
684                 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
685                 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());
686                 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)) })*/ })};
687                 local_ret
688         }
689         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
690                 if let Some(f) = self.set_pubkeys {
691                         (f)(&self);
692                 }
693                 self.pubkeys.get_native_ref()
694         }
695         fn channel_keys_id(&self) -> [u8; 32] {
696                 let mut ret = (self.channel_keys_id)(self.this_arg);
697                 ret.data
698         }
699         fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
700                 (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 })
701         }
702 }
703
704 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
705 // directly as a Deref trait in higher-level structs:
706 impl core::ops::Deref for ChannelSigner {
707         type Target = Self;
708         fn deref(&self) -> &Self {
709                 self
710         }
711 }
712 /// Calls the free function if one is set
713 #[no_mangle]
714 pub extern "C" fn ChannelSigner_free(this_ptr: ChannelSigner) { }
715 impl Drop for ChannelSigner {
716         fn drop(&mut self) {
717                 if let Some(f) = self.free {
718                         f(self.this_arg);
719                 }
720         }
721 }
722 /// A trait to sign Lightning channel transactions as described in
723 /// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
724 ///
725 /// Signing services could be implemented on a hardware wallet and should implement signing
726 /// policies in order to be secure. Please refer to the [VLS Policy
727 /// Controls](https://gitlab.com/lightning-signer/validating-lightning-signer/-/blob/main/docs/policy-controls.md)
728 /// for an example of such policies.
729 #[repr(C)]
730 pub struct EcdsaChannelSigner {
731         /// An opaque pointer which is passed to your function implementations as an argument.
732         /// This has no meaning in the LDK, and can be NULL or any other value.
733         pub this_arg: *mut c_void,
734         /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
735         ///
736         /// Note that if signing fails or is rejected, the channel will be force-closed.
737         ///
738         /// Policy checks should be implemented in this function, including checking the amount
739         /// sent to us and checking the HTLCs.
740         ///
741         /// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
742         /// A validating signer should ensure that an HTLC output is removed only when the matching
743         /// preimage is provided, or when the value to holder is restored.
744         ///
745         /// Note that all the relevant preimages will be provided, but there may also be additional
746         /// irrelevant or duplicate preimages.
747         #[must_use]
748         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,
749         /// Validate the counterparty's revocation.
750         ///
751         /// This is required in order for the signer to make sure that the state has moved
752         /// forward and it is safe to sign the next counterparty commitment.
753         #[must_use]
754         pub validate_counterparty_revocation: extern "C" fn (this_arg: *const c_void, idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ,
755         /// Creates a signature for a holder's commitment transaction and its claiming HTLC transactions.
756         ///
757         /// This will be called
758         /// - with a non-revoked `commitment_tx`.
759         /// - with the latest `commitment_tx` when we initiate a force-close.
760         /// - with the previous `commitment_tx`, just to get claiming HTLC
761         ///   signatures, if we are reacting to a [`ChannelMonitor`]
762         ///   [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas)
763         ///   that decided to broadcast before it had been updated to the latest `commitment_tx`.
764         ///
765         /// This may be called multiple times for the same transaction.
766         ///
767         /// An external signer implementation should check that the commitment has not been revoked.
768         ///
769         /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
770         #[must_use]
771         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,
772         /// Create a signature for the given input in a transaction spending an HTLC transaction output
773         /// or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
774         ///
775         /// A justice transaction may claim multiple outputs at the same time if timelocks are
776         /// similar, but only a signature for the input at index `input` should be signed for here.
777         /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
778         /// to an upcoming timelock expiration.
779         ///
780         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
781         ///
782         /// `per_commitment_key` is revocation secret which was provided by our counterparty when they
783         /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
784         /// not allow the spending of any funds by itself (you need our holder `revocation_secret` to do
785         /// so).
786         #[must_use]
787         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,
788         /// Create a signature for the given input in a transaction spending a commitment transaction
789         /// HTLC output when our counterparty broadcasts an old state.
790         ///
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.
795         ///
796         /// `amount` is the value of the output spent by this input, committed to in the BIP 143
797         /// signature.
798         ///
799         /// `per_commitment_key` is revocation secret which was provided by our counterparty when they
800         /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
801         /// not allow the spending of any funds by itself (you need our holder revocation_secret to do
802         /// so).
803         ///
804         /// `htlc` holds HTLC elements (hash, timelock), thus changing the format of the witness script
805         /// (which is committed to in the BIP 143 signatures).
806         #[must_use]
807         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,
808         /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
809         /// transaction, either offered or received.
810         ///
811         /// Such a transaction may claim multiples offered outputs at same time if we know the
812         /// preimage for each when we create it, but only the input at index `input` should be
813         /// signed for here. It may be called multiple times for same output(s) if a fee-bump is
814         /// needed with regards to an upcoming timelock expiration.
815         ///
816         /// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
817         /// outputs.
818         ///
819         /// `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
820         ///
821         /// `per_commitment_point` is the dynamic point corresponding to the channel state
822         /// detected onchain. It has been generated by our counterparty and is used to derive
823         /// channel state keys, which are then included in the witness script and committed to in the
824         /// BIP 143 signature.
825         #[must_use]
826         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,
827         /// Create a signature for a (proposed) closing transaction.
828         ///
829         /// Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
830         /// chosen to forgo their output as dust.
831         #[must_use]
832         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,
833         /// Computes the signature for a commitment transaction's anchor output used as an
834         /// input within `anchor_tx`, which spends the commitment transaction, at index `input`.
835         #[must_use]
836         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,
837         /// Signs a channel announcement message with our funding key proving it comes from one of the
838         /// channel participants.
839         ///
840         /// Channel announcements also require a signature from each node's network key. Our node
841         /// signature is computed through [`NodeSigner::sign_gossip_message`].
842         ///
843         /// Note that if this fails or is rejected, the channel will not be publicly announced and
844         /// our counterparty may (though likely will not) close the channel on us for violating the
845         /// protocol.
846         #[must_use]
847         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,
848         /// Implementation of ChannelSigner for this object.
849         pub ChannelSigner: crate::lightning::chain::keysinterface::ChannelSigner,
850         /// Frees any resources associated with this object given its this_arg pointer.
851         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
852         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
853 }
854 unsafe impl Send for EcdsaChannelSigner {}
855 unsafe impl Sync for EcdsaChannelSigner {}
856 #[no_mangle]
857 pub(crate) extern "C" fn EcdsaChannelSigner_clone_fields(orig: &EcdsaChannelSigner) -> EcdsaChannelSigner {
858         EcdsaChannelSigner {
859                 this_arg: orig.this_arg,
860                 sign_counterparty_commitment: Clone::clone(&orig.sign_counterparty_commitment),
861                 validate_counterparty_revocation: Clone::clone(&orig.validate_counterparty_revocation),
862                 sign_holder_commitment_and_htlcs: Clone::clone(&orig.sign_holder_commitment_and_htlcs),
863                 sign_justice_revoked_output: Clone::clone(&orig.sign_justice_revoked_output),
864                 sign_justice_revoked_htlc: Clone::clone(&orig.sign_justice_revoked_htlc),
865                 sign_counterparty_htlc_transaction: Clone::clone(&orig.sign_counterparty_htlc_transaction),
866                 sign_closing_transaction: Clone::clone(&orig.sign_closing_transaction),
867                 sign_holder_anchor_input: Clone::clone(&orig.sign_holder_anchor_input),
868                 sign_channel_announcement_with_funding_key: Clone::clone(&orig.sign_channel_announcement_with_funding_key),
869                 ChannelSigner: crate::lightning::chain::keysinterface::ChannelSigner_clone_fields(&orig.ChannelSigner),
870                 free: Clone::clone(&orig.free),
871         }
872 }
873 impl lightning::chain::keysinterface::ChannelSigner for EcdsaChannelSigner {
874         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
875                 let mut ret = (self.ChannelSigner.get_per_commitment_point)(self.ChannelSigner.this_arg, idx);
876                 ret.into_rust()
877         }
878         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
879                 let mut ret = (self.ChannelSigner.release_commitment_secret)(self.ChannelSigner.this_arg, idx);
880                 ret.data
881         }
882         fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
883                 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
884                 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());
885                 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)) })*/ })};
886                 local_ret
887         }
888         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
889                 if let Some(f) = self.ChannelSigner.set_pubkeys {
890                         (f)(&self.ChannelSigner);
891                 }
892                 self.ChannelSigner.pubkeys.get_native_ref()
893         }
894         fn channel_keys_id(&self) -> [u8; 32] {
895                 let mut ret = (self.ChannelSigner.channel_keys_id)(self.ChannelSigner.this_arg);
896                 ret.data
897         }
898         fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
899                 (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 })
900         }
901 }
902
903 use lightning::chain::keysinterface::EcdsaChannelSigner as rustEcdsaChannelSigner;
904 impl rustEcdsaChannelSigner for EcdsaChannelSigner {
905         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>), ()> {
906                 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
907                 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());
908                 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)) })*/ })};
909                 local_ret
910         }
911         fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
912                 let mut ret = (self.validate_counterparty_revocation)(self.this_arg, idx, secret.as_ref());
913                 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)) })*/ })};
914                 local_ret
915         }
916         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>), ()> {
917                 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 });
918                 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)) })*/ })};
919                 local_ret
920         }
921         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, ()> {
922                 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());
923                 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)) })*/ })};
924                 local_ret
925         }
926         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, ()> {
927                 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 });
928                 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)) })*/ })};
929                 local_ret
930         }
931         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, ()> {
932                 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 });
933                 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)) })*/ })};
934                 local_ret
935         }
936         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, ()> {
937                 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 });
938                 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)) })*/ })};
939                 local_ret
940         }
941         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, ()> {
942                 let mut ret = (self.sign_holder_anchor_input)(self.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
943                 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)) })*/ })};
944                 local_ret
945         }
946         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, ()> {
947                 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 });
948                 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)) })*/ })};
949                 local_ret
950         }
951 }
952
953 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
954 // directly as a Deref trait in higher-level structs:
955 impl core::ops::Deref for EcdsaChannelSigner {
956         type Target = Self;
957         fn deref(&self) -> &Self {
958                 self
959         }
960 }
961 /// Calls the free function if one is set
962 #[no_mangle]
963 pub extern "C" fn EcdsaChannelSigner_free(this_ptr: EcdsaChannelSigner) { }
964 impl Drop for EcdsaChannelSigner {
965         fn drop(&mut self) {
966                 if let Some(f) = self.free {
967                         f(self.this_arg);
968                 }
969         }
970 }
971 /// A writeable signer.
972 ///
973 /// There will always be two instances of a signer per channel, one occupied by the
974 /// [`ChannelManager`] and another by the channel's [`ChannelMonitor`].
975 ///
976 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
977 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
978 #[repr(C)]
979 pub struct WriteableEcdsaChannelSigner {
980         /// An opaque pointer which is passed to your function implementations as an argument.
981         /// This has no meaning in the LDK, and can be NULL or any other value.
982         pub this_arg: *mut c_void,
983         /// Implementation of EcdsaChannelSigner for this object.
984         pub EcdsaChannelSigner: crate::lightning::chain::keysinterface::EcdsaChannelSigner,
985         /// Serialize the object into a byte array
986         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
987         /// Frees any resources associated with this object given its this_arg pointer.
988         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
989         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
990 }
991 unsafe impl Send for WriteableEcdsaChannelSigner {}
992 unsafe impl Sync for WriteableEcdsaChannelSigner {}
993 #[no_mangle]
994 pub(crate) extern "C" fn WriteableEcdsaChannelSigner_clone_fields(orig: &WriteableEcdsaChannelSigner) -> WriteableEcdsaChannelSigner {
995         WriteableEcdsaChannelSigner {
996                 this_arg: orig.this_arg,
997                 EcdsaChannelSigner: crate::lightning::chain::keysinterface::EcdsaChannelSigner_clone_fields(&orig.EcdsaChannelSigner),
998                 write: Clone::clone(&orig.write),
999                 free: Clone::clone(&orig.free),
1000         }
1001 }
1002 impl lightning::chain::keysinterface::EcdsaChannelSigner for WriteableEcdsaChannelSigner {
1003         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>), ()> {
1004                 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1005                 let mut ret = (self.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());
1006                 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)) })*/ })};
1007                 local_ret
1008         }
1009         fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
1010                 let mut ret = (self.EcdsaChannelSigner.validate_counterparty_revocation)(self.EcdsaChannelSigner.this_arg, idx, secret.as_ref());
1011                 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)) })*/ })};
1012                 local_ret
1013         }
1014         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>), ()> {
1015                 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 });
1016                 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)) })*/ })};
1017                 local_ret
1018         }
1019         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, ()> {
1020                 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());
1021                 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)) })*/ })};
1022                 local_ret
1023         }
1024         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, ()> {
1025                 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 });
1026                 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)) })*/ })};
1027                 local_ret
1028         }
1029         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, ()> {
1030                 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 });
1031                 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)) })*/ })};
1032                 local_ret
1033         }
1034         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, ()> {
1035                 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 });
1036                 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)) })*/ })};
1037                 local_ret
1038         }
1039         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, ()> {
1040                 let mut ret = (self.EcdsaChannelSigner.sign_holder_anchor_input)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
1041                 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)) })*/ })};
1042                 local_ret
1043         }
1044         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, ()> {
1045                 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 });
1046                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1047                 local_ret
1048         }
1049 }
1050 impl lightning::chain::keysinterface::ChannelSigner for WriteableEcdsaChannelSigner {
1051         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
1052                 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.get_per_commitment_point)(self.EcdsaChannelSigner.ChannelSigner.this_arg, idx);
1053                 ret.into_rust()
1054         }
1055         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
1056                 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.release_commitment_secret)(self.EcdsaChannelSigner.ChannelSigner.this_arg, idx);
1057                 ret.data
1058         }
1059         fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
1060                 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1061                 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());
1062                 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)) })*/ })};
1063                 local_ret
1064         }
1065         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
1066                 if let Some(f) = self.EcdsaChannelSigner.ChannelSigner.set_pubkeys {
1067                         (f)(&self.EcdsaChannelSigner.ChannelSigner);
1068                 }
1069                 self.EcdsaChannelSigner.ChannelSigner.pubkeys.get_native_ref()
1070         }
1071         fn channel_keys_id(&self) -> [u8; 32] {
1072                 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.channel_keys_id)(self.EcdsaChannelSigner.ChannelSigner.this_arg);
1073                 ret.data
1074         }
1075         fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
1076                 (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 })
1077         }
1078 }
1079 impl lightning::util::ser::Writeable for WriteableEcdsaChannelSigner {
1080         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
1081                 let vec = (self.write)(self.this_arg);
1082                 w.write_all(vec.as_slice())
1083         }
1084 }
1085
1086 use lightning::chain::keysinterface::WriteableEcdsaChannelSigner as rustWriteableEcdsaChannelSigner;
1087 impl rustWriteableEcdsaChannelSigner for WriteableEcdsaChannelSigner {
1088 }
1089
1090 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1091 // directly as a Deref trait in higher-level structs:
1092 impl core::ops::Deref for WriteableEcdsaChannelSigner {
1093         type Target = Self;
1094         fn deref(&self) -> &Self {
1095                 self
1096         }
1097 }
1098 /// Calls the free function if one is set
1099 #[no_mangle]
1100 pub extern "C" fn WriteableEcdsaChannelSigner_free(this_ptr: WriteableEcdsaChannelSigner) { }
1101 impl Drop for WriteableEcdsaChannelSigner {
1102         fn drop(&mut self) {
1103                 if let Some(f) = self.free {
1104                         f(self.this_arg);
1105                 }
1106         }
1107 }
1108 /// Specifies the recipient of an invoice.
1109 ///
1110 /// This indicates to [`NodeSigner::sign_invoice`] what node secret key should be used to sign
1111 /// the invoice.
1112 #[derive(Clone)]
1113 #[must_use]
1114 #[repr(C)]
1115 pub enum Recipient {
1116         /// The invoice should be signed with the local node secret key.
1117         Node,
1118         /// The invoice should be signed with the phantom node secret key. This secret key must be the
1119         /// same for all nodes participating in the [phantom node payment].
1120         ///
1121         /// [phantom node payment]: PhantomKeysManager
1122         PhantomNode,
1123 }
1124 use lightning::chain::keysinterface::Recipient as RecipientImport;
1125 pub(crate) type nativeRecipient = RecipientImport;
1126
1127 impl Recipient {
1128         #[allow(unused)]
1129         pub(crate) fn to_native(&self) -> nativeRecipient {
1130                 match self {
1131                         Recipient::Node => nativeRecipient::Node,
1132                         Recipient::PhantomNode => nativeRecipient::PhantomNode,
1133                 }
1134         }
1135         #[allow(unused)]
1136         pub(crate) fn into_native(self) -> nativeRecipient {
1137                 match self {
1138                         Recipient::Node => nativeRecipient::Node,
1139                         Recipient::PhantomNode => nativeRecipient::PhantomNode,
1140                 }
1141         }
1142         #[allow(unused)]
1143         pub(crate) fn from_native(native: &nativeRecipient) -> Self {
1144                 match native {
1145                         nativeRecipient::Node => Recipient::Node,
1146                         nativeRecipient::PhantomNode => Recipient::PhantomNode,
1147                 }
1148         }
1149         #[allow(unused)]
1150         pub(crate) fn native_into(native: nativeRecipient) -> Self {
1151                 match native {
1152                         nativeRecipient::Node => Recipient::Node,
1153                         nativeRecipient::PhantomNode => Recipient::PhantomNode,
1154                 }
1155         }
1156 }
1157 /// Creates a copy of the Recipient
1158 #[no_mangle]
1159 pub extern "C" fn Recipient_clone(orig: &Recipient) -> Recipient {
1160         orig.clone()
1161 }
1162 #[no_mangle]
1163 /// Utility method to constructs a new Node-variant Recipient
1164 pub extern "C" fn Recipient_node() -> Recipient {
1165         Recipient::Node}
1166 #[no_mangle]
1167 /// Utility method to constructs a new PhantomNode-variant Recipient
1168 pub extern "C" fn Recipient_phantom_node() -> Recipient {
1169         Recipient::PhantomNode}
1170 /// A trait that describes a source of entropy.
1171 #[repr(C)]
1172 pub struct EntropySource {
1173         /// An opaque pointer which is passed to your function implementations as an argument.
1174         /// This has no meaning in the LDK, and can be NULL or any other value.
1175         pub this_arg: *mut c_void,
1176         /// Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
1177         /// different value each time it is called.
1178         #[must_use]
1179         pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1180         /// Frees any resources associated with this object given its this_arg pointer.
1181         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1182         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1183 }
1184 unsafe impl Send for EntropySource {}
1185 unsafe impl Sync for EntropySource {}
1186 #[no_mangle]
1187 pub(crate) extern "C" fn EntropySource_clone_fields(orig: &EntropySource) -> EntropySource {
1188         EntropySource {
1189                 this_arg: orig.this_arg,
1190                 get_secure_random_bytes: Clone::clone(&orig.get_secure_random_bytes),
1191                 free: Clone::clone(&orig.free),
1192         }
1193 }
1194
1195 use lightning::chain::keysinterface::EntropySource as rustEntropySource;
1196 impl rustEntropySource for EntropySource {
1197         fn get_secure_random_bytes(&self) -> [u8; 32] {
1198                 let mut ret = (self.get_secure_random_bytes)(self.this_arg);
1199                 ret.data
1200         }
1201 }
1202
1203 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1204 // directly as a Deref trait in higher-level structs:
1205 impl core::ops::Deref for EntropySource {
1206         type Target = Self;
1207         fn deref(&self) -> &Self {
1208                 self
1209         }
1210 }
1211 /// Calls the free function if one is set
1212 #[no_mangle]
1213 pub extern "C" fn EntropySource_free(this_ptr: EntropySource) { }
1214 impl Drop for EntropySource {
1215         fn drop(&mut self) {
1216                 if let Some(f) = self.free {
1217                         f(self.this_arg);
1218                 }
1219         }
1220 }
1221 /// A trait that can handle cryptographic operations at the scope level of a node.
1222 #[repr(C)]
1223 pub struct NodeSigner {
1224         /// An opaque pointer which is passed to your function implementations as an argument.
1225         /// This has no meaning in the LDK, and can be NULL or any other value.
1226         pub this_arg: *mut c_void,
1227         /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
1228         ///
1229         /// If the implementor of this trait supports [phantom node payments], then every node that is
1230         /// intended to be included in the phantom invoice route hints must return the same value from
1231         /// this method.
1232         ///
1233         /// This method must return the same value each time it is called.
1234         ///
1235         /// [phantom node payments]: PhantomKeysManager
1236         #[must_use]
1237         pub get_inbound_payment_key_material: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1238         /// Get node id based on the provided [`Recipient`].
1239         ///
1240         /// This method must return the same value each time it is called with a given [`Recipient`]
1241         /// parameter.
1242         ///
1243         /// Errors if the [`Recipient`] variant is not supported by the implementation.
1244         #[must_use]
1245         pub get_node_id: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ,
1246         /// Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
1247         /// one is provided. Note that this tweak can be applied to `other_key` instead of our node
1248         /// secret, though this is less efficient.
1249         ///
1250         /// Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
1251         /// should be resolved to allow LDK to resume forwarding HTLCs.
1252         ///
1253         /// Errors if the [`Recipient`] variant is not supported by the implementation.
1254         #[must_use]
1255         pub ecdh: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::chain::keysinterface::Recipient, other_key: crate::c_types::PublicKey, tweak: crate::c_types::derived::COption_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ,
1256         /// Sign an invoice.
1257         ///
1258         /// By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
1259         /// this trait to parse the invoice and make sure they're signing what they expect, rather than
1260         /// blindly signing the hash.
1261         ///
1262         /// The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
1263         ///
1264         /// The secret key used to sign the invoice is dependent on the [`Recipient`].
1265         ///
1266         /// Errors if the [`Recipient`] variant is not supported by the implementation.
1267         #[must_use]
1268         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::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ,
1269         /// Sign a gossip message.
1270         ///
1271         /// Note that if this fails, LDK may panic and the message will not be broadcast to the network
1272         /// or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
1273         /// message to be broadcast, as otherwise it may prevent one from receiving funds over the
1274         /// corresponding channel.
1275         #[must_use]
1276         pub sign_gossip_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_SignatureNoneZ,
1277         /// Frees any resources associated with this object given its this_arg pointer.
1278         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1279         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1280 }
1281 unsafe impl Send for NodeSigner {}
1282 unsafe impl Sync for NodeSigner {}
1283 #[no_mangle]
1284 pub(crate) extern "C" fn NodeSigner_clone_fields(orig: &NodeSigner) -> NodeSigner {
1285         NodeSigner {
1286                 this_arg: orig.this_arg,
1287                 get_inbound_payment_key_material: Clone::clone(&orig.get_inbound_payment_key_material),
1288                 get_node_id: Clone::clone(&orig.get_node_id),
1289                 ecdh: Clone::clone(&orig.ecdh),
1290                 sign_invoice: Clone::clone(&orig.sign_invoice),
1291                 sign_gossip_message: Clone::clone(&orig.sign_gossip_message),
1292                 free: Clone::clone(&orig.free),
1293         }
1294 }
1295
1296 use lightning::chain::keysinterface::NodeSigner as rustNodeSigner;
1297 impl rustNodeSigner for NodeSigner {
1298         fn get_inbound_payment_key_material(&self) -> lightning::chain::keysinterface::KeyMaterial {
1299                 let mut ret = (self.get_inbound_payment_key_material)(self.this_arg);
1300                 ::lightning::chain::keysinterface::KeyMaterial(ret.data)
1301         }
1302         fn get_node_id(&self, mut recipient: lightning::chain::keysinterface::Recipient) -> Result<bitcoin::secp256k1::PublicKey, ()> {
1303                 let mut ret = (self.get_node_id)(self.this_arg, crate::lightning::chain::keysinterface::Recipient::native_into(recipient));
1304                 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)) })*/ })};
1305                 local_ret
1306         }
1307         fn ecdh(&self, mut recipient: lightning::chain::keysinterface::Recipient, mut other_key: &bitcoin::secp256k1::PublicKey, mut tweak: Option<&bitcoin::secp256k1::Scalar>) -> Result<bitcoin::secp256k1::ecdh::SharedSecret, ()> {
1308                 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.clone().unwrap()) }) };
1309                 let mut ret = (self.ecdh)(self.this_arg, crate::lightning::chain::keysinterface::Recipient::native_into(recipient), crate::c_types::PublicKey::from_rust(&other_key), local_tweak);
1310                 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)) })*/ })};
1311                 local_ret
1312         }
1313         fn sign_invoice(&self, mut hrp_bytes: &[u8], mut invoice_data: &[bitcoin::bech32::u5], mut recipient: lightning::chain::keysinterface::Recipient) -> Result<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
1314                 let mut local_hrp_bytes = crate::c_types::u8slice::from_slice(hrp_bytes);
1315                 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() }); };
1316                 let mut ret = (self.sign_invoice)(self.this_arg, local_hrp_bytes, local_invoice_data.into(), crate::lightning::chain::keysinterface::Recipient::native_into(recipient));
1317                 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)) })*/ })};
1318                 local_ret
1319         }
1320         fn sign_gossip_message(&self, mut msg: lightning::ln::msgs::UnsignedGossipMessage) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1321                 let mut ret = (self.sign_gossip_message)(self.this_arg, crate::lightning::ln::msgs::UnsignedGossipMessage::native_into(msg));
1322                 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)) })*/ })};
1323                 local_ret
1324         }
1325 }
1326
1327 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1328 // directly as a Deref trait in higher-level structs:
1329 impl core::ops::Deref for NodeSigner {
1330         type Target = Self;
1331         fn deref(&self) -> &Self {
1332                 self
1333         }
1334 }
1335 /// Calls the free function if one is set
1336 #[no_mangle]
1337 pub extern "C" fn NodeSigner_free(this_ptr: NodeSigner) { }
1338 impl Drop for NodeSigner {
1339         fn drop(&mut self) {
1340                 if let Some(f) = self.free {
1341                         f(self.this_arg);
1342                 }
1343         }
1344 }
1345 /// A trait that can return signer instances for individual channels.
1346 #[repr(C)]
1347 pub struct SignerProvider {
1348         /// An opaque pointer which is passed to your function implementations as an argument.
1349         /// This has no meaning in the LDK, and can be NULL or any other value.
1350         pub this_arg: *mut c_void,
1351         /// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
1352         /// [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
1353         /// implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
1354         /// `channel_keys_id`.
1355         ///
1356         /// This method must return a different value each time it is called.
1357         #[must_use]
1358         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,
1359         /// Derives the private key material backing a `Signer`.
1360         ///
1361         /// To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
1362         /// [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
1363         /// re-derived from its `channel_keys_id`, which can be obtained through its trait method
1364         /// [`ChannelSigner::channel_keys_id`].
1365         #[must_use]
1366         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::chain::keysinterface::WriteableEcdsaChannelSigner,
1367         /// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
1368         /// This is only called during deserialization of other objects which contain
1369         /// [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
1370         /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
1371         /// contain no versioning scheme. You may wish to include your own version prefix and ensure
1372         /// you've read all of the provided bytes to ensure no corruption occurred.
1373         ///
1374         /// This method is slowly being phased out -- it will only be called when reading objects
1375         /// written by LDK versions prior to 0.0.113.
1376         ///
1377         /// [`Signer`]: Self::Signer
1378         /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
1379         /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1380         #[must_use]
1381         pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ,
1382         /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
1383         ///
1384         /// This method should return a different value each time it is called, to avoid linking
1385         /// on-chain funds across channels as controlled to the same user.
1386         #[must_use]
1387         pub get_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
1388         /// Get a script pubkey which we will send funds to when closing a channel.
1389         ///
1390         /// This method should return a different value each time it is called, to avoid linking
1391         /// on-chain funds across channels as controlled to the same user.
1392         #[must_use]
1393         pub get_shutdown_scriptpubkey: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::script::ShutdownScript,
1394         /// Frees any resources associated with this object given its this_arg pointer.
1395         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1396         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1397 }
1398 unsafe impl Send for SignerProvider {}
1399 unsafe impl Sync for SignerProvider {}
1400 #[no_mangle]
1401 pub(crate) extern "C" fn SignerProvider_clone_fields(orig: &SignerProvider) -> SignerProvider {
1402         SignerProvider {
1403                 this_arg: orig.this_arg,
1404                 generate_channel_keys_id: Clone::clone(&orig.generate_channel_keys_id),
1405                 derive_channel_signer: Clone::clone(&orig.derive_channel_signer),
1406                 read_chan_signer: Clone::clone(&orig.read_chan_signer),
1407                 get_destination_script: Clone::clone(&orig.get_destination_script),
1408                 get_shutdown_scriptpubkey: Clone::clone(&orig.get_shutdown_scriptpubkey),
1409                 free: Clone::clone(&orig.free),
1410         }
1411 }
1412
1413 use lightning::chain::keysinterface::SignerProvider as rustSignerProvider;
1414 impl rustSignerProvider for SignerProvider {
1415         type Signer = crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner;
1416         fn generate_channel_keys_id(&self, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: u128) -> [u8; 32] {
1417                 let mut ret = (self.generate_channel_keys_id)(self.this_arg, inbound, channel_value_satoshis, user_channel_id.into());
1418                 ret.data
1419         }
1420         fn derive_channel_signer(&self, mut channel_value_satoshis: u64, mut channel_keys_id: [u8; 32]) -> crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner {
1421                 let mut ret = (self.derive_channel_signer)(self.this_arg, channel_value_satoshis, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
1422                 ret
1423         }
1424         fn read_chan_signer(&self, mut reader: &[u8]) -> Result<crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner, lightning::ln::msgs::DecodeError> {
1425                 let mut local_reader = crate::c_types::u8slice::from_slice(reader);
1426                 let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
1427                 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() })};
1428                 local_ret
1429         }
1430         fn get_destination_script(&self) -> bitcoin::blockdata::script::Script {
1431                 let mut ret = (self.get_destination_script)(self.this_arg);
1432                 ::bitcoin::blockdata::script::Script::from(ret.into_rust())
1433         }
1434         fn get_shutdown_scriptpubkey(&self) -> lightning::ln::script::ShutdownScript {
1435                 let mut ret = (self.get_shutdown_scriptpubkey)(self.this_arg);
1436                 *unsafe { Box::from_raw(ret.take_inner()) }
1437         }
1438 }
1439
1440 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1441 // directly as a Deref trait in higher-level structs:
1442 impl core::ops::Deref for SignerProvider {
1443         type Target = Self;
1444         fn deref(&self) -> &Self {
1445                 self
1446         }
1447 }
1448 /// Calls the free function if one is set
1449 #[no_mangle]
1450 pub extern "C" fn SignerProvider_free(this_ptr: SignerProvider) { }
1451 impl Drop for SignerProvider {
1452         fn drop(&mut self) {
1453                 if let Some(f) = self.free {
1454                         f(self.this_arg);
1455                 }
1456         }
1457 }
1458
1459 use lightning::chain::keysinterface::InMemorySigner as nativeInMemorySignerImport;
1460 pub(crate) type nativeInMemorySigner = nativeInMemorySignerImport;
1461
1462 /// A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
1463 ///
1464 /// This implementation performs no policy checks and is insufficient by itself as
1465 /// a secure external signer.
1466 #[must_use]
1467 #[repr(C)]
1468 pub struct InMemorySigner {
1469         /// A pointer to the opaque Rust object.
1470
1471         /// Nearly everywhere, inner must be non-null, however in places where
1472         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1473         pub inner: *mut nativeInMemorySigner,
1474         /// Indicates that this is the only struct which contains the same pointer.
1475
1476         /// Rust functions which take ownership of an object provided via an argument require
1477         /// this to be true and invalidate the object pointed to by inner.
1478         pub is_owned: bool,
1479 }
1480
1481 impl Drop for InMemorySigner {
1482         fn drop(&mut self) {
1483                 if self.is_owned && !<*mut nativeInMemorySigner>::is_null(self.inner) {
1484                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1485                 }
1486         }
1487 }
1488 /// Frees any resources used by the InMemorySigner, if is_owned is set and inner is non-NULL.
1489 #[no_mangle]
1490 pub extern "C" fn InMemorySigner_free(this_obj: InMemorySigner) { }
1491 #[allow(unused)]
1492 /// Used only if an object of this type is returned as a trait impl by a method
1493 pub(crate) extern "C" fn InMemorySigner_free_void(this_ptr: *mut c_void) {
1494         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInMemorySigner) };
1495 }
1496 #[allow(unused)]
1497 impl InMemorySigner {
1498         pub(crate) fn get_native_ref(&self) -> &'static nativeInMemorySigner {
1499                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1500         }
1501         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInMemorySigner {
1502                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1503         }
1504         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1505         pub(crate) fn take_inner(mut self) -> *mut nativeInMemorySigner {
1506                 assert!(self.is_owned);
1507                 let ret = ObjOps::untweak_ptr(self.inner);
1508                 self.inner = core::ptr::null_mut();
1509                 ret
1510         }
1511 }
1512 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1513 /// holder's anchor output in a commitment transaction, if one is present.
1514 #[no_mangle]
1515 pub extern "C" fn InMemorySigner_get_funding_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1516         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_key;
1517         inner_val.as_ref()
1518 }
1519 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1520 /// holder's anchor output in a commitment transaction, if one is present.
1521 #[no_mangle]
1522 pub extern "C" fn InMemorySigner_set_funding_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1523         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_key = val.into_rust();
1524 }
1525 /// Holder secret key for blinded revocation pubkey.
1526 #[no_mangle]
1527 pub extern "C" fn InMemorySigner_get_revocation_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1528         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_base_key;
1529         inner_val.as_ref()
1530 }
1531 /// Holder secret key for blinded revocation pubkey.
1532 #[no_mangle]
1533 pub extern "C" fn InMemorySigner_set_revocation_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1534         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_base_key = val.into_rust();
1535 }
1536 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1537 #[no_mangle]
1538 pub extern "C" fn InMemorySigner_get_payment_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1539         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_key;
1540         inner_val.as_ref()
1541 }
1542 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1543 #[no_mangle]
1544 pub extern "C" fn InMemorySigner_set_payment_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1545         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_key = val.into_rust();
1546 }
1547 /// Holder secret key used in an HTLC transaction.
1548 #[no_mangle]
1549 pub extern "C" fn InMemorySigner_get_delayed_payment_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1550         let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_base_key;
1551         inner_val.as_ref()
1552 }
1553 /// Holder secret key used in an HTLC transaction.
1554 #[no_mangle]
1555 pub extern "C" fn InMemorySigner_set_delayed_payment_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1556         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_base_key = val.into_rust();
1557 }
1558 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1559 #[no_mangle]
1560 pub extern "C" fn InMemorySigner_get_htlc_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1561         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_base_key;
1562         inner_val.as_ref()
1563 }
1564 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1565 #[no_mangle]
1566 pub extern "C" fn InMemorySigner_set_htlc_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1567         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_base_key = val.into_rust();
1568 }
1569 /// Commitment seed.
1570 #[no_mangle]
1571 pub extern "C" fn InMemorySigner_get_commitment_seed(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1572         let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_seed;
1573         inner_val
1574 }
1575 /// Commitment seed.
1576 #[no_mangle]
1577 pub extern "C" fn InMemorySigner_set_commitment_seed(this_ptr: &mut InMemorySigner, mut val: crate::c_types::ThirtyTwoBytes) {
1578         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_seed = val.data;
1579 }
1580 impl Clone for InMemorySigner {
1581         fn clone(&self) -> Self {
1582                 Self {
1583                         inner: if <*mut nativeInMemorySigner>::is_null(self.inner) { core::ptr::null_mut() } else {
1584                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1585                         is_owned: true,
1586                 }
1587         }
1588 }
1589 #[allow(unused)]
1590 /// Used only if an object of this type is returned as a trait impl by a method
1591 pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void {
1592         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInMemorySigner)).clone() })) as *mut c_void
1593 }
1594 #[no_mangle]
1595 /// Creates a copy of the InMemorySigner
1596 pub extern "C" fn InMemorySigner_clone(orig: &InMemorySigner) -> InMemorySigner {
1597         orig.clone()
1598 }
1599 /// Creates a new [`InMemorySigner`].
1600 #[must_use]
1601 #[no_mangle]
1602 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) -> crate::lightning::chain::keysinterface::InMemorySigner {
1603         let mut ret = lightning::chain::keysinterface::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);
1604         crate::lightning::chain::keysinterface::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
1605 }
1606
1607 /// Returns the counterparty's pubkeys.
1608 ///
1609 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1610 #[must_use]
1611 #[no_mangle]
1612 pub extern "C" fn InMemorySigner_counterparty_pubkeys(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1613         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_pubkeys();
1614         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 }
1615 }
1616
1617 /// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
1618 /// transactions, i.e., the amount of time that we have to wait to recover our funds if we
1619 /// broadcast a transaction.
1620 ///
1621 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1622 #[must_use]
1623 #[no_mangle]
1624 pub extern "C" fn InMemorySigner_counterparty_selected_contest_delay(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> u16 {
1625         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_selected_contest_delay();
1626         ret
1627 }
1628
1629 /// Returns the `contest_delay` value specified by us and applied on transactions broadcastable
1630 /// by our counterparty, i.e., the amount of time that they have to wait to recover their funds
1631 /// if they broadcast a transaction.
1632 ///
1633 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1634 #[must_use]
1635 #[no_mangle]
1636 pub extern "C" fn InMemorySigner_holder_selected_contest_delay(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> u16 {
1637         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.holder_selected_contest_delay();
1638         ret
1639 }
1640
1641 /// Returns whether the holder is the initiator.
1642 ///
1643 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1644 #[must_use]
1645 #[no_mangle]
1646 pub extern "C" fn InMemorySigner_is_outbound(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> bool {
1647         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
1648         ret
1649 }
1650
1651 /// Funding outpoint
1652 ///
1653 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1654 #[must_use]
1655 #[no_mangle]
1656 pub extern "C" fn InMemorySigner_funding_outpoint(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> crate::lightning::chain::transaction::OutPoint {
1657         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
1658         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::chain::transaction::OutPoint<>) as *mut _) }, is_owned: false }
1659 }
1660
1661 /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
1662 /// building transactions.
1663 ///
1664 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1665 #[must_use]
1666 #[no_mangle]
1667 pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
1668         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_channel_parameters();
1669         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 }
1670 }
1671
1672 /// Returns whether anchors should be used.
1673 ///
1674 /// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
1675 #[must_use]
1676 #[no_mangle]
1677 pub extern "C" fn InMemorySigner_opt_anchors(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> bool {
1678         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.opt_anchors();
1679         ret
1680 }
1681
1682 /// Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
1683 /// by `descriptor`, returning the witness stack for the input.
1684 ///
1685 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
1686 /// is not spending the outpoint described by [`descriptor.outpoint`],
1687 /// or if an output descriptor `script_pubkey` does not match the one we can spend.
1688 ///
1689 /// [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
1690 #[must_use]
1691 #[no_mangle]
1692 pub extern "C" fn InMemorySigner_sign_counterparty_payment_input(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CResult_CVec_CVec_u8ZZNoneZ {
1693         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);
1694         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() };
1695         local_ret
1696 }
1697
1698 /// Sign the single input of `spend_tx` at index `input_idx` which spends the output
1699 /// described by `descriptor`, returning the witness stack for the input.
1700 ///
1701 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
1702 /// is not spending the outpoint described by [`descriptor.outpoint`], does not have a
1703 /// sequence set to [`descriptor.to_self_delay`], or if an output descriptor
1704 /// `script_pubkey` does not match the one we can spend.
1705 ///
1706 /// [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
1707 /// [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
1708 #[must_use]
1709 #[no_mangle]
1710 pub extern "C" fn InMemorySigner_sign_dynamic_p2wsh_input(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CResult_CVec_CVec_u8ZZNoneZ {
1711         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);
1712         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() };
1713         local_ret
1714 }
1715
1716 impl From<nativeInMemorySigner> for crate::lightning::chain::keysinterface::ChannelSigner {
1717         fn from(obj: nativeInMemorySigner) -> Self {
1718                 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1719                 let mut ret = InMemorySigner_as_ChannelSigner(&rust_obj);
1720                 // 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
1721                 rust_obj.inner = core::ptr::null_mut();
1722                 ret.free = Some(InMemorySigner_free_void);
1723                 ret
1724         }
1725 }
1726 /// Constructs a new ChannelSigner which calls the relevant methods on this_arg.
1727 /// This copies the `inner` pointer in this_arg and thus the returned ChannelSigner must be freed before this_arg is
1728 #[no_mangle]
1729 pub extern "C" fn InMemorySigner_as_ChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::chain::keysinterface::ChannelSigner {
1730         crate::lightning::chain::keysinterface::ChannelSigner {
1731                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1732                 free: None,
1733                 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
1734                 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
1735                 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
1736
1737                 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true },
1738                 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
1739                 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
1740                 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
1741         }
1742 }
1743
1744 #[must_use]
1745 extern "C" fn InMemorySigner_ChannelSigner_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey {
1746         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::ChannelSigner<>>::get_per_commitment_point(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, secp256k1::global::SECP256K1);
1747         crate::c_types::PublicKey::from_rust(&ret)
1748 }
1749 #[must_use]
1750 extern "C" fn InMemorySigner_ChannelSigner_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
1751         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::ChannelSigner<>>::release_commitment_secret(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx);
1752         crate::c_types::ThirtyTwoBytes { data: ret }
1753 }
1754 #[must_use]
1755 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 {
1756         let mut local_preimages = Vec::new(); for mut item in preimages.into_rust().drain(..) { local_preimages.push( { ::lightning::ln::PaymentPreimage(item.data) }); };
1757         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::ChannelSigner<>>::validate_holder_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, holder_tx.get_native_ref(), local_preimages);
1758         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() };
1759         local_ret
1760 }
1761 #[must_use]
1762 extern "C" fn InMemorySigner_ChannelSigner_pubkeys(this_arg: *const c_void) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1763         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::ChannelSigner<>>::pubkeys(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1764         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 }
1765 }
1766 extern "C" fn InMemorySigner_ChannelSigner_set_pubkeys(trait_self_arg: &ChannelSigner) {
1767         // This is a bit race-y in the general case, but for our specific use-cases today, we're safe
1768         // Specifically, we must ensure that the first time we're called it can never be in parallel
1769         if trait_self_arg.pubkeys.inner.is_null() {
1770                 unsafe { &mut *(trait_self_arg as *const ChannelSigner  as *mut ChannelSigner) }.pubkeys = InMemorySigner_ChannelSigner_pubkeys(trait_self_arg.this_arg);
1771         }
1772 }
1773 #[must_use]
1774 extern "C" fn InMemorySigner_ChannelSigner_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1775         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::ChannelSigner<>>::channel_keys_id(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1776         crate::c_types::ThirtyTwoBytes { data: ret }
1777 }
1778 extern "C" fn InMemorySigner_ChannelSigner_provide_channel_parameters(this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
1779         <nativeInMemorySigner as lightning::chain::keysinterface::ChannelSigner<>>::provide_channel_parameters(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, channel_parameters.get_native_ref())
1780 }
1781
1782 impl From<nativeInMemorySigner> for crate::lightning::chain::keysinterface::EcdsaChannelSigner {
1783         fn from(obj: nativeInMemorySigner) -> Self {
1784                 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1785                 let mut ret = InMemorySigner_as_EcdsaChannelSigner(&rust_obj);
1786                 // 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
1787                 rust_obj.inner = core::ptr::null_mut();
1788                 ret.free = Some(InMemorySigner_free_void);
1789                 ret
1790         }
1791 }
1792 /// Constructs a new EcdsaChannelSigner which calls the relevant methods on this_arg.
1793 /// This copies the `inner` pointer in this_arg and thus the returned EcdsaChannelSigner must be freed before this_arg is
1794 #[no_mangle]
1795 pub extern "C" fn InMemorySigner_as_EcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::chain::keysinterface::EcdsaChannelSigner {
1796         crate::lightning::chain::keysinterface::EcdsaChannelSigner {
1797                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1798                 free: None,
1799                 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
1800                 validate_counterparty_revocation: InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation,
1801                 sign_holder_commitment_and_htlcs: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs,
1802                 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
1803                 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
1804                 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
1805                 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
1806                 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
1807                 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
1808                 ChannelSigner: crate::lightning::chain::keysinterface::ChannelSigner {
1809                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1810                         free: None,
1811                         get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
1812                         release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
1813                         validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
1814
1815                         pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true },
1816                         set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
1817                         channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
1818                         provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
1819                 },
1820         }
1821 }
1822
1823 #[must_use]
1824 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 {
1825         let mut local_preimages = Vec::new(); for mut item in preimages.into_rust().drain(..) { local_preimages.push( { ::lightning::ln::PaymentPreimage(item.data) }); };
1826         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::EcdsaChannelSigner<>>::sign_counterparty_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), local_preimages, secp256k1::global::SECP256K1);
1827         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() };
1828         local_ret
1829 }
1830 #[must_use]
1831 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 {
1832         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::EcdsaChannelSigner<>>::validate_counterparty_revocation(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *secret}[..]).unwrap());
1833         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() };
1834         local_ret
1835 }
1836 #[must_use]
1837 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 {
1838         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::EcdsaChannelSigner<>>::sign_holder_commitment_and_htlcs(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), secp256k1::global::SECP256K1);
1839         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() };
1840         local_ret
1841 }
1842 #[must_use]
1843 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 {
1844         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::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);
1845         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() };
1846         local_ret
1847 }
1848 #[must_use]
1849 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 {
1850         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::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);
1851         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() };
1852         local_ret
1853 }
1854 #[must_use]
1855 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 {
1856         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::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);
1857         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() };
1858         local_ret
1859 }
1860 #[must_use]
1861 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 {
1862         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::EcdsaChannelSigner<>>::sign_closing_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, closing_tx.get_native_ref(), secp256k1::global::SECP256K1);
1863         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() };
1864         local_ret
1865 }
1866 #[must_use]
1867 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 {
1868         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::EcdsaChannelSigner<>>::sign_holder_anchor_input(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &anchor_tx.into_bitcoin(), input, secp256k1::global::SECP256K1);
1869         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() };
1870         local_ret
1871 }
1872 #[must_use]
1873 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 {
1874         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::EcdsaChannelSigner<>>::sign_channel_announcement_with_funding_key(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, msg.get_native_ref(), secp256k1::global::SECP256K1);
1875         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() };
1876         local_ret
1877 }
1878
1879 impl From<nativeInMemorySigner> for crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner {
1880         fn from(obj: nativeInMemorySigner) -> Self {
1881                 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1882                 let mut ret = InMemorySigner_as_WriteableEcdsaChannelSigner(&rust_obj);
1883                 // 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
1884                 rust_obj.inner = core::ptr::null_mut();
1885                 ret.free = Some(InMemorySigner_free_void);
1886                 ret
1887         }
1888 }
1889 /// Constructs a new WriteableEcdsaChannelSigner which calls the relevant methods on this_arg.
1890 /// This copies the `inner` pointer in this_arg and thus the returned WriteableEcdsaChannelSigner must be freed before this_arg is
1891 #[no_mangle]
1892 pub extern "C" fn InMemorySigner_as_WriteableEcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner {
1893         crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner {
1894                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1895                 free: None,
1896                 EcdsaChannelSigner: crate::lightning::chain::keysinterface::EcdsaChannelSigner {
1897                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1898                         free: None,
1899                         sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
1900                         validate_counterparty_revocation: InMemorySigner_EcdsaChannelSigner_validate_counterparty_revocation,
1901                         sign_holder_commitment_and_htlcs: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment_and_htlcs,
1902                         sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
1903                         sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
1904                         sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
1905                         sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
1906                         sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
1907                         sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
1908                         ChannelSigner: crate::lightning::chain::keysinterface::ChannelSigner {
1909                                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1910                                 free: None,
1911                                 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
1912                                 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
1913                                 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
1914
1915                                 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true },
1916                                 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
1917                                 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
1918                                 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
1919                         },
1920                 },
1921                 write: InMemorySigner_write_void,
1922         }
1923 }
1924
1925
1926 #[no_mangle]
1927 /// Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
1928 pub extern "C" fn InMemorySigner_write(obj: &crate::lightning::chain::keysinterface::InMemorySigner) -> crate::c_types::derived::CVec_u8Z {
1929         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1930 }
1931 #[no_mangle]
1932 pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1933         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) })
1934 }
1935 #[no_mangle]
1936 /// Read a InMemorySigner from a byte array, created by InMemorySigner_write
1937 pub extern "C" fn InMemorySigner_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InMemorySignerDecodeErrorZ {
1938         let res: Result<lightning::chain::keysinterface::InMemorySigner, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1939         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::keysinterface::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() };
1940         local_res
1941 }
1942
1943 use lightning::chain::keysinterface::KeysManager as nativeKeysManagerImport;
1944 pub(crate) type nativeKeysManager = nativeKeysManagerImport;
1945
1946 /// Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a
1947 /// 32-byte seed for use as a BIP 32 extended key and derives keys from that.
1948 ///
1949 /// Your `node_id` is seed/0'.
1950 /// Unilateral closes may use seed/1'.
1951 /// Cooperative closes may use seed/2'.
1952 /// The two close keys may be needed to claim on-chain funds!
1953 ///
1954 /// This struct cannot be used for nodes that wish to support receiving phantom payments;
1955 /// [`PhantomKeysManager`] must be used instead.
1956 ///
1957 /// Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
1958 /// previously issued invoices and attempts to pay previous invoices will fail.
1959 #[must_use]
1960 #[repr(C)]
1961 pub struct KeysManager {
1962         /// A pointer to the opaque Rust object.
1963
1964         /// Nearly everywhere, inner must be non-null, however in places where
1965         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1966         pub inner: *mut nativeKeysManager,
1967         /// Indicates that this is the only struct which contains the same pointer.
1968
1969         /// Rust functions which take ownership of an object provided via an argument require
1970         /// this to be true and invalidate the object pointed to by inner.
1971         pub is_owned: bool,
1972 }
1973
1974 impl Drop for KeysManager {
1975         fn drop(&mut self) {
1976                 if self.is_owned && !<*mut nativeKeysManager>::is_null(self.inner) {
1977                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1978                 }
1979         }
1980 }
1981 /// Frees any resources used by the KeysManager, if is_owned is set and inner is non-NULL.
1982 #[no_mangle]
1983 pub extern "C" fn KeysManager_free(this_obj: KeysManager) { }
1984 #[allow(unused)]
1985 /// Used only if an object of this type is returned as a trait impl by a method
1986 pub(crate) extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) {
1987         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeKeysManager) };
1988 }
1989 #[allow(unused)]
1990 impl KeysManager {
1991         pub(crate) fn get_native_ref(&self) -> &'static nativeKeysManager {
1992                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1993         }
1994         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeKeysManager {
1995                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1996         }
1997         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1998         pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager {
1999                 assert!(self.is_owned);
2000                 let ret = ObjOps::untweak_ptr(self.inner);
2001                 self.inner = core::ptr::null_mut();
2002                 ret
2003         }
2004 }
2005 /// Constructs a [`KeysManager`] from a 32-byte seed. If the seed is in some way biased (e.g.,
2006 /// your CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
2007 /// `starting_time` isn't strictly required to actually be a time, but it must absolutely,
2008 /// without a doubt, be unique to this instance. ie if you start multiple times with the same
2009 /// `seed`, `starting_time` must be unique to each run. Thus, the easiest way to achieve this
2010 /// is to simply use the current time (with very high precision).
2011 ///
2012 /// The `seed` MUST be backed up safely prior to use so that the keys can be re-created, however,
2013 /// obviously, `starting_time` should be unique every time you reload the library - it is only
2014 /// used to generate new ephemeral key data (which will be stored by the individual channel if
2015 /// necessary).
2016 ///
2017 /// Note that the seed is required to recover certain on-chain funds independent of
2018 /// [`ChannelMonitor`] data, though a current copy of [`ChannelMonitor`] data is also required
2019 /// for any channel, and some on-chain during-closing funds.
2020 ///
2021 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
2022 #[must_use]
2023 #[no_mangle]
2024 pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32) -> crate::lightning::chain::keysinterface::KeysManager {
2025         let mut ret = lightning::chain::keysinterface::KeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos);
2026         crate::lightning::chain::keysinterface::KeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2027 }
2028
2029 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2030 #[must_use]
2031 #[no_mangle]
2032 pub extern "C" fn KeysManager_get_node_secret_key(this_arg: &crate::lightning::chain::keysinterface::KeysManager) -> crate::c_types::SecretKey {
2033         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2034         crate::c_types::SecretKey::from_rust(ret)
2035 }
2036
2037 /// Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
2038 #[must_use]
2039 #[no_mangle]
2040 pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &crate::lightning::chain::keysinterface::KeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::lightning::chain::keysinterface::InMemorySigner {
2041         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2042         crate::lightning::chain::keysinterface::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2043 }
2044
2045 /// Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
2046 /// output to the given change destination (if sufficient change value remains). The
2047 /// transaction will have a feerate, at least, of the given value.
2048 ///
2049 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
2050 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
2051 /// does not match the one we can spend.
2052 ///
2053 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
2054 ///
2055 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
2056 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2057 #[must_use]
2058 #[no_mangle]
2059 pub extern "C" fn KeysManager_spend_spendable_outputs(this_arg: &crate::lightning::chain::keysinterface::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) -> crate::c_types::derived::CResult_TransactionNoneZ {
2060         let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2061         let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2062         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, secp256k1::global::SECP256K1);
2063         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() };
2064         local_ret
2065 }
2066
2067 impl From<nativeKeysManager> for crate::lightning::chain::keysinterface::EntropySource {
2068         fn from(obj: nativeKeysManager) -> Self {
2069                 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2070                 let mut ret = KeysManager_as_EntropySource(&rust_obj);
2071                 // 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
2072                 rust_obj.inner = core::ptr::null_mut();
2073                 ret.free = Some(KeysManager_free_void);
2074                 ret
2075         }
2076 }
2077 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2078 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2079 #[no_mangle]
2080 pub extern "C" fn KeysManager_as_EntropySource(this_arg: &KeysManager) -> crate::lightning::chain::keysinterface::EntropySource {
2081         crate::lightning::chain::keysinterface::EntropySource {
2082                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2083                 free: None,
2084                 get_secure_random_bytes: KeysManager_EntropySource_get_secure_random_bytes,
2085         }
2086 }
2087
2088 #[must_use]
2089 extern "C" fn KeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2090         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2091         crate::c_types::ThirtyTwoBytes { data: ret }
2092 }
2093
2094 impl From<nativeKeysManager> for crate::lightning::chain::keysinterface::NodeSigner {
2095         fn from(obj: nativeKeysManager) -> Self {
2096                 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2097                 let mut ret = KeysManager_as_NodeSigner(&rust_obj);
2098                 // 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
2099                 rust_obj.inner = core::ptr::null_mut();
2100                 ret.free = Some(KeysManager_free_void);
2101                 ret
2102         }
2103 }
2104 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2105 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2106 #[no_mangle]
2107 pub extern "C" fn KeysManager_as_NodeSigner(this_arg: &KeysManager) -> crate::lightning::chain::keysinterface::NodeSigner {
2108         crate::lightning::chain::keysinterface::NodeSigner {
2109                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2110                 free: None,
2111                 get_inbound_payment_key_material: KeysManager_NodeSigner_get_inbound_payment_key_material,
2112                 get_node_id: KeysManager_NodeSigner_get_node_id,
2113                 ecdh: KeysManager_NodeSigner_ecdh,
2114                 sign_invoice: KeysManager_NodeSigner_sign_invoice,
2115                 sign_gossip_message: KeysManager_NodeSigner_sign_gossip_message,
2116         }
2117 }
2118
2119 #[must_use]
2120 extern "C" fn KeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2121         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::NodeSigner<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2122         crate::c_types::ThirtyTwoBytes { data: ret.0 }
2123 }
2124 #[must_use]
2125 extern "C" fn KeysManager_NodeSigner_get_node_id(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ {
2126         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::NodeSigner<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native());
2127         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() };
2128         local_ret
2129 }
2130 #[must_use]
2131 extern "C" fn KeysManager_NodeSigner_ecdh(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient, mut other_key: crate::c_types::PublicKey, mut tweak: crate::c_types::derived::COption_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ {
2132         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();
2133         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::NodeSigner<>>::ecdh(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native(), &other_key.into_rust(), local_tweak);
2134         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() };
2135         local_ret
2136 }
2137 #[must_use]
2138 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::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ {
2139         let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2140         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::NodeSigner<>>::sign_invoice(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, hrp_bytes.to_slice(), &local_invoice_data[..], recipient.into_native());
2141         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() };
2142         local_ret
2143 }
2144 #[must_use]
2145 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 {
2146         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::NodeSigner<>>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, msg.into_native());
2147         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() };
2148         local_ret
2149 }
2150
2151 impl From<nativeKeysManager> for crate::lightning::chain::keysinterface::SignerProvider {
2152         fn from(obj: nativeKeysManager) -> Self {
2153                 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2154                 let mut ret = KeysManager_as_SignerProvider(&rust_obj);
2155                 // 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
2156                 rust_obj.inner = core::ptr::null_mut();
2157                 ret.free = Some(KeysManager_free_void);
2158                 ret
2159         }
2160 }
2161 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2162 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2163 #[no_mangle]
2164 pub extern "C" fn KeysManager_as_SignerProvider(this_arg: &KeysManager) -> crate::lightning::chain::keysinterface::SignerProvider {
2165         crate::lightning::chain::keysinterface::SignerProvider {
2166                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2167                 free: None,
2168                 generate_channel_keys_id: KeysManager_SignerProvider_generate_channel_keys_id,
2169                 derive_channel_signer: KeysManager_SignerProvider_derive_channel_signer,
2170                 read_chan_signer: KeysManager_SignerProvider_read_chan_signer,
2171                 get_destination_script: KeysManager_SignerProvider_get_destination_script,
2172                 get_shutdown_scriptpubkey: KeysManager_SignerProvider_get_shutdown_scriptpubkey,
2173         }
2174 }
2175
2176 #[must_use]
2177 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 {
2178         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::SignerProvider<>>::generate_channel_keys_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, inbound, channel_value_satoshis, user_channel_id.into());
2179         crate::c_types::ThirtyTwoBytes { data: ret }
2180 }
2181 #[must_use]
2182 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::chain::keysinterface::WriteableEcdsaChannelSigner {
2183         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::SignerProvider<>>::derive_channel_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, channel_value_satoshis, channel_keys_id.data);
2184         Into::into(ret)
2185 }
2186 #[must_use]
2187 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 {
2188         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::SignerProvider<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, reader.to_slice());
2189         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() };
2190         local_ret
2191 }
2192 #[must_use]
2193 extern "C" fn KeysManager_SignerProvider_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2194         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::SignerProvider<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2195         ret.into_bytes().into()
2196 }
2197 #[must_use]
2198 extern "C" fn KeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::lightning::ln::script::ShutdownScript {
2199         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::SignerProvider<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2200         crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(ret), is_owned: true }
2201 }
2202
2203
2204 use lightning::chain::keysinterface::PhantomKeysManager as nativePhantomKeysManagerImport;
2205 pub(crate) type nativePhantomKeysManager = nativePhantomKeysManagerImport;
2206
2207 /// Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
2208 /// payments.
2209 ///
2210 /// A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
2211 /// paid to one of multiple nodes. This works because we encode the invoice route hints such that
2212 /// LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
2213 /// itself without ever needing to forward to this fake node.
2214 ///
2215 /// Phantom node payments are useful for load balancing between multiple LDK nodes. They also
2216 /// provide some fault tolerance, because payers will automatically retry paying other provided
2217 /// nodes in the case that one node goes down.
2218 ///
2219 /// Note that multi-path payments are not supported in phantom invoices for security reasons.
2220 /// Switching between this struct and [`KeysManager`] will invalidate any previously issued
2221 /// invoices and attempts to pay previous invoices will fail.
2222 #[must_use]
2223 #[repr(C)]
2224 pub struct PhantomKeysManager {
2225         /// A pointer to the opaque Rust object.
2226
2227         /// Nearly everywhere, inner must be non-null, however in places where
2228         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2229         pub inner: *mut nativePhantomKeysManager,
2230         /// Indicates that this is the only struct which contains the same pointer.
2231
2232         /// Rust functions which take ownership of an object provided via an argument require
2233         /// this to be true and invalidate the object pointed to by inner.
2234         pub is_owned: bool,
2235 }
2236
2237 impl Drop for PhantomKeysManager {
2238         fn drop(&mut self) {
2239                 if self.is_owned && !<*mut nativePhantomKeysManager>::is_null(self.inner) {
2240                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2241                 }
2242         }
2243 }
2244 /// Frees any resources used by the PhantomKeysManager, if is_owned is set and inner is non-NULL.
2245 #[no_mangle]
2246 pub extern "C" fn PhantomKeysManager_free(this_obj: PhantomKeysManager) { }
2247 #[allow(unused)]
2248 /// Used only if an object of this type is returned as a trait impl by a method
2249 pub(crate) extern "C" fn PhantomKeysManager_free_void(this_ptr: *mut c_void) {
2250         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomKeysManager) };
2251 }
2252 #[allow(unused)]
2253 impl PhantomKeysManager {
2254         pub(crate) fn get_native_ref(&self) -> &'static nativePhantomKeysManager {
2255                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2256         }
2257         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomKeysManager {
2258                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2259         }
2260         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2261         pub(crate) fn take_inner(mut self) -> *mut nativePhantomKeysManager {
2262                 assert!(self.is_owned);
2263                 let ret = ObjOps::untweak_ptr(self.inner);
2264                 self.inner = core::ptr::null_mut();
2265                 ret
2266         }
2267 }
2268 impl From<nativePhantomKeysManager> for crate::lightning::chain::keysinterface::EntropySource {
2269         fn from(obj: nativePhantomKeysManager) -> Self {
2270                 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2271                 let mut ret = PhantomKeysManager_as_EntropySource(&rust_obj);
2272                 // 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
2273                 rust_obj.inner = core::ptr::null_mut();
2274                 ret.free = Some(PhantomKeysManager_free_void);
2275                 ret
2276         }
2277 }
2278 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2279 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2280 #[no_mangle]
2281 pub extern "C" fn PhantomKeysManager_as_EntropySource(this_arg: &PhantomKeysManager) -> crate::lightning::chain::keysinterface::EntropySource {
2282         crate::lightning::chain::keysinterface::EntropySource {
2283                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2284                 free: None,
2285                 get_secure_random_bytes: PhantomKeysManager_EntropySource_get_secure_random_bytes,
2286         }
2287 }
2288
2289 #[must_use]
2290 extern "C" fn PhantomKeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2291         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::EntropySource<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2292         crate::c_types::ThirtyTwoBytes { data: ret }
2293 }
2294
2295 impl From<nativePhantomKeysManager> for crate::lightning::chain::keysinterface::NodeSigner {
2296         fn from(obj: nativePhantomKeysManager) -> Self {
2297                 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2298                 let mut ret = PhantomKeysManager_as_NodeSigner(&rust_obj);
2299                 // 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
2300                 rust_obj.inner = core::ptr::null_mut();
2301                 ret.free = Some(PhantomKeysManager_free_void);
2302                 ret
2303         }
2304 }
2305 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2306 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2307 #[no_mangle]
2308 pub extern "C" fn PhantomKeysManager_as_NodeSigner(this_arg: &PhantomKeysManager) -> crate::lightning::chain::keysinterface::NodeSigner {
2309         crate::lightning::chain::keysinterface::NodeSigner {
2310                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2311                 free: None,
2312                 get_inbound_payment_key_material: PhantomKeysManager_NodeSigner_get_inbound_payment_key_material,
2313                 get_node_id: PhantomKeysManager_NodeSigner_get_node_id,
2314                 ecdh: PhantomKeysManager_NodeSigner_ecdh,
2315                 sign_invoice: PhantomKeysManager_NodeSigner_sign_invoice,
2316                 sign_gossip_message: PhantomKeysManager_NodeSigner_sign_gossip_message,
2317         }
2318 }
2319
2320 #[must_use]
2321 extern "C" fn PhantomKeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2322         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::NodeSigner<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2323         crate::c_types::ThirtyTwoBytes { data: ret.0 }
2324 }
2325 #[must_use]
2326 extern "C" fn PhantomKeysManager_NodeSigner_get_node_id(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ {
2327         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::NodeSigner<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native());
2328         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() };
2329         local_ret
2330 }
2331 #[must_use]
2332 extern "C" fn PhantomKeysManager_NodeSigner_ecdh(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient, mut other_key: crate::c_types::PublicKey, mut tweak: crate::c_types::derived::COption_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ {
2333         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();
2334         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::NodeSigner<>>::ecdh(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native(), &other_key.into_rust(), local_tweak);
2335         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() };
2336         local_ret
2337 }
2338 #[must_use]
2339 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::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ {
2340         let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2341         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::NodeSigner<>>::sign_invoice(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, hrp_bytes.to_slice(), &local_invoice_data[..], recipient.into_native());
2342         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() };
2343         local_ret
2344 }
2345 #[must_use]
2346 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 {
2347         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::NodeSigner<>>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, msg.into_native());
2348         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() };
2349         local_ret
2350 }
2351
2352 impl From<nativePhantomKeysManager> for crate::lightning::chain::keysinterface::SignerProvider {
2353         fn from(obj: nativePhantomKeysManager) -> Self {
2354                 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2355                 let mut ret = PhantomKeysManager_as_SignerProvider(&rust_obj);
2356                 // 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
2357                 rust_obj.inner = core::ptr::null_mut();
2358                 ret.free = Some(PhantomKeysManager_free_void);
2359                 ret
2360         }
2361 }
2362 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2363 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2364 #[no_mangle]
2365 pub extern "C" fn PhantomKeysManager_as_SignerProvider(this_arg: &PhantomKeysManager) -> crate::lightning::chain::keysinterface::SignerProvider {
2366         crate::lightning::chain::keysinterface::SignerProvider {
2367                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2368                 free: None,
2369                 generate_channel_keys_id: PhantomKeysManager_SignerProvider_generate_channel_keys_id,
2370                 derive_channel_signer: PhantomKeysManager_SignerProvider_derive_channel_signer,
2371                 read_chan_signer: PhantomKeysManager_SignerProvider_read_chan_signer,
2372                 get_destination_script: PhantomKeysManager_SignerProvider_get_destination_script,
2373                 get_shutdown_scriptpubkey: PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey,
2374         }
2375 }
2376
2377 #[must_use]
2378 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 {
2379         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::SignerProvider<>>::generate_channel_keys_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, inbound, channel_value_satoshis, user_channel_id.into());
2380         crate::c_types::ThirtyTwoBytes { data: ret }
2381 }
2382 #[must_use]
2383 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::chain::keysinterface::WriteableEcdsaChannelSigner {
2384         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::SignerProvider<>>::derive_channel_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, channel_value_satoshis, channel_keys_id.data);
2385         Into::into(ret)
2386 }
2387 #[must_use]
2388 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 {
2389         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::SignerProvider<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, reader.to_slice());
2390         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() };
2391         local_ret
2392 }
2393 #[must_use]
2394 extern "C" fn PhantomKeysManager_SignerProvider_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2395         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::SignerProvider<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2396         ret.into_bytes().into()
2397 }
2398 #[must_use]
2399 extern "C" fn PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::lightning::ln::script::ShutdownScript {
2400         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::SignerProvider<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2401         crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(ret), is_owned: true }
2402 }
2403
2404 /// Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
2405 /// that is shared across all nodes that intend to participate in [phantom node payments]
2406 /// together.
2407 ///
2408 /// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
2409 /// `starting_time_nanos`.
2410 ///
2411 /// `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
2412 /// same across restarts, or else inbound payments may fail.
2413 ///
2414 /// [phantom node payments]: PhantomKeysManager
2415 #[must_use]
2416 #[no_mangle]
2417 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::chain::keysinterface::PhantomKeysManager {
2418         let mut ret = lightning::chain::keysinterface::PhantomKeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos, unsafe { &*cross_node_seed});
2419         crate::lightning::chain::keysinterface::PhantomKeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2420 }
2421
2422 /// See [`KeysManager::spend_spendable_outputs`] for documentation on this method.
2423 #[must_use]
2424 #[no_mangle]
2425 pub extern "C" fn PhantomKeysManager_spend_spendable_outputs(this_arg: &crate::lightning::chain::keysinterface::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) -> crate::c_types::derived::CResult_TransactionNoneZ {
2426         let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2427         let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2428         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, secp256k1::global::SECP256K1);
2429         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() };
2430         local_ret
2431 }
2432
2433 /// See [`KeysManager::derive_channel_keys`] for documentation on this method.
2434 #[must_use]
2435 #[no_mangle]
2436 pub extern "C" fn PhantomKeysManager_derive_channel_keys(this_arg: &crate::lightning::chain::keysinterface::PhantomKeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::lightning::chain::keysinterface::InMemorySigner {
2437         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2438         crate::lightning::chain::keysinterface::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2439 }
2440
2441 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2442 #[must_use]
2443 #[no_mangle]
2444 pub extern "C" fn PhantomKeysManager_get_node_secret_key(this_arg: &crate::lightning::chain::keysinterface::PhantomKeysManager) -> crate::c_types::SecretKey {
2445         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2446         crate::c_types::SecretKey::from_rust(ret)
2447 }
2448
2449 /// Gets the \"node_id\" secret key of the phantom node used to sign invoices, decode the
2450 /// last-hop onion data, etc.
2451 #[must_use]
2452 #[no_mangle]
2453 pub extern "C" fn PhantomKeysManager_get_phantom_node_secret_key(this_arg: &crate::lightning::chain::keysinterface::PhantomKeysManager) -> crate::c_types::SecretKey {
2454         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_node_secret_key();
2455         crate::c_types::SecretKey::from_rust(ret)
2456 }
2457