Add auto-generated bindings of `lightning_transaction_sync`
[ldk-c-bindings] / lightning-c-bindings / src / lightning / sign / mod.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 alloc::string::String;
16 use core::ffi::c_void;
17 use core::convert::Infallible;
18 use bitcoin::hashes::Hash;
19 use crate::c_types::*;
20 #[cfg(feature="no-std")]
21 use alloc::{vec::Vec, boxed::Box};
22
23 pub mod ecdsa;
24 mod type_resolver {
25
26 use alloc::str::FromStr;
27 use alloc::string::String;
28 use core::ffi::c_void;
29 use core::convert::Infallible;
30 use bitcoin::hashes::Hash;
31 use crate::c_types::*;
32 #[cfg(feature="no-std")]
33 use alloc::{vec::Vec, boxed::Box};
34
35 }
36
37 use lightning::sign::DelayedPaymentOutputDescriptor as nativeDelayedPaymentOutputDescriptorImport;
38 pub(crate) type nativeDelayedPaymentOutputDescriptor = nativeDelayedPaymentOutputDescriptorImport;
39
40 /// Information about a spendable output to a P2WSH script.
41 ///
42 /// See [`SpendableOutputDescriptor::DelayedPaymentOutput`] for more details on how to spend this.
43 #[must_use]
44 #[repr(C)]
45 pub struct DelayedPaymentOutputDescriptor {
46         /// A pointer to the opaque Rust object.
47
48         /// Nearly everywhere, inner must be non-null, however in places where
49         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
50         pub inner: *mut nativeDelayedPaymentOutputDescriptor,
51         /// Indicates that this is the only struct which contains the same pointer.
52
53         /// Rust functions which take ownership of an object provided via an argument require
54         /// this to be true and invalidate the object pointed to by inner.
55         pub is_owned: bool,
56 }
57
58 impl Drop for DelayedPaymentOutputDescriptor {
59         fn drop(&mut self) {
60                 if self.is_owned && !<*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) {
61                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
62                 }
63         }
64 }
65 /// Frees any resources used by the DelayedPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
66 #[no_mangle]
67 pub extern "C" fn DelayedPaymentOutputDescriptor_free(this_obj: DelayedPaymentOutputDescriptor) { }
68 #[allow(unused)]
69 /// Used only if an object of this type is returned as a trait impl by a method
70 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
71         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDelayedPaymentOutputDescriptor) };
72 }
73 #[allow(unused)]
74 impl DelayedPaymentOutputDescriptor {
75         pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentOutputDescriptor {
76                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
77         }
78         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentOutputDescriptor {
79                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
80         }
81         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
82         pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentOutputDescriptor {
83                 assert!(self.is_owned);
84                 let ret = ObjOps::untweak_ptr(self.inner);
85                 self.inner = core::ptr::null_mut();
86                 ret
87         }
88 }
89 /// The outpoint which is spendable.
90 #[no_mangle]
91 pub extern "C" fn DelayedPaymentOutputDescriptor_get_outpoint(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
92         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
93         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::transaction::OutPoint<>) as *mut _) }, is_owned: false }
94 }
95 /// The outpoint which is spendable.
96 #[no_mangle]
97 pub extern "C" fn DelayedPaymentOutputDescriptor_set_outpoint(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
98         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
99 }
100 /// Per commitment point to derive the delayed payment key by key holder.
101 #[no_mangle]
102 pub extern "C" fn DelayedPaymentOutputDescriptor_get_per_commitment_point(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
103         let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
104         crate::c_types::PublicKey::from_rust(&inner_val)
105 }
106 /// Per commitment point to derive the delayed payment key by key holder.
107 #[no_mangle]
108 pub extern "C" fn DelayedPaymentOutputDescriptor_set_per_commitment_point(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
109         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
110 }
111 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
112 /// the witness_script.
113 #[no_mangle]
114 pub extern "C" fn DelayedPaymentOutputDescriptor_get_to_self_delay(this_ptr: &DelayedPaymentOutputDescriptor) -> u16 {
115         let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay;
116         *inner_val
117 }
118 /// The `nSequence` value which must be set in the spending input to satisfy the `OP_CSV` in
119 /// the witness_script.
120 #[no_mangle]
121 pub extern "C" fn DelayedPaymentOutputDescriptor_set_to_self_delay(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u16) {
122         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val;
123 }
124 /// The output which is referenced by the given outpoint.
125 #[no_mangle]
126 pub extern "C" fn DelayedPaymentOutputDescriptor_get_output(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::TxOut {
127         let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
128         crate::c_types::TxOut::from_rust(inner_val)
129 }
130 /// The output which is referenced by the given outpoint.
131 #[no_mangle]
132 pub extern "C" fn DelayedPaymentOutputDescriptor_set_output(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
133         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
134 }
135 /// The revocation point specific to the commitment transaction which was broadcast. Used to
136 /// derive the witnessScript for this output.
137 #[no_mangle]
138 pub extern "C" fn DelayedPaymentOutputDescriptor_get_revocation_pubkey(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::ln::channel_keys::RevocationKey {
139         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_pubkey;
140         crate::lightning::ln::channel_keys::RevocationKey { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::channel_keys::RevocationKey<>) as *mut _) }, is_owned: false }
141 }
142 /// The revocation point specific to the commitment transaction which was broadcast. Used to
143 /// derive the witnessScript for this output.
144 #[no_mangle]
145 pub extern "C" fn DelayedPaymentOutputDescriptor_set_revocation_pubkey(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::ln::channel_keys::RevocationKey) {
146         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_pubkey = *unsafe { Box::from_raw(val.take_inner()) };
147 }
148 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
149 /// This may be useful in re-deriving keys used in the channel to spend the output.
150 #[no_mangle]
151 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &DelayedPaymentOutputDescriptor) -> *const [u8; 32] {
152         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
153         inner_val
154 }
155 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
156 /// This may be useful in re-deriving keys used in the channel to spend the output.
157 #[no_mangle]
158 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
159         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
160 }
161 /// The value of the channel which this output originated from, possibly indirectly.
162 #[no_mangle]
163 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &DelayedPaymentOutputDescriptor) -> u64 {
164         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
165         *inner_val
166 }
167 /// The value of the channel which this output originated from, possibly indirectly.
168 #[no_mangle]
169 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u64) {
170         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
171 }
172 /// The channel public keys and other parameters needed to generate a spending transaction or
173 /// to provide to a re-derived signer through [`ChannelSigner::provide_channel_parameters`].
174 ///
175 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.123 or later.
176 ///
177 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
178 #[no_mangle]
179 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_transaction_parameters(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
180         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_transaction_parameters;
181         let mut local_inner_val = crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _ }, is_owned: false };
182         local_inner_val
183 }
184 /// The channel public keys and other parameters needed to generate a spending transaction or
185 /// to provide to a re-derived signer through [`ChannelSigner::provide_channel_parameters`].
186 ///
187 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.123 or later.
188 ///
189 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
190 #[no_mangle]
191 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_transaction_parameters(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
192         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
193         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_transaction_parameters = local_val;
194 }
195 /// Constructs a new DelayedPaymentOutputDescriptor given each field
196 ///
197 /// Note that channel_transaction_parameters_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
198 #[must_use]
199 #[no_mangle]
200 pub extern "C" fn DelayedPaymentOutputDescriptor_new(mut outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut per_commitment_point_arg: crate::c_types::PublicKey, mut to_self_delay_arg: u16, mut output_arg: crate::c_types::TxOut, mut revocation_pubkey_arg: crate::lightning::ln::channel_keys::RevocationKey, mut channel_keys_id_arg: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis_arg: u64, mut channel_transaction_parameters_arg: crate::lightning::ln::chan_utils::ChannelTransactionParameters) -> DelayedPaymentOutputDescriptor {
201         let mut local_channel_transaction_parameters_arg = if channel_transaction_parameters_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_transaction_parameters_arg.take_inner()) } }) };
202         DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeDelayedPaymentOutputDescriptor {
203                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
204                 per_commitment_point: per_commitment_point_arg.into_rust(),
205                 to_self_delay: to_self_delay_arg,
206                 output: output_arg.into_rust(),
207                 revocation_pubkey: *unsafe { Box::from_raw(revocation_pubkey_arg.take_inner()) },
208                 channel_keys_id: channel_keys_id_arg.data,
209                 channel_value_satoshis: channel_value_satoshis_arg,
210                 channel_transaction_parameters: local_channel_transaction_parameters_arg,
211         }), is_owned: true }
212 }
213 impl Clone for DelayedPaymentOutputDescriptor {
214         fn clone(&self) -> Self {
215                 Self {
216                         inner: if <*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
217                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
218                         is_owned: true,
219                 }
220         }
221 }
222 #[allow(unused)]
223 /// Used only if an object of this type is returned as a trait impl by a method
224 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
225         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void
226 }
227 #[no_mangle]
228 /// Creates a copy of the DelayedPaymentOutputDescriptor
229 pub extern "C" fn DelayedPaymentOutputDescriptor_clone(orig: &DelayedPaymentOutputDescriptor) -> DelayedPaymentOutputDescriptor {
230         orig.clone()
231 }
232 /// Get a string which allows debug introspection of a DelayedPaymentOutputDescriptor object
233 pub extern "C" fn DelayedPaymentOutputDescriptor_debug_str_void(o: *const c_void) -> Str {
234         alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::DelayedPaymentOutputDescriptor }).into()}
235 /// Generates a non-cryptographic 64-bit hash of the DelayedPaymentOutputDescriptor.
236 #[no_mangle]
237 pub extern "C" fn DelayedPaymentOutputDescriptor_hash(o: &DelayedPaymentOutputDescriptor) -> u64 {
238         if o.inner.is_null() { return 0; }
239         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
240         #[allow(deprecated)]
241         let mut hasher = core::hash::SipHasher::new();
242         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
243         core::hash::Hasher::finish(&hasher)
244 }
245 /// Checks if two DelayedPaymentOutputDescriptors contain equal inner contents.
246 /// This ignores pointers and is_owned flags and looks at the values in fields.
247 /// Two objects with NULL inner values will be considered "equal" here.
248 #[no_mangle]
249 pub extern "C" fn DelayedPaymentOutputDescriptor_eq(a: &DelayedPaymentOutputDescriptor, b: &DelayedPaymentOutputDescriptor) -> bool {
250         if a.inner == b.inner { return true; }
251         if a.inner.is_null() || b.inner.is_null() { return false; }
252         if a.get_native_ref() == b.get_native_ref() { true } else { false }
253 }
254 #[no_mangle]
255 /// Serialize the DelayedPaymentOutputDescriptor object into a byte array which can be read by DelayedPaymentOutputDescriptor_read
256 pub extern "C" fn DelayedPaymentOutputDescriptor_write(obj: &crate::lightning::sign::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
257         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
258 }
259 #[allow(unused)]
260 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
261         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentOutputDescriptor) })
262 }
263 #[no_mangle]
264 /// Read a DelayedPaymentOutputDescriptor from a byte array, created by DelayedPaymentOutputDescriptor_write
265 pub extern "C" fn DelayedPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentOutputDescriptorDecodeErrorZ {
266         let res: Result<lightning::sign::DelayedPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
267         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
268         local_res
269 }
270
271 use lightning::sign::StaticPaymentOutputDescriptor as nativeStaticPaymentOutputDescriptorImport;
272 pub(crate) type nativeStaticPaymentOutputDescriptor = nativeStaticPaymentOutputDescriptorImport;
273
274 /// Information about a spendable output to our \"payment key\".
275 ///
276 /// See [`SpendableOutputDescriptor::StaticPaymentOutput`] for more details on how to spend this.
277 #[must_use]
278 #[repr(C)]
279 pub struct StaticPaymentOutputDescriptor {
280         /// A pointer to the opaque Rust object.
281
282         /// Nearly everywhere, inner must be non-null, however in places where
283         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
284         pub inner: *mut nativeStaticPaymentOutputDescriptor,
285         /// Indicates that this is the only struct which contains the same pointer.
286
287         /// Rust functions which take ownership of an object provided via an argument require
288         /// this to be true and invalidate the object pointed to by inner.
289         pub is_owned: bool,
290 }
291
292 impl Drop for StaticPaymentOutputDescriptor {
293         fn drop(&mut self) {
294                 if self.is_owned && !<*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) {
295                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
296                 }
297         }
298 }
299 /// Frees any resources used by the StaticPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
300 #[no_mangle]
301 pub extern "C" fn StaticPaymentOutputDescriptor_free(this_obj: StaticPaymentOutputDescriptor) { }
302 #[allow(unused)]
303 /// Used only if an object of this type is returned as a trait impl by a method
304 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
305         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeStaticPaymentOutputDescriptor) };
306 }
307 #[allow(unused)]
308 impl StaticPaymentOutputDescriptor {
309         pub(crate) fn get_native_ref(&self) -> &'static nativeStaticPaymentOutputDescriptor {
310                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
311         }
312         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeStaticPaymentOutputDescriptor {
313                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
314         }
315         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
316         pub(crate) fn take_inner(mut self) -> *mut nativeStaticPaymentOutputDescriptor {
317                 assert!(self.is_owned);
318                 let ret = ObjOps::untweak_ptr(self.inner);
319                 self.inner = core::ptr::null_mut();
320                 ret
321         }
322 }
323 /// The outpoint which is spendable.
324 #[no_mangle]
325 pub extern "C" fn StaticPaymentOutputDescriptor_get_outpoint(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
326         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
327         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::transaction::OutPoint<>) as *mut _) }, is_owned: false }
328 }
329 /// The outpoint which is spendable.
330 #[no_mangle]
331 pub extern "C" fn StaticPaymentOutputDescriptor_set_outpoint(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
332         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
333 }
334 /// The output which is referenced by the given outpoint.
335 #[no_mangle]
336 pub extern "C" fn StaticPaymentOutputDescriptor_get_output(this_ptr: &StaticPaymentOutputDescriptor) -> crate::c_types::TxOut {
337         let mut inner_val = &mut this_ptr.get_native_mut_ref().output;
338         crate::c_types::TxOut::from_rust(inner_val)
339 }
340 /// The output which is referenced by the given outpoint.
341 #[no_mangle]
342 pub extern "C" fn StaticPaymentOutputDescriptor_set_output(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
343         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
344 }
345 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
346 /// This may be useful in re-deriving keys used in the channel to spend the output.
347 #[no_mangle]
348 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &StaticPaymentOutputDescriptor) -> *const [u8; 32] {
349         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
350         inner_val
351 }
352 /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`].
353 /// This may be useful in re-deriving keys used in the channel to spend the output.
354 #[no_mangle]
355 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
356         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
357 }
358 /// The value of the channel which this transactions spends.
359 #[no_mangle]
360 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &StaticPaymentOutputDescriptor) -> u64 {
361         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
362         *inner_val
363 }
364 /// The value of the channel which this transactions spends.
365 #[no_mangle]
366 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: u64) {
367         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
368 }
369 /// The necessary channel parameters that need to be provided to the re-derived signer through
370 /// [`ChannelSigner::provide_channel_parameters`].
371 ///
372 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
373 ///
374 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
375 #[no_mangle]
376 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_transaction_parameters(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
377         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_transaction_parameters;
378         let mut local_inner_val = crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _ }, is_owned: false };
379         local_inner_val
380 }
381 /// The necessary channel parameters that need to be provided to the re-derived signer through
382 /// [`ChannelSigner::provide_channel_parameters`].
383 ///
384 /// Added as optional, but always `Some` if the descriptor was produced in v0.0.117 or later.
385 ///
386 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
387 #[no_mangle]
388 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_transaction_parameters(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
389         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
390         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_transaction_parameters = local_val;
391 }
392 /// Constructs a new StaticPaymentOutputDescriptor given each field
393 ///
394 /// Note that channel_transaction_parameters_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
395 #[must_use]
396 #[no_mangle]
397 pub extern "C" fn StaticPaymentOutputDescriptor_new(mut outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut output_arg: crate::c_types::TxOut, mut channel_keys_id_arg: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis_arg: u64, mut channel_transaction_parameters_arg: crate::lightning::ln::chan_utils::ChannelTransactionParameters) -> StaticPaymentOutputDescriptor {
398         let mut local_channel_transaction_parameters_arg = if channel_transaction_parameters_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_transaction_parameters_arg.take_inner()) } }) };
399         StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeStaticPaymentOutputDescriptor {
400                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
401                 output: output_arg.into_rust(),
402                 channel_keys_id: channel_keys_id_arg.data,
403                 channel_value_satoshis: channel_value_satoshis_arg,
404                 channel_transaction_parameters: local_channel_transaction_parameters_arg,
405         }), is_owned: true }
406 }
407 impl Clone for StaticPaymentOutputDescriptor {
408         fn clone(&self) -> Self {
409                 Self {
410                         inner: if <*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
411                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
412                         is_owned: true,
413                 }
414         }
415 }
416 #[allow(unused)]
417 /// Used only if an object of this type is returned as a trait impl by a method
418 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
419         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void
420 }
421 #[no_mangle]
422 /// Creates a copy of the StaticPaymentOutputDescriptor
423 pub extern "C" fn StaticPaymentOutputDescriptor_clone(orig: &StaticPaymentOutputDescriptor) -> StaticPaymentOutputDescriptor {
424         orig.clone()
425 }
426 /// Get a string which allows debug introspection of a StaticPaymentOutputDescriptor object
427 pub extern "C" fn StaticPaymentOutputDescriptor_debug_str_void(o: *const c_void) -> Str {
428         alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::StaticPaymentOutputDescriptor }).into()}
429 /// Generates a non-cryptographic 64-bit hash of the StaticPaymentOutputDescriptor.
430 #[no_mangle]
431 pub extern "C" fn StaticPaymentOutputDescriptor_hash(o: &StaticPaymentOutputDescriptor) -> u64 {
432         if o.inner.is_null() { return 0; }
433         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
434         #[allow(deprecated)]
435         let mut hasher = core::hash::SipHasher::new();
436         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
437         core::hash::Hasher::finish(&hasher)
438 }
439 /// Checks if two StaticPaymentOutputDescriptors contain equal inner contents.
440 /// This ignores pointers and is_owned flags and looks at the values in fields.
441 /// Two objects with NULL inner values will be considered "equal" here.
442 #[no_mangle]
443 pub extern "C" fn StaticPaymentOutputDescriptor_eq(a: &StaticPaymentOutputDescriptor, b: &StaticPaymentOutputDescriptor) -> bool {
444         if a.inner == b.inner { return true; }
445         if a.inner.is_null() || b.inner.is_null() { return false; }
446         if a.get_native_ref() == b.get_native_ref() { true } else { false }
447 }
448 /// Returns the `witness_script` of the spendable output.
449 ///
450 /// Note that this will only return `Some` for [`StaticPaymentOutputDescriptor`]s that
451 /// originated from an anchor outputs channel, as they take the form of a P2WSH script.
452 #[must_use]
453 #[no_mangle]
454 pub extern "C" fn StaticPaymentOutputDescriptor_witness_script(this_arg: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::COption_CVec_u8ZZ {
455         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script();
456         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { ret.unwrap().to_bytes().into() }) };
457         local_ret
458 }
459
460 /// The maximum length a well-formed witness spending one of these should have.
461 /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
462 /// shorter.
463 #[must_use]
464 #[no_mangle]
465 pub extern "C" fn StaticPaymentOutputDescriptor_max_witness_length(this_arg: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> u64 {
466         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.max_witness_length();
467         ret
468 }
469
470 #[no_mangle]
471 /// Serialize the StaticPaymentOutputDescriptor object into a byte array which can be read by StaticPaymentOutputDescriptor_read
472 pub extern "C" fn StaticPaymentOutputDescriptor_write(obj: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
473         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
474 }
475 #[allow(unused)]
476 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
477         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeStaticPaymentOutputDescriptor) })
478 }
479 #[no_mangle]
480 /// Read a StaticPaymentOutputDescriptor from a byte array, created by StaticPaymentOutputDescriptor_write
481 pub extern "C" fn StaticPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_StaticPaymentOutputDescriptorDecodeErrorZ {
482         let res: Result<lightning::sign::StaticPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
483         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
484         local_res
485 }
486 /// Describes the necessary information to spend a spendable output.
487 ///
488 /// When on-chain outputs are created by LDK (which our counterparty is not able to claim at any
489 /// point in the future) a [`SpendableOutputs`] event is generated which you must track and be able
490 /// to spend on-chain. The information needed to do this is provided in this enum, including the
491 /// outpoint describing which `txid` and output `index` is available, the full output which exists
492 /// at that `txid`/`index`, and any keys or other information required to sign.
493 ///
494 /// [`SpendableOutputs`]: crate::events::Event::SpendableOutputs
495 #[derive(Clone)]
496 #[must_use]
497 #[repr(C)]
498 pub enum SpendableOutputDescriptor {
499         /// An output to a script which was provided via [`SignerProvider`] directly, either from
500         /// [`get_destination_script`] or [`get_shutdown_scriptpubkey`], thus you should already
501         /// know how to spend it. No secret keys are provided as LDK was never given any key.
502         /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
503         /// on-chain using the payment preimage or after it has timed out.
504         ///
505         /// [`get_shutdown_scriptpubkey`]: SignerProvider::get_shutdown_scriptpubkey
506         /// [`get_destination_script`]: SignerProvider::get_shutdown_scriptpubkey
507         StaticOutput {
508                 /// The outpoint which is spendable.
509                 outpoint: crate::lightning::chain::transaction::OutPoint,
510                 /// The output which is referenced by the given outpoint.
511                 output: crate::c_types::TxOut,
512                 /// The `channel_keys_id` for the channel which this output came from.
513                 ///
514                 /// For channels which were generated on LDK 0.0.119 or later, this is the value which was
515                 /// passed to the [`SignerProvider::get_destination_script`] call which provided this
516                 /// output script.
517                 ///
518                 /// For channels which were generated prior to LDK 0.0.119, no such argument existed,
519                 /// however this field may still be filled in if such data is available.
520                 ///
521                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
522                 channel_keys_id: crate::c_types::ThirtyTwoBytes,
523         },
524         /// An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
525         /// delay.
526         ///
527         /// The witness in the spending input should be:
528         /// ```bitcoin
529         /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
530         /// ```
531         ///
532         /// Note that the `nSequence` field in the spending input must be set to
533         /// [`DelayedPaymentOutputDescriptor::to_self_delay`] (which means the transaction is not
534         /// broadcastable until at least [`DelayedPaymentOutputDescriptor::to_self_delay`] blocks after
535         /// the outpoint confirms, see [BIP
536         /// 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki)). Also note that LDK
537         /// won't generate a [`SpendableOutputDescriptor`] until the corresponding block height
538         /// is reached.
539         ///
540         /// These are generally the result of a \"revocable\" output to us, spendable only by us unless
541         /// it is an output from an old state which we broadcast (which should never happen).
542         ///
543         /// To derive the delayed payment key which is used to sign this input, you must pass the
544         /// holder [`InMemorySigner::delayed_payment_base_key`] (i.e., the private key which corresponds to the
545         /// [`ChannelPublicKeys::delayed_payment_basepoint`] in [`ChannelSigner::pubkeys`]) and the provided
546         /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to [`chan_utils::derive_private_key`]. The DelayedPaymentKey can be
547         /// generated without the secret key using [`DelayedPaymentKey::from_basepoint`] and only the
548         /// [`ChannelPublicKeys::delayed_payment_basepoint`] which appears in [`ChannelSigner::pubkeys`].
549         ///
550         /// To derive the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] provided here (which is
551         /// used in the witness script generation), you must pass the counterparty
552         /// [`ChannelPublicKeys::revocation_basepoint`] (which appears in the call to
553         /// [`ChannelSigner::provide_channel_parameters`]) and the provided
554         /// [`DelayedPaymentOutputDescriptor::per_commitment_point`] to
555         /// [`RevocationKey`].
556         ///
557         /// The witness script which is hashed and included in the output `script_pubkey` may be
558         /// regenerated by passing the [`DelayedPaymentOutputDescriptor::revocation_pubkey`] (derived
559         /// as explained above), our delayed payment pubkey (derived as explained above), and the
560         /// [`DelayedPaymentOutputDescriptor::to_self_delay`] contained here to
561         /// [`chan_utils::get_revokeable_redeemscript`].
562         DelayedPaymentOutput(
563                 crate::lightning::sign::DelayedPaymentOutputDescriptor),
564         /// An output spendable exclusively by our payment key (i.e., the private key that corresponds
565         /// to the `payment_point` in [`ChannelSigner::pubkeys`]). The output type depends on the
566         /// channel type negotiated.
567         ///
568         /// On an anchor outputs channel, the witness in the spending input is:
569         /// ```bitcoin
570         /// <BIP 143 signature> <witness script>
571         /// ```
572         ///
573         /// Otherwise, it is:
574         /// ```bitcoin
575         /// <BIP 143 signature> <payment key>
576         /// ```
577         ///
578         /// These are generally the result of our counterparty having broadcast the current state,
579         /// allowing us to claim the non-HTLC-encumbered outputs immediately, or after one confirmation
580         /// in the case of anchor outputs channels.
581         StaticPaymentOutput(
582                 crate::lightning::sign::StaticPaymentOutputDescriptor),
583 }
584 use lightning::sign::SpendableOutputDescriptor as SpendableOutputDescriptorImport;
585 pub(crate) type nativeSpendableOutputDescriptor = SpendableOutputDescriptorImport;
586
587 impl SpendableOutputDescriptor {
588         #[allow(unused)]
589         pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor {
590                 match self {
591                         SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, ref channel_keys_id, } => {
592                                 let mut outpoint_nonref = Clone::clone(outpoint);
593                                 let mut output_nonref = Clone::clone(output);
594                                 let mut channel_keys_id_nonref = Clone::clone(channel_keys_id);
595                                 let mut local_channel_keys_id_nonref = if channel_keys_id_nonref.data == [0; 32] { None } else { Some( { channel_keys_id_nonref.data }) };
596                                 nativeSpendableOutputDescriptor::StaticOutput {
597                                         outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
598                                         output: output_nonref.into_rust(),
599                                         channel_keys_id: local_channel_keys_id_nonref,
600                                 }
601                         },
602                         SpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
603                                 let mut a_nonref = Clone::clone(a);
604                                 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
605                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
606                                 )
607                         },
608                         SpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
609                                 let mut a_nonref = Clone::clone(a);
610                                 nativeSpendableOutputDescriptor::StaticPaymentOutput (
611                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
612                                 )
613                         },
614                 }
615         }
616         #[allow(unused)]
617         pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor {
618                 match self {
619                         SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, mut channel_keys_id, } => {
620                                 let mut local_channel_keys_id = if channel_keys_id.data == [0; 32] { None } else { Some( { channel_keys_id.data }) };
621                                 nativeSpendableOutputDescriptor::StaticOutput {
622                                         outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
623                                         output: output.into_rust(),
624                                         channel_keys_id: local_channel_keys_id,
625                                 }
626                         },
627                         SpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
628                                 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
629                                         *unsafe { Box::from_raw(a.take_inner()) },
630                                 )
631                         },
632                         SpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
633                                 nativeSpendableOutputDescriptor::StaticPaymentOutput (
634                                         *unsafe { Box::from_raw(a.take_inner()) },
635                                 )
636                         },
637                 }
638         }
639         #[allow(unused)]
640         pub(crate) fn from_native(native: &SpendableOutputDescriptorImport) -> Self {
641                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSpendableOutputDescriptor) };
642                 match native {
643                         nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, ref channel_keys_id, } => {
644                                 let mut outpoint_nonref = Clone::clone(outpoint);
645                                 let mut output_nonref = Clone::clone(output);
646                                 let mut channel_keys_id_nonref = Clone::clone(channel_keys_id);
647                                 let mut local_channel_keys_id_nonref = if channel_keys_id_nonref.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else {  { crate::c_types::ThirtyTwoBytes { data: (channel_keys_id_nonref.unwrap()) } } };
648                                 SpendableOutputDescriptor::StaticOutput {
649                                         outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true },
650                                         output: crate::c_types::TxOut::from_rust(&output_nonref),
651                                         channel_keys_id: local_channel_keys_id_nonref,
652                                 }
653                         },
654                         nativeSpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
655                                 let mut a_nonref = Clone::clone(a);
656                                 SpendableOutputDescriptor::DelayedPaymentOutput (
657                                         crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
658                                 )
659                         },
660                         nativeSpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
661                                 let mut a_nonref = Clone::clone(a);
662                                 SpendableOutputDescriptor::StaticPaymentOutput (
663                                         crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
664                                 )
665                         },
666                 }
667         }
668         #[allow(unused)]
669         pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self {
670                 match native {
671                         nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, mut channel_keys_id, } => {
672                                 let mut local_channel_keys_id = if channel_keys_id.is_none() { crate::c_types::ThirtyTwoBytes { data: [0; 32] } } else {  { crate::c_types::ThirtyTwoBytes { data: (channel_keys_id.unwrap()) } } };
673                                 SpendableOutputDescriptor::StaticOutput {
674                                         outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true },
675                                         output: crate::c_types::TxOut::from_rust(&output),
676                                         channel_keys_id: local_channel_keys_id,
677                                 }
678                         },
679                         nativeSpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
680                                 SpendableOutputDescriptor::DelayedPaymentOutput (
681                                         crate::lightning::sign::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
682                                 )
683                         },
684                         nativeSpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
685                                 SpendableOutputDescriptor::StaticPaymentOutput (
686                                         crate::lightning::sign::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
687                                 )
688                         },
689                 }
690         }
691 }
692 /// Frees any resources used by the SpendableOutputDescriptor
693 #[no_mangle]
694 pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { }
695 /// Creates a copy of the SpendableOutputDescriptor
696 #[no_mangle]
697 pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor {
698         orig.clone()
699 }
700 #[allow(unused)]
701 /// Used only if an object of this type is returned as a trait impl by a method
702 pub(crate) extern "C" fn SpendableOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
703         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SpendableOutputDescriptor)).clone() })) as *mut c_void
704 }
705 #[allow(unused)]
706 /// Used only if an object of this type is returned as a trait impl by a method
707 pub(crate) extern "C" fn SpendableOutputDescriptor_free_void(this_ptr: *mut c_void) {
708         let _ = unsafe { Box::from_raw(this_ptr as *mut SpendableOutputDescriptor) };
709 }
710 #[no_mangle]
711 /// Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
712 pub extern "C" fn SpendableOutputDescriptor_static_output(outpoint: crate::lightning::chain::transaction::OutPoint, output: crate::c_types::TxOut, channel_keys_id: crate::c_types::ThirtyTwoBytes) -> SpendableOutputDescriptor {
713         SpendableOutputDescriptor::StaticOutput {
714                 outpoint,
715                 output,
716                 channel_keys_id,
717         }
718 }
719 #[no_mangle]
720 /// Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
721 pub extern "C" fn SpendableOutputDescriptor_delayed_payment_output(a: crate::lightning::sign::DelayedPaymentOutputDescriptor) -> SpendableOutputDescriptor {
722         SpendableOutputDescriptor::DelayedPaymentOutput(a, )
723 }
724 #[no_mangle]
725 /// Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
726 pub extern "C" fn SpendableOutputDescriptor_static_payment_output(a: crate::lightning::sign::StaticPaymentOutputDescriptor) -> SpendableOutputDescriptor {
727         SpendableOutputDescriptor::StaticPaymentOutput(a, )
728 }
729 /// Get a string which allows debug introspection of a SpendableOutputDescriptor object
730 pub extern "C" fn SpendableOutputDescriptor_debug_str_void(o: *const c_void) -> Str {
731         alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::SpendableOutputDescriptor }).into()}
732 /// Generates a non-cryptographic 64-bit hash of the SpendableOutputDescriptor.
733 #[no_mangle]
734 pub extern "C" fn SpendableOutputDescriptor_hash(o: &SpendableOutputDescriptor) -> u64 {
735         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
736         #[allow(deprecated)]
737         let mut hasher = core::hash::SipHasher::new();
738         core::hash::Hash::hash(&o.to_native(), &mut hasher);
739         core::hash::Hasher::finish(&hasher)
740 }
741 /// Checks if two SpendableOutputDescriptors contain equal inner contents.
742 /// This ignores pointers and is_owned flags and looks at the values in fields.
743 #[no_mangle]
744 pub extern "C" fn SpendableOutputDescriptor_eq(a: &SpendableOutputDescriptor, b: &SpendableOutputDescriptor) -> bool {
745         if &a.to_native() == &b.to_native() { true } else { false }
746 }
747 #[no_mangle]
748 /// Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
749 pub extern "C" fn SpendableOutputDescriptor_write(obj: &crate::lightning::sign::SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
750         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
751 }
752 #[allow(unused)]
753 pub(crate) extern "C" fn SpendableOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
754         SpendableOutputDescriptor_write(unsafe { &*(obj as *const SpendableOutputDescriptor) })
755 }
756 #[no_mangle]
757 /// Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
758 pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
759         let res: Result<lightning::sign::SpendableOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
760         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::SpendableOutputDescriptor::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
761         local_res
762 }
763 /// Creates an unsigned [`PartiallySignedTransaction`] which spends the given descriptors to
764 /// the given outputs, plus an output to the given change destination (if sufficient
765 /// change value remains). The PSBT will have a feerate, at least, of the given value.
766 ///
767 /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
768 /// transaction will have a locktime of 0. It it recommended to set this to the current block
769 /// height to avoid fee sniping, unless you have some specific reason to use a different
770 /// locktime.
771 ///
772 /// Returns the PSBT and expected max transaction weight.
773 ///
774 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
775 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
776 /// does not match the one we can spend.
777 ///
778 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
779 #[must_use]
780 #[no_mangle]
781 pub extern "C" fn SpendableOutputDescriptor_create_spendable_outputs_psbt(mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut outputs: crate::c_types::derived::CVec_TxOutZ, mut change_destination_script: crate::c_types::derived::CVec_u8Z, mut feerate_sat_per_1000_weight: u32, mut locktime: crate::c_types::derived::COption_u32Z) -> crate::c_types::derived::CResult_C2Tuple_CVec_u8Zu64ZNoneZ {
782         let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
783         let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
784         let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus({ locktime_opt.take() }) }})} };
785         let mut ret = lightning::sign::SpendableOutputDescriptor::create_spendable_outputs_psbt(secp256k1::global::SECP256K1, &local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::ScriptBuf::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime);
786         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (orig_ret_0_0.serialize().into(), orig_ret_0_1).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
787         local_ret
788 }
789
790
791 use lightning::sign::ChannelDerivationParameters as nativeChannelDerivationParametersImport;
792 pub(crate) type nativeChannelDerivationParameters = nativeChannelDerivationParametersImport;
793
794 /// The parameters required to derive a channel signer via [`SignerProvider`].
795 #[must_use]
796 #[repr(C)]
797 pub struct ChannelDerivationParameters {
798         /// A pointer to the opaque Rust object.
799
800         /// Nearly everywhere, inner must be non-null, however in places where
801         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
802         pub inner: *mut nativeChannelDerivationParameters,
803         /// Indicates that this is the only struct which contains the same pointer.
804
805         /// Rust functions which take ownership of an object provided via an argument require
806         /// this to be true and invalidate the object pointed to by inner.
807         pub is_owned: bool,
808 }
809
810 impl Drop for ChannelDerivationParameters {
811         fn drop(&mut self) {
812                 if self.is_owned && !<*mut nativeChannelDerivationParameters>::is_null(self.inner) {
813                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
814                 }
815         }
816 }
817 /// Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL.
818 #[no_mangle]
819 pub extern "C" fn ChannelDerivationParameters_free(this_obj: ChannelDerivationParameters) { }
820 #[allow(unused)]
821 /// Used only if an object of this type is returned as a trait impl by a method
822 pub(crate) extern "C" fn ChannelDerivationParameters_free_void(this_ptr: *mut c_void) {
823         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelDerivationParameters) };
824 }
825 #[allow(unused)]
826 impl ChannelDerivationParameters {
827         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelDerivationParameters {
828                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
829         }
830         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelDerivationParameters {
831                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
832         }
833         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
834         pub(crate) fn take_inner(mut self) -> *mut nativeChannelDerivationParameters {
835                 assert!(self.is_owned);
836                 let ret = ObjOps::untweak_ptr(self.inner);
837                 self.inner = core::ptr::null_mut();
838                 ret
839         }
840 }
841 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
842 #[no_mangle]
843 pub extern "C" fn ChannelDerivationParameters_get_value_satoshis(this_ptr: &ChannelDerivationParameters) -> u64 {
844         let mut inner_val = &mut this_ptr.get_native_mut_ref().value_satoshis;
845         *inner_val
846 }
847 /// The value in satoshis of the channel we're attempting to spend the anchor output of.
848 #[no_mangle]
849 pub extern "C" fn ChannelDerivationParameters_set_value_satoshis(this_ptr: &mut ChannelDerivationParameters, mut val: u64) {
850         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.value_satoshis = val;
851 }
852 /// The unique identifier to re-derive the signer for the associated channel.
853 #[no_mangle]
854 pub extern "C" fn ChannelDerivationParameters_get_keys_id(this_ptr: &ChannelDerivationParameters) -> *const [u8; 32] {
855         let mut inner_val = &mut this_ptr.get_native_mut_ref().keys_id;
856         inner_val
857 }
858 /// The unique identifier to re-derive the signer for the associated channel.
859 #[no_mangle]
860 pub extern "C" fn ChannelDerivationParameters_set_keys_id(this_ptr: &mut ChannelDerivationParameters, mut val: crate::c_types::ThirtyTwoBytes) {
861         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.keys_id = val.data;
862 }
863 /// The necessary channel parameters that need to be provided to the re-derived signer through
864 /// [`ChannelSigner::provide_channel_parameters`].
865 #[no_mangle]
866 pub extern "C" fn ChannelDerivationParameters_get_transaction_parameters(this_ptr: &ChannelDerivationParameters) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
867         let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_parameters;
868         crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false }
869 }
870 /// The necessary channel parameters that need to be provided to the re-derived signer through
871 /// [`ChannelSigner::provide_channel_parameters`].
872 #[no_mangle]
873 pub extern "C" fn ChannelDerivationParameters_set_transaction_parameters(this_ptr: &mut ChannelDerivationParameters, mut val: crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
874         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_parameters = *unsafe { Box::from_raw(val.take_inner()) };
875 }
876 /// Constructs a new ChannelDerivationParameters given each field
877 #[must_use]
878 #[no_mangle]
879 pub extern "C" fn ChannelDerivationParameters_new(mut value_satoshis_arg: u64, mut keys_id_arg: crate::c_types::ThirtyTwoBytes, mut transaction_parameters_arg: crate::lightning::ln::chan_utils::ChannelTransactionParameters) -> ChannelDerivationParameters {
880         ChannelDerivationParameters { inner: ObjOps::heap_alloc(nativeChannelDerivationParameters {
881                 value_satoshis: value_satoshis_arg,
882                 keys_id: keys_id_arg.data,
883                 transaction_parameters: *unsafe { Box::from_raw(transaction_parameters_arg.take_inner()) },
884         }), is_owned: true }
885 }
886 impl Clone for ChannelDerivationParameters {
887         fn clone(&self) -> Self {
888                 Self {
889                         inner: if <*mut nativeChannelDerivationParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
890                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
891                         is_owned: true,
892                 }
893         }
894 }
895 #[allow(unused)]
896 /// Used only if an object of this type is returned as a trait impl by a method
897 pub(crate) extern "C" fn ChannelDerivationParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
898         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelDerivationParameters)).clone() })) as *mut c_void
899 }
900 #[no_mangle]
901 /// Creates a copy of the ChannelDerivationParameters
902 pub extern "C" fn ChannelDerivationParameters_clone(orig: &ChannelDerivationParameters) -> ChannelDerivationParameters {
903         orig.clone()
904 }
905 /// Get a string which allows debug introspection of a ChannelDerivationParameters object
906 pub extern "C" fn ChannelDerivationParameters_debug_str_void(o: *const c_void) -> Str {
907         alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::ChannelDerivationParameters }).into()}
908 /// Checks if two ChannelDerivationParameterss contain equal inner contents.
909 /// This ignores pointers and is_owned flags and looks at the values in fields.
910 /// Two objects with NULL inner values will be considered "equal" here.
911 #[no_mangle]
912 pub extern "C" fn ChannelDerivationParameters_eq(a: &ChannelDerivationParameters, b: &ChannelDerivationParameters) -> bool {
913         if a.inner == b.inner { return true; }
914         if a.inner.is_null() || b.inner.is_null() { return false; }
915         if a.get_native_ref() == b.get_native_ref() { true } else { false }
916 }
917 #[no_mangle]
918 /// Serialize the ChannelDerivationParameters object into a byte array which can be read by ChannelDerivationParameters_read
919 pub extern "C" fn ChannelDerivationParameters_write(obj: &crate::lightning::sign::ChannelDerivationParameters) -> crate::c_types::derived::CVec_u8Z {
920         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
921 }
922 #[allow(unused)]
923 pub(crate) extern "C" fn ChannelDerivationParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
924         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelDerivationParameters) })
925 }
926 #[no_mangle]
927 /// Read a ChannelDerivationParameters from a byte array, created by ChannelDerivationParameters_write
928 pub extern "C" fn ChannelDerivationParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelDerivationParametersDecodeErrorZ {
929         let res: Result<lightning::sign::ChannelDerivationParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
930         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::ChannelDerivationParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
931         local_res
932 }
933
934 use lightning::sign::HTLCDescriptor as nativeHTLCDescriptorImport;
935 pub(crate) type nativeHTLCDescriptor = nativeHTLCDescriptorImport;
936
937 /// A descriptor used to sign for a commitment transaction's HTLC output.
938 #[must_use]
939 #[repr(C)]
940 pub struct HTLCDescriptor {
941         /// A pointer to the opaque Rust object.
942
943         /// Nearly everywhere, inner must be non-null, however in places where
944         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
945         pub inner: *mut nativeHTLCDescriptor,
946         /// Indicates that this is the only struct which contains the same pointer.
947
948         /// Rust functions which take ownership of an object provided via an argument require
949         /// this to be true and invalidate the object pointed to by inner.
950         pub is_owned: bool,
951 }
952
953 impl Drop for HTLCDescriptor {
954         fn drop(&mut self) {
955                 if self.is_owned && !<*mut nativeHTLCDescriptor>::is_null(self.inner) {
956                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
957                 }
958         }
959 }
960 /// Frees any resources used by the HTLCDescriptor, if is_owned is set and inner is non-NULL.
961 #[no_mangle]
962 pub extern "C" fn HTLCDescriptor_free(this_obj: HTLCDescriptor) { }
963 #[allow(unused)]
964 /// Used only if an object of this type is returned as a trait impl by a method
965 pub(crate) extern "C" fn HTLCDescriptor_free_void(this_ptr: *mut c_void) {
966         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHTLCDescriptor) };
967 }
968 #[allow(unused)]
969 impl HTLCDescriptor {
970         pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCDescriptor {
971                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
972         }
973         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCDescriptor {
974                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
975         }
976         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
977         pub(crate) fn take_inner(mut self) -> *mut nativeHTLCDescriptor {
978                 assert!(self.is_owned);
979                 let ret = ObjOps::untweak_ptr(self.inner);
980                 self.inner = core::ptr::null_mut();
981                 ret
982         }
983 }
984 /// The parameters required to derive the signer for the HTLC input.
985 #[no_mangle]
986 pub extern "C" fn HTLCDescriptor_get_channel_derivation_parameters(this_ptr: &HTLCDescriptor) -> crate::lightning::sign::ChannelDerivationParameters {
987         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_derivation_parameters;
988         crate::lightning::sign::ChannelDerivationParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::sign::ChannelDerivationParameters<>) as *mut _) }, is_owned: false }
989 }
990 /// The parameters required to derive the signer for the HTLC input.
991 #[no_mangle]
992 pub extern "C" fn HTLCDescriptor_set_channel_derivation_parameters(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::sign::ChannelDerivationParameters) {
993         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_derivation_parameters = *unsafe { Box::from_raw(val.take_inner()) };
994 }
995 /// The txid of the commitment transaction in which the HTLC output lives.
996 #[no_mangle]
997 pub extern "C" fn HTLCDescriptor_get_commitment_txid(this_ptr: &HTLCDescriptor) -> *const [u8; 32] {
998         let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_txid;
999         inner_val.as_ref()
1000 }
1001 /// The txid of the commitment transaction in which the HTLC output lives.
1002 #[no_mangle]
1003 pub extern "C" fn HTLCDescriptor_set_commitment_txid(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
1004         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap();
1005 }
1006 /// The number of the commitment transaction in which the HTLC output lives.
1007 #[no_mangle]
1008 pub extern "C" fn HTLCDescriptor_get_per_commitment_number(this_ptr: &HTLCDescriptor) -> u64 {
1009         let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_number;
1010         *inner_val
1011 }
1012 /// The number of the commitment transaction in which the HTLC output lives.
1013 #[no_mangle]
1014 pub extern "C" fn HTLCDescriptor_set_per_commitment_number(this_ptr: &mut HTLCDescriptor, mut val: u64) {
1015         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_number = val;
1016 }
1017 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
1018 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
1019 /// arrive at unique keys per commitment.
1020 ///
1021 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
1022 #[no_mangle]
1023 pub extern "C" fn HTLCDescriptor_get_per_commitment_point(this_ptr: &HTLCDescriptor) -> crate::c_types::PublicKey {
1024         let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
1025         crate::c_types::PublicKey::from_rust(&inner_val)
1026 }
1027 /// The key tweak corresponding to the number of the commitment transaction in which the HTLC
1028 /// output lives. This tweak is applied to all the basepoints for both parties in the channel to
1029 /// arrive at unique keys per commitment.
1030 ///
1031 /// See <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys> for more info.
1032 #[no_mangle]
1033 pub extern "C" fn HTLCDescriptor_set_per_commitment_point(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::PublicKey) {
1034         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
1035 }
1036 /// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
1037 /// originating from a channel supporting anchor outputs, otherwise it is the channel's
1038 /// negotiated feerate at the time the commitment transaction was built.
1039 #[no_mangle]
1040 pub extern "C" fn HTLCDescriptor_get_feerate_per_kw(this_ptr: &HTLCDescriptor) -> u32 {
1041         let mut inner_val = &mut this_ptr.get_native_mut_ref().feerate_per_kw;
1042         *inner_val
1043 }
1044 /// The feerate to use on the HTLC claiming transaction. This is always `0` for HTLCs
1045 /// originating from a channel supporting anchor outputs, otherwise it is the channel's
1046 /// negotiated feerate at the time the commitment transaction was built.
1047 #[no_mangle]
1048 pub extern "C" fn HTLCDescriptor_set_feerate_per_kw(this_ptr: &mut HTLCDescriptor, mut val: u32) {
1049         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.feerate_per_kw = val;
1050 }
1051 /// The details of the HTLC as it appears in the commitment transaction.
1052 #[no_mangle]
1053 pub extern "C" fn HTLCDescriptor_get_htlc(this_ptr: &HTLCDescriptor) -> crate::lightning::ln::chan_utils::HTLCOutputInCommitment {
1054         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc;
1055         crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false }
1056 }
1057 /// The details of the HTLC as it appears in the commitment transaction.
1058 #[no_mangle]
1059 pub extern "C" fn HTLCDescriptor_set_htlc(this_ptr: &mut HTLCDescriptor, mut val: crate::lightning::ln::chan_utils::HTLCOutputInCommitment) {
1060         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc = *unsafe { Box::from_raw(val.take_inner()) };
1061 }
1062 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
1063 /// taken.
1064 #[no_mangle]
1065 pub extern "C" fn HTLCDescriptor_get_preimage(this_ptr: &HTLCDescriptor) -> crate::c_types::derived::COption_ThirtyTwoBytesZ {
1066         let mut inner_val = &mut this_ptr.get_native_mut_ref().preimage;
1067         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*inner_val.as_ref().unwrap()).clone().0 } }) };
1068         local_inner_val
1069 }
1070 /// The preimage, if `Some`, to claim the HTLC output with. If `None`, the timeout path must be
1071 /// taken.
1072 #[no_mangle]
1073 pub extern "C" fn HTLCDescriptor_set_preimage(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::derived::COption_ThirtyTwoBytesZ) {
1074         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::lightning::ln::types::PaymentPreimage({ val_opt.take() }.data) }})} };
1075         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.preimage = local_val;
1076 }
1077 /// The counterparty's signature required to spend the HTLC output.
1078 #[no_mangle]
1079 pub extern "C" fn HTLCDescriptor_get_counterparty_sig(this_ptr: &HTLCDescriptor) -> crate::c_types::ECDSASignature {
1080         let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig;
1081         crate::c_types::ECDSASignature::from_rust(&inner_val)
1082 }
1083 /// The counterparty's signature required to spend the HTLC output.
1084 #[no_mangle]
1085 pub extern "C" fn HTLCDescriptor_set_counterparty_sig(this_ptr: &mut HTLCDescriptor, mut val: crate::c_types::ECDSASignature) {
1086         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust();
1087 }
1088 /// Constructs a new HTLCDescriptor given each field
1089 #[must_use]
1090 #[no_mangle]
1091 pub extern "C" fn HTLCDescriptor_new(mut channel_derivation_parameters_arg: crate::lightning::sign::ChannelDerivationParameters, mut commitment_txid_arg: crate::c_types::ThirtyTwoBytes, mut per_commitment_number_arg: u64, mut per_commitment_point_arg: crate::c_types::PublicKey, mut feerate_per_kw_arg: u32, mut htlc_arg: crate::lightning::ln::chan_utils::HTLCOutputInCommitment, mut preimage_arg: crate::c_types::derived::COption_ThirtyTwoBytesZ, mut counterparty_sig_arg: crate::c_types::ECDSASignature) -> HTLCDescriptor {
1092         let mut local_preimage_arg = { /*preimage_arg*/ let preimage_arg_opt = preimage_arg; if preimage_arg_opt.is_none() { None } else { Some({ { ::lightning::ln::types::PaymentPreimage({ preimage_arg_opt.take() }.data) }})} };
1093         HTLCDescriptor { inner: ObjOps::heap_alloc(nativeHTLCDescriptor {
1094                 channel_derivation_parameters: *unsafe { Box::from_raw(channel_derivation_parameters_arg.take_inner()) },
1095                 commitment_txid: ::bitcoin::hash_types::Txid::from_slice(&commitment_txid_arg.data[..]).unwrap(),
1096                 per_commitment_number: per_commitment_number_arg,
1097                 per_commitment_point: per_commitment_point_arg.into_rust(),
1098                 feerate_per_kw: feerate_per_kw_arg,
1099                 htlc: *unsafe { Box::from_raw(htlc_arg.take_inner()) },
1100                 preimage: local_preimage_arg,
1101                 counterparty_sig: counterparty_sig_arg.into_rust(),
1102         }), is_owned: true }
1103 }
1104 impl Clone for HTLCDescriptor {
1105         fn clone(&self) -> Self {
1106                 Self {
1107                         inner: if <*mut nativeHTLCDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
1108                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1109                         is_owned: true,
1110                 }
1111         }
1112 }
1113 #[allow(unused)]
1114 /// Used only if an object of this type is returned as a trait impl by a method
1115 pub(crate) extern "C" fn HTLCDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
1116         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHTLCDescriptor)).clone() })) as *mut c_void
1117 }
1118 #[no_mangle]
1119 /// Creates a copy of the HTLCDescriptor
1120 pub extern "C" fn HTLCDescriptor_clone(orig: &HTLCDescriptor) -> HTLCDescriptor {
1121         orig.clone()
1122 }
1123 /// Get a string which allows debug introspection of a HTLCDescriptor object
1124 pub extern "C" fn HTLCDescriptor_debug_str_void(o: *const c_void) -> Str {
1125         alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::HTLCDescriptor }).into()}
1126 /// Checks if two HTLCDescriptors contain equal inner contents.
1127 /// This ignores pointers and is_owned flags and looks at the values in fields.
1128 /// Two objects with NULL inner values will be considered "equal" here.
1129 #[no_mangle]
1130 pub extern "C" fn HTLCDescriptor_eq(a: &HTLCDescriptor, b: &HTLCDescriptor) -> bool {
1131         if a.inner == b.inner { return true; }
1132         if a.inner.is_null() || b.inner.is_null() { return false; }
1133         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1134 }
1135 #[no_mangle]
1136 /// Serialize the HTLCDescriptor object into a byte array which can be read by HTLCDescriptor_read
1137 pub extern "C" fn HTLCDescriptor_write(obj: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z {
1138         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1139 }
1140 #[allow(unused)]
1141 pub(crate) extern "C" fn HTLCDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1142         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCDescriptor) })
1143 }
1144 #[no_mangle]
1145 /// Read a HTLCDescriptor from a byte array, created by HTLCDescriptor_write
1146 pub extern "C" fn HTLCDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCDescriptorDecodeErrorZ {
1147         let res: Result<lightning::sign::HTLCDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1148         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::HTLCDescriptor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1149         local_res
1150 }
1151 /// Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint
1152 /// being spent by the HTLC input in the HTLC transaction.
1153 #[must_use]
1154 #[no_mangle]
1155 pub extern "C" fn HTLCDescriptor_outpoint(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::lightning::chain::transaction::OutPoint {
1156         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.outpoint();
1157         crate::c_types::bitcoin_to_C_outpoint(&ret)
1158 }
1159
1160 /// Returns the UTXO to be spent by the HTLC input, which can be obtained via
1161 /// [`Self::unsigned_tx_input`].
1162 #[must_use]
1163 #[no_mangle]
1164 pub extern "C" fn HTLCDescriptor_previous_utxo(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxOut {
1165         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.previous_utxo(secp256k1::global::SECP256K1);
1166         crate::c_types::TxOut::from_rust(&ret)
1167 }
1168
1169 /// Returns the unsigned transaction input spending the HTLC output in the commitment
1170 /// transaction.
1171 #[must_use]
1172 #[no_mangle]
1173 pub extern "C" fn HTLCDescriptor_unsigned_tx_input(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxIn {
1174         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.unsigned_tx_input();
1175         crate::c_types::TxIn::from_rust(&ret)
1176 }
1177
1178 /// Returns the delayed output created as a result of spending the HTLC output in the commitment
1179 /// transaction.
1180 #[must_use]
1181 #[no_mangle]
1182 pub extern "C" fn HTLCDescriptor_tx_output(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::TxOut {
1183         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_output(secp256k1::global::SECP256K1);
1184         crate::c_types::TxOut::from_rust(&ret)
1185 }
1186
1187 /// Returns the witness script of the HTLC output in the commitment transaction.
1188 #[must_use]
1189 #[no_mangle]
1190 pub extern "C" fn HTLCDescriptor_witness_script(this_arg: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CVec_u8Z {
1191         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.witness_script(secp256k1::global::SECP256K1);
1192         ret.to_bytes().into()
1193 }
1194
1195 /// Returns the fully signed witness required to spend the HTLC output in the commitment
1196 /// transaction.
1197 #[must_use]
1198 #[no_mangle]
1199 pub extern "C" fn HTLCDescriptor_tx_input_witness(this_arg: &crate::lightning::sign::HTLCDescriptor, mut signature: crate::c_types::ECDSASignature, mut witness_script: crate::c_types::u8slice) -> crate::c_types::Witness {
1200         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tx_input_witness(&signature.into_rust(), ::bitcoin::blockdata::script::Script::from_bytes(witness_script.to_slice()));
1201         crate::c_types::Witness::from_bitcoin(&ret)
1202 }
1203
1204 /// Derives the channel signer required to sign the HTLC input.
1205 #[must_use]
1206 #[no_mangle]
1207 pub extern "C" fn HTLCDescriptor_derive_channel_signer(this_arg: &crate::lightning::sign::HTLCDescriptor, signer_provider: &crate::lightning::sign::SignerProvider) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
1208         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_signer(signer_provider);
1209         Into::into(ret)
1210 }
1211
1212 /// A trait to handle Lightning channel key material without concretizing the channel type or
1213 /// the signature mechanism.
1214 #[repr(C)]
1215 pub struct ChannelSigner {
1216         /// An opaque pointer which is passed to your function implementations as an argument.
1217         /// This has no meaning in the LDK, and can be NULL or any other value.
1218         pub this_arg: *mut c_void,
1219         /// Gets the per-commitment point for a specific commitment number
1220         ///
1221         /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
1222         pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey,
1223         /// Gets the commitment secret for a specific commitment number as part of the revocation process
1224         ///
1225         /// An external signer implementation should error here if the commitment was already signed
1226         /// and should refuse to sign it in the future.
1227         ///
1228         /// May be called more than once for the same index.
1229         ///
1230         /// Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
1231         pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes,
1232         /// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
1233         ///
1234         /// This is required in order for the signer to make sure that releasing a commitment
1235         /// secret won't leave us without a broadcastable holder transaction.
1236         /// Policy checks should be implemented in this function, including checking the amount
1237         /// sent to us and checking the HTLCs.
1238         ///
1239         /// The preimages of outbound HTLCs that were fulfilled since the last commitment are provided.
1240         /// A validating signer should ensure that an HTLC output is removed only when the matching
1241         /// preimage is provided, or when the value to holder is restored.
1242         ///
1243         /// Note that all the relevant preimages will be provided, but there may also be additional
1244         /// irrelevant or duplicate preimages.
1245         pub validate_holder_commitment: extern "C" fn (this_arg: *const c_void, holder_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction, outbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_NoneNoneZ,
1246         /// Validate the counterparty's revocation.
1247         ///
1248         /// This is required in order for the signer to make sure that the state has moved
1249         /// forward and it is safe to sign the next counterparty commitment.
1250         pub validate_counterparty_revocation: extern "C" fn (this_arg: *const c_void, idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ,
1251         /// Returns the holder's channel public keys and basepoints.
1252         pub pubkeys: core::cell::UnsafeCell<crate::lightning::ln::chan_utils::ChannelPublicKeys>,
1253         /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns
1254         /// Note that this takes a pointer to this object, not the this_ptr like other methods do
1255         /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
1256         pub set_pubkeys: Option<extern "C" fn(&ChannelSigner)>,
1257         /// Returns an arbitrary identifier describing the set of keys which are provided back to you in
1258         /// some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
1259         /// [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
1260         pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1261         /// Set the counterparty static channel data, including basepoints,
1262         /// `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
1263         ///
1264         /// This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
1265         /// instance, LDK will call this method exactly once - either immediately after construction
1266         /// (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
1267         /// information has been generated.
1268         ///
1269         /// channel_parameters.is_populated() MUST be true.
1270         pub provide_channel_parameters: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters),
1271         /// Frees any resources associated with this object given its this_arg pointer.
1272         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1273         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1274 }
1275 unsafe impl Send for ChannelSigner {}
1276 unsafe impl Sync for ChannelSigner {}
1277 #[allow(unused)]
1278 pub(crate) fn ChannelSigner_clone_fields(orig: &ChannelSigner) -> ChannelSigner {
1279         ChannelSigner {
1280                 this_arg: orig.this_arg,
1281                 get_per_commitment_point: Clone::clone(&orig.get_per_commitment_point),
1282                 release_commitment_secret: Clone::clone(&orig.release_commitment_secret),
1283                 validate_holder_commitment: Clone::clone(&orig.validate_holder_commitment),
1284                 validate_counterparty_revocation: Clone::clone(&orig.validate_counterparty_revocation),
1285                 pubkeys: Clone::clone(unsafe { &*core::cell::UnsafeCell::get(&orig.pubkeys)}).into(),
1286                 set_pubkeys: Clone::clone(&orig.set_pubkeys),
1287                 channel_keys_id: Clone::clone(&orig.channel_keys_id),
1288                 provide_channel_parameters: Clone::clone(&orig.provide_channel_parameters),
1289                 free: Clone::clone(&orig.free),
1290         }
1291 }
1292
1293 use lightning::sign::ChannelSigner as rustChannelSigner;
1294 impl rustChannelSigner for ChannelSigner {
1295         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
1296                 let mut ret = (self.get_per_commitment_point)(self.this_arg, idx);
1297                 ret.into_rust()
1298         }
1299         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
1300                 let mut ret = (self.release_commitment_secret)(self.this_arg, idx);
1301                 ret.data
1302         }
1303         fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut outbound_htlc_preimages: Vec<lightning::ln::types::PaymentPreimage>) -> Result<(), ()> {
1304                 let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.drain(..) { local_outbound_htlc_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
1305                 let mut ret = (self.validate_holder_commitment)(self.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((holder_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false }, local_outbound_htlc_preimages.into());
1306                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1307                 local_ret
1308         }
1309         fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
1310                 let mut ret = (self.validate_counterparty_revocation)(self.this_arg, idx, secret.as_ref());
1311                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1312                 local_ret
1313         }
1314         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
1315                 if let Some(f) = self.set_pubkeys {
1316                         (f)(&self);
1317                 }
1318                 unsafe { &*self.pubkeys.get() }.get_native_ref()
1319         }
1320         fn channel_keys_id(&self) -> [u8; 32] {
1321                 let mut ret = (self.channel_keys_id)(self.this_arg);
1322                 ret.data
1323         }
1324         fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
1325                 (self.provide_channel_parameters)(self.this_arg, &crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((channel_parameters as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false })
1326         }
1327 }
1328
1329 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1330 // directly as a Deref trait in higher-level structs:
1331 impl core::ops::Deref for ChannelSigner {
1332         type Target = Self;
1333         fn deref(&self) -> &Self {
1334                 self
1335         }
1336 }
1337 impl core::ops::DerefMut for ChannelSigner {
1338         fn deref_mut(&mut self) -> &mut Self {
1339                 self
1340         }
1341 }
1342 /// Calls the free function if one is set
1343 #[no_mangle]
1344 pub extern "C" fn ChannelSigner_free(this_ptr: ChannelSigner) { }
1345 impl Drop for ChannelSigner {
1346         fn drop(&mut self) {
1347                 if let Some(f) = self.free {
1348                         f(self.this_arg);
1349                 }
1350         }
1351 }
1352 /// Specifies the recipient of an invoice.
1353 ///
1354 /// This indicates to [`NodeSigner::sign_invoice`] what node secret key should be used to sign
1355 /// the invoice.
1356 #[derive(Clone)]
1357 #[must_use]
1358 #[repr(C)]
1359 pub enum Recipient {
1360         /// The invoice should be signed with the local node secret key.
1361         Node,
1362         /// The invoice should be signed with the phantom node secret key. This secret key must be the
1363         /// same for all nodes participating in the [phantom node payment].
1364         ///
1365         /// [phantom node payment]: PhantomKeysManager
1366         PhantomNode,
1367 }
1368 use lightning::sign::Recipient as RecipientImport;
1369 pub(crate) type nativeRecipient = RecipientImport;
1370
1371 impl Recipient {
1372         #[allow(unused)]
1373         pub(crate) fn to_native(&self) -> nativeRecipient {
1374                 match self {
1375                         Recipient::Node => nativeRecipient::Node,
1376                         Recipient::PhantomNode => nativeRecipient::PhantomNode,
1377                 }
1378         }
1379         #[allow(unused)]
1380         pub(crate) fn into_native(self) -> nativeRecipient {
1381                 match self {
1382                         Recipient::Node => nativeRecipient::Node,
1383                         Recipient::PhantomNode => nativeRecipient::PhantomNode,
1384                 }
1385         }
1386         #[allow(unused)]
1387         pub(crate) fn from_native(native: &RecipientImport) -> Self {
1388                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeRecipient) };
1389                 match native {
1390                         nativeRecipient::Node => Recipient::Node,
1391                         nativeRecipient::PhantomNode => Recipient::PhantomNode,
1392                 }
1393         }
1394         #[allow(unused)]
1395         pub(crate) fn native_into(native: nativeRecipient) -> Self {
1396                 match native {
1397                         nativeRecipient::Node => Recipient::Node,
1398                         nativeRecipient::PhantomNode => Recipient::PhantomNode,
1399                 }
1400         }
1401 }
1402 /// Creates a copy of the Recipient
1403 #[no_mangle]
1404 pub extern "C" fn Recipient_clone(orig: &Recipient) -> Recipient {
1405         orig.clone()
1406 }
1407 #[allow(unused)]
1408 /// Used only if an object of this type is returned as a trait impl by a method
1409 pub(crate) extern "C" fn Recipient_clone_void(this_ptr: *const c_void) -> *mut c_void {
1410         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Recipient)).clone() })) as *mut c_void
1411 }
1412 #[allow(unused)]
1413 /// Used only if an object of this type is returned as a trait impl by a method
1414 pub(crate) extern "C" fn Recipient_free_void(this_ptr: *mut c_void) {
1415         let _ = unsafe { Box::from_raw(this_ptr as *mut Recipient) };
1416 }
1417 #[no_mangle]
1418 /// Utility method to constructs a new Node-variant Recipient
1419 pub extern "C" fn Recipient_node() -> Recipient {
1420         Recipient::Node}
1421 #[no_mangle]
1422 /// Utility method to constructs a new PhantomNode-variant Recipient
1423 pub extern "C" fn Recipient_phantom_node() -> Recipient {
1424         Recipient::PhantomNode}
1425 /// A trait that describes a source of entropy.
1426 #[repr(C)]
1427 pub struct EntropySource {
1428         /// An opaque pointer which is passed to your function implementations as an argument.
1429         /// This has no meaning in the LDK, and can be NULL or any other value.
1430         pub this_arg: *mut c_void,
1431         /// Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
1432         /// different value each time it is called.
1433         pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1434         /// Frees any resources associated with this object given its this_arg pointer.
1435         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1436         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1437 }
1438 unsafe impl Send for EntropySource {}
1439 unsafe impl Sync for EntropySource {}
1440 #[allow(unused)]
1441 pub(crate) fn EntropySource_clone_fields(orig: &EntropySource) -> EntropySource {
1442         EntropySource {
1443                 this_arg: orig.this_arg,
1444                 get_secure_random_bytes: Clone::clone(&orig.get_secure_random_bytes),
1445                 free: Clone::clone(&orig.free),
1446         }
1447 }
1448
1449 use lightning::sign::EntropySource as rustEntropySource;
1450 impl rustEntropySource for EntropySource {
1451         fn get_secure_random_bytes(&self) -> [u8; 32] {
1452                 let mut ret = (self.get_secure_random_bytes)(self.this_arg);
1453                 ret.data
1454         }
1455 }
1456
1457 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1458 // directly as a Deref trait in higher-level structs:
1459 impl core::ops::Deref for EntropySource {
1460         type Target = Self;
1461         fn deref(&self) -> &Self {
1462                 self
1463         }
1464 }
1465 impl core::ops::DerefMut for EntropySource {
1466         fn deref_mut(&mut self) -> &mut Self {
1467                 self
1468         }
1469 }
1470 /// Calls the free function if one is set
1471 #[no_mangle]
1472 pub extern "C" fn EntropySource_free(this_ptr: EntropySource) { }
1473 impl Drop for EntropySource {
1474         fn drop(&mut self) {
1475                 if let Some(f) = self.free {
1476                         f(self.this_arg);
1477                 }
1478         }
1479 }
1480 /// A trait that can handle cryptographic operations at the scope level of a node.
1481 #[repr(C)]
1482 pub struct NodeSigner {
1483         /// An opaque pointer which is passed to your function implementations as an argument.
1484         /// This has no meaning in the LDK, and can be NULL or any other value.
1485         pub this_arg: *mut c_void,
1486         /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
1487         ///
1488         /// If the implementor of this trait supports [phantom node payments], then every node that is
1489         /// intended to be included in the phantom invoice route hints must return the same value from
1490         /// this method.
1491         ///
1492         /// This method must return the same value each time it is called.
1493         ///
1494         /// [phantom node payments]: PhantomKeysManager
1495         pub get_inbound_payment_key_material: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1496         /// Get node id based on the provided [`Recipient`].
1497         ///
1498         /// This method must return the same value each time it is called with a given [`Recipient`]
1499         /// parameter.
1500         ///
1501         /// Errors if the [`Recipient`] variant is not supported by the implementation.
1502         pub get_node_id: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ,
1503         /// Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
1504         /// one is provided. Note that this tweak can be applied to `other_key` instead of our node
1505         /// secret, though this is less efficient.
1506         ///
1507         /// Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
1508         /// should be resolved to allow LDK to resume forwarding HTLCs.
1509         ///
1510         /// Errors if the [`Recipient`] variant is not supported by the implementation.
1511         pub ecdh: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::sign::Recipient, other_key: crate::c_types::PublicKey, tweak: crate::c_types::derived::COption_BigEndianScalarZ) -> crate::c_types::derived::CResult_ThirtyTwoBytesNoneZ,
1512         /// Sign an invoice.
1513         ///
1514         /// By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
1515         /// this trait to parse the invoice and make sure they're signing what they expect, rather than
1516         /// blindly signing the hash.
1517         ///
1518         /// The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
1519         ///
1520         /// The secret key used to sign the invoice is dependent on the [`Recipient`].
1521         ///
1522         /// Errors if the [`Recipient`] variant is not supported by the implementation.
1523         pub sign_invoice: extern "C" fn (this_arg: *const c_void, hrp_bytes: crate::c_types::u8slice, invoice_data: crate::c_types::derived::CVec_U5Z, recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ,
1524         /// Signs the [`TaggedHash`] of a BOLT 12 invoice request.
1525         ///
1526         /// May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
1527         /// `invoice_request` is the callee.
1528         ///
1529         /// Implementors may check that the `invoice_request` is expected rather than blindly signing
1530         /// the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
1531         /// the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
1532         /// [`UnsignedInvoiceRequest::payer_id`].
1533         ///
1534         /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
1535         pub sign_bolt12_invoice_request: extern "C" fn (this_arg: *const c_void, invoice_request: &crate::lightning::offers::invoice_request::UnsignedInvoiceRequest) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ,
1536         /// Signs the [`TaggedHash`] of a BOLT 12 invoice.
1537         ///
1538         /// May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
1539         /// callee.
1540         ///
1541         /// Implementors may check that the `invoice` is expected rather than blindly signing the tagged
1542         /// hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
1543         /// key or an ephemeral key to preserve privacy, whichever is associated with
1544         /// [`UnsignedBolt12Invoice::signing_pubkey`].
1545         ///
1546         /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
1547         pub sign_bolt12_invoice: extern "C" fn (this_arg: *const c_void, invoice: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ,
1548         /// Sign a gossip message.
1549         ///
1550         /// Note that if this fails, LDK may panic and the message will not be broadcast to the network
1551         /// or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
1552         /// message to be broadcast, as otherwise it may prevent one from receiving funds over the
1553         /// corresponding channel.
1554         pub sign_gossip_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
1555         /// Frees any resources associated with this object given its this_arg pointer.
1556         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1557         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1558 }
1559 unsafe impl Send for NodeSigner {}
1560 unsafe impl Sync for NodeSigner {}
1561 #[allow(unused)]
1562 pub(crate) fn NodeSigner_clone_fields(orig: &NodeSigner) -> NodeSigner {
1563         NodeSigner {
1564                 this_arg: orig.this_arg,
1565                 get_inbound_payment_key_material: Clone::clone(&orig.get_inbound_payment_key_material),
1566                 get_node_id: Clone::clone(&orig.get_node_id),
1567                 ecdh: Clone::clone(&orig.ecdh),
1568                 sign_invoice: Clone::clone(&orig.sign_invoice),
1569                 sign_bolt12_invoice_request: Clone::clone(&orig.sign_bolt12_invoice_request),
1570                 sign_bolt12_invoice: Clone::clone(&orig.sign_bolt12_invoice),
1571                 sign_gossip_message: Clone::clone(&orig.sign_gossip_message),
1572                 free: Clone::clone(&orig.free),
1573         }
1574 }
1575
1576 use lightning::sign::NodeSigner as rustNodeSigner;
1577 impl rustNodeSigner for NodeSigner {
1578         fn get_inbound_payment_key_material(&self) -> lightning::sign::KeyMaterial {
1579                 let mut ret = (self.get_inbound_payment_key_material)(self.this_arg);
1580                 ::lightning::sign::KeyMaterial(ret.data)
1581         }
1582         fn get_node_id(&self, mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::PublicKey, ()> {
1583                 let mut ret = (self.get_node_id)(self.this_arg, crate::lightning::sign::Recipient::native_into(recipient));
1584                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1585                 local_ret
1586         }
1587         fn ecdh(&self, mut recipient: lightning::sign::Recipient, mut other_key: &bitcoin::secp256k1::PublicKey, mut tweak: Option<&bitcoin::secp256k1::Scalar>) -> Result<bitcoin::secp256k1::ecdh::SharedSecret, ()> {
1588                 let mut local_tweak = if tweak.is_none() { crate::c_types::derived::COption_BigEndianScalarZ::None } else { crate::c_types::derived::COption_BigEndianScalarZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::BigEndianScalar::from_rust(&(*tweak.as_ref().unwrap()).clone()) }) };
1589                 let mut ret = (self.ecdh)(self.this_arg, crate::lightning::sign::Recipient::native_into(recipient), crate::c_types::PublicKey::from_rust(&other_key), local_tweak);
1590                 let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::secp256k1::ecdh::SharedSecret::from_bytes((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).data) }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1591                 local_ret
1592         }
1593         fn sign_invoice(&self, mut hrp_bytes: &[u8], mut invoice_data: &[bitcoin::bech32::u5], mut recipient: lightning::sign::Recipient) -> Result<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
1594                 let mut local_hrp_bytes = crate::c_types::u8slice::from_slice(hrp_bytes);
1595                 let mut local_invoice_data_clone = Vec::new(); local_invoice_data_clone.extend_from_slice(invoice_data); let mut invoice_data = local_invoice_data_clone; let mut local_invoice_data = Vec::new(); for mut item in invoice_data.drain(..) { local_invoice_data.push( { item.into() }); };
1596                 let mut ret = (self.sign_invoice)(self.this_arg, local_hrp_bytes, local_invoice_data.into(), crate::lightning::sign::Recipient::native_into(recipient));
1597                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1598                 local_ret
1599         }
1600         fn sign_bolt12_invoice_request(&self, mut invoice_request: &lightning::offers::invoice_request::UnsignedInvoiceRequest) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
1601                 let mut ret = (self.sign_bolt12_invoice_request)(self.this_arg, &crate::lightning::offers::invoice_request::UnsignedInvoiceRequest { inner: unsafe { ObjOps::nonnull_ptr_to_inner((invoice_request as *const lightning::offers::invoice_request::UnsignedInvoiceRequest<>) as *mut _) }, is_owned: false });
1602                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1603                 local_ret
1604         }
1605         fn sign_bolt12_invoice(&self, mut invoice: &lightning::offers::invoice::UnsignedBolt12Invoice) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
1606                 let mut ret = (self.sign_bolt12_invoice)(self.this_arg, &crate::lightning::offers::invoice::UnsignedBolt12Invoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((invoice as *const lightning::offers::invoice::UnsignedBolt12Invoice<>) as *mut _) }, is_owned: false });
1607                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1608                 local_ret
1609         }
1610         fn sign_gossip_message(&self, mut msg: lightning::ln::msgs::UnsignedGossipMessage) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
1611                 let mut ret = (self.sign_gossip_message)(self.this_arg, crate::lightning::ln::msgs::UnsignedGossipMessage::native_into(msg));
1612                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1613                 local_ret
1614         }
1615 }
1616
1617 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1618 // directly as a Deref trait in higher-level structs:
1619 impl core::ops::Deref for NodeSigner {
1620         type Target = Self;
1621         fn deref(&self) -> &Self {
1622                 self
1623         }
1624 }
1625 impl core::ops::DerefMut for NodeSigner {
1626         fn deref_mut(&mut self) -> &mut Self {
1627                 self
1628         }
1629 }
1630 /// Calls the free function if one is set
1631 #[no_mangle]
1632 pub extern "C" fn NodeSigner_free(this_ptr: NodeSigner) { }
1633 impl Drop for NodeSigner {
1634         fn drop(&mut self) {
1635                 if let Some(f) = self.free {
1636                         f(self.this_arg);
1637                 }
1638         }
1639 }
1640 /// A trait that describes a wallet capable of creating a spending [`Transaction`] from a set of
1641 /// [`SpendableOutputDescriptor`]s.
1642 #[repr(C)]
1643 pub struct OutputSpender {
1644         /// An opaque pointer which is passed to your function implementations as an argument.
1645         /// This has no meaning in the LDK, and can be NULL or any other value.
1646         pub this_arg: *mut c_void,
1647         /// Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
1648         /// output to the given change destination (if sufficient change value remains). The
1649         /// transaction will have a feerate, at least, of the given value.
1650         ///
1651         /// The `locktime` argument is used to set the transaction's locktime. If `None`, the
1652         /// transaction will have a locktime of 0. It it recommended to set this to the current block
1653         /// height to avoid fee sniping, unless you have some specific reason to use a different
1654         /// locktime.
1655         ///
1656         /// Returns `Err(())` if the output value is greater than the input value minus required fee,
1657         /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
1658         /// does not match the one we can spend.
1659         pub spend_spendable_outputs: extern "C" fn (this_arg: *const c_void, descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, outputs: crate::c_types::derived::CVec_TxOutZ, change_destination_script: crate::c_types::derived::CVec_u8Z, feerate_sat_per_1000_weight: u32, locktime: crate::c_types::derived::COption_u32Z) -> crate::c_types::derived::CResult_TransactionNoneZ,
1660         /// Frees any resources associated with this object given its this_arg pointer.
1661         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1662         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1663 }
1664 unsafe impl Send for OutputSpender {}
1665 unsafe impl Sync for OutputSpender {}
1666 #[allow(unused)]
1667 pub(crate) fn OutputSpender_clone_fields(orig: &OutputSpender) -> OutputSpender {
1668         OutputSpender {
1669                 this_arg: orig.this_arg,
1670                 spend_spendable_outputs: Clone::clone(&orig.spend_spendable_outputs),
1671                 free: Clone::clone(&orig.free),
1672         }
1673 }
1674
1675 use lightning::sign::OutputSpender as rustOutputSpender;
1676 impl rustOutputSpender for OutputSpender {
1677         fn spend_spendable_outputs<C:bitcoin::secp256k1::Signing>(&self, mut descriptors: &[&lightning::sign::SpendableOutputDescriptor], mut outputs: Vec<bitcoin::blockdata::transaction::TxOut>, mut change_destination_script: bitcoin::blockdata::script::ScriptBuf, mut feerate_sat_per_1000_weight: u32, mut locktime: Option<bitcoin::blockdata::locktime::absolute::LockTime>, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<C>) -> Result<bitcoin::blockdata::transaction::Transaction, ()> {
1678                 let mut local_descriptors = Vec::new(); for item in descriptors.iter() { local_descriptors.push( { crate::lightning::sign::SpendableOutputDescriptor::from_native((*item)) }); };
1679                 let mut local_outputs = Vec::new(); for mut item in outputs.drain(..) { local_outputs.push( { crate::c_types::TxOut::from_rust(&item) }); };
1680                 let mut local_locktime = if locktime.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { locktime.unwrap().to_consensus_u32() }) };
1681                 let mut ret = (self.spend_spendable_outputs)(self.this_arg, local_descriptors.into(), local_outputs.into(), change_destination_script.to_bytes().into(), feerate_sat_per_1000_weight, local_locktime);
1682                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_bitcoin() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1683                 local_ret
1684         }
1685 }
1686
1687 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1688 // directly as a Deref trait in higher-level structs:
1689 impl core::ops::Deref for OutputSpender {
1690         type Target = Self;
1691         fn deref(&self) -> &Self {
1692                 self
1693         }
1694 }
1695 impl core::ops::DerefMut for OutputSpender {
1696         fn deref_mut(&mut self) -> &mut Self {
1697                 self
1698         }
1699 }
1700 /// Calls the free function if one is set
1701 #[no_mangle]
1702 pub extern "C" fn OutputSpender_free(this_ptr: OutputSpender) { }
1703 impl Drop for OutputSpender {
1704         fn drop(&mut self) {
1705                 if let Some(f) = self.free {
1706                         f(self.this_arg);
1707                 }
1708         }
1709 }
1710 /// A trait that can return signer instances for individual channels.
1711 #[repr(C)]
1712 pub struct SignerProvider {
1713         /// An opaque pointer which is passed to your function implementations as an argument.
1714         /// This has no meaning in the LDK, and can be NULL or any other value.
1715         pub this_arg: *mut c_void,
1716         /// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::EcdsaSigner`] through
1717         /// [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
1718         /// implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
1719         /// `channel_keys_id`.
1720         ///
1721         /// This method must return a different value each time it is called.
1722         pub generate_channel_keys_id: extern "C" fn (this_arg: *const c_void, inbound: bool, channel_value_satoshis: u64, user_channel_id: crate::c_types::U128) -> crate::c_types::ThirtyTwoBytes,
1723         /// Derives the private key material backing a `Signer`.
1724         ///
1725         /// To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
1726         /// [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
1727         /// re-derived from its `channel_keys_id`, which can be obtained through its trait method
1728         /// [`ChannelSigner::channel_keys_id`].
1729         pub derive_channel_signer: extern "C" fn (this_arg: *const c_void, channel_value_satoshis: u64, channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner,
1730         /// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
1731         /// This is only called during deserialization of other objects which contain
1732         /// [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
1733         /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
1734         /// contain no versioning scheme. You may wish to include your own version prefix and ensure
1735         /// you've read all of the provided bytes to ensure no corruption occurred.
1736         ///
1737         /// This method is slowly being phased out -- it will only be called when reading objects
1738         /// written by LDK versions prior to 0.0.113.
1739         ///
1740         /// [`Signer`]: Self::EcdsaSigner
1741         /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
1742         /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1743         pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ,
1744         /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
1745         ///
1746         /// If this function returns an error, this will result in a channel failing to open.
1747         ///
1748         /// This method should return a different value each time it is called, to avoid linking
1749         /// on-chain funds across channels as controlled to the same user. `channel_keys_id` may be
1750         /// used to derive a unique value for each channel.
1751         pub get_destination_script: extern "C" fn (this_arg: *const c_void, channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ,
1752         /// Get a script pubkey which we will send funds to when closing a channel.
1753         ///
1754         /// If this function returns an error, this will result in a channel failing to open or close.
1755         /// In the event of a failure when the counterparty is initiating a close, this can result in a
1756         /// channel force close.
1757         ///
1758         /// This method should return a different value each time it is called, to avoid linking
1759         /// on-chain funds across channels as controlled to the same user.
1760         pub get_shutdown_scriptpubkey: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ,
1761         /// Frees any resources associated with this object given its this_arg pointer.
1762         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1763         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1764 }
1765 unsafe impl Send for SignerProvider {}
1766 unsafe impl Sync for SignerProvider {}
1767 #[allow(unused)]
1768 pub(crate) fn SignerProvider_clone_fields(orig: &SignerProvider) -> SignerProvider {
1769         SignerProvider {
1770                 this_arg: orig.this_arg,
1771                 generate_channel_keys_id: Clone::clone(&orig.generate_channel_keys_id),
1772                 derive_channel_signer: Clone::clone(&orig.derive_channel_signer),
1773                 read_chan_signer: Clone::clone(&orig.read_chan_signer),
1774                 get_destination_script: Clone::clone(&orig.get_destination_script),
1775                 get_shutdown_scriptpubkey: Clone::clone(&orig.get_shutdown_scriptpubkey),
1776                 free: Clone::clone(&orig.free),
1777         }
1778 }
1779
1780 use lightning::sign::SignerProvider as rustSignerProvider;
1781 impl rustSignerProvider for SignerProvider {
1782         type EcdsaSigner = crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner;
1783         fn generate_channel_keys_id(&self, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: u128) -> [u8; 32] {
1784                 let mut ret = (self.generate_channel_keys_id)(self.this_arg, inbound, channel_value_satoshis, user_channel_id.into());
1785                 ret.data
1786         }
1787         fn derive_channel_signer(&self, mut channel_value_satoshis: u64, mut channel_keys_id: [u8; 32]) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
1788                 let mut ret = (self.derive_channel_signer)(self.this_arg, channel_value_satoshis, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
1789                 ret
1790         }
1791         fn read_chan_signer(&self, mut reader: &[u8]) -> Result<crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner, lightning::ln::msgs::DecodeError> {
1792                 let mut local_reader = crate::c_types::u8slice::from_slice(reader);
1793                 let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
1794                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
1795                 local_ret
1796         }
1797         fn get_destination_script(&self, mut channel_keys_id: [u8; 32]) -> Result<bitcoin::blockdata::script::ScriptBuf, ()> {
1798                 let mut ret = (self.get_destination_script)(self.this_arg, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
1799                 let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::blockdata::script::ScriptBuf::from((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust()) }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1800                 local_ret
1801         }
1802         fn get_shutdown_scriptpubkey(&self) -> Result<lightning::ln::script::ShutdownScript, ()> {
1803                 let mut ret = (self.get_shutdown_scriptpubkey)(self.this_arg);
1804                 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1805                 local_ret
1806         }
1807 }
1808
1809 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1810 // directly as a Deref trait in higher-level structs:
1811 impl core::ops::Deref for SignerProvider {
1812         type Target = Self;
1813         fn deref(&self) -> &Self {
1814                 self
1815         }
1816 }
1817 impl core::ops::DerefMut for SignerProvider {
1818         fn deref_mut(&mut self) -> &mut Self {
1819                 self
1820         }
1821 }
1822 /// Calls the free function if one is set
1823 #[no_mangle]
1824 pub extern "C" fn SignerProvider_free(this_ptr: SignerProvider) { }
1825 impl Drop for SignerProvider {
1826         fn drop(&mut self) {
1827                 if let Some(f) = self.free {
1828                         f(self.this_arg);
1829                 }
1830         }
1831 }
1832 /// A helper trait that describes an on-chain wallet capable of returning a (change) destination
1833 /// script.
1834 #[repr(C)]
1835 pub struct ChangeDestinationSource {
1836         /// An opaque pointer which is passed to your function implementations as an argument.
1837         /// This has no meaning in the LDK, and can be NULL or any other value.
1838         pub this_arg: *mut c_void,
1839         /// Returns a script pubkey which can be used as a change destination for
1840         /// [`OutputSpender::spend_spendable_outputs`].
1841         ///
1842         /// This method should return a different value each time it is called, to avoid linking
1843         /// on-chain funds controlled to the same user.
1844         pub get_change_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ,
1845         /// Frees any resources associated with this object given its this_arg pointer.
1846         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1847         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1848 }
1849 unsafe impl Send for ChangeDestinationSource {}
1850 unsafe impl Sync for ChangeDestinationSource {}
1851 #[allow(unused)]
1852 pub(crate) fn ChangeDestinationSource_clone_fields(orig: &ChangeDestinationSource) -> ChangeDestinationSource {
1853         ChangeDestinationSource {
1854                 this_arg: orig.this_arg,
1855                 get_change_destination_script: Clone::clone(&orig.get_change_destination_script),
1856                 free: Clone::clone(&orig.free),
1857         }
1858 }
1859
1860 use lightning::sign::ChangeDestinationSource as rustChangeDestinationSource;
1861 impl rustChangeDestinationSource for ChangeDestinationSource {
1862         fn get_change_destination_script(&self) -> Result<bitcoin::blockdata::script::ScriptBuf, ()> {
1863                 let mut ret = (self.get_change_destination_script)(self.this_arg);
1864                 let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::blockdata::script::ScriptBuf::from((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust()) }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
1865                 local_ret
1866         }
1867 }
1868
1869 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1870 // directly as a Deref trait in higher-level structs:
1871 impl core::ops::Deref for ChangeDestinationSource {
1872         type Target = Self;
1873         fn deref(&self) -> &Self {
1874                 self
1875         }
1876 }
1877 impl core::ops::DerefMut for ChangeDestinationSource {
1878         fn deref_mut(&mut self) -> &mut Self {
1879                 self
1880         }
1881 }
1882 /// Calls the free function if one is set
1883 #[no_mangle]
1884 pub extern "C" fn ChangeDestinationSource_free(this_ptr: ChangeDestinationSource) { }
1885 impl Drop for ChangeDestinationSource {
1886         fn drop(&mut self) {
1887                 if let Some(f) = self.free {
1888                         f(self.this_arg);
1889                 }
1890         }
1891 }
1892
1893 use lightning::sign::InMemorySigner as nativeInMemorySignerImport;
1894 pub(crate) type nativeInMemorySigner = nativeInMemorySignerImport;
1895
1896 /// A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
1897 ///
1898 /// This implementation performs no policy checks and is insufficient by itself as
1899 /// a secure external signer.
1900 #[must_use]
1901 #[repr(C)]
1902 pub struct InMemorySigner {
1903         /// A pointer to the opaque Rust object.
1904
1905         /// Nearly everywhere, inner must be non-null, however in places where
1906         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1907         pub inner: *mut nativeInMemorySigner,
1908         /// Indicates that this is the only struct which contains the same pointer.
1909
1910         /// Rust functions which take ownership of an object provided via an argument require
1911         /// this to be true and invalidate the object pointed to by inner.
1912         pub is_owned: bool,
1913 }
1914
1915 impl Drop for InMemorySigner {
1916         fn drop(&mut self) {
1917                 if self.is_owned && !<*mut nativeInMemorySigner>::is_null(self.inner) {
1918                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1919                 }
1920         }
1921 }
1922 /// Frees any resources used by the InMemorySigner, if is_owned is set and inner is non-NULL.
1923 #[no_mangle]
1924 pub extern "C" fn InMemorySigner_free(this_obj: InMemorySigner) { }
1925 #[allow(unused)]
1926 /// Used only if an object of this type is returned as a trait impl by a method
1927 pub(crate) extern "C" fn InMemorySigner_free_void(this_ptr: *mut c_void) {
1928         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInMemorySigner) };
1929 }
1930 #[allow(unused)]
1931 impl InMemorySigner {
1932         pub(crate) fn get_native_ref(&self) -> &'static nativeInMemorySigner {
1933                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1934         }
1935         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInMemorySigner {
1936                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1937         }
1938         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1939         pub(crate) fn take_inner(mut self) -> *mut nativeInMemorySigner {
1940                 assert!(self.is_owned);
1941                 let ret = ObjOps::untweak_ptr(self.inner);
1942                 self.inner = core::ptr::null_mut();
1943                 ret
1944         }
1945 }
1946 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1947 /// holder's anchor output in a commitment transaction, if one is present.
1948 #[no_mangle]
1949 pub extern "C" fn InMemorySigner_get_funding_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1950         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_key;
1951         inner_val.as_ref()
1952 }
1953 /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
1954 /// holder's anchor output in a commitment transaction, if one is present.
1955 #[no_mangle]
1956 pub extern "C" fn InMemorySigner_set_funding_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1957         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_key = val.into_rust();
1958 }
1959 /// Holder secret key for blinded revocation pubkey.
1960 #[no_mangle]
1961 pub extern "C" fn InMemorySigner_get_revocation_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1962         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_base_key;
1963         inner_val.as_ref()
1964 }
1965 /// Holder secret key for blinded revocation pubkey.
1966 #[no_mangle]
1967 pub extern "C" fn InMemorySigner_set_revocation_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1968         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_base_key = val.into_rust();
1969 }
1970 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1971 #[no_mangle]
1972 pub extern "C" fn InMemorySigner_get_payment_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1973         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_key;
1974         inner_val.as_ref()
1975 }
1976 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
1977 #[no_mangle]
1978 pub extern "C" fn InMemorySigner_set_payment_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1979         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_key = val.into_rust();
1980 }
1981 /// Holder secret key used in an HTLC transaction.
1982 #[no_mangle]
1983 pub extern "C" fn InMemorySigner_get_delayed_payment_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1984         let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_base_key;
1985         inner_val.as_ref()
1986 }
1987 /// Holder secret key used in an HTLC transaction.
1988 #[no_mangle]
1989 pub extern "C" fn InMemorySigner_set_delayed_payment_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1990         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_base_key = val.into_rust();
1991 }
1992 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1993 #[no_mangle]
1994 pub extern "C" fn InMemorySigner_get_htlc_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1995         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_base_key;
1996         inner_val.as_ref()
1997 }
1998 /// Holder HTLC secret key used in commitment transaction HTLC outputs.
1999 #[no_mangle]
2000 pub extern "C" fn InMemorySigner_set_htlc_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
2001         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_base_key = val.into_rust();
2002 }
2003 /// Commitment seed.
2004 #[no_mangle]
2005 pub extern "C" fn InMemorySigner_get_commitment_seed(this_ptr: &InMemorySigner) -> *const [u8; 32] {
2006         let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_seed;
2007         inner_val
2008 }
2009 /// Commitment seed.
2010 #[no_mangle]
2011 pub extern "C" fn InMemorySigner_set_commitment_seed(this_ptr: &mut InMemorySigner, mut val: crate::c_types::ThirtyTwoBytes) {
2012         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_seed = val.data;
2013 }
2014 /// Get a string which allows debug introspection of a InMemorySigner object
2015 pub extern "C" fn InMemorySigner_debug_str_void(o: *const c_void) -> Str {
2016         alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::InMemorySigner }).into()}
2017 impl Clone for InMemorySigner {
2018         fn clone(&self) -> Self {
2019                 Self {
2020                         inner: if <*mut nativeInMemorySigner>::is_null(self.inner) { core::ptr::null_mut() } else {
2021                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2022                         is_owned: true,
2023                 }
2024         }
2025 }
2026 #[allow(unused)]
2027 /// Used only if an object of this type is returned as a trait impl by a method
2028 pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void {
2029         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInMemorySigner)).clone() })) as *mut c_void
2030 }
2031 #[no_mangle]
2032 /// Creates a copy of the InMemorySigner
2033 pub extern "C" fn InMemorySigner_clone(orig: &InMemorySigner) -> InMemorySigner {
2034         orig.clone()
2035 }
2036 /// Creates a new [`InMemorySigner`].
2037 #[must_use]
2038 #[no_mangle]
2039 pub extern "C" fn InMemorySigner_new(mut funding_key: crate::c_types::SecretKey, mut revocation_base_key: crate::c_types::SecretKey, mut payment_key: crate::c_types::SecretKey, mut delayed_payment_base_key: crate::c_types::SecretKey, mut htlc_base_key: crate::c_types::SecretKey, mut commitment_seed: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes, mut rand_bytes_unique_start: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::InMemorySigner {
2040         let mut ret = lightning::sign::InMemorySigner::new(secp256k1::global::SECP256K1, funding_key.into_rust(), revocation_base_key.into_rust(), payment_key.into_rust(), delayed_payment_base_key.into_rust(), htlc_base_key.into_rust(), commitment_seed.data, channel_value_satoshis, channel_keys_id.data, rand_bytes_unique_start.data);
2041         crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2042 }
2043
2044 /// Returns the counterparty's pubkeys.
2045 ///
2046 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2047 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2048 ///
2049 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2050 #[must_use]
2051 #[no_mangle]
2052 pub extern "C" fn InMemorySigner_counterparty_pubkeys(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
2053         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_pubkeys();
2054         let mut local_ret = crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::chan_utils::ChannelPublicKeys<>) as *mut _ }, is_owned: false };
2055         local_ret
2056 }
2057
2058 /// Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
2059 /// transactions, i.e., the amount of time that we have to wait to recover our funds if we
2060 /// broadcast a transaction.
2061 ///
2062 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2063 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2064 #[must_use]
2065 #[no_mangle]
2066 pub extern "C" fn InMemorySigner_counterparty_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_u16Z {
2067         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_selected_contest_delay();
2068         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u16Z::None } else { crate::c_types::derived::COption_u16Z::Some( { ret.unwrap() }) };
2069         local_ret
2070 }
2071
2072 /// Returns the `contest_delay` value specified by us and applied on transactions broadcastable
2073 /// by our counterparty, i.e., the amount of time that they have to wait to recover their funds
2074 /// if they broadcast a transaction.
2075 ///
2076 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2077 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2078 #[must_use]
2079 #[no_mangle]
2080 pub extern "C" fn InMemorySigner_holder_selected_contest_delay(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_u16Z {
2081         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.holder_selected_contest_delay();
2082         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u16Z::None } else { crate::c_types::derived::COption_u16Z::Some( { ret.unwrap() }) };
2083         local_ret
2084 }
2085
2086 /// Returns whether the holder is the initiator.
2087 ///
2088 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2089 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2090 #[must_use]
2091 #[no_mangle]
2092 pub extern "C" fn InMemorySigner_is_outbound(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::COption_boolZ {
2093         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
2094         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_boolZ::None } else { crate::c_types::derived::COption_boolZ::Some( { ret.unwrap() }) };
2095         local_ret
2096 }
2097
2098 /// Funding outpoint
2099 ///
2100 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2101 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2102 ///
2103 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2104 #[must_use]
2105 #[no_mangle]
2106 pub extern "C" fn InMemorySigner_funding_outpoint(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::chain::transaction::OutPoint {
2107         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
2108         let mut local_ret = crate::lightning::chain::transaction::OutPoint { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::chain::transaction::OutPoint<>) as *mut _ }, is_owned: false };
2109         local_ret
2110 }
2111
2112 /// Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
2113 /// building transactions.
2114 ///
2115 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2116 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2117 ///
2118 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2119 #[must_use]
2120 #[no_mangle]
2121 pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
2122         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_channel_parameters();
2123         let mut local_ret = crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _ }, is_owned: false };
2124         local_ret
2125 }
2126
2127 /// Returns the channel type features of the channel parameters. Should be helpful for
2128 /// determining a channel's category, i. e. legacy/anchors/taproot/etc.
2129 ///
2130 /// Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
2131 /// In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
2132 ///
2133 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2134 #[must_use]
2135 #[no_mangle]
2136 pub extern "C" fn InMemorySigner_channel_type_features(this_arg: &crate::lightning::sign::InMemorySigner) -> crate::lightning::ln::features::ChannelTypeFeatures {
2137         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_type_features();
2138         let mut local_ret = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false };
2139         local_ret
2140 }
2141
2142 /// Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
2143 /// by `descriptor`, returning the witness stack for the input.
2144 ///
2145 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
2146 /// is not spending the outpoint described by [`descriptor.outpoint`],
2147 /// or if an output descriptor `script_pubkey` does not match the one we can spend.
2148 ///
2149 /// [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
2150 #[must_use]
2151 #[no_mangle]
2152 pub extern "C" fn InMemorySigner_sign_counterparty_payment_input(this_arg: &crate::lightning::sign::InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::lightning::sign::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CResult_WitnessNoneZ {
2153         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_counterparty_payment_input(&spend_tx.into_bitcoin(), input_idx, descriptor.get_native_ref(), secp256k1::global::SECP256K1);
2154         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Witness::from_bitcoin(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2155         local_ret
2156 }
2157
2158 /// Sign the single input of `spend_tx` at index `input_idx` which spends the output
2159 /// described by `descriptor`, returning the witness stack for the input.
2160 ///
2161 /// Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
2162 /// is not spending the outpoint described by [`descriptor.outpoint`], does not have a
2163 /// sequence set to [`descriptor.to_self_delay`], or if an output descriptor
2164 /// `script_pubkey` does not match the one we can spend.
2165 ///
2166 /// [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
2167 /// [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
2168 #[must_use]
2169 #[no_mangle]
2170 pub extern "C" fn InMemorySigner_sign_dynamic_p2wsh_input(this_arg: &crate::lightning::sign::InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::lightning::sign::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CResult_WitnessNoneZ {
2171         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_dynamic_p2wsh_input(&spend_tx.into_bitcoin(), input_idx, descriptor.get_native_ref(), secp256k1::global::SECP256K1);
2172         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Witness::from_bitcoin(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2173         local_ret
2174 }
2175
2176 impl From<nativeInMemorySigner> for crate::lightning::sign::EntropySource {
2177         fn from(obj: nativeInMemorySigner) -> Self {
2178                 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2179                 let mut ret = InMemorySigner_as_EntropySource(&rust_obj);
2180                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2181                 core::mem::forget(rust_obj);
2182                 ret.free = Some(InMemorySigner_free_void);
2183                 ret
2184         }
2185 }
2186 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2187 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2188 #[no_mangle]
2189 pub extern "C" fn InMemorySigner_as_EntropySource(this_arg: &InMemorySigner) -> crate::lightning::sign::EntropySource {
2190         crate::lightning::sign::EntropySource {
2191                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2192                 free: None,
2193                 get_secure_random_bytes: InMemorySigner_EntropySource_get_secure_random_bytes,
2194         }
2195 }
2196
2197 #[must_use]
2198 extern "C" fn InMemorySigner_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2199         let mut ret = <nativeInMemorySigner as lightning::sign::EntropySource>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2200         crate::c_types::ThirtyTwoBytes { data: ret }
2201 }
2202
2203 impl From<nativeInMemorySigner> for crate::lightning::sign::ChannelSigner {
2204         fn from(obj: nativeInMemorySigner) -> Self {
2205                 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2206                 let mut ret = InMemorySigner_as_ChannelSigner(&rust_obj);
2207                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2208                 core::mem::forget(rust_obj);
2209                 ret.free = Some(InMemorySigner_free_void);
2210                 ret
2211         }
2212 }
2213 /// Constructs a new ChannelSigner which calls the relevant methods on this_arg.
2214 /// This copies the `inner` pointer in this_arg and thus the returned ChannelSigner must be freed before this_arg is
2215 #[no_mangle]
2216 pub extern "C" fn InMemorySigner_as_ChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ChannelSigner {
2217         crate::lightning::sign::ChannelSigner {
2218                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2219                 free: None,
2220                 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2221                 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2222                 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2223                 validate_counterparty_revocation: InMemorySigner_ChannelSigner_validate_counterparty_revocation,
2224
2225                 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2226                 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2227                 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2228                 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2229         }
2230 }
2231
2232 #[must_use]
2233 extern "C" fn InMemorySigner_ChannelSigner_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey {
2234         let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::get_per_commitment_point(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, secp256k1::global::SECP256K1);
2235         crate::c_types::PublicKey::from_rust(&ret)
2236 }
2237 #[must_use]
2238 extern "C" fn InMemorySigner_ChannelSigner_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
2239         let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::release_commitment_secret(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx);
2240         crate::c_types::ThirtyTwoBytes { data: ret }
2241 }
2242 #[must_use]
2243 extern "C" fn InMemorySigner_ChannelSigner_validate_holder_commitment(this_arg: *const c_void, holder_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction, mut outbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_NoneNoneZ {
2244         let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.into_rust().drain(..) { local_outbound_htlc_preimages.push( { ::lightning::ln::types::PaymentPreimage(item.data) }); };
2245         let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::validate_holder_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, holder_tx.get_native_ref(), local_outbound_htlc_preimages);
2246         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2247         local_ret
2248 }
2249 #[must_use]
2250 extern "C" fn InMemorySigner_ChannelSigner_validate_counterparty_revocation(this_arg: *const c_void, mut idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ {
2251         let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::validate_counterparty_revocation(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *secret}[..]).unwrap());
2252         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2253         local_ret
2254 }
2255 #[must_use]
2256 extern "C" fn InMemorySigner_ChannelSigner_pubkeys(this_arg: *const c_void) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
2257         let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::pubkeys(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2258         crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::chan_utils::ChannelPublicKeys<>) as *mut _) }, is_owned: false }
2259 }
2260 extern "C" fn InMemorySigner_ChannelSigner_set_pubkeys(trait_self_arg: &ChannelSigner) {
2261         // This is a bit race-y in the general case, but for our specific use-cases today, we're safe
2262         // Specifically, we must ensure that the first time we're called it can never be in parallel
2263         if unsafe { &*trait_self_arg.pubkeys.get() }.inner.is_null() {
2264                 *unsafe { &mut *(&*(trait_self_arg as *const ChannelSigner)).pubkeys.get() } = InMemorySigner_ChannelSigner_pubkeys(trait_self_arg.this_arg).into();
2265         }
2266 }
2267 #[must_use]
2268 extern "C" fn InMemorySigner_ChannelSigner_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2269         let mut ret = <nativeInMemorySigner as lightning::sign::ChannelSigner>::channel_keys_id(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
2270         crate::c_types::ThirtyTwoBytes { data: ret }
2271 }
2272 extern "C" fn InMemorySigner_ChannelSigner_provide_channel_parameters(this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
2273         <nativeInMemorySigner as lightning::sign::ChannelSigner>::provide_channel_parameters(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, channel_parameters.get_native_ref())
2274 }
2275
2276 impl From<nativeInMemorySigner> for crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2277         fn from(obj: nativeInMemorySigner) -> Self {
2278                 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2279                 let mut ret = InMemorySigner_as_EcdsaChannelSigner(&rust_obj);
2280                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2281                 core::mem::forget(rust_obj);
2282                 ret.free = Some(InMemorySigner_free_void);
2283                 ret
2284         }
2285 }
2286 /// Constructs a new EcdsaChannelSigner which calls the relevant methods on this_arg.
2287 /// This copies the `inner` pointer in this_arg and thus the returned EcdsaChannelSigner must be freed before this_arg is
2288 #[no_mangle]
2289 pub extern "C" fn InMemorySigner_as_EcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2290         crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2291                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2292                 free: None,
2293                 sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
2294                 sign_holder_commitment: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment,
2295                 sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
2296                 sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
2297                 sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
2298                 sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
2299                 sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
2300                 sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
2301                 sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
2302                 ChannelSigner: crate::lightning::sign::ChannelSigner {
2303                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2304                         free: None,
2305                         get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2306                         release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2307                         validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2308                         validate_counterparty_revocation: InMemorySigner_ChannelSigner_validate_counterparty_revocation,
2309
2310                         pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2311                         set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2312                         channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2313                         provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2314                 },
2315         }
2316 }
2317
2318 #[must_use]
2319 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::CommitmentTransaction, mut inbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ, mut outbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ {
2320         let mut local_inbound_htlc_preimages = Vec::new(); for mut item in inbound_htlc_preimages.into_rust().drain(..) { local_inbound_htlc_preimages.push( { ::lightning::ln::types::PaymentPreimage(item.data) }); };
2321         let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.into_rust().drain(..) { local_outbound_htlc_preimages.push( { ::lightning::ln::types::PaymentPreimage(item.data) }); };
2322         let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_counterparty_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), local_inbound_htlc_preimages, local_outbound_htlc_preimages, secp256k1::global::SECP256K1);
2323         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::ECDSASignature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::ECDSASignature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2324         local_ret
2325 }
2326 #[must_use]
2327 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_commitment(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2328         let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_holder_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), secp256k1::global::SECP256K1);
2329         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2330         local_ret
2331 }
2332 #[must_use]
2333 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output(this_arg: *const c_void, mut justice_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_key: *const [u8; 32]) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2334         let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_justice_revoked_output(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &justice_tx.into_bitcoin(), input, amount, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), secp256k1::global::SECP256K1);
2335         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2336         local_ret
2337 }
2338 #[must_use]
2339 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc(this_arg: *const c_void, mut justice_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2340         let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_justice_revoked_htlc(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &justice_tx.into_bitcoin(), input, amount, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), htlc.get_native_ref(), secp256k1::global::SECP256K1);
2341         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2342         local_ret
2343 }
2344 #[must_use]
2345 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, htlc_descriptor: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2346         let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_holder_htlc_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &htlc_tx.into_bitcoin(), input, htlc_descriptor.get_native_ref(), secp256k1::global::SECP256K1);
2347         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2348         local_ret
2349 }
2350 #[must_use]
2351 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: crate::c_types::PublicKey, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2352         let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_counterparty_htlc_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &htlc_tx.into_bitcoin(), input, amount, &per_commitment_point.into_rust(), htlc.get_native_ref(), secp256k1::global::SECP256K1);
2353         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2354         local_ret
2355 }
2356 #[must_use]
2357 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_closing_transaction(this_arg: *const c_void, closing_tx: &crate::lightning::ln::chan_utils::ClosingTransaction) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2358         let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_closing_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, closing_tx.get_native_ref(), secp256k1::global::SECP256K1);
2359         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2360         local_ret
2361 }
2362 #[must_use]
2363 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input(this_arg: *const c_void, mut anchor_tx: crate::c_types::Transaction, mut input: usize) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2364         let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_holder_anchor_input(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &anchor_tx.into_bitcoin(), input, secp256k1::global::SECP256K1);
2365         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2366         local_ret
2367 }
2368 #[must_use]
2369 extern "C" fn InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2370         let mut ret = <nativeInMemorySigner as lightning::sign::ecdsa::EcdsaChannelSigner>::sign_channel_announcement_with_funding_key(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, msg.get_native_ref(), secp256k1::global::SECP256K1);
2371         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2372         local_ret
2373 }
2374
2375 impl From<nativeInMemorySigner> for crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2376         fn from(obj: nativeInMemorySigner) -> Self {
2377                 let rust_obj = crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
2378                 let mut ret = InMemorySigner_as_WriteableEcdsaChannelSigner(&rust_obj);
2379                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2380                 core::mem::forget(rust_obj);
2381                 ret.free = Some(InMemorySigner_free_void);
2382                 ret
2383         }
2384 }
2385 /// Constructs a new WriteableEcdsaChannelSigner which calls the relevant methods on this_arg.
2386 /// This copies the `inner` pointer in this_arg and thus the returned WriteableEcdsaChannelSigner must be freed before this_arg is
2387 #[no_mangle]
2388 pub extern "C" fn InMemorySigner_as_WriteableEcdsaChannelSigner(this_arg: &InMemorySigner) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2389         crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2390                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2391                 free: None,
2392                 EcdsaChannelSigner: crate::lightning::sign::ecdsa::EcdsaChannelSigner {
2393                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2394                         free: None,
2395                         sign_counterparty_commitment: InMemorySigner_EcdsaChannelSigner_sign_counterparty_commitment,
2396                         sign_holder_commitment: InMemorySigner_EcdsaChannelSigner_sign_holder_commitment,
2397                         sign_justice_revoked_output: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_output,
2398                         sign_justice_revoked_htlc: InMemorySigner_EcdsaChannelSigner_sign_justice_revoked_htlc,
2399                         sign_holder_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_holder_htlc_transaction,
2400                         sign_counterparty_htlc_transaction: InMemorySigner_EcdsaChannelSigner_sign_counterparty_htlc_transaction,
2401                         sign_closing_transaction: InMemorySigner_EcdsaChannelSigner_sign_closing_transaction,
2402                         sign_holder_anchor_input: InMemorySigner_EcdsaChannelSigner_sign_holder_anchor_input,
2403                         sign_channel_announcement_with_funding_key: InMemorySigner_EcdsaChannelSigner_sign_channel_announcement_with_funding_key,
2404                         ChannelSigner: crate::lightning::sign::ChannelSigner {
2405                                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2406                                 free: None,
2407                                 get_per_commitment_point: InMemorySigner_ChannelSigner_get_per_commitment_point,
2408                                 release_commitment_secret: InMemorySigner_ChannelSigner_release_commitment_secret,
2409                                 validate_holder_commitment: InMemorySigner_ChannelSigner_validate_holder_commitment,
2410                                 validate_counterparty_revocation: InMemorySigner_ChannelSigner_validate_counterparty_revocation,
2411
2412                                 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true }.into(),
2413                                 set_pubkeys: Some(InMemorySigner_ChannelSigner_set_pubkeys),
2414                                 channel_keys_id: InMemorySigner_ChannelSigner_channel_keys_id,
2415                                 provide_channel_parameters: InMemorySigner_ChannelSigner_provide_channel_parameters,
2416                         },
2417                 },
2418                 write: InMemorySigner_write_void,
2419                 cloned: Some(WriteableEcdsaChannelSigner_InMemorySigner_cloned),
2420         }
2421 }
2422
2423 extern "C" fn WriteableEcdsaChannelSigner_InMemorySigner_cloned(new_obj: &mut crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner) {
2424         new_obj.this_arg = InMemorySigner_clone_void(new_obj.this_arg);
2425         new_obj.free = Some(InMemorySigner_free_void);
2426         new_obj.EcdsaChannelSigner.this_arg = new_obj.this_arg;
2427         new_obj.EcdsaChannelSigner.free = None;
2428         new_obj.EcdsaChannelSigner.ChannelSigner.this_arg = new_obj.this_arg;
2429         new_obj.EcdsaChannelSigner.ChannelSigner.free = None;
2430 }
2431
2432 #[no_mangle]
2433 /// Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
2434 pub extern "C" fn InMemorySigner_write(obj: &crate::lightning::sign::InMemorySigner) -> crate::c_types::derived::CVec_u8Z {
2435         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2436 }
2437 #[allow(unused)]
2438 pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2439         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) })
2440 }
2441 #[no_mangle]
2442 /// Read a InMemorySigner from a byte array, created by InMemorySigner_write
2443 pub extern "C" fn InMemorySigner_read(ser: crate::c_types::u8slice, arg: crate::lightning::sign::EntropySource) -> crate::c_types::derived::CResult_InMemorySignerDecodeErrorZ {
2444         let arg_conv = arg;
2445         let res: Result<lightning::sign::InMemorySigner, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
2446         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2447         local_res
2448 }
2449
2450 use lightning::sign::KeysManager as nativeKeysManagerImport;
2451 pub(crate) type nativeKeysManager = nativeKeysManagerImport;
2452
2453 /// Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a
2454 /// 32-byte seed for use as a BIP 32 extended key and derives keys from that.
2455 ///
2456 /// Your `node_id` is seed/0'.
2457 /// Unilateral closes may use seed/1'.
2458 /// Cooperative closes may use seed/2'.
2459 /// The two close keys may be needed to claim on-chain funds!
2460 ///
2461 /// This struct cannot be used for nodes that wish to support receiving phantom payments;
2462 /// [`PhantomKeysManager`] must be used instead.
2463 ///
2464 /// Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
2465 /// previously issued invoices and attempts to pay previous invoices will fail.
2466 #[must_use]
2467 #[repr(C)]
2468 pub struct KeysManager {
2469         /// A pointer to the opaque Rust object.
2470
2471         /// Nearly everywhere, inner must be non-null, however in places where
2472         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2473         pub inner: *mut nativeKeysManager,
2474         /// Indicates that this is the only struct which contains the same pointer.
2475
2476         /// Rust functions which take ownership of an object provided via an argument require
2477         /// this to be true and invalidate the object pointed to by inner.
2478         pub is_owned: bool,
2479 }
2480
2481 impl Drop for KeysManager {
2482         fn drop(&mut self) {
2483                 if self.is_owned && !<*mut nativeKeysManager>::is_null(self.inner) {
2484                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2485                 }
2486         }
2487 }
2488 /// Frees any resources used by the KeysManager, if is_owned is set and inner is non-NULL.
2489 #[no_mangle]
2490 pub extern "C" fn KeysManager_free(this_obj: KeysManager) { }
2491 #[allow(unused)]
2492 /// Used only if an object of this type is returned as a trait impl by a method
2493 pub(crate) extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) {
2494         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeKeysManager) };
2495 }
2496 #[allow(unused)]
2497 impl KeysManager {
2498         pub(crate) fn get_native_ref(&self) -> &'static nativeKeysManager {
2499                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2500         }
2501         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeKeysManager {
2502                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2503         }
2504         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2505         pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager {
2506                 assert!(self.is_owned);
2507                 let ret = ObjOps::untweak_ptr(self.inner);
2508                 self.inner = core::ptr::null_mut();
2509                 ret
2510         }
2511 }
2512 /// Constructs a [`KeysManager`] from a 32-byte seed. If the seed is in some way biased (e.g.,
2513 /// your CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
2514 /// `starting_time` isn't strictly required to actually be a time, but it must absolutely,
2515 /// without a doubt, be unique to this instance. ie if you start multiple times with the same
2516 /// `seed`, `starting_time` must be unique to each run. Thus, the easiest way to achieve this
2517 /// is to simply use the current time (with very high precision).
2518 ///
2519 /// The `seed` MUST be backed up safely prior to use so that the keys can be re-created, however,
2520 /// obviously, `starting_time` should be unique every time you reload the library - it is only
2521 /// used to generate new ephemeral key data (which will be stored by the individual channel if
2522 /// necessary).
2523 ///
2524 /// Note that the seed is required to recover certain on-chain funds independent of
2525 /// [`ChannelMonitor`] data, though a current copy of [`ChannelMonitor`] data is also required
2526 /// for any channel, and some on-chain during-closing funds.
2527 ///
2528 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
2529 #[must_use]
2530 #[no_mangle]
2531 pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32) -> crate::lightning::sign::KeysManager {
2532         let mut ret = lightning::sign::KeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos);
2533         crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2534 }
2535
2536 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
2537 #[must_use]
2538 #[no_mangle]
2539 pub extern "C" fn KeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::KeysManager) -> crate::c_types::SecretKey {
2540         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
2541         crate::c_types::SecretKey::from_rust(ret)
2542 }
2543
2544 /// Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
2545 #[must_use]
2546 #[no_mangle]
2547 pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &crate::lightning::sign::KeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::lightning::sign::InMemorySigner {
2548         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2549         crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2550 }
2551
2552 /// Signs the given [`PartiallySignedTransaction`] which spends the given [`SpendableOutputDescriptor`]s.
2553 /// The resulting inputs will be finalized and the PSBT will be ready for broadcast if there
2554 /// are no other inputs that need signing.
2555 ///
2556 /// Returns `Err(())` if the PSBT is missing a descriptor or if we fail to sign.
2557 ///
2558 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
2559 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
2560 #[must_use]
2561 #[no_mangle]
2562 pub extern "C" fn KeysManager_sign_spendable_outputs_psbt(this_arg: &crate::lightning::sign::KeysManager, mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut psbt: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ {
2563         let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2564         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign_spendable_outputs_psbt(&local_descriptors.iter().collect::<Vec<_>>()[..], ::bitcoin::psbt::PartiallySignedTransaction::deserialize(psbt.as_slice()).expect("Invalid PSBT format"), secp256k1::global::SECP256K1);
2565         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.serialize().into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2566         local_ret
2567 }
2568
2569 impl From<nativeKeysManager> for crate::lightning::sign::EntropySource {
2570         fn from(obj: nativeKeysManager) -> Self {
2571                 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2572                 let mut ret = KeysManager_as_EntropySource(&rust_obj);
2573                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2574                 core::mem::forget(rust_obj);
2575                 ret.free = Some(KeysManager_free_void);
2576                 ret
2577         }
2578 }
2579 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2580 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2581 #[no_mangle]
2582 pub extern "C" fn KeysManager_as_EntropySource(this_arg: &KeysManager) -> crate::lightning::sign::EntropySource {
2583         crate::lightning::sign::EntropySource {
2584                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2585                 free: None,
2586                 get_secure_random_bytes: KeysManager_EntropySource_get_secure_random_bytes,
2587         }
2588 }
2589
2590 #[must_use]
2591 extern "C" fn KeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2592         let mut ret = <nativeKeysManager as lightning::sign::EntropySource>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2593         crate::c_types::ThirtyTwoBytes { data: ret }
2594 }
2595
2596 impl From<nativeKeysManager> for crate::lightning::sign::NodeSigner {
2597         fn from(obj: nativeKeysManager) -> Self {
2598                 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2599                 let mut ret = KeysManager_as_NodeSigner(&rust_obj);
2600                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2601                 core::mem::forget(rust_obj);
2602                 ret.free = Some(KeysManager_free_void);
2603                 ret
2604         }
2605 }
2606 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2607 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2608 #[no_mangle]
2609 pub extern "C" fn KeysManager_as_NodeSigner(this_arg: &KeysManager) -> crate::lightning::sign::NodeSigner {
2610         crate::lightning::sign::NodeSigner {
2611                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2612                 free: None,
2613                 get_inbound_payment_key_material: KeysManager_NodeSigner_get_inbound_payment_key_material,
2614                 get_node_id: KeysManager_NodeSigner_get_node_id,
2615                 ecdh: KeysManager_NodeSigner_ecdh,
2616                 sign_invoice: KeysManager_NodeSigner_sign_invoice,
2617                 sign_bolt12_invoice_request: KeysManager_NodeSigner_sign_bolt12_invoice_request,
2618                 sign_bolt12_invoice: KeysManager_NodeSigner_sign_bolt12_invoice,
2619                 sign_gossip_message: KeysManager_NodeSigner_sign_gossip_message,
2620         }
2621 }
2622
2623 #[must_use]
2624 extern "C" fn KeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2625         let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2626         crate::c_types::ThirtyTwoBytes { data: ret.0 }
2627 }
2628 #[must_use]
2629 extern "C" fn KeysManager_NodeSigner_get_node_id(this_arg: *const c_void, mut recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ {
2630         let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::get_node_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native());
2631         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2632         local_ret
2633 }
2634 #[must_use]
2635 extern "C" fn KeysManager_NodeSigner_ecdh(this_arg: *const c_void, mut recipient: crate::lightning::sign::Recipient, mut other_key: crate::c_types::PublicKey, mut tweak: crate::c_types::derived::COption_BigEndianScalarZ) -> crate::c_types::derived::CResult_ThirtyTwoBytesNoneZ {
2636         let mut local_tweak_base = { /*tweak*/ let tweak_opt = tweak; if tweak_opt.is_none() { None } else { Some({ { { tweak_opt.take() }.into_rust() }})} }; let mut local_tweak = local_tweak_base.as_ref();
2637         let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::ecdh(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native(), &other_key.into_rust(), local_tweak);
2638         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.secret_bytes() } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2639         local_ret
2640 }
2641 #[must_use]
2642 extern "C" fn KeysManager_NodeSigner_sign_invoice(this_arg: *const c_void, mut hrp_bytes: crate::c_types::u8slice, mut invoice_data: crate::c_types::derived::CVec_U5Z, mut recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ {
2643         let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2644         let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::sign_invoice(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, hrp_bytes.to_slice(), &local_invoice_data[..], recipient.into_native());
2645         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::RecoverableSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2646         local_ret
2647 }
2648 #[must_use]
2649 extern "C" fn KeysManager_NodeSigner_sign_bolt12_invoice_request(this_arg: *const c_void, invoice_request: &crate::lightning::offers::invoice_request::UnsignedInvoiceRequest) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ {
2650         let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::sign_bolt12_invoice_request(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, invoice_request.get_native_ref());
2651         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SchnorrSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2652         local_ret
2653 }
2654 #[must_use]
2655 extern "C" fn KeysManager_NodeSigner_sign_bolt12_invoice(this_arg: *const c_void, invoice: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ {
2656         let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::sign_bolt12_invoice(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, invoice.get_native_ref());
2657         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SchnorrSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2658         local_ret
2659 }
2660 #[must_use]
2661 extern "C" fn KeysManager_NodeSigner_sign_gossip_message(this_arg: *const c_void, mut msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2662         let mut ret = <nativeKeysManager as lightning::sign::NodeSigner>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, msg.into_native());
2663         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2664         local_ret
2665 }
2666
2667 impl From<nativeKeysManager> for crate::lightning::sign::OutputSpender {
2668         fn from(obj: nativeKeysManager) -> Self {
2669                 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2670                 let mut ret = KeysManager_as_OutputSpender(&rust_obj);
2671                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2672                 core::mem::forget(rust_obj);
2673                 ret.free = Some(KeysManager_free_void);
2674                 ret
2675         }
2676 }
2677 /// Constructs a new OutputSpender which calls the relevant methods on this_arg.
2678 /// This copies the `inner` pointer in this_arg and thus the returned OutputSpender must be freed before this_arg is
2679 #[no_mangle]
2680 pub extern "C" fn KeysManager_as_OutputSpender(this_arg: &KeysManager) -> crate::lightning::sign::OutputSpender {
2681         crate::lightning::sign::OutputSpender {
2682                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2683                 free: None,
2684                 spend_spendable_outputs: KeysManager_OutputSpender_spend_spendable_outputs,
2685         }
2686 }
2687
2688 #[must_use]
2689 extern "C" fn KeysManager_OutputSpender_spend_spendable_outputs(this_arg: *const c_void, mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut outputs: crate::c_types::derived::CVec_TxOutZ, mut change_destination_script: crate::c_types::derived::CVec_u8Z, mut feerate_sat_per_1000_weight: u32, mut locktime: crate::c_types::derived::COption_u32Z) -> crate::c_types::derived::CResult_TransactionNoneZ {
2690         let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2691         let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2692         let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus({ locktime_opt.take() }) }})} };
2693         let mut ret = <nativeKeysManager as lightning::sign::OutputSpender>::spend_spendable_outputs(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, &local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::ScriptBuf::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime, secp256k1::global::SECP256K1);
2694         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Transaction::from_bitcoin(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2695         local_ret
2696 }
2697
2698 impl From<nativeKeysManager> for crate::lightning::sign::SignerProvider {
2699         fn from(obj: nativeKeysManager) -> Self {
2700                 let rust_obj = crate::lightning::sign::KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2701                 let mut ret = KeysManager_as_SignerProvider(&rust_obj);
2702                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2703                 core::mem::forget(rust_obj);
2704                 ret.free = Some(KeysManager_free_void);
2705                 ret
2706         }
2707 }
2708 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2709 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2710 #[no_mangle]
2711 pub extern "C" fn KeysManager_as_SignerProvider(this_arg: &KeysManager) -> crate::lightning::sign::SignerProvider {
2712         crate::lightning::sign::SignerProvider {
2713                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2714                 free: None,
2715                 generate_channel_keys_id: KeysManager_SignerProvider_generate_channel_keys_id,
2716                 derive_channel_signer: KeysManager_SignerProvider_derive_channel_signer,
2717                 read_chan_signer: KeysManager_SignerProvider_read_chan_signer,
2718                 get_destination_script: KeysManager_SignerProvider_get_destination_script,
2719                 get_shutdown_scriptpubkey: KeysManager_SignerProvider_get_shutdown_scriptpubkey,
2720         }
2721 }
2722
2723 #[must_use]
2724 extern "C" fn KeysManager_SignerProvider_generate_channel_keys_id(this_arg: *const c_void, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: crate::c_types::U128) -> crate::c_types::ThirtyTwoBytes {
2725         let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::generate_channel_keys_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, inbound, channel_value_satoshis, user_channel_id.into());
2726         crate::c_types::ThirtyTwoBytes { data: ret }
2727 }
2728 #[must_use]
2729 extern "C" fn KeysManager_SignerProvider_derive_channel_signer(this_arg: *const c_void, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2730         let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::derive_channel_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, channel_value_satoshis, channel_keys_id.data);
2731         Into::into(ret)
2732 }
2733 #[must_use]
2734 extern "C" fn KeysManager_SignerProvider_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ {
2735         let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, reader.to_slice());
2736         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { Into::into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2737         local_ret
2738 }
2739 #[must_use]
2740 extern "C" fn KeysManager_SignerProvider_get_destination_script(this_arg: *const c_void, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ {
2741         let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, channel_keys_id.data);
2742         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.to_bytes().into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2743         local_ret
2744 }
2745 #[must_use]
2746 extern "C" fn KeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2747         let mut ret = <nativeKeysManager as lightning::sign::SignerProvider>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
2748         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2749         local_ret
2750 }
2751
2752
2753 use lightning::sign::PhantomKeysManager as nativePhantomKeysManagerImport;
2754 pub(crate) type nativePhantomKeysManager = nativePhantomKeysManagerImport;
2755
2756 /// Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
2757 /// payments.
2758 ///
2759 /// A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
2760 /// paid to one of multiple nodes. This works because we encode the invoice route hints such that
2761 /// LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
2762 /// itself without ever needing to forward to this fake node.
2763 ///
2764 /// Phantom node payments are useful for load balancing between multiple LDK nodes. They also
2765 /// provide some fault tolerance, because payers will automatically retry paying other provided
2766 /// nodes in the case that one node goes down.
2767 ///
2768 /// Note that multi-path payments are not supported in phantom invoices for security reasons.
2769 /// Switching between this struct and [`KeysManager`] will invalidate any previously issued
2770 /// invoices and attempts to pay previous invoices will fail.
2771 #[must_use]
2772 #[repr(C)]
2773 pub struct PhantomKeysManager {
2774         /// A pointer to the opaque Rust object.
2775
2776         /// Nearly everywhere, inner must be non-null, however in places where
2777         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2778         pub inner: *mut nativePhantomKeysManager,
2779         /// Indicates that this is the only struct which contains the same pointer.
2780
2781         /// Rust functions which take ownership of an object provided via an argument require
2782         /// this to be true and invalidate the object pointed to by inner.
2783         pub is_owned: bool,
2784 }
2785
2786 impl Drop for PhantomKeysManager {
2787         fn drop(&mut self) {
2788                 if self.is_owned && !<*mut nativePhantomKeysManager>::is_null(self.inner) {
2789                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2790                 }
2791         }
2792 }
2793 /// Frees any resources used by the PhantomKeysManager, if is_owned is set and inner is non-NULL.
2794 #[no_mangle]
2795 pub extern "C" fn PhantomKeysManager_free(this_obj: PhantomKeysManager) { }
2796 #[allow(unused)]
2797 /// Used only if an object of this type is returned as a trait impl by a method
2798 pub(crate) extern "C" fn PhantomKeysManager_free_void(this_ptr: *mut c_void) {
2799         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePhantomKeysManager) };
2800 }
2801 #[allow(unused)]
2802 impl PhantomKeysManager {
2803         pub(crate) fn get_native_ref(&self) -> &'static nativePhantomKeysManager {
2804                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2805         }
2806         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomKeysManager {
2807                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2808         }
2809         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2810         pub(crate) fn take_inner(mut self) -> *mut nativePhantomKeysManager {
2811                 assert!(self.is_owned);
2812                 let ret = ObjOps::untweak_ptr(self.inner);
2813                 self.inner = core::ptr::null_mut();
2814                 ret
2815         }
2816 }
2817 impl From<nativePhantomKeysManager> for crate::lightning::sign::EntropySource {
2818         fn from(obj: nativePhantomKeysManager) -> Self {
2819                 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2820                 let mut ret = PhantomKeysManager_as_EntropySource(&rust_obj);
2821                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2822                 core::mem::forget(rust_obj);
2823                 ret.free = Some(PhantomKeysManager_free_void);
2824                 ret
2825         }
2826 }
2827 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
2828 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
2829 #[no_mangle]
2830 pub extern "C" fn PhantomKeysManager_as_EntropySource(this_arg: &PhantomKeysManager) -> crate::lightning::sign::EntropySource {
2831         crate::lightning::sign::EntropySource {
2832                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2833                 free: None,
2834                 get_secure_random_bytes: PhantomKeysManager_EntropySource_get_secure_random_bytes,
2835         }
2836 }
2837
2838 #[must_use]
2839 extern "C" fn PhantomKeysManager_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2840         let mut ret = <nativePhantomKeysManager as lightning::sign::EntropySource>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2841         crate::c_types::ThirtyTwoBytes { data: ret }
2842 }
2843
2844 impl From<nativePhantomKeysManager> for crate::lightning::sign::NodeSigner {
2845         fn from(obj: nativePhantomKeysManager) -> Self {
2846                 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2847                 let mut ret = PhantomKeysManager_as_NodeSigner(&rust_obj);
2848                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2849                 core::mem::forget(rust_obj);
2850                 ret.free = Some(PhantomKeysManager_free_void);
2851                 ret
2852         }
2853 }
2854 /// Constructs a new NodeSigner which calls the relevant methods on this_arg.
2855 /// This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
2856 #[no_mangle]
2857 pub extern "C" fn PhantomKeysManager_as_NodeSigner(this_arg: &PhantomKeysManager) -> crate::lightning::sign::NodeSigner {
2858         crate::lightning::sign::NodeSigner {
2859                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2860                 free: None,
2861                 get_inbound_payment_key_material: PhantomKeysManager_NodeSigner_get_inbound_payment_key_material,
2862                 get_node_id: PhantomKeysManager_NodeSigner_get_node_id,
2863                 ecdh: PhantomKeysManager_NodeSigner_ecdh,
2864                 sign_invoice: PhantomKeysManager_NodeSigner_sign_invoice,
2865                 sign_bolt12_invoice_request: PhantomKeysManager_NodeSigner_sign_bolt12_invoice_request,
2866                 sign_bolt12_invoice: PhantomKeysManager_NodeSigner_sign_bolt12_invoice,
2867                 sign_gossip_message: PhantomKeysManager_NodeSigner_sign_gossip_message,
2868         }
2869 }
2870
2871 #[must_use]
2872 extern "C" fn PhantomKeysManager_NodeSigner_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2873         let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2874         crate::c_types::ThirtyTwoBytes { data: ret.0 }
2875 }
2876 #[must_use]
2877 extern "C" fn PhantomKeysManager_NodeSigner_get_node_id(this_arg: *const c_void, mut recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ {
2878         let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::get_node_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native());
2879         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2880         local_ret
2881 }
2882 #[must_use]
2883 extern "C" fn PhantomKeysManager_NodeSigner_ecdh(this_arg: *const c_void, mut recipient: crate::lightning::sign::Recipient, mut other_key: crate::c_types::PublicKey, mut tweak: crate::c_types::derived::COption_BigEndianScalarZ) -> crate::c_types::derived::CResult_ThirtyTwoBytesNoneZ {
2884         let mut local_tweak_base = { /*tweak*/ let tweak_opt = tweak; if tweak_opt.is_none() { None } else { Some({ { { tweak_opt.take() }.into_rust() }})} }; let mut local_tweak = local_tweak_base.as_ref();
2885         let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::ecdh(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native(), &other_key.into_rust(), local_tweak);
2886         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.secret_bytes() } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2887         local_ret
2888 }
2889 #[must_use]
2890 extern "C" fn PhantomKeysManager_NodeSigner_sign_invoice(this_arg: *const c_void, mut hrp_bytes: crate::c_types::u8slice, mut invoice_data: crate::c_types::derived::CVec_U5Z, mut recipient: crate::lightning::sign::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ {
2891         let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2892         let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::sign_invoice(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, hrp_bytes.to_slice(), &local_invoice_data[..], recipient.into_native());
2893         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::RecoverableSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2894         local_ret
2895 }
2896 #[must_use]
2897 extern "C" fn PhantomKeysManager_NodeSigner_sign_bolt12_invoice_request(this_arg: *const c_void, invoice_request: &crate::lightning::offers::invoice_request::UnsignedInvoiceRequest) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ {
2898         let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::sign_bolt12_invoice_request(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, invoice_request.get_native_ref());
2899         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SchnorrSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2900         local_ret
2901 }
2902 #[must_use]
2903 extern "C" fn PhantomKeysManager_NodeSigner_sign_bolt12_invoice(this_arg: *const c_void, invoice: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ {
2904         let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::sign_bolt12_invoice(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, invoice.get_native_ref());
2905         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SchnorrSignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2906         local_ret
2907 }
2908 #[must_use]
2909 extern "C" fn PhantomKeysManager_NodeSigner_sign_gossip_message(this_arg: *const c_void, mut msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ {
2910         let mut ret = <nativePhantomKeysManager as lightning::sign::NodeSigner>::sign_gossip_message(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, msg.into_native());
2911         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ECDSASignature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2912         local_ret
2913 }
2914
2915 impl From<nativePhantomKeysManager> for crate::lightning::sign::OutputSpender {
2916         fn from(obj: nativePhantomKeysManager) -> Self {
2917                 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2918                 let mut ret = PhantomKeysManager_as_OutputSpender(&rust_obj);
2919                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2920                 core::mem::forget(rust_obj);
2921                 ret.free = Some(PhantomKeysManager_free_void);
2922                 ret
2923         }
2924 }
2925 /// Constructs a new OutputSpender which calls the relevant methods on this_arg.
2926 /// This copies the `inner` pointer in this_arg and thus the returned OutputSpender must be freed before this_arg is
2927 #[no_mangle]
2928 pub extern "C" fn PhantomKeysManager_as_OutputSpender(this_arg: &PhantomKeysManager) -> crate::lightning::sign::OutputSpender {
2929         crate::lightning::sign::OutputSpender {
2930                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2931                 free: None,
2932                 spend_spendable_outputs: PhantomKeysManager_OutputSpender_spend_spendable_outputs,
2933         }
2934 }
2935
2936 #[must_use]
2937 extern "C" fn PhantomKeysManager_OutputSpender_spend_spendable_outputs(this_arg: *const c_void, mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut outputs: crate::c_types::derived::CVec_TxOutZ, mut change_destination_script: crate::c_types::derived::CVec_u8Z, mut feerate_sat_per_1000_weight: u32, mut locktime: crate::c_types::derived::COption_u32Z) -> crate::c_types::derived::CResult_TransactionNoneZ {
2938         let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2939         let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2940         let mut local_locktime = { /*locktime*/ let locktime_opt = locktime; if locktime_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::locktime::absolute::LockTime::from_consensus({ locktime_opt.take() }) }})} };
2941         let mut ret = <nativePhantomKeysManager as lightning::sign::OutputSpender>::spend_spendable_outputs(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, &local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::ScriptBuf::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, local_locktime, secp256k1::global::SECP256K1);
2942         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Transaction::from_bitcoin(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2943         local_ret
2944 }
2945
2946 impl From<nativePhantomKeysManager> for crate::lightning::sign::SignerProvider {
2947         fn from(obj: nativePhantomKeysManager) -> Self {
2948                 let rust_obj = crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2949                 let mut ret = PhantomKeysManager_as_SignerProvider(&rust_obj);
2950                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
2951                 core::mem::forget(rust_obj);
2952                 ret.free = Some(PhantomKeysManager_free_void);
2953                 ret
2954         }
2955 }
2956 /// Constructs a new SignerProvider which calls the relevant methods on this_arg.
2957 /// This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
2958 #[no_mangle]
2959 pub extern "C" fn PhantomKeysManager_as_SignerProvider(this_arg: &PhantomKeysManager) -> crate::lightning::sign::SignerProvider {
2960         crate::lightning::sign::SignerProvider {
2961                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2962                 free: None,
2963                 generate_channel_keys_id: PhantomKeysManager_SignerProvider_generate_channel_keys_id,
2964                 derive_channel_signer: PhantomKeysManager_SignerProvider_derive_channel_signer,
2965                 read_chan_signer: PhantomKeysManager_SignerProvider_read_chan_signer,
2966                 get_destination_script: PhantomKeysManager_SignerProvider_get_destination_script,
2967                 get_shutdown_scriptpubkey: PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey,
2968         }
2969 }
2970
2971 #[must_use]
2972 extern "C" fn PhantomKeysManager_SignerProvider_generate_channel_keys_id(this_arg: *const c_void, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: crate::c_types::U128) -> crate::c_types::ThirtyTwoBytes {
2973         let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::generate_channel_keys_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, inbound, channel_value_satoshis, user_channel_id.into());
2974         crate::c_types::ThirtyTwoBytes { data: ret }
2975 }
2976 #[must_use]
2977 extern "C" fn PhantomKeysManager_SignerProvider_derive_channel_signer(this_arg: *const c_void, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::ecdsa::WriteableEcdsaChannelSigner {
2978         let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::derive_channel_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, channel_value_satoshis, channel_keys_id.data);
2979         Into::into(ret)
2980 }
2981 #[must_use]
2982 extern "C" fn PhantomKeysManager_SignerProvider_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ {
2983         let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, reader.to_slice());
2984         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { Into::into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2985         local_ret
2986 }
2987 #[must_use]
2988 extern "C" fn PhantomKeysManager_SignerProvider_get_destination_script(this_arg: *const c_void, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_CVec_u8ZNoneZ {
2989         let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::get_destination_script(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, channel_keys_id.data);
2990         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.to_bytes().into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2991         local_ret
2992 }
2993 #[must_use]
2994 extern "C" fn PhantomKeysManager_SignerProvider_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::c_types::derived::CResult_ShutdownScriptNoneZ {
2995         let mut ret = <nativePhantomKeysManager as lightning::sign::SignerProvider>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2996         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2997         local_ret
2998 }
2999
3000 /// Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
3001 /// that is shared across all nodes that intend to participate in [phantom node payments]
3002 /// together.
3003 ///
3004 /// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
3005 /// `starting_time_nanos`.
3006 ///
3007 /// `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
3008 /// same across restarts, or else inbound payments may fail.
3009 ///
3010 /// [phantom node payments]: PhantomKeysManager
3011 #[must_use]
3012 #[no_mangle]
3013 pub extern "C" fn PhantomKeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32, cross_node_seed: *const [u8; 32]) -> crate::lightning::sign::PhantomKeysManager {
3014         let mut ret = lightning::sign::PhantomKeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos, unsafe { &*cross_node_seed});
3015         crate::lightning::sign::PhantomKeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
3016 }
3017
3018 /// See [`KeysManager::derive_channel_keys`] for documentation on this method.
3019 #[must_use]
3020 #[no_mangle]
3021 pub extern "C" fn PhantomKeysManager_derive_channel_keys(this_arg: &crate::lightning::sign::PhantomKeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::lightning::sign::InMemorySigner {
3022         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
3023         crate::lightning::sign::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
3024 }
3025
3026 /// Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
3027 #[must_use]
3028 #[no_mangle]
3029 pub extern "C" fn PhantomKeysManager_get_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
3030         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_node_secret_key();
3031         crate::c_types::SecretKey::from_rust(ret)
3032 }
3033
3034 /// Gets the \"node_id\" secret key of the phantom node used to sign invoices, decode the
3035 /// last-hop onion data, etc.
3036 #[must_use]
3037 #[no_mangle]
3038 pub extern "C" fn PhantomKeysManager_get_phantom_node_secret_key(this_arg: &crate::lightning::sign::PhantomKeysManager) -> crate::c_types::SecretKey {
3039         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_phantom_node_secret_key();
3040         crate::c_types::SecretKey::from_rust(ret)
3041 }
3042
3043
3044 use lightning::sign::RandomBytes as nativeRandomBytesImport;
3045 pub(crate) type nativeRandomBytes = nativeRandomBytesImport;
3046
3047 /// An implementation of [`EntropySource`] using ChaCha20.
3048 #[must_use]
3049 #[repr(C)]
3050 pub struct RandomBytes {
3051         /// A pointer to the opaque Rust object.
3052
3053         /// Nearly everywhere, inner must be non-null, however in places where
3054         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
3055         pub inner: *mut nativeRandomBytes,
3056         /// Indicates that this is the only struct which contains the same pointer.
3057
3058         /// Rust functions which take ownership of an object provided via an argument require
3059         /// this to be true and invalidate the object pointed to by inner.
3060         pub is_owned: bool,
3061 }
3062
3063 impl Drop for RandomBytes {
3064         fn drop(&mut self) {
3065                 if self.is_owned && !<*mut nativeRandomBytes>::is_null(self.inner) {
3066                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
3067                 }
3068         }
3069 }
3070 /// Frees any resources used by the RandomBytes, if is_owned is set and inner is non-NULL.
3071 #[no_mangle]
3072 pub extern "C" fn RandomBytes_free(this_obj: RandomBytes) { }
3073 #[allow(unused)]
3074 /// Used only if an object of this type is returned as a trait impl by a method
3075 pub(crate) extern "C" fn RandomBytes_free_void(this_ptr: *mut c_void) {
3076         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRandomBytes) };
3077 }
3078 #[allow(unused)]
3079 impl RandomBytes {
3080         pub(crate) fn get_native_ref(&self) -> &'static nativeRandomBytes {
3081                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
3082         }
3083         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRandomBytes {
3084                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
3085         }
3086         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
3087         pub(crate) fn take_inner(mut self) -> *mut nativeRandomBytes {
3088                 assert!(self.is_owned);
3089                 let ret = ObjOps::untweak_ptr(self.inner);
3090                 self.inner = core::ptr::null_mut();
3091                 ret
3092         }
3093 }
3094 /// Get a string which allows debug introspection of a RandomBytes object
3095 pub extern "C" fn RandomBytes_debug_str_void(o: *const c_void) -> Str {
3096         alloc::format!("{:?}", unsafe { o as *const crate::lightning::sign::RandomBytes }).into()}
3097 /// Creates a new instance using the given seed.
3098 #[must_use]
3099 #[no_mangle]
3100 pub extern "C" fn RandomBytes_new(mut seed: crate::c_types::ThirtyTwoBytes) -> crate::lightning::sign::RandomBytes {
3101         let mut ret = lightning::sign::RandomBytes::new(seed.data);
3102         crate::lightning::sign::RandomBytes { inner: ObjOps::heap_alloc(ret), is_owned: true }
3103 }
3104
3105 impl From<nativeRandomBytes> for crate::lightning::sign::EntropySource {
3106         fn from(obj: nativeRandomBytes) -> Self {
3107                 let rust_obj = crate::lightning::sign::RandomBytes { inner: ObjOps::heap_alloc(obj), is_owned: true };
3108                 let mut ret = RandomBytes_as_EntropySource(&rust_obj);
3109                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
3110                 core::mem::forget(rust_obj);
3111                 ret.free = Some(RandomBytes_free_void);
3112                 ret
3113         }
3114 }
3115 /// Constructs a new EntropySource which calls the relevant methods on this_arg.
3116 /// This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
3117 #[no_mangle]
3118 pub extern "C" fn RandomBytes_as_EntropySource(this_arg: &RandomBytes) -> crate::lightning::sign::EntropySource {
3119         crate::lightning::sign::EntropySource {
3120                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
3121                 free: None,
3122                 get_secure_random_bytes: RandomBytes_EntropySource_get_secure_random_bytes,
3123         }
3124 }
3125
3126 #[must_use]
3127 extern "C" fn RandomBytes_EntropySource_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
3128         let mut ret = <nativeRandomBytes as lightning::sign::EntropySource>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeRandomBytes) }, );
3129         crate::c_types::ThirtyTwoBytes { data: ret }
3130 }
3131