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