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