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