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