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 std::str::FromStr;
14 use std::ffi::c_void;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17
18
19 use lightning::chain::keysinterface::DelayedPaymentOutputDescriptor as nativeDelayedPaymentOutputDescriptorImport;
20 type nativeDelayedPaymentOutputDescriptor = nativeDelayedPaymentOutputDescriptorImport;
21
22 /// Information about a spendable output to a P2WSH script. See
23 /// SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this.
24 #[must_use]
25 #[repr(C)]
26 pub struct DelayedPaymentOutputDescriptor {
27         /// A pointer to the opaque Rust object.
28
29         /// Nearly everywhere, inner must be non-null, however in places where
30         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
31         pub inner: *mut nativeDelayedPaymentOutputDescriptor,
32         /// Indicates that this is the only struct which contains the same pointer.
33
34         /// Rust functions which take ownership of an object provided via an argument require
35         /// this to be true and invalidate the object pointed to by inner.
36         pub is_owned: bool,
37 }
38
39 impl Drop for DelayedPaymentOutputDescriptor {
40         fn drop(&mut self) {
41                 if self.is_owned && !<*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) {
42                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
43                 }
44         }
45 }
46 /// Frees any resources used by the DelayedPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
47 #[no_mangle]
48 pub extern "C" fn DelayedPaymentOutputDescriptor_free(this_obj: DelayedPaymentOutputDescriptor) { }
49 #[allow(unused)]
50 /// Used only if an object of this type is returned as a trait impl by a method
51 extern "C" fn DelayedPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
52         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDelayedPaymentOutputDescriptor); }
53 }
54 #[allow(unused)]
55 impl DelayedPaymentOutputDescriptor {
56         pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentOutputDescriptor {
57                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
58         }
59         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentOutputDescriptor {
60                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
61         }
62         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
63         pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentOutputDescriptor {
64                 assert!(self.is_owned);
65                 let ret = ObjOps::untweak_ptr(self.inner);
66                 self.inner = std::ptr::null_mut();
67                 ret
68         }
69 }
70 /// The outpoint which is spendable
71 #[no_mangle]
72 pub extern "C" fn DelayedPaymentOutputDescriptor_get_outpoint(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
73         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
74         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
75 }
76 /// The outpoint which is spendable
77 #[no_mangle]
78 pub extern "C" fn DelayedPaymentOutputDescriptor_set_outpoint(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
79         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
80 }
81 /// Per commitment point to derive delayed_payment_key by key holder
82 #[no_mangle]
83 pub extern "C" fn DelayedPaymentOutputDescriptor_get_per_commitment_point(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
84         let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
85         crate::c_types::PublicKey::from_rust(&inner_val)
86 }
87 /// Per commitment point to derive delayed_payment_key by key holder
88 #[no_mangle]
89 pub extern "C" fn DelayedPaymentOutputDescriptor_set_per_commitment_point(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
90         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
91 }
92 /// The nSequence value which must be set in the spending input to satisfy the OP_CSV in
93 /// the witness_script.
94 #[no_mangle]
95 pub extern "C" fn DelayedPaymentOutputDescriptor_get_to_self_delay(this_ptr: &DelayedPaymentOutputDescriptor) -> u16 {
96         let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay;
97         *inner_val
98 }
99 /// The nSequence value which must be set in the spending input to satisfy the OP_CSV in
100 /// the witness_script.
101 #[no_mangle]
102 pub extern "C" fn DelayedPaymentOutputDescriptor_set_to_self_delay(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u16) {
103         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val;
104 }
105 /// The output which is referenced by the given outpoint
106 #[no_mangle]
107 pub extern "C" fn DelayedPaymentOutputDescriptor_set_output(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
108         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
109 }
110 /// The revocation point specific to the commitment transaction which was broadcast. Used to
111 /// derive the witnessScript for this output.
112 #[no_mangle]
113 pub extern "C" fn DelayedPaymentOutputDescriptor_get_revocation_pubkey(this_ptr: &DelayedPaymentOutputDescriptor) -> crate::c_types::PublicKey {
114         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_pubkey;
115         crate::c_types::PublicKey::from_rust(&inner_val)
116 }
117 /// The revocation point specific to the commitment transaction which was broadcast. Used to
118 /// derive the witnessScript for this output.
119 #[no_mangle]
120 pub extern "C" fn DelayedPaymentOutputDescriptor_set_revocation_pubkey(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::PublicKey) {
121         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_pubkey = val.into_rust();
122 }
123 /// Arbitrary identification information returned by a call to
124 /// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in
125 /// the channel to spend the output.
126 #[no_mangle]
127 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &DelayedPaymentOutputDescriptor) -> *const [u8; 32] {
128         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
129         inner_val
130 }
131 /// Arbitrary identification information returned by a call to
132 /// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in
133 /// the channel to spend the output.
134 #[no_mangle]
135 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
136         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
137 }
138 /// The value of the channel which this output originated from, possibly indirectly.
139 #[no_mangle]
140 pub extern "C" fn DelayedPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &DelayedPaymentOutputDescriptor) -> u64 {
141         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
142         *inner_val
143 }
144 /// The value of the channel which this output originated from, possibly indirectly.
145 #[no_mangle]
146 pub extern "C" fn DelayedPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut DelayedPaymentOutputDescriptor, mut val: u64) {
147         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
148 }
149 /// Constructs a new DelayedPaymentOutputDescriptor given each field
150 #[must_use]
151 #[no_mangle]
152 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 {
153         DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeDelayedPaymentOutputDescriptor {
154                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
155                 per_commitment_point: per_commitment_point_arg.into_rust(),
156                 to_self_delay: to_self_delay_arg,
157                 output: output_arg.into_rust(),
158                 revocation_pubkey: revocation_pubkey_arg.into_rust(),
159                 channel_keys_id: channel_keys_id_arg.data,
160                 channel_value_satoshis: channel_value_satoshis_arg,
161         }), is_owned: true }
162 }
163 impl Clone for DelayedPaymentOutputDescriptor {
164         fn clone(&self) -> Self {
165                 Self {
166                         inner: if <*mut nativeDelayedPaymentOutputDescriptor>::is_null(self.inner) { std::ptr::null_mut() } else {
167                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
168                         is_owned: true,
169                 }
170         }
171 }
172 #[allow(unused)]
173 /// Used only if an object of this type is returned as a trait impl by a method
174 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
175         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDelayedPaymentOutputDescriptor)).clone() })) as *mut c_void
176 }
177 #[no_mangle]
178 /// Creates a copy of the DelayedPaymentOutputDescriptor
179 pub extern "C" fn DelayedPaymentOutputDescriptor_clone(orig: &DelayedPaymentOutputDescriptor) -> DelayedPaymentOutputDescriptor {
180         orig.clone()
181 }
182 #[no_mangle]
183 /// Serialize the DelayedPaymentOutputDescriptor object into a byte array which can be read by DelayedPaymentOutputDescriptor_read
184 pub extern "C" fn DelayedPaymentOutputDescriptor_write(obj: &DelayedPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
185         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
186 }
187 #[no_mangle]
188 pub(crate) extern "C" fn DelayedPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
189         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentOutputDescriptor) })
190 }
191 #[no_mangle]
192 /// Read a DelayedPaymentOutputDescriptor from a byte array, created by DelayedPaymentOutputDescriptor_write
193 pub extern "C" fn DelayedPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentOutputDescriptorDecodeErrorZ {
194         let res = crate::c_types::deserialize_obj(ser);
195         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
196         local_res
197 }
198
199 use lightning::chain::keysinterface::StaticPaymentOutputDescriptor as nativeStaticPaymentOutputDescriptorImport;
200 type nativeStaticPaymentOutputDescriptor = nativeStaticPaymentOutputDescriptorImport;
201
202 /// Information about a spendable output to our \"payment key\". See
203 /// SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this.
204 #[must_use]
205 #[repr(C)]
206 pub struct StaticPaymentOutputDescriptor {
207         /// A pointer to the opaque Rust object.
208
209         /// Nearly everywhere, inner must be non-null, however in places where
210         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
211         pub inner: *mut nativeStaticPaymentOutputDescriptor,
212         /// Indicates that this is the only struct which contains the same pointer.
213
214         /// Rust functions which take ownership of an object provided via an argument require
215         /// this to be true and invalidate the object pointed to by inner.
216         pub is_owned: bool,
217 }
218
219 impl Drop for StaticPaymentOutputDescriptor {
220         fn drop(&mut self) {
221                 if self.is_owned && !<*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) {
222                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
223                 }
224         }
225 }
226 /// Frees any resources used by the StaticPaymentOutputDescriptor, if is_owned is set and inner is non-NULL.
227 #[no_mangle]
228 pub extern "C" fn StaticPaymentOutputDescriptor_free(this_obj: StaticPaymentOutputDescriptor) { }
229 #[allow(unused)]
230 /// Used only if an object of this type is returned as a trait impl by a method
231 extern "C" fn StaticPaymentOutputDescriptor_free_void(this_ptr: *mut c_void) {
232         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeStaticPaymentOutputDescriptor); }
233 }
234 #[allow(unused)]
235 impl StaticPaymentOutputDescriptor {
236         pub(crate) fn get_native_ref(&self) -> &'static nativeStaticPaymentOutputDescriptor {
237                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
238         }
239         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeStaticPaymentOutputDescriptor {
240                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
241         }
242         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
243         pub(crate) fn take_inner(mut self) -> *mut nativeStaticPaymentOutputDescriptor {
244                 assert!(self.is_owned);
245                 let ret = ObjOps::untweak_ptr(self.inner);
246                 self.inner = std::ptr::null_mut();
247                 ret
248         }
249 }
250 /// The outpoint which is spendable
251 #[no_mangle]
252 pub extern "C" fn StaticPaymentOutputDescriptor_get_outpoint(this_ptr: &StaticPaymentOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
253         let mut inner_val = &mut this_ptr.get_native_mut_ref().outpoint;
254         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
255 }
256 /// The outpoint which is spendable
257 #[no_mangle]
258 pub extern "C" fn StaticPaymentOutputDescriptor_set_outpoint(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::lightning::chain::transaction::OutPoint) {
259         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.outpoint = *unsafe { Box::from_raw(val.take_inner()) };
260 }
261 /// The output which is referenced by the given outpoint
262 #[no_mangle]
263 pub extern "C" fn StaticPaymentOutputDescriptor_set_output(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::TxOut) {
264         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.output = val.into_rust();
265 }
266 /// Arbitrary identification information returned by a call to
267 /// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in
268 /// the channel to spend the output.
269 #[no_mangle]
270 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_keys_id(this_ptr: &StaticPaymentOutputDescriptor) -> *const [u8; 32] {
271         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_keys_id;
272         inner_val
273 }
274 /// Arbitrary identification information returned by a call to
275 /// `Sign::channel_keys_id()`. This may be useful in re-deriving keys used in
276 /// the channel to spend the output.
277 #[no_mangle]
278 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_keys_id(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: crate::c_types::ThirtyTwoBytes) {
279         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_keys_id = val.data;
280 }
281 /// The value of the channel which this transactions spends.
282 #[no_mangle]
283 pub extern "C" fn StaticPaymentOutputDescriptor_get_channel_value_satoshis(this_ptr: &StaticPaymentOutputDescriptor) -> u64 {
284         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_value_satoshis;
285         *inner_val
286 }
287 /// The value of the channel which this transactions spends.
288 #[no_mangle]
289 pub extern "C" fn StaticPaymentOutputDescriptor_set_channel_value_satoshis(this_ptr: &mut StaticPaymentOutputDescriptor, mut val: u64) {
290         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_value_satoshis = val;
291 }
292 /// Constructs a new StaticPaymentOutputDescriptor given each field
293 #[must_use]
294 #[no_mangle]
295 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 {
296         StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(nativeStaticPaymentOutputDescriptor {
297                 outpoint: *unsafe { Box::from_raw(outpoint_arg.take_inner()) },
298                 output: output_arg.into_rust(),
299                 channel_keys_id: channel_keys_id_arg.data,
300                 channel_value_satoshis: channel_value_satoshis_arg,
301         }), is_owned: true }
302 }
303 impl Clone for StaticPaymentOutputDescriptor {
304         fn clone(&self) -> Self {
305                 Self {
306                         inner: if <*mut nativeStaticPaymentOutputDescriptor>::is_null(self.inner) { std::ptr::null_mut() } else {
307                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
308                         is_owned: true,
309                 }
310         }
311 }
312 #[allow(unused)]
313 /// Used only if an object of this type is returned as a trait impl by a method
314 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_clone_void(this_ptr: *const c_void) -> *mut c_void {
315         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeStaticPaymentOutputDescriptor)).clone() })) as *mut c_void
316 }
317 #[no_mangle]
318 /// Creates a copy of the StaticPaymentOutputDescriptor
319 pub extern "C" fn StaticPaymentOutputDescriptor_clone(orig: &StaticPaymentOutputDescriptor) -> StaticPaymentOutputDescriptor {
320         orig.clone()
321 }
322 #[no_mangle]
323 /// Serialize the StaticPaymentOutputDescriptor object into a byte array which can be read by StaticPaymentOutputDescriptor_read
324 pub extern "C" fn StaticPaymentOutputDescriptor_write(obj: &StaticPaymentOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
325         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
326 }
327 #[no_mangle]
328 pub(crate) extern "C" fn StaticPaymentOutputDescriptor_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
329         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeStaticPaymentOutputDescriptor) })
330 }
331 #[no_mangle]
332 /// Read a StaticPaymentOutputDescriptor from a byte array, created by StaticPaymentOutputDescriptor_write
333 pub extern "C" fn StaticPaymentOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_StaticPaymentOutputDescriptorDecodeErrorZ {
334         let res = crate::c_types::deserialize_obj(ser);
335         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
336         local_res
337 }
338 /// When on-chain outputs are created by rust-lightning (which our counterparty is not able to
339 /// claim at any point in the future) an event is generated which you must track and be able to
340 /// spend on-chain. The information needed to do this is provided in this enum, including the
341 /// outpoint describing which txid and output index is available, the full output which exists at
342 /// that txid/index, and any keys or other information required to sign.
343 #[must_use]
344 #[derive(Clone)]
345 #[repr(C)]
346 pub enum SpendableOutputDescriptor {
347         /// An output to a script which was provided via KeysInterface directly, either from
348         /// `get_destination_script()` or `get_shutdown_scriptpubkey()`, thus you should already know
349         /// how to spend it. No secret keys are provided as rust-lightning was never given any key.
350         /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
351         /// on-chain using the payment preimage or after it has timed out.
352         StaticOutput {
353                 /// The outpoint which is spendable
354                 outpoint: crate::lightning::chain::transaction::OutPoint,
355                 /// The output which is referenced by the given outpoint.
356                 output: crate::c_types::TxOut,
357         },
358         /// An output to a P2WSH script which can be spent with a single signature after a CSV delay.
359         ///
360         /// The witness in the spending input should be:
361         /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
362         ///
363         /// Note that the nSequence field in the spending input must be set to to_self_delay
364         /// (which means the transaction is not broadcastable until at least to_self_delay
365         /// blocks after the outpoint confirms).
366         ///
367         /// These are generally the result of a \"revocable\" output to us, spendable only by us unless
368         /// it is an output from an old state which we broadcast (which should never happen).
369         ///
370         /// To derive the delayed_payment key which is used to sign for this input, you must pass the
371         /// holder delayed_payment_base_key (ie the private key which corresponds to the pubkey in
372         /// Sign::pubkeys().delayed_payment_basepoint) and the provided per_commitment_point to
373         /// chan_utils::derive_private_key. The public key can be generated without the secret key
374         /// using chan_utils::derive_public_key and only the delayed_payment_basepoint which appears in
375         /// Sign::pubkeys().
376         ///
377         /// To derive the revocation_pubkey provided here (which is used in the witness
378         /// script generation), you must pass the counterparty revocation_basepoint (which appears in the
379         /// call to Sign::ready_channel) and the provided per_commitment point
380         /// to chan_utils::derive_public_revocation_key.
381         ///
382         /// The witness script which is hashed and included in the output script_pubkey may be
383         /// regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey
384         /// (derived as above), and the to_self_delay contained here to
385         /// chan_utils::get_revokeable_redeemscript.
386         DelayedPaymentOutput(crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor),
387         /// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
388         /// corresponds to the public key in Sign::pubkeys().payment_point).
389         /// The witness in the spending input, is, thus, simply:
390         /// <BIP 143 signature> <payment key>
391         ///
392         /// These are generally the result of our counterparty having broadcast the current state,
393         /// allowing us to claim the non-HTLC-encumbered outputs immediately.
394         StaticPaymentOutput(crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor),
395 }
396 use lightning::chain::keysinterface::SpendableOutputDescriptor as nativeSpendableOutputDescriptor;
397 impl SpendableOutputDescriptor {
398         #[allow(unused)]
399         pub(crate) fn to_native(&self) -> nativeSpendableOutputDescriptor {
400                 match self {
401                         SpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
402                                 let mut outpoint_nonref = (*outpoint).clone();
403                                 let mut output_nonref = (*output).clone();
404                                 nativeSpendableOutputDescriptor::StaticOutput {
405                                         outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) },
406                                         output: output_nonref.into_rust(),
407                                 }
408                         },
409                         SpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
410                                 let mut a_nonref = (*a).clone();
411                                 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
412                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
413                                 )
414                         },
415                         SpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
416                                 let mut a_nonref = (*a).clone();
417                                 nativeSpendableOutputDescriptor::StaticPaymentOutput (
418                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
419                                 )
420                         },
421                 }
422         }
423         #[allow(unused)]
424         pub(crate) fn into_native(self) -> nativeSpendableOutputDescriptor {
425                 match self {
426                         SpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
427                                 nativeSpendableOutputDescriptor::StaticOutput {
428                                         outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) },
429                                         output: output.into_rust(),
430                                 }
431                         },
432                         SpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
433                                 nativeSpendableOutputDescriptor::DelayedPaymentOutput (
434                                         *unsafe { Box::from_raw(a.take_inner()) },
435                                 )
436                         },
437                         SpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
438                                 nativeSpendableOutputDescriptor::StaticPaymentOutput (
439                                         *unsafe { Box::from_raw(a.take_inner()) },
440                                 )
441                         },
442                 }
443         }
444         #[allow(unused)]
445         pub(crate) fn from_native(native: &nativeSpendableOutputDescriptor) -> Self {
446                 match native {
447                         nativeSpendableOutputDescriptor::StaticOutput {ref outpoint, ref output, } => {
448                                 let mut outpoint_nonref = (*outpoint).clone();
449                                 let mut output_nonref = (*output).clone();
450                                 SpendableOutputDescriptor::StaticOutput {
451                                         outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint_nonref), is_owned: true },
452                                         output: crate::c_types::TxOut::from_rust(output_nonref),
453                                 }
454                         },
455                         nativeSpendableOutputDescriptor::DelayedPaymentOutput (ref a, ) => {
456                                 let mut a_nonref = (*a).clone();
457                                 SpendableOutputDescriptor::DelayedPaymentOutput (
458                                         crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
459                                 )
460                         },
461                         nativeSpendableOutputDescriptor::StaticPaymentOutput (ref a, ) => {
462                                 let mut a_nonref = (*a).clone();
463                                 SpendableOutputDescriptor::StaticPaymentOutput (
464                                         crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
465                                 )
466                         },
467                 }
468         }
469         #[allow(unused)]
470         pub(crate) fn native_into(native: nativeSpendableOutputDescriptor) -> Self {
471                 match native {
472                         nativeSpendableOutputDescriptor::StaticOutput {mut outpoint, mut output, } => {
473                                 SpendableOutputDescriptor::StaticOutput {
474                                         outpoint: crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(outpoint), is_owned: true },
475                                         output: crate::c_types::TxOut::from_rust(output),
476                                 }
477                         },
478                         nativeSpendableOutputDescriptor::DelayedPaymentOutput (mut a, ) => {
479                                 SpendableOutputDescriptor::DelayedPaymentOutput (
480                                         crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
481                                 )
482                         },
483                         nativeSpendableOutputDescriptor::StaticPaymentOutput (mut a, ) => {
484                                 SpendableOutputDescriptor::StaticPaymentOutput (
485                                         crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor { inner: ObjOps::heap_alloc(a), is_owned: true },
486                                 )
487                         },
488                 }
489         }
490 }
491 /// Frees any resources used by the SpendableOutputDescriptor
492 #[no_mangle]
493 pub extern "C" fn SpendableOutputDescriptor_free(this_ptr: SpendableOutputDescriptor) { }
494 /// Creates a copy of the SpendableOutputDescriptor
495 #[no_mangle]
496 pub extern "C" fn SpendableOutputDescriptor_clone(orig: &SpendableOutputDescriptor) -> SpendableOutputDescriptor {
497         orig.clone()
498 }
499 #[no_mangle]
500 /// Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
501 pub extern "C" fn SpendableOutputDescriptor_static_output(outpoint: crate::lightning::chain::transaction::OutPoint, output: crate::c_types::TxOut) -> SpendableOutputDescriptor {
502         SpendableOutputDescriptor::StaticOutput {
503                 outpoint,
504                 output,
505         }
506 }
507 #[no_mangle]
508 /// Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
509 pub extern "C" fn SpendableOutputDescriptor_delayed_payment_output(a: crate::lightning::chain::keysinterface::DelayedPaymentOutputDescriptor) -> SpendableOutputDescriptor {
510         SpendableOutputDescriptor::DelayedPaymentOutput(a, )
511 }
512 #[no_mangle]
513 /// Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
514 pub extern "C" fn SpendableOutputDescriptor_static_payment_output(a: crate::lightning::chain::keysinterface::StaticPaymentOutputDescriptor) -> SpendableOutputDescriptor {
515         SpendableOutputDescriptor::StaticPaymentOutput(a, )
516 }
517 #[no_mangle]
518 /// Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
519 pub extern "C" fn SpendableOutputDescriptor_write(obj: &SpendableOutputDescriptor) -> crate::c_types::derived::CVec_u8Z {
520         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
521 }
522 #[no_mangle]
523 /// Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
524 pub extern "C" fn SpendableOutputDescriptor_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpendableOutputDescriptorDecodeErrorZ {
525         let res = crate::c_types::deserialize_obj(ser);
526         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
527         local_res
528 }
529 /// A trait to sign lightning channel transactions as described in BOLT 3.
530 ///
531 /// Signing services could be implemented on a hardware wallet. In this case,
532 /// the current Sign would be a front-end on top of a communication
533 /// channel connected to your secure device and lightning key material wouldn't
534 /// reside on a hot server. Nevertheless, a this deployment would still need
535 /// to trust the ChannelManager to avoid loss of funds as this latest component
536 /// could ask to sign commitment transaction with HTLCs paying to attacker pubkeys.
537 ///
538 /// A more secure iteration would be to use hashlock (or payment points) to pair
539 /// invoice/incoming HTLCs with outgoing HTLCs to implement a no-trust-ChannelManager
540 /// at the price of more state and computation on the hardware wallet side. In the future,
541 /// we are looking forward to design such interface.
542 ///
543 /// In any case, ChannelMonitor or fallback watchtowers are always going to be trusted
544 /// to act, as liveness and breach reply correctness are always going to be hard requirements
545 /// of LN security model, orthogonal of key management issues.
546 #[repr(C)]
547 pub struct BaseSign {
548         /// An opaque pointer which is passed to your function implementations as an argument.
549         /// This has no meaning in the LDK, and can be NULL or any other value.
550         pub this_arg: *mut c_void,
551         /// Gets the per-commitment point for a specific commitment number
552         ///
553         /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
554         #[must_use]
555         pub get_per_commitment_point: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::PublicKey,
556         /// Gets the commitment secret for a specific commitment number as part of the revocation process
557         ///
558         /// An external signer implementation should error here if the commitment was already signed
559         /// and should refuse to sign it in the future.
560         ///
561         /// May be called more than once for the same index.
562         ///
563         /// Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
564         #[must_use]
565         pub release_commitment_secret: extern "C" fn (this_arg: *const c_void, idx: u64) -> crate::c_types::ThirtyTwoBytes,
566         /// Gets the holder's channel public keys and basepoints
567         pub pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys,
568         /// Fill in the pubkeys field as a reference to it will be given to Rust after this returns
569         /// Note that this takes a pointer to this object, not the this_ptr like other methods do
570         /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating.
571         pub set_pubkeys: Option<extern "C" fn(&BaseSign)>,
572         /// Gets an arbitrary identifier describing the set of keys which are provided back to you in
573         /// some SpendableOutputDescriptor types. This should be sufficient to identify this
574         /// Sign object uniquely and lookup or re-derive its keys.
575         #[must_use]
576         pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
577         /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
578         ///
579         /// Note that if signing fails or is rejected, the channel will be force-closed.
580         #[must_use]
581         pub sign_counterparty_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ,
582         /// Create a signatures for a holder's commitment transaction and its claiming HTLC transactions.
583         /// This will only ever be called with a non-revoked commitment_tx.  This will be called with the
584         /// latest commitment_tx when we initiate a force-close.
585         /// This will be called with the previous latest, just to get claiming HTLC signatures, if we are
586         /// reacting to a ChannelMonitor replica that decided to broadcast before it had been updated to
587         /// the latest.
588         /// This may be called multiple times for the same transaction.
589         ///
590         /// An external signer implementation should check that the commitment has not been revoked.
591         ///
592         /// May return Err if key derivation fails.  Callers, such as ChannelMonitor, will panic in such a case.
593         #[must_use]
594         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,
595         /// Create a signature for the given input in a transaction spending an HTLC transaction output
596         /// or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
597         ///
598         /// A justice transaction may claim multiple outputs at the same time if timelocks are
599         /// similar, but only a signature for the input at index `input` should be signed for here.
600         /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
601         /// to an upcoming timelock expiration.
602         ///
603         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
604         ///
605         /// per_commitment_key is revocation secret which was provided by our counterparty when they
606         /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
607         /// not allow the spending of any funds by itself (you need our holder revocation_secret to do
608         /// so).
609         #[must_use]
610         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,
611         /// Create a signature for the given input in a transaction spending a commitment transaction
612         /// HTLC output when our counterparty broadcasts an old state.
613         ///
614         /// A justice transaction may claim multiple outputs at the same time if timelocks are
615         /// similar, but only a signature for the input at index `input` should be signed for here.
616         /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
617         /// to an upcoming timelock expiration.
618         ///
619         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
620         ///
621         /// per_commitment_key is revocation secret which was provided by our counterparty when they
622         /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
623         /// not allow the spending of any funds by itself (you need our holder revocation_secret to do
624         /// so).
625         ///
626         /// htlc holds HTLC elements (hash, timelock), thus changing the format of the witness script
627         /// (which is committed to in the BIP 143 signatures).
628         #[must_use]
629         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,
630         /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
631         /// transaction, either offered or received.
632         ///
633         /// Such a transaction may claim multiples offered outputs at same time if we know the
634         /// preimage for each when we create it, but only the input at index `input` should be
635         /// signed for here. It may be called multiple times for same output(s) if a fee-bump is
636         /// needed with regards to an upcoming timelock expiration.
637         ///
638         /// Witness_script is either a offered or received script as defined in BOLT3 for HTLC
639         /// outputs.
640         ///
641         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
642         ///
643         /// Per_commitment_point is the dynamic point corresponding to the channel state
644         /// detected onchain. It has been generated by our counterparty and is used to derive
645         /// channel state keys, which are then included in the witness script and committed to in the
646         /// BIP 143 signature.
647         #[must_use]
648         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,
649         /// Create a signature for a (proposed) closing transaction.
650         ///
651         /// Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
652         /// chosen to forgo their output as dust.
653         #[must_use]
654         pub sign_closing_transaction: extern "C" fn (this_arg: *const c_void, closing_tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_SignatureNoneZ,
655         /// Signs a channel announcement message with our funding key, proving it comes from one
656         /// of the channel participants.
657         ///
658         /// Note that if this fails or is rejected, the channel will not be publicly announced and
659         /// our counterparty may (though likely will not) close the channel on us for violating the
660         /// protocol.
661         #[must_use]
662         pub sign_channel_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ,
663         /// Set the counterparty static channel data, including basepoints,
664         /// counterparty_selected/holder_selected_contest_delay and funding outpoint.
665         /// This is done as soon as the funding outpoint is known.  Since these are static channel data,
666         /// they MUST NOT be allowed to change to different values once set.
667         ///
668         /// channel_parameters.is_populated() MUST be true.
669         ///
670         /// We bind holder_selected_contest_delay late here for API convenience.
671         ///
672         /// Will be called before any signatures are applied.
673         pub ready_channel: extern "C" fn (this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters),
674         /// Frees any resources associated with this object given its this_arg pointer.
675         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
676         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
677 }
678 unsafe impl Send for BaseSign {}
679 unsafe impl Sync for BaseSign {}
680 #[no_mangle]
681 pub(crate) extern "C" fn BaseSign_clone_fields(orig: &BaseSign) -> BaseSign {
682         BaseSign {
683                 this_arg: orig.this_arg,
684                 get_per_commitment_point: Clone::clone(&orig.get_per_commitment_point),
685                 release_commitment_secret: Clone::clone(&orig.release_commitment_secret),
686                 pubkeys: Clone::clone(&orig.pubkeys),
687                 set_pubkeys: Clone::clone(&orig.set_pubkeys),
688                 channel_keys_id: Clone::clone(&orig.channel_keys_id),
689                 sign_counterparty_commitment: Clone::clone(&orig.sign_counterparty_commitment),
690                 sign_holder_commitment_and_htlcs: Clone::clone(&orig.sign_holder_commitment_and_htlcs),
691                 sign_justice_revoked_output: Clone::clone(&orig.sign_justice_revoked_output),
692                 sign_justice_revoked_htlc: Clone::clone(&orig.sign_justice_revoked_htlc),
693                 sign_counterparty_htlc_transaction: Clone::clone(&orig.sign_counterparty_htlc_transaction),
694                 sign_closing_transaction: Clone::clone(&orig.sign_closing_transaction),
695                 sign_channel_announcement: Clone::clone(&orig.sign_channel_announcement),
696                 ready_channel: Clone::clone(&orig.ready_channel),
697                 free: Clone::clone(&orig.free),
698         }
699 }
700
701 use lightning::chain::keysinterface::BaseSign as rustBaseSign;
702 impl rustBaseSign for BaseSign {
703         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::key::PublicKey {
704                 let mut ret = (self.get_per_commitment_point)(self.this_arg, idx);
705                 ret.into_rust()
706         }
707         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
708                 let mut ret = (self.release_commitment_secret)(self.this_arg, idx);
709                 ret.data
710         }
711         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
712                 if let Some(f) = self.set_pubkeys {
713                         (f)(&self);
714                 }
715                 self.pubkeys.get_native_ref()
716         }
717         fn channel_keys_id(&self) -> [u8; 32] {
718                 let mut ret = (self.channel_keys_id)(self.this_arg);
719                 ret.data
720         }
721         fn sign_counterparty_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::Signature, Vec<bitcoin::secp256k1::Signature>), ()> {
722                 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 _) as *mut _) }, is_owned: false });
723                 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)) })*/ })};
724                 local_ret
725         }
726         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::Signature, Vec<bitcoin::secp256k1::Signature>), ()> {
727                 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 _) as *mut _) }, is_owned: false });
728                 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)) })*/ })};
729                 local_ret
730         }
731         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::key::SecretKey, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
732                 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());
733                 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)) })*/ })};
734                 local_ret
735         }
736         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::key::SecretKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
737                 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 _) as *mut _) }, is_owned: false });
738                 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)) })*/ })};
739                 local_ret
740         }
741         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::key::PublicKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
742                 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 _) as *mut _) }, is_owned: false });
743                 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)) })*/ })};
744                 local_ret
745         }
746         fn sign_closing_transaction(&self, mut closing_tx: &bitcoin::blockdata::transaction::Transaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
747                 let mut ret = (self.sign_closing_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(closing_tx));
748                 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)) })*/ })};
749                 local_ret
750         }
751         fn sign_channel_announcement(&self, mut msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
752                 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 _) as *mut _) }, is_owned: false });
753                 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)) })*/ })};
754                 local_ret
755         }
756         fn ready_channel(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
757                 (self.ready_channel)(self.this_arg, &crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((channel_parameters as *const _) as *mut _) }, is_owned: false })
758         }
759 }
760
761 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
762 // directly as a Deref trait in higher-level structs:
763 impl std::ops::Deref for BaseSign {
764         type Target = Self;
765         fn deref(&self) -> &Self {
766                 self
767         }
768 }
769 /// Calls the free function if one is set
770 #[no_mangle]
771 pub extern "C" fn BaseSign_free(this_ptr: BaseSign) { }
772 impl Drop for BaseSign {
773         fn drop(&mut self) {
774                 if let Some(f) = self.free {
775                         f(self.this_arg);
776                 }
777         }
778 }
779 /// A cloneable signer.
780 ///
781 /// Although we require signers to be cloneable, it may be useful for developers to be able to use
782 /// signers in an un-sized way, for example as `dyn BaseSign`. Therefore we separate the Clone trait,
783 /// which implies Sized, into this derived trait.
784 #[repr(C)]
785 pub struct Sign {
786         /// An opaque pointer which is passed to your function implementations as an argument.
787         /// This has no meaning in the LDK, and can be NULL or any other value.
788         pub this_arg: *mut c_void,
789         /// Implementation of BaseSign for this object.
790         pub BaseSign: crate::lightning::chain::keysinterface::BaseSign,
791         /// Serialize the object into a byte array
792         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
793         /// Called, if set, after this Sign has been cloned into a duplicate object.
794         /// The new Sign is provided, and should be mutated as needed to perform a
795         /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
796         pub cloned: Option<extern "C" fn (new_Sign: &mut Sign)>,
797         /// Frees any resources associated with this object given its this_arg pointer.
798         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
799         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
800 }
801 unsafe impl Send for Sign {}
802 unsafe impl Sync for Sign {}
803 #[no_mangle]
804 pub(crate) extern "C" fn Sign_clone_fields(orig: &Sign) -> Sign {
805         Sign {
806                 this_arg: orig.this_arg,
807                 BaseSign: crate::lightning::chain::keysinterface::BaseSign_clone_fields(&orig.BaseSign),
808                 write: Clone::clone(&orig.write),
809                 cloned: Clone::clone(&orig.cloned),
810                 free: Clone::clone(&orig.free),
811         }
812 }
813 impl lightning::chain::keysinterface::BaseSign for Sign {
814         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::key::PublicKey {
815                 let mut ret = (self.BaseSign.get_per_commitment_point)(self.BaseSign.this_arg, idx);
816                 ret.into_rust()
817         }
818         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
819                 let mut ret = (self.BaseSign.release_commitment_secret)(self.BaseSign.this_arg, idx);
820                 ret.data
821         }
822         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
823                 if let Some(f) = self.BaseSign.set_pubkeys {
824                         (f)(&self.BaseSign);
825                 }
826                 self.BaseSign.pubkeys.get_native_ref()
827         }
828         fn channel_keys_id(&self) -> [u8; 32] {
829                 let mut ret = (self.BaseSign.channel_keys_id)(self.BaseSign.this_arg);
830                 ret.data
831         }
832         fn sign_counterparty_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::Signature, Vec<bitcoin::secp256k1::Signature>), ()> {
833                 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 _) as *mut _) }, is_owned: false });
834                 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)) })*/ })};
835                 local_ret
836         }
837         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::Signature, Vec<bitcoin::secp256k1::Signature>), ()> {
838                 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 _) as *mut _) }, is_owned: false });
839                 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)) })*/ })};
840                 local_ret
841         }
842         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::key::SecretKey, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
843                 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());
844                 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)) })*/ })};
845                 local_ret
846         }
847         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::key::SecretKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
848                 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 _) as *mut _) }, is_owned: false });
849                 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)) })*/ })};
850                 local_ret
851         }
852         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::key::PublicKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
853                 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 _) as *mut _) }, is_owned: false });
854                 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)) })*/ })};
855                 local_ret
856         }
857         fn sign_closing_transaction(&self, mut closing_tx: &bitcoin::blockdata::transaction::Transaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
858                 let mut ret = (self.BaseSign.sign_closing_transaction)(self.BaseSign.this_arg, crate::c_types::Transaction::from_bitcoin(closing_tx));
859                 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)) })*/ })};
860                 local_ret
861         }
862         fn sign_channel_announcement(&self, mut msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::Signature, ()> {
863                 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 _) as *mut _) }, is_owned: false });
864                 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)) })*/ })};
865                 local_ret
866         }
867         fn ready_channel(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
868                 (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 _) as *mut _) }, is_owned: false })
869         }
870 }
871 impl lightning::util::ser::Writeable for Sign {
872         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
873                 let vec = (self.write)(self.this_arg);
874                 w.write_all(vec.as_slice())
875         }
876 }
877 #[no_mangle]
878 /// Creates a copy of a Sign
879 pub extern "C" fn Sign_clone(orig: &Sign) -> Sign {
880         let mut res = Sign_clone_fields(orig);
881         if let Some(f) = orig.cloned { (f)(&mut res) };
882         res
883 }
884 impl Clone for Sign {
885         fn clone(&self) -> Self {
886                 Sign_clone(self)
887         }
888 }
889
890 use lightning::chain::keysinterface::Sign as rustSign;
891 impl rustSign for Sign {
892 }
893
894 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
895 // directly as a Deref trait in higher-level structs:
896 impl std::ops::Deref for Sign {
897         type Target = Self;
898         fn deref(&self) -> &Self {
899                 self
900         }
901 }
902 /// Calls the free function if one is set
903 #[no_mangle]
904 pub extern "C" fn Sign_free(this_ptr: Sign) { }
905 impl Drop for Sign {
906         fn drop(&mut self) {
907                 if let Some(f) = self.free {
908                         f(self.this_arg);
909                 }
910         }
911 }
912 /// A trait to describe an object which can get user secrets and key material.
913 #[repr(C)]
914 pub struct KeysInterface {
915         /// An opaque pointer which is passed to your function implementations as an argument.
916         /// This has no meaning in the LDK, and can be NULL or any other value.
917         pub this_arg: *mut c_void,
918         /// Get node secret key (aka node_id or network_key).
919         ///
920         /// This method must return the same value each time it is called.
921         #[must_use]
922         pub get_node_secret: extern "C" fn (this_arg: *const c_void) -> crate::c_types::SecretKey,
923         /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
924         ///
925         /// This method should return a different value each time it is called, to avoid linking
926         /// on-chain funds across channels as controlled to the same user.
927         #[must_use]
928         pub get_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
929         /// Get a script pubkey which we will send funds to when closing a channel.
930         ///
931         /// This method should return a different value each time it is called, to avoid linking
932         /// on-chain funds across channels as controlled to the same user.
933         #[must_use]
934         pub get_shutdown_scriptpubkey: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::script::ShutdownScript,
935         /// Get a new set of Sign for per-channel secrets. These MUST be unique even if you
936         /// restarted with some stale data!
937         ///
938         /// This method must return a different value each time it is called.
939         #[must_use]
940         pub get_channel_signer: extern "C" fn (this_arg: *const c_void, inbound: bool, channel_value_satoshis: u64) -> crate::lightning::chain::keysinterface::Sign,
941         /// Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
942         /// onion packets and for temporary channel IDs. There is no requirement that these be
943         /// persisted anywhere, though they must be unique across restarts.
944         ///
945         /// This method must return a different value each time it is called.
946         #[must_use]
947         pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
948         /// Reads a `Signer` for this `KeysInterface` from the given input stream.
949         /// This is only called during deserialization of other objects which contain
950         /// `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
951         /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
952         /// contain no versioning scheme. You may wish to include your own version prefix and ensure
953         /// you've read all of the provided bytes to ensure no corruption occurred.
954         #[must_use]
955         pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SignDecodeErrorZ,
956         /// Sign an invoice's preimage (note that this is the preimage of the invoice, not the HTLC's
957         /// preimage). By parameterizing by the preimage instead of the hash, we allow implementors of
958         /// this trait to parse the invoice and make sure they're signing what they expect, rather than
959         /// blindly signing the hash.
960         #[must_use]
961         pub sign_invoice: extern "C" fn (this_arg: *const c_void, invoice_preimage: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ,
962         /// Frees any resources associated with this object given its this_arg pointer.
963         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
964         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
965 }
966 unsafe impl Send for KeysInterface {}
967 unsafe impl Sync for KeysInterface {}
968 #[no_mangle]
969 pub(crate) extern "C" fn KeysInterface_clone_fields(orig: &KeysInterface) -> KeysInterface {
970         KeysInterface {
971                 this_arg: orig.this_arg,
972                 get_node_secret: Clone::clone(&orig.get_node_secret),
973                 get_destination_script: Clone::clone(&orig.get_destination_script),
974                 get_shutdown_scriptpubkey: Clone::clone(&orig.get_shutdown_scriptpubkey),
975                 get_channel_signer: Clone::clone(&orig.get_channel_signer),
976                 get_secure_random_bytes: Clone::clone(&orig.get_secure_random_bytes),
977                 read_chan_signer: Clone::clone(&orig.read_chan_signer),
978                 sign_invoice: Clone::clone(&orig.sign_invoice),
979                 free: Clone::clone(&orig.free),
980         }
981 }
982
983 use lightning::chain::keysinterface::KeysInterface as rustKeysInterface;
984 impl rustKeysInterface for KeysInterface {
985         type Signer = crate::lightning::chain::keysinterface::Sign;
986         fn get_node_secret(&self) -> bitcoin::secp256k1::key::SecretKey {
987                 let mut ret = (self.get_node_secret)(self.this_arg);
988                 ret.into_rust()
989         }
990         fn get_destination_script(&self) -> bitcoin::blockdata::script::Script {
991                 let mut ret = (self.get_destination_script)(self.this_arg);
992                 ::bitcoin::blockdata::script::Script::from(ret.into_rust())
993         }
994         fn get_shutdown_scriptpubkey(&self) -> lightning::ln::script::ShutdownScript {
995                 let mut ret = (self.get_shutdown_scriptpubkey)(self.this_arg);
996                 *unsafe { Box::from_raw(ret.take_inner()) }
997         }
998         fn get_channel_signer(&self, mut inbound: bool, mut channel_value_satoshis: u64) -> crate::lightning::chain::keysinterface::Sign {
999                 let mut ret = (self.get_channel_signer)(self.this_arg, inbound, channel_value_satoshis);
1000                 ret
1001         }
1002         fn get_secure_random_bytes(&self) -> [u8; 32] {
1003                 let mut ret = (self.get_secure_random_bytes)(self.this_arg);
1004                 ret.data
1005         }
1006         fn read_chan_signer(&self, mut reader: &[u8]) -> Result<crate::lightning::chain::keysinterface::Sign, lightning::ln::msgs::DecodeError> {
1007                 let mut local_reader = crate::c_types::u8slice::from_slice(reader);
1008                 let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
1009                 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((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
1010                 local_ret
1011         }
1012         fn sign_invoice(&self, mut invoice_preimage: Vec<u8>) -> Result<bitcoin::secp256k1::recovery::RecoverableSignature, ()> {
1013                 let mut local_invoice_preimage = Vec::new(); for mut item in invoice_preimage.drain(..) { local_invoice_preimage.push( { item }); };
1014                 let mut ret = (self.sign_invoice)(self.this_arg, local_invoice_preimage.into());
1015                 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)) })*/ })};
1016                 local_ret
1017         }
1018 }
1019
1020 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
1021 // directly as a Deref trait in higher-level structs:
1022 impl std::ops::Deref for KeysInterface {
1023         type Target = Self;
1024         fn deref(&self) -> &Self {
1025                 self
1026         }
1027 }
1028 /// Calls the free function if one is set
1029 #[no_mangle]
1030 pub extern "C" fn KeysInterface_free(this_ptr: KeysInterface) { }
1031 impl Drop for KeysInterface {
1032         fn drop(&mut self) {
1033                 if let Some(f) = self.free {
1034                         f(self.this_arg);
1035                 }
1036         }
1037 }
1038
1039 use lightning::chain::keysinterface::InMemorySigner as nativeInMemorySignerImport;
1040 type nativeInMemorySigner = nativeInMemorySignerImport;
1041
1042 /// A simple implementation of Sign that just keeps the private keys in memory.
1043 ///
1044 /// This implementation performs no policy checks and is insufficient by itself as
1045 /// a secure external signer.
1046 #[must_use]
1047 #[repr(C)]
1048 pub struct InMemorySigner {
1049         /// A pointer to the opaque Rust object.
1050
1051         /// Nearly everywhere, inner must be non-null, however in places where
1052         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1053         pub inner: *mut nativeInMemorySigner,
1054         /// Indicates that this is the only struct which contains the same pointer.
1055
1056         /// Rust functions which take ownership of an object provided via an argument require
1057         /// this to be true and invalidate the object pointed to by inner.
1058         pub is_owned: bool,
1059 }
1060
1061 impl Drop for InMemorySigner {
1062         fn drop(&mut self) {
1063                 if self.is_owned && !<*mut nativeInMemorySigner>::is_null(self.inner) {
1064                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1065                 }
1066         }
1067 }
1068 /// Frees any resources used by the InMemorySigner, if is_owned is set and inner is non-NULL.
1069 #[no_mangle]
1070 pub extern "C" fn InMemorySigner_free(this_obj: InMemorySigner) { }
1071 #[allow(unused)]
1072 /// Used only if an object of this type is returned as a trait impl by a method
1073 extern "C" fn InMemorySigner_free_void(this_ptr: *mut c_void) {
1074         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInMemorySigner); }
1075 }
1076 #[allow(unused)]
1077 impl InMemorySigner {
1078         pub(crate) fn get_native_ref(&self) -> &'static nativeInMemorySigner {
1079                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1080         }
1081         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInMemorySigner {
1082                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1083         }
1084         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1085         pub(crate) fn take_inner(mut self) -> *mut nativeInMemorySigner {
1086                 assert!(self.is_owned);
1087                 let ret = ObjOps::untweak_ptr(self.inner);
1088                 self.inner = std::ptr::null_mut();
1089                 ret
1090         }
1091 }
1092 /// Private key of anchor tx
1093 #[no_mangle]
1094 pub extern "C" fn InMemorySigner_get_funding_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1095         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_key;
1096         inner_val.as_ref()
1097 }
1098 /// Private key of anchor tx
1099 #[no_mangle]
1100 pub extern "C" fn InMemorySigner_set_funding_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1101         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_key = val.into_rust();
1102 }
1103 /// Holder secret key for blinded revocation pubkey
1104 #[no_mangle]
1105 pub extern "C" fn InMemorySigner_get_revocation_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1106         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_base_key;
1107         inner_val.as_ref()
1108 }
1109 /// Holder secret key for blinded revocation pubkey
1110 #[no_mangle]
1111 pub extern "C" fn InMemorySigner_set_revocation_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1112         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_base_key = val.into_rust();
1113 }
1114 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions
1115 #[no_mangle]
1116 pub extern "C" fn InMemorySigner_get_payment_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1117         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_key;
1118         inner_val.as_ref()
1119 }
1120 /// Holder secret key used for our balance in counterparty-broadcasted commitment transactions
1121 #[no_mangle]
1122 pub extern "C" fn InMemorySigner_set_payment_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1123         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_key = val.into_rust();
1124 }
1125 /// Holder secret key used in HTLC tx
1126 #[no_mangle]
1127 pub extern "C" fn InMemorySigner_get_delayed_payment_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1128         let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_base_key;
1129         inner_val.as_ref()
1130 }
1131 /// Holder secret key used in HTLC tx
1132 #[no_mangle]
1133 pub extern "C" fn InMemorySigner_set_delayed_payment_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1134         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_base_key = val.into_rust();
1135 }
1136 /// Holder htlc secret key used in commitment tx htlc outputs
1137 #[no_mangle]
1138 pub extern "C" fn InMemorySigner_get_htlc_base_key(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1139         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_base_key;
1140         inner_val.as_ref()
1141 }
1142 /// Holder htlc secret key used in commitment tx htlc outputs
1143 #[no_mangle]
1144 pub extern "C" fn InMemorySigner_set_htlc_base_key(this_ptr: &mut InMemorySigner, mut val: crate::c_types::SecretKey) {
1145         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_base_key = val.into_rust();
1146 }
1147 /// Commitment seed
1148 #[no_mangle]
1149 pub extern "C" fn InMemorySigner_get_commitment_seed(this_ptr: &InMemorySigner) -> *const [u8; 32] {
1150         let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_seed;
1151         inner_val
1152 }
1153 /// Commitment seed
1154 #[no_mangle]
1155 pub extern "C" fn InMemorySigner_set_commitment_seed(this_ptr: &mut InMemorySigner, mut val: crate::c_types::ThirtyTwoBytes) {
1156         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_seed = val.data;
1157 }
1158 impl Clone for InMemorySigner {
1159         fn clone(&self) -> Self {
1160                 Self {
1161                         inner: if <*mut nativeInMemorySigner>::is_null(self.inner) { std::ptr::null_mut() } else {
1162                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1163                         is_owned: true,
1164                 }
1165         }
1166 }
1167 #[allow(unused)]
1168 /// Used only if an object of this type is returned as a trait impl by a method
1169 pub(crate) extern "C" fn InMemorySigner_clone_void(this_ptr: *const c_void) -> *mut c_void {
1170         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInMemorySigner)).clone() })) as *mut c_void
1171 }
1172 #[no_mangle]
1173 /// Creates a copy of the InMemorySigner
1174 pub extern "C" fn InMemorySigner_clone(orig: &InMemorySigner) -> InMemorySigner {
1175         orig.clone()
1176 }
1177 /// Create a new InMemorySigner
1178 #[must_use]
1179 #[no_mangle]
1180 pub extern "C" fn InMemorySigner_new(mut funding_key: crate::c_types::SecretKey, mut revocation_base_key: crate::c_types::SecretKey, mut payment_key: crate::c_types::SecretKey, mut delayed_payment_base_key: crate::c_types::SecretKey, mut htlc_base_key: crate::c_types::SecretKey, mut commitment_seed: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::lightning::chain::keysinterface::InMemorySigner {
1181         let mut ret = lightning::chain::keysinterface::InMemorySigner::new(secp256k1::SECP256K1, funding_key.into_rust(), revocation_base_key.into_rust(), payment_key.into_rust(), delayed_payment_base_key.into_rust(), htlc_base_key.into_rust(), commitment_seed.data, channel_value_satoshis, channel_keys_id.data);
1182         crate::lightning::chain::keysinterface::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
1183 }
1184
1185 /// Counterparty pubkeys.
1186 /// Will panic if ready_channel wasn't called.
1187 #[must_use]
1188 #[no_mangle]
1189 pub extern "C" fn InMemorySigner_counterparty_pubkeys(this_arg: &InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1190         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_pubkeys();
1191         crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1192 }
1193
1194 /// The contest_delay value specified by our counterparty and applied on holder-broadcastable
1195 /// transactions, ie the amount of time that we have to wait to recover our funds if we
1196 /// broadcast a transaction.
1197 /// Will panic if ready_channel wasn't called.
1198 #[must_use]
1199 #[no_mangle]
1200 pub extern "C" fn InMemorySigner_counterparty_selected_contest_delay(this_arg: &InMemorySigner) -> u16 {
1201         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.counterparty_selected_contest_delay();
1202         ret
1203 }
1204
1205 /// The contest_delay value specified by us and applied on transactions broadcastable
1206 /// by our counterparty, ie the amount of time that they have to wait to recover their funds
1207 /// if they broadcast a transaction.
1208 /// Will panic if ready_channel wasn't called.
1209 #[must_use]
1210 #[no_mangle]
1211 pub extern "C" fn InMemorySigner_holder_selected_contest_delay(this_arg: &InMemorySigner) -> u16 {
1212         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.holder_selected_contest_delay();
1213         ret
1214 }
1215
1216 /// Whether the holder is the initiator
1217 /// Will panic if ready_channel wasn't called.
1218 #[must_use]
1219 #[no_mangle]
1220 pub extern "C" fn InMemorySigner_is_outbound(this_arg: &InMemorySigner) -> bool {
1221         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
1222         ret
1223 }
1224
1225 /// Funding outpoint
1226 /// Will panic if ready_channel wasn't called.
1227 #[must_use]
1228 #[no_mangle]
1229 pub extern "C" fn InMemorySigner_funding_outpoint(this_arg: &InMemorySigner) -> crate::lightning::chain::transaction::OutPoint {
1230         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
1231         crate::lightning::chain::transaction::OutPoint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1232 }
1233
1234 /// Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
1235 /// building transactions.
1236 ///
1237 /// Will panic if ready_channel wasn't called.
1238 #[must_use]
1239 #[no_mangle]
1240 pub extern "C" fn InMemorySigner_get_channel_parameters(this_arg: &InMemorySigner) -> crate::lightning::ln::chan_utils::ChannelTransactionParameters {
1241         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_channel_parameters();
1242         crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1243 }
1244
1245 /// Sign the single input of spend_tx at index `input_idx` which spends the output
1246 /// described by descriptor, returning the witness stack for the input.
1247 ///
1248 /// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
1249 /// or is not spending the outpoint described by `descriptor.outpoint`.
1250 #[must_use]
1251 #[no_mangle]
1252 pub extern "C" fn InMemorySigner_sign_counterparty_payment_input(this_arg: &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 {
1253         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::SECP256K1);
1254         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() };
1255         local_ret
1256 }
1257
1258 /// Sign the single input of spend_tx at index `input_idx` which spends the output
1259 /// described by descriptor, returning the witness stack for the input.
1260 ///
1261 /// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
1262 /// is not spending the outpoint described by `descriptor.outpoint`, or does not have a
1263 /// sequence set to `descriptor.to_self_delay`.
1264 #[must_use]
1265 #[no_mangle]
1266 pub extern "C" fn InMemorySigner_sign_dynamic_p2wsh_input(this_arg: &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 {
1267         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::SECP256K1);
1268         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() };
1269         local_ret
1270 }
1271
1272 impl From<nativeInMemorySigner> for crate::lightning::chain::keysinterface::BaseSign {
1273         fn from(obj: nativeInMemorySigner) -> Self {
1274                 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1275                 let mut ret = InMemorySigner_as_BaseSign(&rust_obj);
1276                 // 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
1277                 rust_obj.inner = std::ptr::null_mut();
1278                 ret.free = Some(InMemorySigner_free_void);
1279                 ret
1280         }
1281 }
1282 /// Constructs a new BaseSign which calls the relevant methods on this_arg.
1283 /// This copies the `inner` pointer in this_arg and thus the returned BaseSign must be freed before this_arg is
1284 #[no_mangle]
1285 pub extern "C" fn InMemorySigner_as_BaseSign(this_arg: &InMemorySigner) -> crate::lightning::chain::keysinterface::BaseSign {
1286         crate::lightning::chain::keysinterface::BaseSign {
1287                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1288                 free: None,
1289                 get_per_commitment_point: InMemorySigner_BaseSign_get_per_commitment_point,
1290                 release_commitment_secret: InMemorySigner_BaseSign_release_commitment_secret,
1291
1292                 pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: std::ptr::null_mut(), is_owned: true },
1293                 set_pubkeys: Some(InMemorySigner_BaseSign_set_pubkeys),
1294                 channel_keys_id: InMemorySigner_BaseSign_channel_keys_id,
1295                 sign_counterparty_commitment: InMemorySigner_BaseSign_sign_counterparty_commitment,
1296                 sign_holder_commitment_and_htlcs: InMemorySigner_BaseSign_sign_holder_commitment_and_htlcs,
1297                 sign_justice_revoked_output: InMemorySigner_BaseSign_sign_justice_revoked_output,
1298                 sign_justice_revoked_htlc: InMemorySigner_BaseSign_sign_justice_revoked_htlc,
1299                 sign_counterparty_htlc_transaction: InMemorySigner_BaseSign_sign_counterparty_htlc_transaction,
1300                 sign_closing_transaction: InMemorySigner_BaseSign_sign_closing_transaction,
1301                 sign_channel_announcement: InMemorySigner_BaseSign_sign_channel_announcement,
1302                 ready_channel: InMemorySigner_BaseSign_ready_channel,
1303         }
1304 }
1305
1306 #[must_use]
1307 extern "C" fn InMemorySigner_BaseSign_get_per_commitment_point(this_arg: *const c_void, mut idx: u64) -> crate::c_types::PublicKey {
1308         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::get_per_commitment_point(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx, secp256k1::SECP256K1);
1309         crate::c_types::PublicKey::from_rust(&ret)
1310 }
1311 #[must_use]
1312 extern "C" fn InMemorySigner_BaseSign_release_commitment_secret(this_arg: *const c_void, mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
1313         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::release_commitment_secret(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, idx);
1314         crate::c_types::ThirtyTwoBytes { data: ret }
1315 }
1316 #[must_use]
1317 extern "C" fn InMemorySigner_BaseSign_pubkeys(this_arg: *const c_void) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1318         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::pubkeys(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1319         crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1320 }
1321 extern "C" fn InMemorySigner_BaseSign_set_pubkeys(trait_self_arg: &BaseSign) {
1322         // This is a bit race-y in the general case, but for our specific use-cases today, we're safe
1323         // Specifically, we must ensure that the first time we're called it can never be in parallel
1324         if trait_self_arg.pubkeys.inner.is_null() {
1325                 unsafe { &mut *(trait_self_arg as *const BaseSign  as *mut BaseSign) }.pubkeys = InMemorySigner_BaseSign_pubkeys(trait_self_arg.this_arg);
1326         }
1327 }
1328 #[must_use]
1329 extern "C" fn InMemorySigner_BaseSign_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1330         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::channel_keys_id(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, );
1331         crate::c_types::ThirtyTwoBytes { data: ret }
1332 }
1333 #[must_use]
1334 extern "C" fn InMemorySigner_BaseSign_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ {
1335         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::sign_counterparty_commitment(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, commitment_tx.get_native_ref(), secp256k1::SECP256K1);
1336         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() };
1337         local_ret
1338 }
1339 #[must_use]
1340 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 {
1341         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::SECP256K1);
1342         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() };
1343         local_ret
1344 }
1345 #[must_use]
1346 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 {
1347         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::key::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), secp256k1::SECP256K1);
1348         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() };
1349         local_ret
1350 }
1351 #[must_use]
1352 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 {
1353         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::key::SecretKey::from_slice(&unsafe { *per_commitment_key}[..]).unwrap(), htlc.get_native_ref(), secp256k1::SECP256K1);
1354         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() };
1355         local_ret
1356 }
1357 #[must_use]
1358 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 {
1359         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::SECP256K1);
1360         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() };
1361         local_ret
1362 }
1363 #[must_use]
1364 extern "C" fn InMemorySigner_BaseSign_sign_closing_transaction(this_arg: *const c_void, mut closing_tx: crate::c_types::Transaction) -> crate::c_types::derived::CResult_SignatureNoneZ {
1365         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::sign_closing_transaction(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, &closing_tx.into_bitcoin(), secp256k1::SECP256K1);
1366         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() };
1367         local_ret
1368 }
1369 #[must_use]
1370 extern "C" fn InMemorySigner_BaseSign_sign_channel_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_SignatureNoneZ {
1371         let mut ret = <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::sign_channel_announcement(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, msg.get_native_ref(), secp256k1::SECP256K1);
1372         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() };
1373         local_ret
1374 }
1375 extern "C" fn InMemorySigner_BaseSign_ready_channel(this_arg: *mut c_void, channel_parameters: &crate::lightning::ln::chan_utils::ChannelTransactionParameters) {
1376         <nativeInMemorySigner as lightning::chain::keysinterface::BaseSign<>>::ready_channel(unsafe { &mut *(this_arg as *mut nativeInMemorySigner) }, channel_parameters.get_native_ref())
1377 }
1378
1379 impl From<nativeInMemorySigner> for crate::lightning::chain::keysinterface::Sign {
1380         fn from(obj: nativeInMemorySigner) -> Self {
1381                 let mut rust_obj = InMemorySigner { inner: ObjOps::heap_alloc(obj), is_owned: true };
1382                 let mut ret = InMemorySigner_as_Sign(&rust_obj);
1383                 // 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
1384                 rust_obj.inner = std::ptr::null_mut();
1385                 ret.free = Some(InMemorySigner_free_void);
1386                 ret
1387         }
1388 }
1389 /// Constructs a new Sign which calls the relevant methods on this_arg.
1390 /// This copies the `inner` pointer in this_arg and thus the returned Sign must be freed before this_arg is
1391 #[no_mangle]
1392 pub extern "C" fn InMemorySigner_as_Sign(this_arg: &InMemorySigner) -> crate::lightning::chain::keysinterface::Sign {
1393         crate::lightning::chain::keysinterface::Sign {
1394                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1395                 free: None,
1396                 BaseSign: crate::lightning::chain::keysinterface::BaseSign {
1397                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1398                         free: None,
1399                         get_per_commitment_point: InMemorySigner_BaseSign_get_per_commitment_point,
1400                         release_commitment_secret: InMemorySigner_BaseSign_release_commitment_secret,
1401
1402                         pubkeys: crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: std::ptr::null_mut(), is_owned: true },
1403                         set_pubkeys: Some(InMemorySigner_BaseSign_set_pubkeys),
1404                         channel_keys_id: InMemorySigner_BaseSign_channel_keys_id,
1405                         sign_counterparty_commitment: InMemorySigner_BaseSign_sign_counterparty_commitment,
1406                         sign_holder_commitment_and_htlcs: InMemorySigner_BaseSign_sign_holder_commitment_and_htlcs,
1407                         sign_justice_revoked_output: InMemorySigner_BaseSign_sign_justice_revoked_output,
1408                         sign_justice_revoked_htlc: InMemorySigner_BaseSign_sign_justice_revoked_htlc,
1409                         sign_counterparty_htlc_transaction: InMemorySigner_BaseSign_sign_counterparty_htlc_transaction,
1410                         sign_closing_transaction: InMemorySigner_BaseSign_sign_closing_transaction,
1411                         sign_channel_announcement: InMemorySigner_BaseSign_sign_channel_announcement,
1412                         ready_channel: InMemorySigner_BaseSign_ready_channel,
1413                 },
1414                 write: InMemorySigner_write_void,
1415                 cloned: Some(Sign_InMemorySigner_cloned),
1416         }
1417 }
1418
1419 extern "C" fn Sign_InMemorySigner_cloned(new_obj: &mut crate::lightning::chain::keysinterface::Sign) {
1420         new_obj.this_arg = InMemorySigner_clone_void(new_obj.this_arg);
1421         new_obj.free = Some(InMemorySigner_free_void);
1422         new_obj.BaseSign.this_arg = new_obj.this_arg;
1423         new_obj.BaseSign.free = None;
1424 }
1425
1426 #[no_mangle]
1427 /// Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
1428 pub extern "C" fn InMemorySigner_write(obj: &InMemorySigner) -> crate::c_types::derived::CVec_u8Z {
1429         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1430 }
1431 #[no_mangle]
1432 pub(crate) extern "C" fn InMemorySigner_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1433         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInMemorySigner) })
1434 }
1435 #[no_mangle]
1436 /// Read a InMemorySigner from a byte array, created by InMemorySigner_write
1437 pub extern "C" fn InMemorySigner_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InMemorySignerDecodeErrorZ {
1438         let res = crate::c_types::deserialize_obj(ser);
1439         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1440         local_res
1441 }
1442
1443 use lightning::chain::keysinterface::KeysManager as nativeKeysManagerImport;
1444 type nativeKeysManager = nativeKeysManagerImport;
1445
1446 /// Simple KeysInterface implementor that takes a 32-byte seed for use as a BIP 32 extended key
1447 /// and derives keys from that.
1448 ///
1449 /// Your node_id is seed/0'
1450 /// ChannelMonitor closes may use seed/1'
1451 /// Cooperative closes may use seed/2'
1452 /// The two close keys may be needed to claim on-chain funds!
1453 #[must_use]
1454 #[repr(C)]
1455 pub struct KeysManager {
1456         /// A pointer to the opaque Rust object.
1457
1458         /// Nearly everywhere, inner must be non-null, however in places where
1459         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1460         pub inner: *mut nativeKeysManager,
1461         /// Indicates that this is the only struct which contains the same pointer.
1462
1463         /// Rust functions which take ownership of an object provided via an argument require
1464         /// this to be true and invalidate the object pointed to by inner.
1465         pub is_owned: bool,
1466 }
1467
1468 impl Drop for KeysManager {
1469         fn drop(&mut self) {
1470                 if self.is_owned && !<*mut nativeKeysManager>::is_null(self.inner) {
1471                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1472                 }
1473         }
1474 }
1475 /// Frees any resources used by the KeysManager, if is_owned is set and inner is non-NULL.
1476 #[no_mangle]
1477 pub extern "C" fn KeysManager_free(this_obj: KeysManager) { }
1478 #[allow(unused)]
1479 /// Used only if an object of this type is returned as a trait impl by a method
1480 extern "C" fn KeysManager_free_void(this_ptr: *mut c_void) {
1481         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeKeysManager); }
1482 }
1483 #[allow(unused)]
1484 impl KeysManager {
1485         pub(crate) fn get_native_ref(&self) -> &'static nativeKeysManager {
1486                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1487         }
1488         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeKeysManager {
1489                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1490         }
1491         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1492         pub(crate) fn take_inner(mut self) -> *mut nativeKeysManager {
1493                 assert!(self.is_owned);
1494                 let ret = ObjOps::untweak_ptr(self.inner);
1495                 self.inner = std::ptr::null_mut();
1496                 ret
1497         }
1498 }
1499 /// Constructs a KeysManager from a 32-byte seed. If the seed is in some way biased (eg your
1500 /// CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
1501 /// starting_time isn't strictly required to actually be a time, but it must absolutely,
1502 /// without a doubt, be unique to this instance. ie if you start multiple times with the same
1503 /// seed, starting_time must be unique to each run. Thus, the easiest way to achieve this is to
1504 /// simply use the current time (with very high precision).
1505 ///
1506 /// The seed MUST be backed up safely prior to use so that the keys can be re-created, however,
1507 /// obviously, starting_time should be unique every time you reload the library - it is only
1508 /// used to generate new ephemeral key data (which will be stored by the individual channel if
1509 /// necessary).
1510 ///
1511 /// Note that the seed is required to recover certain on-chain funds independent of
1512 /// ChannelMonitor data, though a current copy of ChannelMonitor data is also required for any
1513 /// channel, and some on-chain during-closing funds.
1514 ///
1515 /// Note that until the 0.1 release there is no guarantee of backward compatibility between
1516 /// versions. Once the library is more fully supported, the docs will be updated to include a
1517 /// detailed description of the guarantee.
1518 #[must_use]
1519 #[no_mangle]
1520 pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut starting_time_secs: u64, mut starting_time_nanos: u32) -> KeysManager {
1521         let mut ret = lightning::chain::keysinterface::KeysManager::new(unsafe { &*seed}, starting_time_secs, starting_time_nanos);
1522         KeysManager { inner: ObjOps::heap_alloc(ret), is_owned: true }
1523 }
1524
1525 /// Derive an old Sign containing per-channel secrets based on a key derivation parameters.
1526 ///
1527 /// Key derivation parameters are accessible through a per-channel secrets
1528 /// Sign::channel_keys_id and is provided inside DynamicOuputP2WSH in case of
1529 /// onchain output detection for which a corresponding delayed_payment_key must be derived.
1530 #[must_use]
1531 #[no_mangle]
1532 pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &KeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::lightning::chain::keysinterface::InMemorySigner {
1533         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_channel_keys(channel_value_satoshis, unsafe { &*params});
1534         crate::lightning::chain::keysinterface::InMemorySigner { inner: ObjOps::heap_alloc(ret), is_owned: true }
1535 }
1536
1537 /// Creates a Transaction which spends the given descriptors to the given outputs, plus an
1538 /// output to the given change destination (if sufficient change value remains). The
1539 /// transaction will have a feerate, at least, of the given value.
1540 ///
1541 /// Returns `Err(())` if the output value is greater than the input value minus required fee or
1542 /// if a descriptor was duplicated.
1543 ///
1544 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
1545 ///
1546 /// May panic if the `SpendableOutputDescriptor`s were not generated by Channels which used
1547 /// this KeysManager or one of the `InMemorySigner` created by this KeysManager.
1548 #[must_use]
1549 #[no_mangle]
1550 pub extern "C" fn KeysManager_spend_spendable_outputs(this_arg: &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 {
1551         let mut local_descriptors = Vec::new(); for mut item in descriptors.into_rust().drain(..) { local_descriptors.push( { item.into_native() }); };
1552         let mut local_outputs = Vec::new(); for mut item in outputs.into_rust().drain(..) { local_outputs.push( { item.into_rust() }); };
1553         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::SECP256K1);
1554         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() };
1555         local_ret
1556 }
1557
1558 impl From<nativeKeysManager> for crate::lightning::chain::keysinterface::KeysInterface {
1559         fn from(obj: nativeKeysManager) -> Self {
1560                 let mut rust_obj = KeysManager { inner: ObjOps::heap_alloc(obj), is_owned: true };
1561                 let mut ret = KeysManager_as_KeysInterface(&rust_obj);
1562                 // 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
1563                 rust_obj.inner = std::ptr::null_mut();
1564                 ret.free = Some(KeysManager_free_void);
1565                 ret
1566         }
1567 }
1568 /// Constructs a new KeysInterface which calls the relevant methods on this_arg.
1569 /// This copies the `inner` pointer in this_arg and thus the returned KeysInterface must be freed before this_arg is
1570 #[no_mangle]
1571 pub extern "C" fn KeysManager_as_KeysInterface(this_arg: &KeysManager) -> crate::lightning::chain::keysinterface::KeysInterface {
1572         crate::lightning::chain::keysinterface::KeysInterface {
1573                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1574                 free: None,
1575                 get_node_secret: KeysManager_KeysInterface_get_node_secret,
1576                 get_destination_script: KeysManager_KeysInterface_get_destination_script,
1577                 get_shutdown_scriptpubkey: KeysManager_KeysInterface_get_shutdown_scriptpubkey,
1578                 get_channel_signer: KeysManager_KeysInterface_get_channel_signer,
1579                 get_secure_random_bytes: KeysManager_KeysInterface_get_secure_random_bytes,
1580                 read_chan_signer: KeysManager_KeysInterface_read_chan_signer,
1581                 sign_invoice: KeysManager_KeysInterface_sign_invoice,
1582         }
1583 }
1584
1585 #[must_use]
1586 extern "C" fn KeysManager_KeysInterface_get_node_secret(this_arg: *const c_void) -> crate::c_types::SecretKey {
1587         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_node_secret(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
1588         crate::c_types::SecretKey::from_rust(ret)
1589 }
1590 #[must_use]
1591 extern "C" fn KeysManager_KeysInterface_get_destination_script(this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1592         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_destination_script(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
1593         ret.into_bytes().into()
1594 }
1595 #[must_use]
1596 extern "C" fn KeysManager_KeysInterface_get_shutdown_scriptpubkey(this_arg: *const c_void) -> crate::lightning::ln::script::ShutdownScript {
1597         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_shutdown_scriptpubkey(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
1598         crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(ret), is_owned: true }
1599 }
1600 #[must_use]
1601 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 {
1602         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_channel_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, _inbound, channel_value_satoshis);
1603         ret.into()
1604 }
1605 #[must_use]
1606 extern "C" fn KeysManager_KeysInterface_get_secure_random_bytes(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes {
1607         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::get_secure_random_bytes(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, );
1608         crate::c_types::ThirtyTwoBytes { data: ret }
1609 }
1610 #[must_use]
1611 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 {
1612         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::read_chan_signer(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, reader.to_slice());
1613         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1614         local_ret
1615 }
1616 #[must_use]
1617 extern "C" fn KeysManager_KeysInterface_sign_invoice(this_arg: *const c_void, mut invoice_preimage: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ {
1618         let mut local_invoice_preimage = Vec::new(); for mut item in invoice_preimage.into_rust().drain(..) { local_invoice_preimage.push( { item }); };
1619         let mut ret = <nativeKeysManager as lightning::chain::keysinterface::KeysInterface<>>::sign_invoice(unsafe { &mut *(this_arg as *mut nativeKeysManager) }, local_invoice_preimage);
1620         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() };
1621         local_ret
1622 }
1623