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