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