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