Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / keysinterface.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! keysinterface provides keys into rust-lightning and defines some useful enums which describe
10 //! spendable on-chain outputs which the user owns and is responsible for using just as any other
11 //! on-chain output which is theirs.
12
13 use alloc::str::FromStr;
14 use core::ffi::c_void;
15 use core::convert::Infallible;
16 use bitcoin::hashes::Hash;
17 use crate::c_types::*;
18 #[cfg(feature="no-std")]
19 use alloc::{vec::Vec, boxed::Box};
20
21
22 use lightning::chain::keysinterface::DelayedPaymentOutputDescriptor as nativeDelayedPaymentOutputDescriptorImport;
23 pub(crate) type nativeDelayedPaymentOutputDescriptor = nativeDelayedPaymentOutputDescriptorImport;
24
25 /// Information about a spendable output to a P2WSH script. See
26 /// SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this.
27 #[must_use]
28 #[repr(C)]
29 pub struct DelayedPaymentOutputDescriptor {
30         /// A pointer to the opaque Rust object.
31
32         /// Nearly everywhere, inner must be non-null, however in places where
33         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
34         pub inner: *mut nativeDelayedPaymentOutputDescriptor,
35         /// Indicates that this is the only struct which contains the same pointer.
36
37         /// Rust functions which take ownership of an object provided via an argument require
38         /// this to be true and invalidate the object pointed to by inner.
39         pub is_owned: bool,
40 }
41
42 impl Drop for DelayedPaymentOutputDescriptor {
43         fn drop(&mut self) {
44                 if self.is_owned && !<*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) {
45                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
46                 }
47         }
48 }
49 /// Frees any resources used by the DelayedPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
50 #[no_mangle]
51 pub extern "C" fn DelayedPaymentOutputDescriptor_free(this_obj: DelayedPaymentOutputDescriptor) { }
52 #[allow(unused)]
53 /// Used only if an object of this type is returned as a trait impl by a method
54 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
55         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDelayedPaymentOutputDescriptor); }
56 }
57 #[allow(unused)]
58 impl DelayedPaymentOutputDescriptor {
59         pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentOutputDescriptor {
60                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
61         }
62         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentOutputDescriptor {
63                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
64         }
65         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
66         pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentOutputDescriptor {
67                 assert!(self.is_owned);
68                 let ret = ObjOps::untweak_ptr(self.inner);
69                 self.inner = core::ptr::null_mut();
70                 ret
71         }
72 }
73 /// The outpoint which is spendable
74 #[no_mangle]
75 pub extern "C" fn DelayedPaymentOutputDescriptor_get_outpoint(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
76         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
77         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 }
78 }
79 /// The outpoint which is spendable
80 #[no_mangle]
81 pub extern "C" fn DelayedPaymentOutputDescriptor_set_outpoint(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
82         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
83 }
84 /// Per commitment point to derive delayed_payment_key by key holder
85 #[no_mangle]
86 pub extern "C" fn DelayedPaymentOutputDescriptor_get_per_commitment_point(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
87         let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
88         crate::c_types::PublicKey::from_rust(&inner_val)
89 }
90 /// Per commitment point to derive delayed_payment_key by key holder
91 #[no_mangle]
92 pub extern "C" fn DelayedPaymentOutputDescriptor_set_per_commitment_point(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
93         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
94 }
95 /// The nSequence value which must be set in the spending input to satisfy the OP_CSV in
96 /// the witness_script.
97 #[no_mangle]
98 pub extern "C" fn DelayedPaymentOutputDescriptor_get_to_self_delay(this_ptr: &DelayedPaymentOutputDescriptor) -> u16 {
99         let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay;
100         *inner_val
101 }
102 /// The nSequence value which must be set in the spending input to satisfy the OP_CSV in
103 /// the witness_script.
104 #[no_mangle]
105 pub extern "C" fn DelayedPaymentOutputDescriptor_set_to_self_delay(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u16) {
106         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val;
107 }
108 /// The output which is referenced by the given outpoint
109 ///
110 /// Returns a copy of the field.
111 #[no_mangle]
112 pub extern "C" fn DelayedPaymentOutputDescriptor_get_output(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::TxOut {
113         let mut inner_val = this_ptr.get_native_mut_ref().output.clone();
114         crate::c_types::TxOut::from_rust(inner_val)
115 }
116 /// The output which is referenced by the given outpoint
117 #[no_mangle]
118 pub extern "C" fn DelayedPaymentOutputDescriptor_set_output(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
119         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
120 }
121 /// The revocation point specific to the commitment transaction which was broadcast. Used to
122 /// derive the witnessScript for this output.
123 #[no_mangle]
124 pub extern "C" fn DelayedPaymentOutputDescriptor_get_revocation_pubkey(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
125         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_pubkey;
126         crate::c_types::PublicKey::from_rust(&inner_val)
127 }
128 /// The revocation point specific to the commitment transaction which was broadcast. Used to
129 /// derive the witnessScript for this output.
130 #[no_mangle]
131 pub extern "C" fn DelayedPaymentOutputDescriptor_set_revocation_pubkey(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
132         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_pubkey = val.into_rust();
133 }
134 /// Arbitrary identification information returned by a call to
135 /// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in
136 /// the channel to spend the output.
137 #[no_mangle]
138 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &DelayedPaymentOutputDescriptor) -> *const [u8; 32] {
139         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
140         inner_val
141 }
142 /// Arbitrary identification information returned by a call to
143 /// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in
144 /// the channel to spend the output.
145 #[no_mangle]
146 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
147         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
148 }
149 /// The value of the channel which this output originated from, possibly indirectly.
150 #[no_mangle]
151 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &DelayedPaymentOutputDescriptor) -> u64 {
152         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
153         *inner_val
154 }
155 /// The value of the channel which this output originated from, possibly indirectly.
156 #[no_mangle]
157 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u64) {
158         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
159 }
160 /// Constructs a new DelayedPaymentOutputDescriptor given each field
161 #[must_use]
162 #[no_mangle]
163 pub extern "C" fn DelayedPaymentOutputDescriptor_new(mut outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut per_commitment_point_arg: crate::c_types::PublicKey, mut to_self_delay_arg: u16, mut output_arg: crate::c_types::TxOut, mut revocation_pubkey_arg: crate::c_types::PublicKey, mut channel_keys_id_arg: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis_arg: u64) -> DelayedPaymentOutputDescriptor {
164         DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeDelayedPaymentOutputDescriptor {
165                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
166                 per_commitment_point: per_commitment_point_arg.into_rust(),
167                 to_self_delay: to_self_delay_arg,
168                 output: output_arg.into_rust(),
169                 revocation_pubkey: revocation_pubkey_arg.into_rust(),
170                 channel_keys_id: channel_keys_id_arg.data,
171                 channel_value_satoshis: channel_value_satoshis_arg,
172         }), is_owned: true }
173 }
174 impl Clone for DelayedPaymentOutputDescriptor {
175         fn clone(&self) -> Self {
176                 Self {
177                         inner: if <*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
178                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
179                         is_owned: true,
180                 }
181         }
182 }
183 #[allow(unused)]
184 /// Used only if an object of this type is returned as a trait impl by a method
185 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
186         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void
187 }
188 #[no_mangle]
189 /// Creates a copy of the DelayedPaymentOutputDescriptor
190 pub extern "C" fn DelayedPaymentOutputDescriptor_clone(orig: &DelayedPaymentOutputDescriptor) -> DelayedPaymentOutputDescriptor {
191         orig.clone()
192 }
193 /// Checks if two DelayedPaymentOutputDescriptors contain equal inner contents.
194 /// This ignores pointers and is_owned flags and looks at the values in fields.
195 /// Two objects with NULL inner values will be considered "equal" here.
196 #[no_mangle]
197 pub extern "C" fn DelayedPaymentOutputDescriptor_eq(a: &DelayedPaymentOutputDescriptor, b: &DelayedPaymentOutputDescriptor) -> bool {
198         if a.inner == b.inner { return true; }
199         if a.inner.is_null() || b.inner.is_null() { return false; }
200         if a.get_native_ref() == b.get_native_ref() { true } else { false }
201 }
202 #[no_mangle]
203 /// Serialize the DelayedPaymentOutputDescriptor object into a byte array which can be read by DelayedPaymentOutputDescriptor_read
204 pub extern "C" fn DelayedPaymentOutputDescriptor_write(obj: &crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
205         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
206 }
207 #[no_mangle]
208 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
209         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentOutputDescriptor) })
210 }
211 #[no_mangle]
212 /// Read a DelayedPaymentOutputDescriptor from a byte array, created by DelayedPaymentOutputDescriptor_write
213 pub extern "C" fn DelayedPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentOutputDescriptorDecodeErrorZ {
214         let res: Result<lightning::chain::keysinterface::DelayedPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
215         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
216         local_res
217 }
218
219 use lightning::chain::keysinterface::StaticPaymentOutputDescriptor as nativeStaticPaymentOutputDescriptorImport;
220 pub(crate) type nativeStaticPaymentOutputDescriptor = nativeStaticPaymentOutputDescriptorImport;
221
222 /// Information about a spendable output to our \"payment key\". See
223 /// SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this.
224 #[must_use]
225 #[repr(C)]
226 pub struct StaticPaymentOutputDescriptor {
227         /// A pointer to the opaque Rust object.
228
229         /// Nearly everywhere, inner must be non-null, however in places where
230         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
231         pub inner: *mut nativeStaticPaymentOutputDescriptor,
232         /// Indicates that this is the only struct which contains the same pointer.
233
234         /// Rust functions which take ownership of an object provided via an argument require
235         /// this to be true and invalidate the object pointed to by inner.
236         pub is_owned: bool,
237 }
238
239 impl Drop for StaticPaymentOutputDescriptor {
240         fn drop(&mut self) {
241                 if self.is_owned && !<*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) {
242                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
243                 }
244         }
245 }
246 /// Frees any resources used by the StaticPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
247 #[no_mangle]
248 pub extern "C" fn StaticPaymentOutputDescriptor_free(this_obj: StaticPaymentOutputDescriptor) { }
249 #[allow(unused)]
250 /// Used only if an object of this type is returned as a trait impl by a method
251 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
252         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeStaticPaymentOutputDescriptor); }
253 }
254 #[allow(unused)]
255 impl StaticPaymentOutputDescriptor {
256         pub(crate) fn get_native_ref(&self) -> &'static nativeStaticPaymentOutputDescriptor {
257                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
258         }
259         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeStaticPaymentOutputDescriptor {
260                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
261         }
262         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
263         pub(crate) fn take_inner(mut self) -> *mut nativeStaticPaymentOutputDescriptor {
264                 assert!(self.is_owned);
265                 let ret = ObjOps::untweak_ptr(self.inner);
266                 self.inner = core::ptr::null_mut();
267                 ret
268         }
269 }
270 /// The outpoint which is spendable
271 #[no_mangle]
272 pub extern "C" fn StaticPaymentOutputDescriptor_get_outpoint(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
273         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
274         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::chain::transaction::OutPoint<>) as *mut _) }, is_owned: false }
275 }
276 /// The outpoint which is spendable
277 #[no_mangle]
278 pub extern "C" fn StaticPaymentOutputDescriptor_set_outpoint(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
279         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
280 }
281 /// The output which is referenced by the given outpoint
282 ///
283 /// Returns a copy of the field.
284 #[no_mangle]
285 pub extern "C" fn StaticPaymentOutputDescriptor_get_output(this_ptr: &StaticPaymentOutputDescriptor) -> crate::c_types::TxOut {
286         let mut inner_val = this_ptr.get_native_mut_ref().output.clone();
287         crate::c_types::TxOut::from_rust(inner_val)
288 }
289 /// The output which is referenced by the given outpoint
290 #[no_mangle]
291 pub extern "C" fn StaticPaymentOutputDescriptor_set_output(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
292         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
293 }
294 /// Arbitrary identification information returned by a call to
295 /// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in
296 /// the channel to spend the output.
297 #[no_mangle]
298 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &StaticPaymentOutputDescriptor) -> *const [u8; 32] {
299         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
300         inner_val
301 }
302 /// Arbitrary identification information returned by a call to
303 /// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in
304 /// the channel to spend the output.
305 #[no_mangle]
306 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
307         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
308 }
309 /// The value of the channel which this transactions spends.
310 #[no_mangle]
311 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &StaticPaymentOutputDescriptor) -> u64 {
312         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
313         *inner_val
314 }
315 /// The value of the channel which this transactions spends.
316 #[no_mangle]
317 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: u64) {
318         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
319 }
320 /// Constructs a new StaticPaymentOutputDescriptor given each field
321 #[must_use]
322 #[no_mangle]
323 pub extern "C" fn StaticPaymentOutputDescriptor_new(mut outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut output_arg: crate::c_types::TxOut, mut channel_keys_id_arg: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis_arg: u64) -> StaticPaymentOutputDescriptor {
324         StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeStaticPaymentOutputDescriptor {
325                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
326                 output: output_arg.into_rust(),
327                 channel_keys_id: channel_keys_id_arg.data,
328                 channel_value_satoshis: channel_value_satoshis_arg,
329         }), is_owned: true }
330 }
331 impl Clone for StaticPaymentOutputDescriptor {
332         fn clone(&self) -> Self {
333                 Self {
334                         inner: if <*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { core::ptr::null_mut() } else {
335                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
336                         is_owned: true,
337                 }
338         }
339 }
340 #[allow(unused)]
341 /// Used only if an object of this type is returned as a trait impl by a method
342 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
343         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void
344 }
345 #[no_mangle]
346 /// Creates a copy of the StaticPaymentOutputDescriptor
347 pub extern "C" fn StaticPaymentOutputDescriptor_clone(orig: &StaticPaymentOutputDescriptor) -> StaticPaymentOutputDescriptor {
348         orig.clone()
349 }
350 /// Checks if two StaticPaymentOutputDescriptors contain equal inner contents.
351 /// This ignores pointers and is_owned flags and looks at the values in fields.
352 /// Two objects with NULL inner values will be considered "equal" here.
353 #[no_mangle]
354 pub extern "C" fn StaticPaymentOutputDescriptor_eq(a: &StaticPaymentOutputDescriptor, b: &StaticPaymentOutputDescriptor) -> bool {
355         if a.inner == b.inner { return true; }
356         if a.inner.is_null() || b.inner.is_null() { return false; }
357         if a.get_native_ref() == b.get_native_ref() { true } else { false }
358 }
359 #[no_mangle]
360 /// Serialize the StaticPaymentOutputDescriptor object into a byte array which can be read by StaticPaymentOutputDescriptor_read
361 pub extern "C" fn StaticPaymentOutputDescriptor_write(obj: &crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
362         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
363 }
364 #[no_mangle]
365 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
366         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeStaticPaymentOutputDescriptor) })
367 }
368 #[no_mangle]
369 /// Read a StaticPaymentOutputDescriptor from a byte array, created by StaticPaymentOutputDescriptor_write
370 pub extern "C" fn StaticPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_StaticPaymentOutputDescriptorDecodeErrorZ {
371         let res: Result<lightning::chain::keysinterface::StaticPaymentOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
372         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
373         local_res
374 }
375 /// When on-chain outputs are created by rust-lightning (which our counterparty is not able to
376 /// claim at any point in the future) an event is generated which you must track and be able to
377 /// spend on-chain. The information needed to do this is provided in this enum, including the
378 /// outpoint describing which txid and output index is available, the full output which exists at
379 /// that txid/index, and any keys or other information required to sign.
380 #[derive(Clone)]
381 #[must_use]
382 #[repr(C)]
383 pub enum SpendableOutputDescriptor {
384         /// An output to a script which was provided via KeysInterface directly, either from
385         /// `get_destination_script()` or `get_shutdown_scriptpubkey()`, thus you should already know
386         /// how to spend it. No secret keys are provided as rust-lightning was never given any key.
387         /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
388         /// on-chain using the payment preimage or after it has timed out.
389         StaticOutput {
390                 /// The outpoint which is spendable
391                 outpoint: crate::lightning::chain::transaction::OutPoint,
392                 /// The output which is referenced by the given outpoint.
393                 output: crate::c_types::TxOut,
394         },
395         /// An output to a P2WSH script which can be spent with a single signature after a CSV delay.
396         ///
397         /// The witness in the spending input should be:
398         /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
399         ///
400         /// Note that the nSequence field in the spending input must be set to to_self_delay
401         /// (which means the transaction is not broadcastable until at least to_self_delay
402         /// blocks after the outpoint confirms).
403         ///
404         /// These are generally the result of a \"revocable\" output to us, spendable only by us unless
405         /// it is an output from an old state which we broadcast (which should never happen).
406         ///
407         /// To derive the delayed_payment key which is used to sign for this input, you must pass the
408         /// holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in
409         /// Sign::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to
410         /// chan_utils::derive_private_key. The public key can be generated without the secret key
411         /// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
412         /// Sign::pubkeys().
413         ///
414         /// To derive the revocation_pubkey provided here (which is used in the witness
415         /// script generation), you must pass the counterparty revocation_basepoint (which appears in the
416         /// call to Sign::ready_channel) and the provided per_commitment point
417         /// to chan_utils::derive_public_revocation_key.
418         ///
419         /// The witness script which is hashed and included in the output script_pubkey may be
420         /// regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey
421         /// (derived as above), and the to_self_delay contained here to
422         /// chan_utils::get_revokeable_redeemscript.
423         DelayedPaymentOutput(
424                 crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor),
425         /// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
426         /// corresponds to the public key in Sign::pubkeys().payment_point).
427         /// The witness in the spending input, is, thus, simply:
428         /// <BIP 143 signature> <payment key>
429         ///
430         /// These are generally the result of our counterparty having broadcast the current state,
431         /// allowing us to claim the non-HTLC-encumbered outputs immediately.
432         StaticPaymentOutput(
433                 crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor),
434 }
435 use lightning::chain::keysinterface::SpendableOutputDescriptor as SpendableOutputDescriptorImport;
436 pub(crate) type nativeSpendableOutputDescriptor = SpendableOutputDescriptorImport;
437
438 impl SpendableOutputDescriptor {
439         #[allow(unused)]
440         pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor {
441                 match self {
442                         SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
443                                 let mut outpoint_nonref = (*outpoint).clone();
444                                 let mut output_nonref = (*output).clone();
445                                 nativeSpendableOutputDescriptor::StaticOutput {
446                                         outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
447                                         output: output_nonref.into_rust(),
448                                 }
449                         },
450                         SpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
451                                 let mut a_nonref = (*a).clone();
452                                 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
453                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
454                                 )
455                         },
456                         SpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
457                                 let mut a_nonref = (*a).clone();
458                                 nativeSpendableOutputDescriptor::StaticPaymentOutput (
459                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
460                                 )
461                         },
462                 }
463         }
464         #[allow(unused)]
465         pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor {
466                 match self {
467                         SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
468                                 nativeSpendableOutputDescriptor::StaticOutput {
469                                         outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
470                                         output: output.into_rust(),
471                                 }
472                         },
473                         SpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
474                                 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
475                                         *unsafe { Box::from_raw(a.take_inner()) },
476                                 )
477                         },
478                         SpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
479                                 nativeSpendableOutputDescriptor::StaticPaymentOutput (
480                                         *unsafe { Box::from_raw(a.take_inner()) },
481                                 )
482                         },
483                 }
484         }
485         #[allow(unused)]
486         pub(crate) fn from_native(native: &nativeSpendableOutputDescriptor) -> Self {
487                 match native {
488                         nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
489                                 let mut outpoint_nonref = (*outpoint).clone();
490                                 let mut output_nonref = (*output).clone();
491                                 SpendableOutputDescriptor::StaticOutput {
492                                         outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true },
493                                         output: crate::c_types::TxOut::from_rust(output_nonref),
494                                 }
495                         },
496                         nativeSpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
497                                 let mut a_nonref = (*a).clone();
498                                 SpendableOutputDescriptor::DelayedPaymentOutput (
499                                         crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
500                                 )
501                         },
502                         nativeSpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
503                                 let mut a_nonref = (*a).clone();
504                                 SpendableOutputDescriptor::StaticPaymentOutput (
505                                         crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
506                                 )
507                         },
508                 }
509         }
510         #[allow(unused)]
511         pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self {
512                 match native {
513                         nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
514                                 SpendableOutputDescriptor::StaticOutput {
515                                         outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true },
516                                         output: crate::c_types::TxOut::from_rust(output),
517                                 }
518                         },
519                         nativeSpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
520                                 SpendableOutputDescriptor::DelayedPaymentOutput (
521                                         crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
522                                 )
523                         },
524                         nativeSpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
525                                 SpendableOutputDescriptor::StaticPaymentOutput (
526                                         crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
527                                 )
528                         },
529                 }
530         }
531 }
532 /// Frees any resources used by the SpendableOutputDescriptor
533 #[no_mangle]
534 pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { }
535 /// Creates a copy of the SpendableOutputDescriptor
536 #[no_mangle]
537 pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor {
538         orig.clone()
539 }
540 #[no_mangle]
541 /// Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
542 pub extern "C" fn SpendableOutputDescriptor_static_output(outpoint: crate::lightning::chain::transaction::OutPoint, output: crate::c_types::TxOut) -> SpendableOutputDescriptor {
543         SpendableOutputDescriptor::StaticOutput {
544                 outpoint,
545                 output,
546         }
547 }
548 #[no_mangle]
549 /// Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
550 pub extern "C" fn SpendableOutputDescriptor_delayed_payment_output(a: crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor) -> SpendableOutputDescriptor {
551         SpendableOutputDescriptor::DelayedPaymentOutput(a, )
552 }
553 #[no_mangle]
554 /// Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
555 pub extern "C" fn SpendableOutputDescriptor_static_payment_output(a: crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor) -> SpendableOutputDescriptor {
556         SpendableOutputDescriptor::StaticPaymentOutput(a, )
557 }
558 /// Checks if two SpendableOutputDescriptors contain equal inner contents.
559 /// This ignores pointers and is_owned flags and looks at the values in fields.
560 #[no_mangle]
561 pub extern "C" fn SpendableOutputDescriptor_eq(a: &SpendableOutputDescriptor, b: &SpendableOutputDescriptor) -> bool {
562         if &a.to_native() == &b.to_native() { true } else { false }
563 }
564 #[no_mangle]
565 /// Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
566 pub extern "C" fn SpendableOutputDescriptor_write(obj: &crate::lightning::chain::keysinterface::SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
567         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
568 }
569 #[no_mangle]
570 /// Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
571 pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
572         let res: Result<lightning::chain::keysinterface::SpendableOutputDescriptor, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
573         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::keysinterface::SpendableOutputDescriptor::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
574         local_res
575 }
576 /// A trait to sign lightning channel transactions as described in BOLT 3.
577 ///
578 /// Signing services could be implemented on a hardware wallet. In this case,
579 /// the current Sign would be a front-end on top of a communication
580 /// channel connected to your secure device and lightning key material wouldn't
581 /// reside on a hot server. Nevertheless, a this deployment would still need
582 /// to trust the ChannelManager to avoid loss of funds as this latest component
583 /// could ask to sign commitment transaction with HTLCs paying to attacker pubkeys.
584 ///
585 /// A more secure iteration would be to use hashlock (or payment points) to pair
586 /// invoice/incoming HTLCs with outgoing HTLCs to implement a no-trust-ChannelManager
587 /// at the price of more state and computation on the hardware wallet side. In the future,
588 /// we are looking forward to design such interface.
589 ///
590 /// In any case, ChannelMonitor or fallback watchtowers are always going to be trusted
591 /// to act, as liveness and breach reply correctness are always going to be hard requirements
592 /// of LN security model, orthogonal of key management issues.
593 #[repr(C)]
594 pub struct BaseSign {
595         /// An opaque pointer which is passed to your function implementations as an argument.
596         /// This has no meaning in the LDK, and can be NULL or any other value.
597         pub this_arg: *mut c_void,
598         /// Gets the per-commitment point for a specific commitment number
599         ///
600         /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
601         #[must_use]
602         pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey,
603         /// Gets the commitment secret for a specific commitment number as part of the revocation process
604         ///
605         /// An external signer implementation should error here if the commitment was already signed
606         /// and should refuse to sign it in the future.
607         ///
608         /// May be called more than once for the same index.
609         ///
610         /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
611         #[must_use]
612         pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes,
613         /// Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
614         ///
615         /// This is required in order for the signer to make sure that releasing a commitment
616         /// secret won't leave us without a broadcastable holder transaction.
617         /// Policy checks should be implemented in this function, including checking the amount
618         /// sent to us and checking the HTLCs.
619         ///
620         /// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
621         /// A validating signer should ensure that an HTLC output is removed only when the matching
622         /// preimage is provided, or when the value to holder is restored.
623         ///
624         /// NOTE: all the relevant preimages will be provided, but there may also be additional
625         /// irrelevant or duplicate preimages.
626         #[must_use]
627         pub validate_holder_commitment: extern "C" fn (this_arg: *const c_void, holder_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction, preimages: crate::c_types::derived::CVec_PaymentPreimageZ) -> crate::c_types::derived::CResult_NoneNoneZ,
628         /// Gets the holder's channel public keys and basepoints
629         pub pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys,
630         /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns
631         /// Note that this takes a pointer to this object, not the this_ptr like other methods do
632         /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
633         pub set_pubkeys: Option<extern "C" fn(&BaseSign)>,
634         /// Gets an arbitrary identifier describing the set of keys which are provided back to you in
635         /// some SpendableOutputDescriptor types. This should be sufficient to identify this
636         /// Sign object uniquely and lookup or re-derive its keys.
637         #[must_use]
638         pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
639         /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
640         ///
641         /// Note that if signing fails or is rejected, the channel will be force-closed.
642         ///
643         /// Policy checks should be implemented in this function, including checking the amount
644         /// sent to us and checking the HTLCs.
645         ///
646         /// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
647         /// A validating signer should ensure that an HTLC output is removed only when the matching
648         /// preimage is provided, or when the value to holder is restored.
649         ///
650         /// NOTE: all the relevant preimages will be provided, but there may also be additional
651         /// irrelevant or duplicate preimages.
652         #[must_use]
653         pub sign_counterparty_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::CommitmentTransaction, preimages: crate::c_types::derived::CVec_PaymentPreimageZ) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ,
654         /// Validate the counterparty's revocation.
655         ///
656         /// This is required in order for the signer to make sure that the state has moved
657         /// forward and it is safe to sign the next counterparty commitment.
658         #[must_use]
659         pub validate_counterparty_revocation: extern "C" fn (this_arg: *const c_void, idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ,
660         /// Create a signatures for a holder's commitment transaction and its claiming HTLC transactions.
661         /// This will only ever be called with a non-revoked commitment_tx.  This will be called with the
662         /// latest commitment_tx when we initiate a force-close.
663         /// This will be called with the previous latest, just to get claiming HTLC signatures, if we are
664         /// reacting to a ChannelMonitor replica that decided to broadcast before it had been updated to
665         /// the latest.
666         /// This may be called multiple times for the same transaction.
667         ///
668         /// An external signer implementation should check that the commitment has not been revoked.
669         ///
670         /// May return Err if key derivation fails.  Callers, such as ChannelMonitor, will panic in such a case.
671         #[must_use]
672         pub sign_holder_commitment_and_htlcs: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ,
673         /// Create a signature for the given input in a transaction spending an HTLC transaction output
674         /// or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
675         ///
676         /// A justice transaction may claim multiple outputs at the same time if timelocks are
677         /// similar, but only a signature for the input at index `input` should be signed for here.
678         /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
679         /// to an upcoming timelock expiration.
680         ///
681         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
682         ///
683         /// per_commitment_key is revocation secret which was provided by our counterparty when they
684         /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
685         /// not allow the spending of any funds by itself (you need our holder revocation_secret to do
686         /// so).
687         #[must_use]
688         pub sign_justice_revoked_output: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32]) -> crate::c_types::derived::CResult_SignatureNoneZ,
689         /// Create a signature for the given input in a transaction spending a commitment transaction
690         /// HTLC output when our counterparty broadcasts an old state.
691         ///
692         /// A justice transaction may claim multiple outputs at the same time if timelocks are
693         /// similar, but only a signature for the input at index `input` should be signed for here.
694         /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
695         /// to an upcoming timelock expiration.
696         ///
697         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
698         ///
699         /// per_commitment_key is revocation secret which was provided by our counterparty when they
700         /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
701         /// not allow the spending of any funds by itself (you need our holder revocation_secret to do
702         /// so).
703         ///
704         /// htlc holds HTLC elements (hash, timelock), thus changing the format of the witness script
705         /// (which is committed to in the BIP 143 signatures).
706         #[must_use]
707         pub sign_justice_revoked_htlc: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ,
708         /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
709         /// transaction, either offered or received.
710         ///
711         /// Such a transaction may claim multiples offered outputs at same time if we know the
712         /// preimage for each when we create it, but only the input at index `input` should be
713         /// signed for here. It may be called multiple times for same output(s) if a fee-bump is
714         /// needed with regards to an upcoming timelock expiration.
715         ///
716         /// Witness_script is either a offered or received script as defined in BOLT3 for HTLC
717         /// outputs.
718         ///
719         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
720         ///
721         /// Per_commitment_point is the dynamic point corresponding to the channel state
722         /// detected onchain. It has been generated by our counterparty and is used to derive
723         /// channel state keys, which are then included in the witness script and committed to in the
724         /// BIP 143 signature.
725         #[must_use]
726         pub sign_counterparty_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_point: crate::c_types::PublicKey, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ,
727         /// Create a signature for a (proposed) closing transaction.
728         ///
729         /// Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
730         /// chosen to forgo their output as dust.
731         #[must_use]
732         pub sign_closing_transaction: extern "C" fn (this_arg: *const c_void, closing_tx: &crate::lightning::ln::chan_utils::ClosingTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ,
733         /// Computes the signature for a commitment transaction's anchor output used as an
734         /// input within `anchor_tx`, which spends the commitment transaction, at index `input`.
735         #[must_use]
736         pub sign_holder_anchor_input: extern "C" fn (this_arg: *const c_void, anchor_tx: crate::c_types::Transaction, input: usize) -> crate::c_types::derived::CResult_SignatureNoneZ,
737         /// Signs a channel announcement message with our funding key and our node secret key (aka
738         /// node_id or network_key), proving it comes from one of the channel participants.
739         ///
740         /// The first returned signature should be from our node secret key, the second from our
741         /// funding key.
742         ///
743         /// Note that if this fails or is rejected, the channel will not be publicly announced and
744         /// our counterparty may (though likely will not) close the channel on us for violating the
745         /// protocol.
746         #[must_use]
747         pub sign_channel_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_C2Tuple_SignatureSignatureZNoneZ,
748         /// Set the counterparty static channel data, including basepoints,
749         /// counterparty_selected/holder_selected_contest_delay and funding outpoint.
750         /// This is done as soon as the funding outpoint is known.  Since these are static channel data,
751         /// they MUST NOT be allowed to change to different values once set.
752         ///
753         /// channel_parameters.is_populated() MUST be true.
754         ///
755         /// We bind holder_selected_contest_delay late here for API convenience.
756         ///
757         /// Will be called before any signatures are applied.
758         pub ready_channel: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters),
759         /// Frees any resources associated with this object given its this_arg pointer.
760         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
761         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
762 }
763 unsafe impl Send for BaseSign {}
764 unsafe impl Sync for BaseSign {}
765 #[no_mangle]
766 pub(crate) extern "C" fn BaseSign_clone_fields(orig: &BaseSign) -> BaseSign {
767         BaseSign {
768                 this_arg: orig.this_arg,
769                 get_per_commitment_point: Clone::clone(&orig.get_per_commitment_point),
770                 release_commitment_secret: Clone::clone(&orig.release_commitment_secret),
771                 validate_holder_commitment: Clone::clone(&orig.validate_holder_commitment),
772                 pubkeys: Clone::clone(&orig.pubkeys),
773                 set_pubkeys: Clone::clone(&orig.set_pubkeys),
774                 channel_keys_id: Clone::clone(&orig.channel_keys_id),
775                 sign_counterparty_commitment: Clone::clone(&orig.sign_counterparty_commitment),
776                 validate_counterparty_revocation: Clone::clone(&orig.validate_counterparty_revocation),
777                 sign_holder_commitment_and_htlcs: Clone::clone(&orig.sign_holder_commitment_and_htlcs),
778                 sign_justice_revoked_output: Clone::clone(&orig.sign_justice_revoked_output),
779                 sign_justice_revoked_htlc: Clone::clone(&orig.sign_justice_revoked_htlc),
780                 sign_counterparty_htlc_transaction: Clone::clone(&orig.sign_counterparty_htlc_transaction),
781                 sign_closing_transaction: Clone::clone(&orig.sign_closing_transaction),
782                 sign_holder_anchor_input: Clone::clone(&orig.sign_holder_anchor_input),
783                 sign_channel_announcement: Clone::clone(&orig.sign_channel_announcement),
784                 ready_channel: Clone::clone(&orig.ready_channel),
785                 free: Clone::clone(&orig.free),
786         }
787 }
788
789 use lightning::chain::keysinterface::BaseSign as rustBaseSign;
790 impl rustBaseSign for BaseSign {
791         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
792                 let mut ret = (self.get_per_commitment_point)(self.this_arg, idx);
793                 ret.into_rust()
794         }
795         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
796                 let mut ret = (self.release_commitment_secret)(self.this_arg, idx);
797                 ret.data
798         }
799         fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
800                 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
801                 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());
802                 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)) })*/ })};
803                 local_ret
804         }
805         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
806                 if let Some(f) = self.set_pubkeys {
807                         (f)(&self);
808                 }
809                 self.pubkeys.get_native_ref()
810         }
811         fn channel_keys_id(&self) -> [u8; 32] {
812                 let mut ret = (self.channel_keys_id)(self.this_arg);
813                 ret.data
814         }
815         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>), ()> {
816                 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
817                 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());
818                 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)) })*/ })};
819                 local_ret
820         }
821         fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
822                 let mut ret = (self.validate_counterparty_revocation)(self.this_arg, idx, secret.as_ref());
823                 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)) })*/ })};
824                 local_ret
825         }
826         fn sign_holder_commitment_and_htlcs(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec<bitcoin::secp256k1::ecdsa::Signature>), ()> {
827                 let mut ret = (self.sign_holder_commitment_and_htlcs)(self.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false });
828                 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)) })*/ })};
829                 local_ret
830         }
831         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, ()> {
832                 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());
833                 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)) })*/ })};
834                 local_ret
835         }
836         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, ()> {
837                 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 });
838                 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)) })*/ })};
839                 local_ret
840         }
841         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, ()> {
842                 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 });
843                 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)) })*/ })};
844                 local_ret
845         }
846         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, ()> {
847                 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 });
848                 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)) })*/ })};
849                 local_ret
850         }
851         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, ()> {
852                 let mut ret = (self.sign_holder_anchor_input)(self.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
853                 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)) })*/ })};
854                 local_ret
855         }
856         fn sign_channel_announcement(&self, mut msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, bitcoin::secp256k1::ecdsa::Signature), ()> {
857                 let mut ret = (self.sign_channel_announcement)(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 });
858                 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_ret_0 = (orig_ret_0_0.into_rust(), orig_ret_0_1.into_rust()); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
859                 local_ret
860         }
861         fn ready_channel(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
862                 (self.ready_channel)(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 })
863         }
864 }
865
866 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
867 // directly as a Deref trait in higher-level structs:
868 impl core::ops::Deref for BaseSign {
869         type Target = Self;
870         fn deref(&self) -> &Self {
871                 self
872         }
873 }
874 /// Calls the free function if one is set
875 #[no_mangle]
876 pub extern "C" fn BaseSign_free(this_ptr: BaseSign) { }
877 impl Drop for BaseSign {
878         fn drop(&mut self) {
879                 if let Some(f) = self.free {
880                         f(self.this_arg);
881                 }
882         }
883 }
884 /// A cloneable signer.
885 ///
886 /// Although we require signers to be cloneable, it may be useful for developers to be able to use
887 /// signers in an un-sized way, for example as `dyn BaseSign`. Therefore we separate the Clone trait,
888 /// which implies Sized, into this derived trait.
889 #[repr(C)]
890 pub struct Sign {
891         /// An opaque pointer which is passed to your function implementations as an argument.
892         /// This has no meaning in the LDK, and can be NULL or any other value.
893         pub this_arg: *mut c_void,
894         /// Implementation of BaseSign for this object.
895         pub BaseSign: crate::lightning::chain::keysinterface::BaseSign,
896         /// Serialize the object into a byte array
897         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
898         /// Called, if set, after this Sign has been cloned into a duplicate object.
899         /// The new Sign is provided, and should be mutated as needed to perform a
900         /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
901         pub cloned: Option<extern "C" fn (new_Sign: &mut Sign)>,
902         /// Frees any resources associated with this object given its this_arg pointer.
903         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
904         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
905 }
906 unsafe impl Send for Sign {}
907 unsafe impl Sync for Sign {}
908 #[no_mangle]
909 pub(crate) extern "C" fn Sign_clone_fields(orig: &Sign) -> Sign {
910         Sign {
911                 this_arg: orig.this_arg,
912                 BaseSign: crate::lightning::chain::keysinterface::BaseSign_clone_fields(&orig.BaseSign),
913                 write: Clone::clone(&orig.write),
914                 cloned: Clone::clone(&orig.cloned),
915                 free: Clone::clone(&orig.free),
916         }
917 }
918 impl lightning::chain::keysinterface::BaseSign for Sign {
919         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
920                 let mut ret = (self.BaseSign.get_per_commitment_point)(self.BaseSign.this_arg, idx);
921                 ret.into_rust()
922         }
923         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
924                 let mut ret = (self.BaseSign.release_commitment_secret)(self.BaseSign.this_arg, idx);
925                 ret.data
926         }
927         fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: Vec<lightning::ln::PaymentPreimage>) -> Result<(), ()> {
928                 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
929                 let mut ret = (self.BaseSign.validate_holder_commitment)(self.BaseSign.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());
930                 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)) })*/ })};
931                 local_ret
932         }
933         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
934                 if let Some(f) = self.BaseSign.set_pubkeys {
935                         (f)(&self.BaseSign);
936                 }
937                 self.BaseSign.pubkeys.get_native_ref()
938         }
939         fn channel_keys_id(&self) -> [u8; 32] {
940                 let mut ret = (self.BaseSign.channel_keys_id)(self.BaseSign.this_arg);
941                 ret.data
942         }
943         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>), ()> {
944                 let mut local_preimages = Vec::new(); for mut item in preimages.drain(..) { local_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
945                 let mut ret = (self.BaseSign.sign_counterparty_commitment)(self.BaseSign.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());
946                 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)) })*/ })};
947                 local_ret
948         }
949         fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
950                 let mut ret = (self.BaseSign.validate_counterparty_revocation)(self.BaseSign.this_arg, idx, secret.as_ref());
951                 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)) })*/ })};
952                 local_ret
953         }
954         fn sign_holder_commitment_and_htlcs(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec<bitcoin::secp256k1::ecdsa::Signature>), ()> {
955                 let mut ret = (self.BaseSign.sign_holder_commitment_and_htlcs)(self.BaseSign.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 });
956                 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)) })*/ })};
957                 local_ret
958         }
959         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, ()> {
960                 let mut ret = (self.BaseSign.sign_justice_revoked_output)(self.BaseSign.this_arg, crate::c_types::Transaction::from_bitcoin(justice_tx), input, amount, per_commitment_key.as_ref());
961                 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)) })*/ })};
962                 local_ret
963         }
964         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, ()> {
965                 let mut ret = (self.BaseSign.sign_justice_revoked_htlc)(self.BaseSign.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 });
966                 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)) })*/ })};
967                 local_ret
968         }
969         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, ()> {
970                 let mut ret = (self.BaseSign.sign_counterparty_htlc_transaction)(self.BaseSign.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 });
971                 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)) })*/ })};
972                 local_ret
973         }
974         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, ()> {
975                 let mut ret = (self.BaseSign.sign_closing_transaction)(self.BaseSign.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 });
976                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
977                 local_ret
978         }
979         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, ()> {
980                 let mut ret = (self.BaseSign.sign_holder_anchor_input)(self.BaseSign.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
981                 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)) })*/ })};
982                 local_ret
983         }
984         fn sign_channel_announcement(&self, mut msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, bitcoin::secp256k1::ecdsa::Signature), ()> {
985                 let mut ret = (self.BaseSign.sign_channel_announcement)(self.BaseSign.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 });
986                 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_ret_0 = (orig_ret_0_0.into_rust(), orig_ret_0_1.into_rust()); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
987                 local_ret
988         }
989         fn ready_channel(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
990                 (self.BaseSign.ready_channel)(self.BaseSign.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 })
991         }
992 }
993 impl lightning::util::ser::Writeable for Sign {
994         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
995                 let vec = (self.write)(self.this_arg);
996                 w.write_all(vec.as_slice())
997         }
998 }
999 #[no_mangle]
1000 /// Creates a copy of a Sign
1001 pub extern "C" fn Sign_clone(orig: &Sign) -> Sign {
1002         let mut res = Sign_clone_fields(orig);
1003         if let Some(f) = orig.cloned { (f)(&mut res) };
1004         res
1005 }
1006 impl Clone for Sign {
1007         fn clone(&self) -> Self {
1008                 Sign_clone(self)
1009         }
1010 }
1011
1012 use lightning::chain::keysinterface::Sign as rustSign;
1013 impl rustSign for Sign {
1014 }
1015
1016 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1017 // directly as a Deref trait in higher-level structs:
1018 impl core::ops::Deref for Sign {
1019         type Target = Self;
1020         fn deref(&self) -> &Self {
1021                 self
1022         }
1023 }
1024 /// Calls the free function if one is set
1025 #[no_mangle]
1026 pub extern "C" fn Sign_free(this_ptr: Sign) { }
1027 impl Drop for Sign {
1028         fn drop(&mut self) {
1029                 if let Some(f) = self.free {
1030                         f(self.this_arg);
1031                 }
1032         }
1033 }
1034 /// Specifies the recipient of an invoice, to indicate to [`KeysInterface::sign_invoice`] what node
1035 /// secret key should be used to sign the invoice.
1036 #[derive(Clone)]
1037 #[must_use]
1038 #[repr(C)]
1039 pub enum Recipient {
1040         /// The invoice should be signed with the local node secret key.
1041         Node,
1042         /// The invoice should be signed with the phantom node secret key. This secret key must be the
1043         /// same for all nodes participating in the [phantom node payment].
1044         ///
1045         /// [phantom node payment]: PhantomKeysManager
1046         PhantomNode,
1047 }
1048 use lightning::chain::keysinterface::Recipient as RecipientImport;
1049 pub(crate) type nativeRecipient = RecipientImport;
1050
1051 impl Recipient {
1052         #[allow(unused)]
1053         pub(crate) fn to_native(&self) -> nativeRecipient {
1054                 match self {
1055                         Recipient::Node => nativeRecipient::Node,
1056                         Recipient::PhantomNode => nativeRecipient::PhantomNode,
1057                 }
1058         }
1059         #[allow(unused)]
1060         pub(crate) fn into_native(self) -> nativeRecipient {
1061                 match self {
1062                         Recipient::Node => nativeRecipient::Node,
1063                         Recipient::PhantomNode => nativeRecipient::PhantomNode,
1064                 }
1065         }
1066         #[allow(unused)]
1067         pub(crate) fn from_native(native: &nativeRecipient) -> Self {
1068                 match native {
1069                         nativeRecipient::Node => Recipient::Node,
1070                         nativeRecipient::PhantomNode => Recipient::PhantomNode,
1071                 }
1072         }
1073         #[allow(unused)]
1074         pub(crate) fn native_into(native: nativeRecipient) -> Self {
1075                 match native {
1076                         nativeRecipient::Node => Recipient::Node,
1077                         nativeRecipient::PhantomNode => Recipient::PhantomNode,
1078                 }
1079         }
1080 }
1081 /// Creates a copy of the Recipient
1082 #[no_mangle]
1083 pub extern "C" fn Recipient_clone(orig: &Recipient) -> Recipient {
1084         orig.clone()
1085 }
1086 #[no_mangle]
1087 /// Utility method to constructs a new Node-variant Recipient
1088 pub extern "C" fn Recipient_node() -> Recipient {
1089         Recipient::Node}
1090 #[no_mangle]
1091 /// Utility method to constructs a new PhantomNode-variant Recipient
1092 pub extern "C" fn Recipient_phantom_node() -> Recipient {
1093         Recipient::PhantomNode}
1094 /// A trait to describe an object which can get user secrets and key material.
1095 #[repr(C)]
1096 pub struct KeysInterface {
1097         /// An opaque pointer which is passed to your function implementations as an argument.
1098         /// This has no meaning in the LDK, and can be NULL or any other value.
1099         pub this_arg: *mut c_void,
1100         /// Get node secret key based on the provided [`Recipient`].
1101         ///
1102         /// The node_id/network_key is the public key that corresponds to this secret key.
1103         ///
1104         /// This method must return the same value each time it is called with a given `Recipient`
1105         /// parameter.
1106         ///
1107         /// Errors if the `Recipient` variant is not supported by the implementation.
1108         #[must_use]
1109         pub get_node_secret: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_SecretKeyNoneZ,
1110         /// Get node id based on the provided [`Recipient`]. This public key corresponds to the secret in
1111         /// [`get_node_secret`].
1112         ///
1113         /// This method must return the same value each time it is called with a given `Recipient`
1114         /// parameter.
1115         ///
1116         /// Errors if the `Recipient` variant is not supported by the implementation.
1117         ///
1118         /// [`get_node_secret`]: KeysInterface::get_node_secret
1119         #[must_use]
1120         pub get_node_id: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ,
1121         /// Gets the ECDH shared secret of our [`node secret`] and `other_key`, multiplying by `tweak` if
1122         /// one is provided. Note that this tweak can be applied to `other_key` instead of our node
1123         /// secret, though this is less efficient.
1124         ///
1125         /// Errors if the `Recipient` variant is not supported by the implementation.
1126         ///
1127         /// [`node secret`]: Self::get_node_secret
1128         #[must_use]
1129         pub ecdh: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::chain::keysinterface::Recipient, other_key: crate::c_types::PublicKey, tweak: crate::c_types::derived::COption_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ,
1130         /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
1131         ///
1132         /// This method should return a different value each time it is called, to avoid linking
1133         /// on-chain funds across channels as controlled to the same user.
1134         #[must_use]
1135         pub get_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
1136         /// Get a script pubkey which we will send funds to when closing a channel.
1137         ///
1138         /// This method should return a different value each time it is called, to avoid linking
1139         /// on-chain funds across channels as controlled to the same user.
1140         #[must_use]
1141         pub get_shutdown_scriptpubkey: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::script::ShutdownScript,
1142         /// Get a new set of Sign for per-channel secrets. These MUST be unique even if you
1143         /// restarted with some stale data!
1144         ///
1145         /// This method must return a different value each time it is called.
1146         #[must_use]
1147         pub get_channel_signer: extern "C" fn (this_arg: *const c_void, inbound: bool, channel_value_satoshis: u64) -> crate::lightning::chain::keysinterface::Sign,
1148         /// Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
1149         /// onion packets and for temporary channel IDs. There is no requirement that these be
1150         /// persisted anywhere, though they must be unique across restarts.
1151         ///
1152         /// This method must return a different value each time it is called.
1153         #[must_use]
1154         pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1155         /// Reads a `Signer` for this `KeysInterface` from the given input stream.
1156         /// This is only called during deserialization of other objects which contain
1157         /// `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
1158         /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
1159         /// contain no versioning scheme. You may wish to include your own version prefix and ensure
1160         /// you've read all of the provided bytes to ensure no corruption occurred.
1161         #[must_use]
1162         pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SignDecodeErrorZ,
1163         /// Sign an invoice.
1164         /// By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
1165         /// this trait to parse the invoice and make sure they're signing what they expect, rather than
1166         /// blindly signing the hash.
1167         /// The hrp is ascii bytes, while the invoice data is base32.
1168         ///
1169         /// The secret key used to sign the invoice is dependent on the [`Recipient`].
1170         ///
1171         /// Errors if the `Recipient` variant is not supported by the implementation.
1172         #[must_use]
1173         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, receipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ,
1174         /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
1175         ///
1176         /// If the implementor of this trait supports [phantom node payments], then every node that is
1177         /// intended to be included in the phantom invoice route hints must return the same value from
1178         /// this method.
1179         ///
1180         /// This method must return the same value each time it is called.
1181         ///
1182         /// [phantom node payments]: PhantomKeysManager
1183         #[must_use]
1184         pub get_inbound_payment_key_material: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
1185         /// Frees any resources associated with this object given its this_arg pointer.
1186         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
1187         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
1188 }
1189 unsafe impl Send for KeysInterface {}
1190 unsafe impl Sync for KeysInterface {}
1191 #[no_mangle]
1192 pub(crate) extern "C" fn KeysInterface_clone_fields(orig: &KeysInterface) -> KeysInterface {
1193         KeysInterface {
1194                 this_arg: orig.this_arg,
1195                 get_node_secret: Clone::clone(&orig.get_node_secret),
1196                 get_node_id: Clone::clone(&orig.get_node_id),
1197                 ecdh: Clone::clone(&orig.ecdh),
1198                 get_destination_script: Clone::clone(&orig.get_destination_script),
1199                 get_shutdown_scriptpubkey: Clone::clone(&orig.get_shutdown_scriptpubkey),
1200                 get_channel_signer: Clone::clone(&orig.get_channel_signer),
1201                 get_secure_random_bytes: Clone::clone(&orig.get_secure_random_bytes),
1202                 read_chan_signer: Clone::clone(&orig.read_chan_signer),
1203                 sign_invoice: Clone::clone(&orig.sign_invoice),
1204                 get_inbound_payment_key_material: Clone::clone(&orig.get_inbound_payment_key_material),
1205                 free: Clone::clone(&orig.free),
1206         }
1207 }
1208
1209 use lightning::chain::keysinterface::KeysInterface as rustKeysInterface;
1210 impl rustKeysInterface for KeysInterface {
1211         type Signer = crate::lightning::chain::keysinterface::Sign;
1212         fn get_node_secret(&self, mut recipient: lightning::chain::keysinterface::Recipient) -> Result<bitcoin::secp256k1::SecretKey, ()> {
1213                 let mut ret = (self.get_node_secret)(self.this_arg, crate::lightning::chain::keysinterface::Recipient::native_into(recipient));
1214                 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)) })*/ })};
1215                 local_ret
1216         }
1217         fn get_node_id(&self, mut recipient: lightning::chain::keysinterface::Recipient) -> Result<bitcoin::secp256k1::PublicKey, ()> {
1218                 let mut ret = (self.get_node_id)(self.this_arg, crate::lightning::chain::keysinterface::Recipient::native_into(recipient));
1219                 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)) })*/ })};
1220                 local_ret
1221         }
1222         fn ecdh(&self, mut recipient: lightning::chain::keysinterface::Recipient, mut other_key: &bitcoin::secp256k1::PublicKey, mut tweak: Option<&bitcoin::secp256k1::Scalar>) -> Result<bitcoin::secp256k1::ecdh::SharedSecret, ()> {
1223                 let mut local_tweak = if tweak.is_none() { crate::c_types::derived::COption_ScalarZ::None } else { crate::c_types::derived::COption_ScalarZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::BigEndianScalar::from_rust(tweak.clone().unwrap()) }) };
1224                 let mut ret = (self.ecdh)(self.this_arg, crate::lightning::chain::keysinterface::Recipient::native_into(recipient), crate::c_types::PublicKey::from_rust(&other_key), local_tweak);
1225                 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)) })*/ })};
1226                 local_ret
1227         }
1228         fn get_destination_script(&self) -> bitcoin::blockdata::script::Script {
1229                 let mut ret = (self.get_destination_script)(self.this_arg);
1230                 ::bitcoin::blockdata::script::Script::from(ret.into_rust())
1231         }
1232         fn get_shutdown_scriptpubkey(&self) -> lightning::ln::script::ShutdownScript {
1233                 let mut ret = (self.get_shutdown_scriptpubkey)(self.this_arg);
1234                 *unsafe { Box::from_raw(ret.take_inner()) }
1235         }
1236         fn get_channel_signer(&self, mut inbound: bool, mut channel_value_satoshis: u64) -> crate::lightning::chain::keysinterface::Sign {
1237                 let mut ret = (self.get_channel_signer)(self.this_arg, inbound, channel_value_satoshis);
1238                 ret
1239         }
1240         fn get_secure_random_bytes(&self) -> [u8; 32] {
1241                 let mut ret = (self.get_secure_random_bytes)(self.this_arg);
1242                 ret.data
1243         }
1244         fn read_chan_signer(&self, mut reader: &[u8]) -> Result<crate::lightning::chain::keysinterface::Sign, lightning::ln::msgs::DecodeError> {
1245                 let mut local_reader = crate::c_types::u8slice::from_slice(reader);
1246                 let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
1247                 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() })};
1248                 local_ret
1249         }
1250         fn sign_invoice(&self, mut hrp_bytes: &[u8], mut invoice_data: &[bitcoin::bech32::u5], mut receipient: lightning::chain::keysinterface::Recipient) -> Result<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
1251                 let mut local_hrp_bytes = crate::c_types::u8slice::from_slice(hrp_bytes);
1252                 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() }); };
1253                 let mut ret = (self.sign_invoice)(self.this_arg, local_hrp_bytes, local_invoice_data.into(), crate::lightning::chain::keysinterface::Recipient::native_into(receipient));
1254                 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)) })*/ })};
1255                 local_ret
1256         }
1257         fn get_inbound_payment_key_material(&self) -> lightning::chain::keysinterface::KeyMaterial {
1258                 let mut ret = (self.get_inbound_payment_key_material)(self.this_arg);
1259                 ::lightning::chain::keysinterface::KeyMaterial(ret.data)
1260         }
1261 }
1262
1263 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1264 // directly as a Deref trait in higher-level structs:
1265 impl core::ops::Deref for KeysInterface {
1266         type Target = Self;
1267         fn deref(&self) -> &Self {
1268                 self
1269         }
1270 }
1271 /// Calls the free function if one is set
1272 #[no_mangle]
1273 pub extern "C" fn KeysInterface_free(this_ptr: KeysInterface) { }
1274 impl Drop for KeysInterface {
1275         fn drop(&mut self) {
1276                 if let Some(f) = self.free {
1277                         f(self.this_arg);
1278                 }
1279         }
1280 }
1281
1282 use lightning::chain::keysinterface::InMemorySigner as nativeInMemorySignerImport;
1283 pub(crate) type nativeInMemorySigner = nativeInMemorySignerImport;
1284
1285 /// A simple implementation of Sign that just keeps the private keys in memory.
1286 ///
1287 /// This implementation performs no policy checks and is insufficient by itself as
1288 /// a secure external signer.
1289 #[must_use]
1290 #[repr(C)]
1291 pub struct InMemorySigner {
1292         /// A pointer to the opaque Rust object.
1293
1294         /// Nearly everywhere, inner must be non-null, however in places where
1295         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1296         pub inner: *mut nativeInMemorySigner,
1297         /// Indicates that this is the only struct which contains the same pointer.
1298
1299         /// Rust functions which take ownership of an object provided via an argument require
1300         /// this to be true and invalidate the object pointed to by inner.
1301         pub is_owned: bool,
1302 }
1303
1304 impl Drop for InMemorySigner {
1305         fn drop(&mut self) {
1306                 if self.is_owned && !<*mut nativeInMemorySigner>::is_null(self.inner) {
1307                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1308                 }
1309         }
1310 }
1311 /// Frees any resources used by the InMemorySigner, if is_owned is set and inner is non-NULL.
1312 #[no_mangle]
1313 pub extern "C" fn InMemorySigner_free(this_obj: InMemorySigner) { }
1314 #[allow(unused)]
1315 /// Used only if an object of this type is returned as a trait impl by a method
1316 pub(crate) extern "C" fn InMemorySigner_free_void(this_ptr: *mut c_void) {
1317         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInMemorySigner); }
1318 }
1319 #[allow(unused)]
1320 impl InMemorySigner {
1321         pub(crate) fn get_native_ref(&self) -> &'static nativeInMemorySigner {
1322                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1323         }
1324         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInMemorySigner {
1325                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1326         }
1327         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1328         pub(crate) fn take_inner(mut self) -> *mut nativeInMemorySigner {
1329                 assert!(self.is_owned);
1330                 let ret = ObjOps::untweak_ptr(self.inner);
1331                 self.inner = core::ptr::null_mut();
1332                 ret
1333         }
1334 }
1335 /// Private key of anchor tx
1336 #[no_mangle]
1337 pub extern "C" fn InMemorySigner_get_funding_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1338         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_key;
1339         inner_val.as_ref()
1340 }
1341 /// Private key of anchor tx
1342 #[no_mangle]
1343 pub extern "C" fn InMemorySigner_set_funding_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1344         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_key = val.into_rust();
1345 }
1346 /// Holder secret key for blinded revocation pubkey
1347 #[no_mangle]
1348 pub extern "C" fn InMemorySigner_get_revocation_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1349         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_base_key;
1350         inner_val.as_ref()
1351 }
1352 /// Holder secret key for blinded revocation pubkey
1353 #[no_mangle]
1354 pub extern "C" fn InMemorySigner_set_revocation_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1355         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_base_key = val.into_rust();
1356 }
1357 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions
1358 #[no_mangle]
1359 pub extern "C" fn InMemorySigner_get_payment_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1360         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_key;
1361         inner_val.as_ref()
1362 }
1363 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions
1364 #[no_mangle]
1365 pub extern "C" fn InMemorySigner_set_payment_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1366         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_key = val.into_rust();
1367 }
1368 /// Holder secret key used in HTLC tx
1369 #[no_mangle]
1370 pub extern "C" fn InMemorySigner_get_delayed_payment_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1371         let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_base_key;
1372         inner_val.as_ref()
1373 }
1374 /// Holder secret key used in HTLC tx
1375 #[no_mangle]
1376 pub extern "C" fn InMemorySigner_set_delayed_payment_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1377         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_base_key = val.into_rust();
1378 }
1379 /// Holder htlc secret key used in commitment tx htlc outputs
1380 #[no_mangle]
1381 pub extern "C" fn InMemorySigner_get_htlc_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1382         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_base_key;
1383         inner_val.as_ref()
1384 }
1385 /// Holder htlc secret key used in commitment tx htlc outputs
1386 #[no_mangle]
1387 pub extern "C" fn InMemorySigner_set_htlc_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1388         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_base_key = val.into_rust();
1389 }
1390 /// Commitment seed
1391 #[no_mangle]
1392 pub extern "C" fn InMemorySigner_get_commitment_seed(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1393         let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_seed;
1394         inner_val
1395 }
1396 /// Commitment seed
1397 #[no_mangle]
1398 pub extern "C" fn InMemorySigner_set_commitment_seed(this_ptr: &mut InMemorySigner, mut val: crate::c_types::ThirtyTwoBytes) {
1399         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_seed = val.data;
1400 }
1401 impl Clone for InMemorySigner {
1402         fn clone(&self) -> Self {
1403                 Self {
1404                         inner: if <*mut nativeInMemorySigner>::is_null(self.inner) { core::ptr::null_mut() } else {
1405                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1406                         is_owned: true,
1407                 }
1408         }
1409 }
1410 #[allow(unused)]
1411 /// Used only if an object of this type is returned as a trait impl by a method
1412 pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void {
1413         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInMemorySigner)).clone() })) as *mut c_void
1414 }
1415 #[no_mangle]
1416 /// Creates a copy of the InMemorySigner
1417 pub extern "C" fn InMemorySigner_clone(orig: &InMemorySigner) -> InMemorySigner {
1418         orig.clone()
1419 }
1420 /// Create a new InMemorySigner
1421 #[must_use]
1422 #[no_mangle]
1423 pub extern "C" fn InMemorySigner_new(mut node_secret: crate::c_types::SecretKey, mut funding_key: crate::c_types::SecretKey, mut revocation_base_key: crate::c_types::SecretKey, mut payment_key: crate::c_types::SecretKey, mut delayed_payment_base_key: crate::c_types::SecretKey, mut htlc_base_key: crate::c_types::SecretKey, mut commitment_seed: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::lightning::chain::keysinterface::InMemorySigner {
1424         let mut ret = lightning::chain::keysinterface::InMemorySigner::new(secp256k1::global::SECP256K1, node_secret.into_rust(), 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);
1425         crate::lightning::chain::keysinterface::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
1426 }
1427
1428 /// Counterparty pubkeys.
1429 /// Will panic if ready_channel wasn't called.
1430 #[must_use]
1431 #[no_mangle]
1432 pub extern "C" fn InMemorySigner_counterparty_pubkeys(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1433         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_pubkeys();
1434         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 }
1435 }
1436
1437 /// The contest_delay value specified by our counterparty and applied on holder-broadcastable
1438 /// transactions, ie the amount of time that we have to wait to recover our funds if we
1439 /// broadcast a transaction.
1440 /// Will panic if ready_channel wasn't called.
1441 #[must_use]
1442 #[no_mangle]
1443 pub extern "C" fn InMemorySigner_counterparty_selected_contest_delay(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> u16 {
1444         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_selected_contest_delay();
1445         ret
1446 }
1447
1448 /// The contest_delay value specified by us and applied on transactions broadcastable
1449 /// by our counterparty, ie the amount of time that they have to wait to recover their funds
1450 /// if they broadcast a transaction.
1451 /// Will panic if ready_channel wasn't called.
1452 #[must_use]
1453 #[no_mangle]
1454 pub extern "C" fn InMemorySigner_holder_selected_contest_delay(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> u16 {
1455         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.holder_selected_contest_delay();
1456         ret
1457 }
1458
1459 /// Whether the holder is the initiator
1460 /// Will panic if ready_channel wasn't called.
1461 #[must_use]
1462 #[no_mangle]
1463 pub extern "C" fn InMemorySigner_is_outbound(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> bool {
1464         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
1465         ret
1466 }
1467
1468 /// Funding outpoint
1469 /// Will panic if ready_channel wasn't called.
1470 #[must_use]
1471 #[no_mangle]
1472 pub extern "C" fn InMemorySigner_funding_outpoint(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> crate::lightning::chain::transaction::OutPoint {
1473         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
1474         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::chain::transaction::OutPoint<>) as *mut _) }, is_owned: false }
1475 }
1476
1477 /// Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
1478 /// building transactions.
1479 ///
1480 /// Will panic if ready_channel wasn't called.
1481 #[must_use]
1482 #[no_mangle]
1483 pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
1484         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_channel_parameters();
1485         crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false }
1486 }
1487
1488 /// Whether anchors should be used.
1489 /// Will panic if ready_channel wasn't called.
1490 #[must_use]
1491 #[no_mangle]
1492 pub extern "C" fn InMemorySigner_opt_anchors(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner) -> bool {
1493         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.opt_anchors();
1494         ret
1495 }
1496
1497 /// Sign the single input of spend_tx at index `input_idx` which spends the output
1498 /// described by descriptor, returning the witness stack for the input.
1499 ///
1500 /// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
1501 /// is not spending the outpoint described by `descriptor.outpoint`,
1502 /// or if an output descriptor script_pubkey does not match the one we can spend.
1503 #[must_use]
1504 #[no_mangle]
1505 pub extern "C" fn InMemorySigner_sign_counterparty_payment_input(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor) -> crate::c_types::derived::CResult_CVec_CVec_u8ZZNoneZ {
1506         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);
1507         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() };
1508         local_ret
1509 }
1510
1511 /// Sign the single input of spend_tx at index `input_idx` which spends the output
1512 /// described by descriptor, returning the witness stack for the input.
1513 ///
1514 /// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
1515 /// is not spending the outpoint described by `descriptor.outpoint`, does not have a
1516 /// sequence set to `descriptor.to_self_delay`, or if an output descriptor
1517 /// script_pubkey does not match the one we can spend.
1518 #[must_use]
1519 #[no_mangle]
1520 pub extern "C" fn InMemorySigner_sign_dynamic_p2wsh_input(this_arg: &crate::lightning::chain::keysinterface::InMemorySigner, mut spend_tx: crate::c_types::Transaction, mut input_idx: usize, descriptor: &crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CResult_CVec_CVec_u8ZZNoneZ {
1521         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);
1522         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() };
1523         local_ret
1524 }
1525
1526 impl From<nativeInMemorySigner> for crate::lightning::chain::keysinterface::BaseSign {
1527         fn from(obj: nativeInMemorySigner) -> Self {
1528                 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1529                 let mut ret = InMemorySigner_as_BaseSign(&rust_obj);
1530                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1531                 rust_obj.inner = core::ptr::null_mut();
1532                 ret.free = Some(InMemorySigner_free_void);
1533                 ret
1534         }
1535 }
1536 /// Constructs a new BaseSign which calls the relevant methods on this_arg.
1537 /// This copies the `inner` pointer in this_arg and thus the returned BaseSign must be freed before this_arg is
1538 #[no_mangle]
1539 pub extern "C" fn InMemorySigner_as_BaseSign(this_arg: &InMemorySigner) -> crate::lightning::chain::keysinterface::BaseSign {
1540         crate::lightning::chain::keysinterface::BaseSign {
1541                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1542                 free: None,
1543                 get_per_commitment_point: InMemorySigner_BaseSign_get_per_commitment_point,
1544                 release_commitment_secret: InMemorySigner_BaseSign_release_commitment_secret,
1545                 validate_holder_commitment: InMemorySigner_BaseSign_validate_holder_commitment,
1546
1547                 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true },
1548                 set_pubkeys: Some(InMemorySigner_BaseSign_set_pubkeys),
1549                 channel_keys_id: InMemorySigner_BaseSign_channel_keys_id,
1550                 sign_counterparty_commitment: InMemorySigner_BaseSign_sign_counterparty_commitment,
1551                 validate_counterparty_revocation: InMemorySigner_BaseSign_validate_counterparty_revocation,
1552                 sign_holder_commitment_and_htlcs: InMemorySigner_BaseSign_sign_holder_commitment_and_htlcs,
1553                 sign_justice_revoked_output: InMemorySigner_BaseSign_sign_justice_revoked_output,
1554                 sign_justice_revoked_htlc: InMemorySigner_BaseSign_sign_justice_revoked_htlc,
1555                 sign_counterparty_htlc_transaction: InMemorySigner_BaseSign_sign_counterparty_htlc_transaction,
1556                 sign_closing_transaction: InMemorySigner_BaseSign_sign_closing_transaction,
1557                 sign_holder_anchor_input: InMemorySigner_BaseSign_sign_holder_anchor_input,
1558                 sign_channel_announcement: InMemorySigner_BaseSign_sign_channel_announcement,
1559                 ready_channel: InMemorySigner_BaseSign_ready_channel,
1560         }
1561 }
1562
1563 #[must_use]
1564 extern "C" fn InMemorySigner_BaseSign_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey {
1565         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::get_per_commitment_point(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, secp256k1::global::SECP256K1);
1566         crate::c_types::PublicKey::from_rust(&ret)
1567 }
1568 #[must_use]
1569 extern "C" fn InMemorySigner_BaseSign_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
1570         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::release_commitment_secret(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx);
1571         crate::c_types::ThirtyTwoBytes { data: ret }
1572 }
1573 #[must_use]
1574 extern "C" fn InMemorySigner_BaseSign_validate_holder_commitment(this_arg: *const c_void, holder_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction, mut preimages: crate::c_types::derived::CVec_PaymentPreimageZ) -> crate::c_types::derived::CResult_NoneNoneZ {
1575         let mut local_preimages = Vec::new(); for mut item in preimages.into_rust().drain(..) { local_preimages.push( { ::lightning::ln::PaymentPreimage(item.data) }); };
1576         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::validate_holder_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, holder_tx.get_native_ref(), local_preimages);
1577         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() };
1578         local_ret
1579 }
1580 #[must_use]
1581 extern "C" fn InMemorySigner_BaseSign_pubkeys(this_arg: *const c_void) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1582         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::pubkeys(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1583         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 }
1584 }
1585 extern "C" fn InMemorySigner_BaseSign_set_pubkeys(trait_self_arg: &BaseSign) {
1586         // This is a bit race-y in the general case, but for our specific use-cases today, we're safe
1587         // Specifically, we must ensure that the first time we're called it can never be in parallel
1588         if trait_self_arg.pubkeys.inner.is_null() {
1589                 unsafe { &mut *(trait_self_arg as *const BaseSign  as *mut BaseSign) }.pubkeys = InMemorySigner_BaseSign_pubkeys(trait_self_arg.this_arg);
1590         }
1591 }
1592 #[must_use]
1593 extern "C" fn InMemorySigner_BaseSign_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1594         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::channel_keys_id(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1595         crate::c_types::ThirtyTwoBytes { data: ret }
1596 }
1597 #[must_use]
1598 extern "C" fn InMemorySigner_BaseSign_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::CommitmentTransaction, mut preimages: crate::c_types::derived::CVec_PaymentPreimageZ) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ {
1599         let mut local_preimages = Vec::new(); for mut item in preimages.into_rust().drain(..) { local_preimages.push( { ::lightning::ln::PaymentPreimage(item.data) }); };
1600         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::sign_counterparty_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), local_preimages, secp256k1::global::SECP256K1);
1601         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1602         local_ret
1603 }
1604 #[must_use]
1605 extern "C" fn InMemorySigner_BaseSign_validate_counterparty_revocation(this_arg: *const c_void, mut idx: u64, secret: *const [u8; 32]) -> crate::c_types::derived::CResult_NoneNoneZ {
1606         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::validate_counterparty_revocation(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *secret}[..]).unwrap());
1607         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() };
1608         local_ret
1609 }
1610 #[must_use]
1611 extern "C" fn InMemorySigner_BaseSign_sign_holder_commitment_and_htlcs(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ {
1612         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::sign_holder_commitment_and_htlcs(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), secp256k1::global::SECP256K1);
1613         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::c_types::Signature::from_rust(&item) }); }; let mut local_ret_0 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), local_orig_ret_0_1.into()).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1614         local_ret
1615 }
1616 #[must_use]
1617 extern "C" fn InMemorySigner_BaseSign_sign_justice_revoked_output(this_arg: *const c_void, mut justice_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_key: *const [u8; 32]) -> crate::c_types::derived::CResult_SignatureNoneZ {
1618         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::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);
1619         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1620         local_ret
1621 }
1622 #[must_use]
1623 extern "C" fn InMemorySigner_BaseSign_sign_justice_revoked_htlc(this_arg: *const c_void, mut justice_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ {
1624         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::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);
1625         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1626         local_ret
1627 }
1628 #[must_use]
1629 extern "C" fn InMemorySigner_BaseSign_sign_counterparty_htlc_transaction(this_arg: *const c_void, mut htlc_tx: crate::c_types::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: crate::c_types::PublicKey, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_SignatureNoneZ {
1630         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::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);
1631         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1632         local_ret
1633 }
1634 #[must_use]
1635 extern "C" fn InMemorySigner_BaseSign_sign_closing_transaction(this_arg: *const c_void, closing_tx: &crate::lightning::ln::chan_utils::ClosingTransaction) -> crate::c_types::derived::CResult_SignatureNoneZ {
1636         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::sign_closing_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, closing_tx.get_native_ref(), secp256k1::global::SECP256K1);
1637         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1638         local_ret
1639 }
1640 #[must_use]
1641 extern "C" fn InMemorySigner_BaseSign_sign_holder_anchor_input(this_arg: *const c_void, mut anchor_tx: crate::c_types::Transaction, mut input: usize) -> crate::c_types::derived::CResult_SignatureNoneZ {
1642         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::sign_holder_anchor_input(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &anchor_tx.into_bitcoin(), input, secp256k1::global::SECP256K1);
1643         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::Signature::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1644         local_ret
1645 }
1646 #[must_use]
1647 extern "C" fn InMemorySigner_BaseSign_sign_channel_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_C2Tuple_SignatureSignatureZNoneZ {
1648         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::sign_channel_announcement(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, msg.get_native_ref(), secp256k1::global::SECP256K1);
1649         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 = (crate::c_types::Signature::from_rust(&orig_ret_0_0), crate::c_types::Signature::from_rust(&orig_ret_0_1)).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1650         local_ret
1651 }
1652 extern "C" fn InMemorySigner_BaseSign_ready_channel(this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
1653         <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::ready_channel(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, channel_parameters.get_native_ref())
1654 }
1655
1656 impl From<nativeInMemorySigner> for crate::lightning::chain::keysinterface::Sign {
1657         fn from(obj: nativeInMemorySigner) -> Self {
1658                 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1659                 let mut ret = InMemorySigner_as_Sign(&rust_obj);
1660                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1661                 rust_obj.inner = core::ptr::null_mut();
1662                 ret.free = Some(InMemorySigner_free_void);
1663                 ret
1664         }
1665 }
1666 /// Constructs a new Sign which calls the relevant methods on this_arg.
1667 /// This copies the `inner` pointer in this_arg and thus the returned Sign must be freed before this_arg is
1668 #[no_mangle]
1669 pub extern "C" fn InMemorySigner_as_Sign(this_arg: &InMemorySigner) -> crate::lightning::chain::keysinterface::Sign {
1670         crate::lightning::chain::keysinterface::Sign {
1671                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1672                 free: None,
1673                 BaseSign: crate::lightning::chain::keysinterface::BaseSign {
1674                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1675                         free: None,
1676                         get_per_commitment_point: InMemorySigner_BaseSign_get_per_commitment_point,
1677                         release_commitment_secret: InMemorySigner_BaseSign_release_commitment_secret,
1678                         validate_holder_commitment: InMemorySigner_BaseSign_validate_holder_commitment,
1679
1680                         pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: core::ptr::null_mut(), is_owned: true },
1681                         set_pubkeys: Some(InMemorySigner_BaseSign_set_pubkeys),
1682                         channel_keys_id: InMemorySigner_BaseSign_channel_keys_id,
1683                         sign_counterparty_commitment: InMemorySigner_BaseSign_sign_counterparty_commitment,
1684                         validate_counterparty_revocation: InMemorySigner_BaseSign_validate_counterparty_revocation,
1685                         sign_holder_commitment_and_htlcs: InMemorySigner_BaseSign_sign_holder_commitment_and_htlcs,
1686                         sign_justice_revoked_output: InMemorySigner_BaseSign_sign_justice_revoked_output,
1687                         sign_justice_revoked_htlc: InMemorySigner_BaseSign_sign_justice_revoked_htlc,
1688                         sign_counterparty_htlc_transaction: InMemorySigner_BaseSign_sign_counterparty_htlc_transaction,
1689                         sign_closing_transaction: InMemorySigner_BaseSign_sign_closing_transaction,
1690                         sign_holder_anchor_input: InMemorySigner_BaseSign_sign_holder_anchor_input,
1691                         sign_channel_announcement: InMemorySigner_BaseSign_sign_channel_announcement,
1692                         ready_channel: InMemorySigner_BaseSign_ready_channel,
1693                 },
1694                 write: InMemorySigner_write_void,
1695                 cloned: Some(Sign_InMemorySigner_cloned),
1696         }
1697 }
1698
1699 extern "C" fn Sign_InMemorySigner_cloned(new_obj: &mut crate::lightning::chain::keysinterface::Sign) {
1700         new_obj.this_arg = InMemorySigner_clone_void(new_obj.this_arg);
1701         new_obj.free = Some(InMemorySigner_free_void);
1702         new_obj.BaseSign.this_arg = new_obj.this_arg;
1703         new_obj.BaseSign.free = None;
1704 }
1705
1706 #[no_mangle]
1707 /// Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
1708 pub extern "C" fn InMemorySigner_write(obj: &crate::lightning::chain::keysinterface::InMemorySigner) -> crate::c_types::derived::CVec_u8Z {
1709         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1710 }
1711 #[no_mangle]
1712 pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1713         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) })
1714 }
1715 #[no_mangle]
1716 /// Read a InMemorySigner from a byte array, created by InMemorySigner_write
1717 pub extern "C" fn InMemorySigner_read(ser: crate::c_types::u8slice, arg: crate::c_types::SecretKey) -> crate::c_types::derived::CResult_InMemorySignerDecodeErrorZ {
1718         let arg_conv = arg.into_rust();
1719         let res: Result<lightning::chain::keysinterface::InMemorySigner, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1720         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::chain::keysinterface::InMemorySigner { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1721         local_res
1722 }
1723
1724 use lightning::chain::keysinterface::KeysManager as nativeKeysManagerImport;
1725 pub(crate) type nativeKeysManager = nativeKeysManagerImport;
1726
1727 /// Simple KeysInterface implementor that takes a 32-byte seed for use as a BIP 32 extended key
1728 /// and derives keys from that.
1729 ///
1730 /// Your node_id is seed/0'
1731 /// ChannelMonitor closes may use seed/1'
1732 /// Cooperative closes may use seed/2'
1733 /// The two close keys may be needed to claim on-chain funds!
1734 ///
1735 /// This struct cannot be used for nodes that wish to support receiving phantom payments;
1736 /// [`PhantomKeysManager`] must be used instead.
1737 ///
1738 /// Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
1739 /// previously issued invoices and attempts to pay previous invoices will fail.
1740 #[must_use]
1741 #[repr(C)]
1742 pub struct KeysManager {
1743         /// A pointer to the opaque Rust object.
1744
1745         /// Nearly everywhere, inner must be non-null, however in places where
1746         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1747         pub inner: *mut nativeKeysManager,
1748         /// Indicates that this is the only struct which contains the same pointer.
1749
1750         /// Rust functions which take ownership of an object provided via an argument require
1751         /// this to be true and invalidate the object pointed to by inner.
1752         pub is_owned: bool,
1753 }
1754
1755 impl Drop for KeysManager {
1756         fn drop(&mut self) {
1757                 if self.is_owned && !<*mut nativeKeysManager>::is_null(self.inner) {
1758                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1759                 }
1760         }
1761 }
1762 /// Frees any resources used by the KeysManager, if is_owned is set and inner is non-NULL.
1763 #[no_mangle]
1764 pub extern "C" fn KeysManager_free(this_obj: KeysManager) { }
1765 #[allow(unused)]
1766 /// Used only if an object of this type is returned as a trait impl by a method
1767 pub(crate) extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) {
1768         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeKeysManager); }
1769 }
1770 #[allow(unused)]
1771 impl KeysManager {
1772         pub(crate) fn get_native_ref(&self) -> &'static nativeKeysManager {
1773                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1774         }
1775         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeKeysManager {
1776                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1777         }
1778         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1779         pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager {
1780                 assert!(self.is_owned);
1781                 let ret = ObjOps::untweak_ptr(self.inner);
1782                 self.inner = core::ptr::null_mut();
1783                 ret
1784         }
1785 }
1786 /// Constructs a KeysManager from a 32-byte seed. If the seed is in some way biased (eg your
1787 /// CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
1788 /// starting_time isn't strictly required to actually be a time, but it must absolutely,
1789 /// without a doubt, be unique to this instance. ie if you start multiple times with the same
1790 /// seed, starting_time must be unique to each run. Thus, the easiest way to achieve this is to
1791 /// simply use the current time (with very high precision).
1792 ///
1793 /// The seed MUST be backed up safely prior to use so that the keys can be re-created, however,
1794 /// obviously, starting_time should be unique every time you reload the library - it is only
1795 /// used to generate new ephemeral key data (which will be stored by the individual channel if
1796 /// necessary).
1797 ///
1798 /// Note that the seed is required to recover certain on-chain funds independent of
1799 /// ChannelMonitor data, though a current copy of ChannelMonitor data is also required for any
1800 /// channel, and some on-chain during-closing funds.
1801 ///
1802 /// Note that until the 0.1 release there is no guarantee of backward compatibility between
1803 /// versions. Once the library is more fully supported, the docs will be updated to include a
1804 /// detailed description of the guarantee.
1805 #[must_use]
1806 #[no_mangle]
1807 pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32) -> crate::lightning::chain::keysinterface::KeysManager {
1808         let mut ret = lightning::chain::keysinterface::KeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos);
1809         crate::lightning::chain::keysinterface::KeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1810 }
1811
1812 /// Derive an old Sign containing per-channel secrets based on a key derivation parameters.
1813 ///
1814 /// Key derivation parameters are accessible through a per-channel secrets
1815 /// Sign::channel_keys_id and is provided inside DynamicOuputP2WSH in case of
1816 /// onchain output detection for which a corresponding delayed_payment_key must be derived.
1817 #[must_use]
1818 #[no_mangle]
1819 pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &crate::lightning::chain::keysinterface::KeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::lightning::chain::keysinterface::InMemorySigner {
1820         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
1821         crate::lightning::chain::keysinterface::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
1822 }
1823
1824 /// Creates a Transaction which spends the given descriptors to the given outputs, plus an
1825 /// output to the given change destination (if sufficient change value remains). The
1826 /// transaction will have a feerate, at least, of the given value.
1827 ///
1828 /// Returns `Err(())` if the output value is greater than the input value minus required fee,
1829 /// if a descriptor was duplicated, or if an output descriptor `script_pubkey`
1830 /// does not match the one we can spend.
1831 ///
1832 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
1833 ///
1834 /// May panic if the `SpendableOutputDescriptor`s were not generated by Channels which used
1835 /// this KeysManager or one of the `InMemorySigner` created by this KeysManager.
1836 #[must_use]
1837 #[no_mangle]
1838 pub extern "C" fn KeysManager_spend_spendable_outputs(this_arg: &crate::lightning::chain::keysinterface::KeysManager, mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut outputs: crate::c_types::derived::CVec_TxOutZ, mut change_destination_script: crate::c_types::derived::CVec_u8Z, mut feerate_sat_per_1000_weight: u32) -> crate::c_types::derived::CResult_TransactionNoneZ {
1839         let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
1840         let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
1841         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.spend_spendable_outputs(&local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::Script::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, secp256k1::global::SECP256K1);
1842         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() };
1843         local_ret
1844 }
1845
1846 impl From<nativeKeysManager> for crate::lightning::chain::keysinterface::KeysInterface {
1847         fn from(obj: nativeKeysManager) -> Self {
1848                 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1849                 let mut ret = KeysManager_as_KeysInterface(&rust_obj);
1850                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
1851                 rust_obj.inner = core::ptr::null_mut();
1852                 ret.free = Some(KeysManager_free_void);
1853                 ret
1854         }
1855 }
1856 /// Constructs a new KeysInterface which calls the relevant methods on this_arg.
1857 /// This copies the `inner` pointer in this_arg and thus the returned KeysInterface must be freed before this_arg is
1858 #[no_mangle]
1859 pub extern "C" fn KeysManager_as_KeysInterface(this_arg: &KeysManager) -> crate::lightning::chain::keysinterface::KeysInterface {
1860         crate::lightning::chain::keysinterface::KeysInterface {
1861                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1862                 free: None,
1863                 get_node_secret: KeysManager_KeysInterface_get_node_secret,
1864                 get_node_id: KeysManager_KeysInterface_get_node_id,
1865                 ecdh: KeysManager_KeysInterface_ecdh,
1866                 get_destination_script: KeysManager_KeysInterface_get_destination_script,
1867                 get_shutdown_scriptpubkey: KeysManager_KeysInterface_get_shutdown_scriptpubkey,
1868                 get_channel_signer: KeysManager_KeysInterface_get_channel_signer,
1869                 get_secure_random_bytes: KeysManager_KeysInterface_get_secure_random_bytes,
1870                 read_chan_signer: KeysManager_KeysInterface_read_chan_signer,
1871                 sign_invoice: KeysManager_KeysInterface_sign_invoice,
1872                 get_inbound_payment_key_material: KeysManager_KeysInterface_get_inbound_payment_key_material,
1873         }
1874 }
1875
1876 #[must_use]
1877 extern "C" fn KeysManager_KeysInterface_get_node_secret(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_SecretKeyNoneZ {
1878         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_node_secret(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native());
1879         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SecretKey::from_rust(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1880         local_ret
1881 }
1882 #[must_use]
1883 extern "C" fn KeysManager_KeysInterface_get_node_id(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ {
1884         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native());
1885         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() };
1886         local_ret
1887 }
1888 #[must_use]
1889 extern "C" fn KeysManager_KeysInterface_ecdh(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient, mut other_key: crate::c_types::PublicKey, mut tweak: crate::c_types::derived::COption_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ {
1890         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();
1891         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::ecdh(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, recipient.into_native(), &other_key.into_rust(), local_tweak);
1892         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() };
1893         local_ret
1894 }
1895 #[must_use]
1896 extern "C" fn KeysManager_KeysInterface_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1897         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
1898         ret.into_bytes().into()
1899 }
1900 #[must_use]
1901 extern "C" fn KeysManager_KeysInterface_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::lightning::ln::script::ShutdownScript {
1902         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
1903         crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(ret), is_owned: true }
1904 }
1905 #[must_use]
1906 extern "C" fn KeysManager_KeysInterface_get_channel_signer(this_arg: *const c_void, mut inbound: bool, mut channel_value_satoshis: u64) -> crate::lightning::chain::keysinterface::Sign {
1907         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_channel_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, inbound, channel_value_satoshis);
1908         Into::into(ret)
1909 }
1910 #[must_use]
1911 extern "C" fn KeysManager_KeysInterface_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1912         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
1913         crate::c_types::ThirtyTwoBytes { data: ret }
1914 }
1915 #[must_use]
1916 extern "C" fn KeysManager_KeysInterface_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SignDecodeErrorZ {
1917         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, reader.to_slice());
1918         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() };
1919         local_ret
1920 }
1921 #[must_use]
1922 extern "C" fn KeysManager_KeysInterface_sign_invoice(this_arg: *const c_void, mut hrp_bytes: crate::c_types::u8slice, mut invoice_data: crate::c_types::derived::CVec_u5Z, mut receipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ {
1923         let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
1924         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::sign_invoice(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, hrp_bytes.to_slice(), &local_invoice_data[..], receipient.into_native());
1925         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() };
1926         local_ret
1927 }
1928 #[must_use]
1929 extern "C" fn KeysManager_KeysInterface_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1930         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
1931         crate::c_types::ThirtyTwoBytes { data: ret.0 }
1932 }
1933
1934
1935 use lightning::chain::keysinterface::PhantomKeysManager as nativePhantomKeysManagerImport;
1936 pub(crate) type nativePhantomKeysManager = nativePhantomKeysManagerImport;
1937
1938 /// Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
1939 /// payments.
1940 ///
1941 /// A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
1942 /// paid to one of multiple nodes. This works because we encode the invoice route hints such that
1943 /// LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
1944 /// itself without ever needing to forward to this fake node.
1945 ///
1946 /// Phantom node payments are useful for load balancing between multiple LDK nodes. They also
1947 /// provide some fault tolerance, because payers will automatically retry paying other provided
1948 /// nodes in the case that one node goes down.
1949 ///
1950 /// Note that multi-path payments are not supported in phantom invoices for security reasons.
1951 /// Switching between this struct and [`KeysManager`] will invalidate any previously issued
1952 /// invoices and attempts to pay previous invoices will fail.
1953 #[must_use]
1954 #[repr(C)]
1955 pub struct PhantomKeysManager {
1956         /// A pointer to the opaque Rust object.
1957
1958         /// Nearly everywhere, inner must be non-null, however in places where
1959         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1960         pub inner: *mut nativePhantomKeysManager,
1961         /// Indicates that this is the only struct which contains the same pointer.
1962
1963         /// Rust functions which take ownership of an object provided via an argument require
1964         /// this to be true and invalidate the object pointed to by inner.
1965         pub is_owned: bool,
1966 }
1967
1968 impl Drop for PhantomKeysManager {
1969         fn drop(&mut self) {
1970                 if self.is_owned && !<*mut nativePhantomKeysManager>::is_null(self.inner) {
1971                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1972                 }
1973         }
1974 }
1975 /// Frees any resources used by the PhantomKeysManager, if is_owned is set and inner is non-NULL.
1976 #[no_mangle]
1977 pub extern "C" fn PhantomKeysManager_free(this_obj: PhantomKeysManager) { }
1978 #[allow(unused)]
1979 /// Used only if an object of this type is returned as a trait impl by a method
1980 pub(crate) extern "C" fn PhantomKeysManager_free_void(this_ptr: *mut c_void) {
1981         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePhantomKeysManager); }
1982 }
1983 #[allow(unused)]
1984 impl PhantomKeysManager {
1985         pub(crate) fn get_native_ref(&self) -> &'static nativePhantomKeysManager {
1986                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1987         }
1988         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePhantomKeysManager {
1989                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1990         }
1991         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1992         pub(crate) fn take_inner(mut self) -> *mut nativePhantomKeysManager {
1993                 assert!(self.is_owned);
1994                 let ret = ObjOps::untweak_ptr(self.inner);
1995                 self.inner = core::ptr::null_mut();
1996                 ret
1997         }
1998 }
1999 impl From<nativePhantomKeysManager> for crate::lightning::chain::keysinterface::KeysInterface {
2000         fn from(obj: nativePhantomKeysManager) -> Self {
2001                 let mut rust_obj = PhantomKeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
2002                 let mut ret = PhantomKeysManager_as_KeysInterface(&rust_obj);
2003                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
2004                 rust_obj.inner = core::ptr::null_mut();
2005                 ret.free = Some(PhantomKeysManager_free_void);
2006                 ret
2007         }
2008 }
2009 /// Constructs a new KeysInterface which calls the relevant methods on this_arg.
2010 /// This copies the `inner` pointer in this_arg and thus the returned KeysInterface must be freed before this_arg is
2011 #[no_mangle]
2012 pub extern "C" fn PhantomKeysManager_as_KeysInterface(this_arg: &PhantomKeysManager) -> crate::lightning::chain::keysinterface::KeysInterface {
2013         crate::lightning::chain::keysinterface::KeysInterface {
2014                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
2015                 free: None,
2016                 get_node_secret: PhantomKeysManager_KeysInterface_get_node_secret,
2017                 get_node_id: PhantomKeysManager_KeysInterface_get_node_id,
2018                 ecdh: PhantomKeysManager_KeysInterface_ecdh,
2019                 get_destination_script: PhantomKeysManager_KeysInterface_get_destination_script,
2020                 get_shutdown_scriptpubkey: PhantomKeysManager_KeysInterface_get_shutdown_scriptpubkey,
2021                 get_channel_signer: PhantomKeysManager_KeysInterface_get_channel_signer,
2022                 get_secure_random_bytes: PhantomKeysManager_KeysInterface_get_secure_random_bytes,
2023                 read_chan_signer: PhantomKeysManager_KeysInterface_read_chan_signer,
2024                 sign_invoice: PhantomKeysManager_KeysInterface_sign_invoice,
2025                 get_inbound_payment_key_material: PhantomKeysManager_KeysInterface_get_inbound_payment_key_material,
2026         }
2027 }
2028
2029 #[must_use]
2030 extern "C" fn PhantomKeysManager_KeysInterface_get_node_secret(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_SecretKeyNoneZ {
2031         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_node_secret(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native());
2032         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SecretKey::from_rust(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
2033         local_ret
2034 }
2035 #[must_use]
2036 extern "C" fn PhantomKeysManager_KeysInterface_get_node_id(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ {
2037         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_node_id(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native());
2038         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() };
2039         local_ret
2040 }
2041 #[must_use]
2042 extern "C" fn PhantomKeysManager_KeysInterface_ecdh(this_arg: *const c_void, mut recipient: crate::lightning::chain::keysinterface::Recipient, mut other_key: crate::c_types::PublicKey, mut tweak: crate::c_types::derived::COption_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ {
2043         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();
2044         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::ecdh(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, recipient.into_native(), &other_key.into_rust(), local_tweak);
2045         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() };
2046         local_ret
2047 }
2048 #[must_use]
2049 extern "C" fn PhantomKeysManager_KeysInterface_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2050         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2051         ret.into_bytes().into()
2052 }
2053 #[must_use]
2054 extern "C" fn PhantomKeysManager_KeysInterface_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::lightning::ln::script::ShutdownScript {
2055         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2056         crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(ret), is_owned: true }
2057 }
2058 #[must_use]
2059 extern "C" fn PhantomKeysManager_KeysInterface_get_channel_signer(this_arg: *const c_void, mut inbound: bool, mut channel_value_satoshis: u64) -> crate::lightning::chain::keysinterface::Sign {
2060         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_channel_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, inbound, channel_value_satoshis);
2061         Into::into(ret)
2062 }
2063 #[must_use]
2064 extern "C" fn PhantomKeysManager_KeysInterface_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2065         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2066         crate::c_types::ThirtyTwoBytes { data: ret }
2067 }
2068 #[must_use]
2069 extern "C" fn PhantomKeysManager_KeysInterface_read_chan_signer(this_arg: *const c_void, mut reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SignDecodeErrorZ {
2070         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, reader.to_slice());
2071         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() };
2072         local_ret
2073 }
2074 #[must_use]
2075 extern "C" fn PhantomKeysManager_KeysInterface_sign_invoice(this_arg: *const c_void, mut hrp_bytes: crate::c_types::u8slice, mut invoice_data: crate::c_types::derived::CVec_u5Z, mut receipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ {
2076         let mut local_invoice_data = Vec::new(); for mut item in invoice_data.into_rust().drain(..) { local_invoice_data.push( { item.into() }); };
2077         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::sign_invoice(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, hrp_bytes.to_slice(), &local_invoice_data[..], receipient.into_native());
2078         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() };
2079         local_ret
2080 }
2081 #[must_use]
2082 extern "C" fn PhantomKeysManager_KeysInterface_get_inbound_payment_key_material(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
2083         let mut ret = <nativePhantomKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_inbound_payment_key_material(unsafe { &mut *(this_arg as *mut nativePhantomKeysManager) }, );
2084         crate::c_types::ThirtyTwoBytes { data: ret.0 }
2085 }
2086
2087 /// Constructs a `PhantomKeysManager` given a 32-byte seed and an additional `cross_node_seed`
2088 /// that is shared across all nodes that intend to participate in [phantom node payments] together.
2089 ///
2090 /// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
2091 /// `starting_time_nanos`.
2092 ///
2093 /// `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
2094 /// same across restarts, or else inbound payments may fail.
2095 ///
2096 /// [phantom node payments]: PhantomKeysManager
2097 #[must_use]
2098 #[no_mangle]
2099 pub extern "C" fn PhantomKeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32, cross_node_seed: *const [u8; 32]) -> crate::lightning::chain::keysinterface::PhantomKeysManager {
2100         let mut ret = lightning::chain::keysinterface::PhantomKeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos, unsafe { &*cross_node_seed});
2101         crate::lightning::chain::keysinterface::PhantomKeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
2102 }
2103
2104 /// See [`KeysManager::spend_spendable_outputs`] for documentation on this method.
2105 #[must_use]
2106 #[no_mangle]
2107 pub extern "C" fn PhantomKeysManager_spend_spendable_outputs(this_arg: &crate::lightning::chain::keysinterface::PhantomKeysManager, mut descriptors: crate::c_types::derived::CVec_SpendableOutputDescriptorZ, mut outputs: crate::c_types::derived::CVec_TxOutZ, mut change_destination_script: crate::c_types::derived::CVec_u8Z, mut feerate_sat_per_1000_weight: u32) -> crate::c_types::derived::CResult_TransactionNoneZ {
2108         let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
2109         let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
2110         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.spend_spendable_outputs(&local_descriptors.iter().collect::<Vec<_>>()[..], local_outputs, ::bitcoin::blockdata::script::Script::from(change_destination_script.into_rust()), feerate_sat_per_1000_weight, secp256k1::global::SECP256K1);
2111         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() };
2112         local_ret
2113 }
2114
2115 /// See [`KeysManager::derive_channel_keys`] for documentation on this method.
2116 #[must_use]
2117 #[no_mangle]
2118 pub extern "C" fn PhantomKeysManager_derive_channel_keys(this_arg: &crate::lightning::chain::keysinterface::PhantomKeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::lightning::chain::keysinterface::InMemorySigner {
2119         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
2120         crate::lightning::chain::keysinterface::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
2121 }
2122