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