Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / chan_utils.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 //! Various utilities for building scripts and deriving keys related to channels. These are
10 //! largely of interest for those implementing chain::keysinterface::Sign message signing by hand.
11
12 use alloc::str::FromStr;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
19
20 /// Gets the weight for an HTLC-Success transaction.
21 #[no_mangle]
22 pub extern "C" fn htlc_success_tx_weight(mut opt_anchors: bool) -> u64 {
23         let mut ret = lightning::ln::chan_utils::htlc_success_tx_weight(opt_anchors);
24         ret
25 }
26
27 /// Gets the weight for an HTLC-Timeout transaction.
28 #[no_mangle]
29 pub extern "C" fn htlc_timeout_tx_weight(mut opt_anchors: bool) -> u64 {
30         let mut ret = lightning::ln::chan_utils::htlc_timeout_tx_weight(opt_anchors);
31         ret
32 }
33
34 /// Build the commitment secret from the seed and the commitment number
35 #[no_mangle]
36 pub extern "C" fn build_commitment_secret(commitment_seed: *const [u8; 32], mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
37         let mut ret = lightning::ln::chan_utils::build_commitment_secret(unsafe { &*commitment_seed}, idx);
38         crate::c_types::ThirtyTwoBytes { data: ret }
39 }
40
41 /// Build a closing transaction
42 #[no_mangle]
43 pub extern "C" fn build_closing_transaction(mut to_holder_value_sat: u64, mut to_counterparty_value_sat: u64, mut to_holder_script: crate::c_types::derived::CVec_u8Z, mut to_counterparty_script: crate::c_types::derived::CVec_u8Z, mut funding_outpoint: crate::lightning::chain::transaction::OutPoint) -> crate::c_types::Transaction {
44         let mut ret = lightning::ln::chan_utils::build_closing_transaction(to_holder_value_sat, to_counterparty_value_sat, ::bitcoin::blockdata::script::Script::from(to_holder_script.into_rust()), ::bitcoin::blockdata::script::Script::from(to_counterparty_script.into_rust()), crate::c_types::C_to_bitcoin_outpoint(funding_outpoint));
45         crate::c_types::Transaction::from_bitcoin(&ret)
46 }
47
48 /// Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
49 /// from the base secret and the per_commitment_point.
50 ///
51 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
52 /// generated (ie our own).
53 #[no_mangle]
54 pub extern "C" fn derive_private_key(mut per_commitment_point: crate::c_types::PublicKey, base_secret: *const [u8; 32]) -> crate::c_types::derived::CResult_SecretKeyErrorZ {
55         let mut ret = lightning::ln::chan_utils::derive_private_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *base_secret}[..]).unwrap());
56         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( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
57         local_ret
58 }
59
60 /// Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
61 /// from the base point and the per_commitment_key. This is the public equivalent of
62 /// derive_private_key - using only public keys to derive a public key instead of private keys.
63 ///
64 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
65 /// generated (ie our own).
66 #[no_mangle]
67 pub extern "C" fn derive_public_key(mut per_commitment_point: crate::c_types::PublicKey, mut base_point: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_PublicKeyErrorZ {
68         let mut ret = lightning::ln::chan_utils::derive_public_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &base_point.into_rust());
69         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
70         local_ret
71 }
72
73 /// Derives a per-commitment-transaction revocation key from its constituent parts.
74 ///
75 /// Only the cheating participant owns a valid witness to propagate a revoked 
76 /// commitment transaction, thus per_commitment_secret always come from cheater
77 /// and revocation_base_secret always come from punisher, which is the broadcaster
78 /// of the transaction spending with this key knowledge.
79 ///
80 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
81 /// generated (ie our own).
82 #[no_mangle]
83 pub extern "C" fn derive_private_revocation_key(per_commitment_secret: *const [u8; 32], countersignatory_revocation_base_secret: *const [u8; 32]) -> crate::c_types::derived::CResult_SecretKeyErrorZ {
84         let mut ret = lightning::ln::chan_utils::derive_private_revocation_key(secp256k1::SECP256K1, &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *per_commitment_secret}[..]).unwrap(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *countersignatory_revocation_base_secret}[..]).unwrap());
85         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( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
86         local_ret
87 }
88
89 /// Derives a per-commitment-transaction revocation public key from its constituent parts. This is
90 /// the public equivalend of derive_private_revocation_key - using only public keys to derive a
91 /// public key instead of private keys.
92 ///
93 /// Only the cheating participant owns a valid witness to propagate a revoked 
94 /// commitment transaction, thus per_commitment_point always come from cheater
95 /// and revocation_base_point always come from punisher, which is the broadcaster
96 /// of the transaction spending with this key knowledge.
97 ///
98 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
99 /// generated (ie our own).
100 #[no_mangle]
101 pub extern "C" fn derive_public_revocation_key(mut per_commitment_point: crate::c_types::PublicKey, mut countersignatory_revocation_base_point: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_PublicKeyErrorZ {
102         let mut ret = lightning::ln::chan_utils::derive_public_revocation_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &countersignatory_revocation_base_point.into_rust());
103         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
104         local_ret
105 }
106
107
108 use lightning::ln::chan_utils::TxCreationKeys as nativeTxCreationKeysImport;
109 pub(crate) type nativeTxCreationKeys = nativeTxCreationKeysImport;
110
111 /// The set of public keys which are used in the creation of one commitment transaction.
112 /// These are derived from the channel base keys and per-commitment data.
113 ///
114 /// A broadcaster key is provided from potential broadcaster of the computed transaction.
115 /// A countersignatory key is coming from a protocol participant unable to broadcast the
116 /// transaction.
117 ///
118 /// These keys are assumed to be good, either because the code derived them from
119 /// channel basepoints via the new function, or they were obtained via
120 /// CommitmentTransaction.trust().keys() because we trusted the source of the
121 /// pre-calculated keys.
122 #[must_use]
123 #[repr(C)]
124 pub struct TxCreationKeys {
125         /// A pointer to the opaque Rust object.
126
127         /// Nearly everywhere, inner must be non-null, however in places where
128         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
129         pub inner: *mut nativeTxCreationKeys,
130         /// Indicates that this is the only struct which contains the same pointer.
131
132         /// Rust functions which take ownership of an object provided via an argument require
133         /// this to be true and invalidate the object pointed to by inner.
134         pub is_owned: bool,
135 }
136
137 impl Drop for TxCreationKeys {
138         fn drop(&mut self) {
139                 if self.is_owned && !<*mut nativeTxCreationKeys>::is_null(self.inner) {
140                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
141                 }
142         }
143 }
144 /// Frees any resources used by the TxCreationKeys, if is_owned is set and inner is non-NULL.
145 #[no_mangle]
146 pub extern "C" fn TxCreationKeys_free(this_obj: TxCreationKeys) { }
147 #[allow(unused)]
148 /// Used only if an object of this type is returned as a trait impl by a method
149 pub(crate) extern "C" fn TxCreationKeys_free_void(this_ptr: *mut c_void) {
150         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTxCreationKeys); }
151 }
152 #[allow(unused)]
153 impl TxCreationKeys {
154         pub(crate) fn get_native_ref(&self) -> &'static nativeTxCreationKeys {
155                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
156         }
157         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeTxCreationKeys {
158                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
159         }
160         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
161         pub(crate) fn take_inner(mut self) -> *mut nativeTxCreationKeys {
162                 assert!(self.is_owned);
163                 let ret = ObjOps::untweak_ptr(self.inner);
164                 self.inner = core::ptr::null_mut();
165                 ret
166         }
167 }
168 /// The broadcaster's per-commitment public key which was used to derive the other keys.
169 #[no_mangle]
170 pub extern "C" fn TxCreationKeys_get_per_commitment_point(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
171         let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
172         crate::c_types::PublicKey::from_rust(&inner_val)
173 }
174 /// The broadcaster's per-commitment public key which was used to derive the other keys.
175 #[no_mangle]
176 pub extern "C" fn TxCreationKeys_set_per_commitment_point(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
177         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
178 }
179 /// The revocation key which is used to allow the broadcaster of the commitment
180 /// transaction to provide their counterparty the ability to punish them if they broadcast
181 /// an old state.
182 #[no_mangle]
183 pub extern "C" fn TxCreationKeys_get_revocation_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
184         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_key;
185         crate::c_types::PublicKey::from_rust(&inner_val)
186 }
187 /// The revocation key which is used to allow the broadcaster of the commitment
188 /// transaction to provide their counterparty the ability to punish them if they broadcast
189 /// an old state.
190 #[no_mangle]
191 pub extern "C" fn TxCreationKeys_set_revocation_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
192         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_key = val.into_rust();
193 }
194 /// Broadcaster's HTLC Key
195 #[no_mangle]
196 pub extern "C" fn TxCreationKeys_get_broadcaster_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
197         let mut inner_val = &mut this_ptr.get_native_mut_ref().broadcaster_htlc_key;
198         crate::c_types::PublicKey::from_rust(&inner_val)
199 }
200 /// Broadcaster's HTLC Key
201 #[no_mangle]
202 pub extern "C" fn TxCreationKeys_set_broadcaster_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
203         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.broadcaster_htlc_key = val.into_rust();
204 }
205 /// Countersignatory's HTLC Key
206 #[no_mangle]
207 pub extern "C" fn TxCreationKeys_get_countersignatory_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
208         let mut inner_val = &mut this_ptr.get_native_mut_ref().countersignatory_htlc_key;
209         crate::c_types::PublicKey::from_rust(&inner_val)
210 }
211 /// Countersignatory's HTLC Key
212 #[no_mangle]
213 pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
214         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.countersignatory_htlc_key = val.into_rust();
215 }
216 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
217 #[no_mangle]
218 pub extern "C" fn TxCreationKeys_get_broadcaster_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
219         let mut inner_val = &mut this_ptr.get_native_mut_ref().broadcaster_delayed_payment_key;
220         crate::c_types::PublicKey::from_rust(&inner_val)
221 }
222 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
223 #[no_mangle]
224 pub extern "C" fn TxCreationKeys_set_broadcaster_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
225         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.broadcaster_delayed_payment_key = val.into_rust();
226 }
227 /// Constructs a new TxCreationKeys given each field
228 #[must_use]
229 #[no_mangle]
230 pub extern "C" fn TxCreationKeys_new(mut per_commitment_point_arg: crate::c_types::PublicKey, mut revocation_key_arg: crate::c_types::PublicKey, mut broadcaster_htlc_key_arg: crate::c_types::PublicKey, mut countersignatory_htlc_key_arg: crate::c_types::PublicKey, mut broadcaster_delayed_payment_key_arg: crate::c_types::PublicKey) -> TxCreationKeys {
231         TxCreationKeys { inner: ObjOps::heap_alloc(nativeTxCreationKeys {
232                 per_commitment_point: per_commitment_point_arg.into_rust(),
233                 revocation_key: revocation_key_arg.into_rust(),
234                 broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(),
235                 countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(),
236                 broadcaster_delayed_payment_key: broadcaster_delayed_payment_key_arg.into_rust(),
237         }), is_owned: true }
238 }
239 impl Clone for TxCreationKeys {
240         fn clone(&self) -> Self {
241                 Self {
242                         inner: if <*mut nativeTxCreationKeys>::is_null(self.inner) { core::ptr::null_mut() } else {
243                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
244                         is_owned: true,
245                 }
246         }
247 }
248 #[allow(unused)]
249 /// Used only if an object of this type is returned as a trait impl by a method
250 pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
251         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxCreationKeys)).clone() })) as *mut c_void
252 }
253 #[no_mangle]
254 /// Creates a copy of the TxCreationKeys
255 pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys {
256         orig.clone()
257 }
258 #[no_mangle]
259 /// Serialize the TxCreationKeys object into a byte array which can be read by TxCreationKeys_read
260 pub extern "C" fn TxCreationKeys_write(obj: &TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
261         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
262 }
263 #[no_mangle]
264 pub(crate) extern "C" fn TxCreationKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
265         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxCreationKeys) })
266 }
267 #[no_mangle]
268 /// Read a TxCreationKeys from a byte array, created by TxCreationKeys_write
269 pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_TxCreationKeysDecodeErrorZ {
270         let res: Result<lightning::ln::chan_utils::TxCreationKeys, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
271         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::TxCreationKeys { 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() };
272         local_res
273 }
274
275 use lightning::ln::chan_utils::ChannelPublicKeys as nativeChannelPublicKeysImport;
276 pub(crate) type nativeChannelPublicKeys = nativeChannelPublicKeysImport;
277
278 /// One counterparty's public keys which do not change over the life of a channel.
279 #[must_use]
280 #[repr(C)]
281 pub struct ChannelPublicKeys {
282         /// A pointer to the opaque Rust object.
283
284         /// Nearly everywhere, inner must be non-null, however in places where
285         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
286         pub inner: *mut nativeChannelPublicKeys,
287         /// Indicates that this is the only struct which contains the same pointer.
288
289         /// Rust functions which take ownership of an object provided via an argument require
290         /// this to be true and invalidate the object pointed to by inner.
291         pub is_owned: bool,
292 }
293
294 impl Drop for ChannelPublicKeys {
295         fn drop(&mut self) {
296                 if self.is_owned && !<*mut nativeChannelPublicKeys>::is_null(self.inner) {
297                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
298                 }
299         }
300 }
301 /// Frees any resources used by the ChannelPublicKeys, if is_owned is set and inner is non-NULL.
302 #[no_mangle]
303 pub extern "C" fn ChannelPublicKeys_free(this_obj: ChannelPublicKeys) { }
304 #[allow(unused)]
305 /// Used only if an object of this type is returned as a trait impl by a method
306 pub(crate) extern "C" fn ChannelPublicKeys_free_void(this_ptr: *mut c_void) {
307         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelPublicKeys); }
308 }
309 #[allow(unused)]
310 impl ChannelPublicKeys {
311         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelPublicKeys {
312                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
313         }
314         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelPublicKeys {
315                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
316         }
317         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
318         pub(crate) fn take_inner(mut self) -> *mut nativeChannelPublicKeys {
319                 assert!(self.is_owned);
320                 let ret = ObjOps::untweak_ptr(self.inner);
321                 self.inner = core::ptr::null_mut();
322                 ret
323         }
324 }
325 /// The public key which is used to sign all commitment transactions, as it appears in the
326 /// on-chain channel lock-in 2-of-2 multisig output.
327 #[no_mangle]
328 pub extern "C" fn ChannelPublicKeys_get_funding_pubkey(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
329         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_pubkey;
330         crate::c_types::PublicKey::from_rust(&inner_val)
331 }
332 /// The public key which is used to sign all commitment transactions, as it appears in the
333 /// on-chain channel lock-in 2-of-2 multisig output.
334 #[no_mangle]
335 pub extern "C" fn ChannelPublicKeys_set_funding_pubkey(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
336         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_pubkey = val.into_rust();
337 }
338 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
339 /// revocation keys. This is combined with the per-commitment-secret generated by the
340 /// counterparty to create a secret which the counterparty can reveal to revoke previous
341 /// states.
342 #[no_mangle]
343 pub extern "C" fn ChannelPublicKeys_get_revocation_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
344         let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_basepoint;
345         crate::c_types::PublicKey::from_rust(&inner_val)
346 }
347 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
348 /// revocation keys. This is combined with the per-commitment-secret generated by the
349 /// counterparty to create a secret which the counterparty can reveal to revoke previous
350 /// states.
351 #[no_mangle]
352 pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
353         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_basepoint = val.into_rust();
354 }
355 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
356 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
357 /// static across every commitment transaction.
358 #[no_mangle]
359 pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
360         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_point;
361         crate::c_types::PublicKey::from_rust(&inner_val)
362 }
363 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
364 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
365 /// static across every commitment transaction.
366 #[no_mangle]
367 pub extern "C" fn ChannelPublicKeys_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
368         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_point = val.into_rust();
369 }
370 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
371 /// public key which receives non-HTLC-encumbered funds which are only available for spending
372 /// after some delay (or can be claimed via the revocation path).
373 #[no_mangle]
374 pub extern "C" fn ChannelPublicKeys_get_delayed_payment_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
375         let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_basepoint;
376         crate::c_types::PublicKey::from_rust(&inner_val)
377 }
378 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
379 /// public key which receives non-HTLC-encumbered funds which are only available for spending
380 /// after some delay (or can be claimed via the revocation path).
381 #[no_mangle]
382 pub extern "C" fn ChannelPublicKeys_set_delayed_payment_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
383         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_basepoint = val.into_rust();
384 }
385 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
386 /// which is used to encumber HTLC-in-flight outputs.
387 #[no_mangle]
388 pub extern "C" fn ChannelPublicKeys_get_htlc_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
389         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_basepoint;
390         crate::c_types::PublicKey::from_rust(&inner_val)
391 }
392 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
393 /// which is used to encumber HTLC-in-flight outputs.
394 #[no_mangle]
395 pub extern "C" fn ChannelPublicKeys_set_htlc_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
396         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_basepoint = val.into_rust();
397 }
398 /// Constructs a new ChannelPublicKeys given each field
399 #[must_use]
400 #[no_mangle]
401 pub extern "C" fn ChannelPublicKeys_new(mut funding_pubkey_arg: crate::c_types::PublicKey, mut revocation_basepoint_arg: crate::c_types::PublicKey, mut payment_point_arg: crate::c_types::PublicKey, mut delayed_payment_basepoint_arg: crate::c_types::PublicKey, mut htlc_basepoint_arg: crate::c_types::PublicKey) -> ChannelPublicKeys {
402         ChannelPublicKeys { inner: ObjOps::heap_alloc(nativeChannelPublicKeys {
403                 funding_pubkey: funding_pubkey_arg.into_rust(),
404                 revocation_basepoint: revocation_basepoint_arg.into_rust(),
405                 payment_point: payment_point_arg.into_rust(),
406                 delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(),
407                 htlc_basepoint: htlc_basepoint_arg.into_rust(),
408         }), is_owned: true }
409 }
410 impl Clone for ChannelPublicKeys {
411         fn clone(&self) -> Self {
412                 Self {
413                         inner: if <*mut nativeChannelPublicKeys>::is_null(self.inner) { core::ptr::null_mut() } else {
414                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
415                         is_owned: true,
416                 }
417         }
418 }
419 #[allow(unused)]
420 /// Used only if an object of this type is returned as a trait impl by a method
421 pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
422         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelPublicKeys)).clone() })) as *mut c_void
423 }
424 #[no_mangle]
425 /// Creates a copy of the ChannelPublicKeys
426 pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys {
427         orig.clone()
428 }
429 #[no_mangle]
430 /// Serialize the ChannelPublicKeys object into a byte array which can be read by ChannelPublicKeys_read
431 pub extern "C" fn ChannelPublicKeys_write(obj: &ChannelPublicKeys) -> crate::c_types::derived::CVec_u8Z {
432         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
433 }
434 #[no_mangle]
435 pub(crate) extern "C" fn ChannelPublicKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
436         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelPublicKeys) })
437 }
438 #[no_mangle]
439 /// Read a ChannelPublicKeys from a byte array, created by ChannelPublicKeys_write
440 pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelPublicKeysDecodeErrorZ {
441         let res: Result<lightning::ln::chan_utils::ChannelPublicKeys, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
442         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::ChannelPublicKeys { 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() };
443         local_res
444 }
445 /// Create per-state keys from channel base points and the per-commitment point.
446 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
447 #[must_use]
448 #[no_mangle]
449 pub extern "C" fn TxCreationKeys_derive_new(mut per_commitment_point: crate::c_types::PublicKey, mut broadcaster_delayed_payment_base: crate::c_types::PublicKey, mut broadcaster_htlc_base: crate::c_types::PublicKey, mut countersignatory_revocation_base: crate::c_types::PublicKey, mut countersignatory_htlc_base: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_TxCreationKeysErrorZ {
450         let mut ret = lightning::ln::chan_utils::TxCreationKeys::derive_new(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &broadcaster_delayed_payment_base.into_rust(), &broadcaster_htlc_base.into_rust(), &countersignatory_revocation_base.into_rust(), &countersignatory_htlc_base.into_rust());
451         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::TxCreationKeys { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
452         local_ret
453 }
454
455 /// Generate per-state keys from channel static keys.
456 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
457 #[must_use]
458 #[no_mangle]
459 pub extern "C" fn TxCreationKeys_from_channel_static_keys(mut per_commitment_point: crate::c_types::PublicKey, broadcaster_keys: &crate::lightning::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::lightning::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TxCreationKeysErrorZ {
460         let mut ret = lightning::ln::chan_utils::TxCreationKeys::from_channel_static_keys(&per_commitment_point.into_rust(), broadcaster_keys.get_native_ref(), countersignatory_keys.get_native_ref(), secp256k1::SECP256K1);
461         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::TxCreationKeys { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
462         local_ret
463 }
464
465 /// The maximum length of a script returned by get_revokeable_redeemscript.
466
467 #[no_mangle]
468 pub static REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH: usize = lightning::ln::chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH;
469 /// A script either spendable by the revocation
470 /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
471 /// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
472 #[no_mangle]
473 pub extern "C" fn get_revokeable_redeemscript(mut revocation_key: crate::c_types::PublicKey, mut contest_delay: u16, mut broadcaster_delayed_payment_key: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z {
474         let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), contest_delay, &broadcaster_delayed_payment_key.into_rust());
475         ret.into_bytes().into()
476 }
477
478
479 use lightning::ln::chan_utils::HTLCOutputInCommitment as nativeHTLCOutputInCommitmentImport;
480 pub(crate) type nativeHTLCOutputInCommitment = nativeHTLCOutputInCommitmentImport;
481
482 /// Information about an HTLC as it appears in a commitment transaction
483 #[must_use]
484 #[repr(C)]
485 pub struct HTLCOutputInCommitment {
486         /// A pointer to the opaque Rust object.
487
488         /// Nearly everywhere, inner must be non-null, however in places where
489         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
490         pub inner: *mut nativeHTLCOutputInCommitment,
491         /// Indicates that this is the only struct which contains the same pointer.
492
493         /// Rust functions which take ownership of an object provided via an argument require
494         /// this to be true and invalidate the object pointed to by inner.
495         pub is_owned: bool,
496 }
497
498 impl Drop for HTLCOutputInCommitment {
499         fn drop(&mut self) {
500                 if self.is_owned && !<*mut nativeHTLCOutputInCommitment>::is_null(self.inner) {
501                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
502                 }
503         }
504 }
505 /// Frees any resources used by the HTLCOutputInCommitment, if is_owned is set and inner is non-NULL.
506 #[no_mangle]
507 pub extern "C" fn HTLCOutputInCommitment_free(this_obj: HTLCOutputInCommitment) { }
508 #[allow(unused)]
509 /// Used only if an object of this type is returned as a trait impl by a method
510 pub(crate) extern "C" fn HTLCOutputInCommitment_free_void(this_ptr: *mut c_void) {
511         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCOutputInCommitment); }
512 }
513 #[allow(unused)]
514 impl HTLCOutputInCommitment {
515         pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCOutputInCommitment {
516                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
517         }
518         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCOutputInCommitment {
519                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
520         }
521         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
522         pub(crate) fn take_inner(mut self) -> *mut nativeHTLCOutputInCommitment {
523                 assert!(self.is_owned);
524                 let ret = ObjOps::untweak_ptr(self.inner);
525                 self.inner = core::ptr::null_mut();
526                 ret
527         }
528 }
529 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
530 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
531 /// need to compare this value to whether the commitment transaction in question is that of
532 /// the counterparty or our own.
533 #[no_mangle]
534 pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool {
535         let mut inner_val = &mut this_ptr.get_native_mut_ref().offered;
536         *inner_val
537 }
538 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
539 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
540 /// need to compare this value to whether the commitment transaction in question is that of
541 /// the counterparty or our own.
542 #[no_mangle]
543 pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) {
544         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.offered = val;
545 }
546 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
547 /// this divided by 1000.
548 #[no_mangle]
549 pub extern "C" fn HTLCOutputInCommitment_get_amount_msat(this_ptr: &HTLCOutputInCommitment) -> u64 {
550         let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_msat;
551         *inner_val
552 }
553 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
554 /// this divided by 1000.
555 #[no_mangle]
556 pub extern "C" fn HTLCOutputInCommitment_set_amount_msat(this_ptr: &mut HTLCOutputInCommitment, mut val: u64) {
557         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_msat = val;
558 }
559 /// The CLTV lock-time at which this HTLC expires.
560 #[no_mangle]
561 pub extern "C" fn HTLCOutputInCommitment_get_cltv_expiry(this_ptr: &HTLCOutputInCommitment) -> u32 {
562         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry;
563         *inner_val
564 }
565 /// The CLTV lock-time at which this HTLC expires.
566 #[no_mangle]
567 pub extern "C" fn HTLCOutputInCommitment_set_cltv_expiry(this_ptr: &mut HTLCOutputInCommitment, mut val: u32) {
568         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry = val;
569 }
570 /// The hash of the preimage which unlocks this HTLC.
571 #[no_mangle]
572 pub extern "C" fn HTLCOutputInCommitment_get_payment_hash(this_ptr: &HTLCOutputInCommitment) -> *const [u8; 32] {
573         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_hash;
574         &inner_val.0
575 }
576 /// The hash of the preimage which unlocks this HTLC.
577 #[no_mangle]
578 pub extern "C" fn HTLCOutputInCommitment_set_payment_hash(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::ThirtyTwoBytes) {
579         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_hash = ::lightning::ln::PaymentHash(val.data);
580 }
581 /// The position within the commitment transactions' outputs. This may be None if the value is
582 /// below the dust limit (in which case no output appears in the commitment transaction and the
583 /// value is spent to additional transaction fees).
584 #[no_mangle]
585 pub extern "C" fn HTLCOutputInCommitment_get_transaction_output_index(this_ptr: &HTLCOutputInCommitment) -> crate::c_types::derived::COption_u32Z {
586         let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_output_index;
587         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { inner_val.unwrap() }) };
588         local_inner_val
589 }
590 /// The position within the commitment transactions' outputs. This may be None if the value is
591 /// below the dust limit (in which case no output appears in the commitment transaction and the
592 /// value is spent to additional transaction fees).
593 #[no_mangle]
594 pub extern "C" fn HTLCOutputInCommitment_set_transaction_output_index(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::derived::COption_u32Z) {
595         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
596         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_output_index = local_val;
597 }
598 /// Constructs a new HTLCOutputInCommitment given each field
599 #[must_use]
600 #[no_mangle]
601 pub extern "C" fn HTLCOutputInCommitment_new(mut offered_arg: bool, mut amount_msat_arg: u64, mut cltv_expiry_arg: u32, mut payment_hash_arg: crate::c_types::ThirtyTwoBytes, mut transaction_output_index_arg: crate::c_types::derived::COption_u32Z) -> HTLCOutputInCommitment {
602         let mut local_transaction_output_index_arg = if transaction_output_index_arg.is_some() { Some( { transaction_output_index_arg.take() }) } else { None };
603         HTLCOutputInCommitment { inner: ObjOps::heap_alloc(nativeHTLCOutputInCommitment {
604                 offered: offered_arg,
605                 amount_msat: amount_msat_arg,
606                 cltv_expiry: cltv_expiry_arg,
607                 payment_hash: ::lightning::ln::PaymentHash(payment_hash_arg.data),
608                 transaction_output_index: local_transaction_output_index_arg,
609         }), is_owned: true }
610 }
611 impl Clone for HTLCOutputInCommitment {
612         fn clone(&self) -> Self {
613                 Self {
614                         inner: if <*mut nativeHTLCOutputInCommitment>::is_null(self.inner) { core::ptr::null_mut() } else {
615                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
616                         is_owned: true,
617                 }
618         }
619 }
620 #[allow(unused)]
621 /// Used only if an object of this type is returned as a trait impl by a method
622 pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_void) -> *mut c_void {
623         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCOutputInCommitment)).clone() })) as *mut c_void
624 }
625 #[no_mangle]
626 /// Creates a copy of the HTLCOutputInCommitment
627 pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment {
628         orig.clone()
629 }
630 #[no_mangle]
631 /// Serialize the HTLCOutputInCommitment object into a byte array which can be read by HTLCOutputInCommitment_read
632 pub extern "C" fn HTLCOutputInCommitment_write(obj: &HTLCOutputInCommitment) -> crate::c_types::derived::CVec_u8Z {
633         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
634 }
635 #[no_mangle]
636 pub(crate) extern "C" fn HTLCOutputInCommitment_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
637         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCOutputInCommitment) })
638 }
639 #[no_mangle]
640 /// Read a HTLCOutputInCommitment from a byte array, created by HTLCOutputInCommitment_write
641 pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCOutputInCommitmentDecodeErrorZ {
642         let res: Result<lightning::ln::chan_utils::HTLCOutputInCommitment, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
643         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::HTLCOutputInCommitment { 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() };
644         local_res
645 }
646 /// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
647 /// does not need to have its previous_output_index filled.
648 #[no_mangle]
649 pub extern "C" fn get_htlc_redeemscript(htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment, mut opt_anchors: bool, keys: &crate::lightning::ln::chan_utils::TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
650         let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(htlc.get_native_ref(), opt_anchors, keys.get_native_ref());
651         ret.into_bytes().into()
652 }
653
654 /// Gets the redeemscript for a funding output from the two funding public keys.
655 /// Note that the order of funding public keys does not matter.
656 #[no_mangle]
657 pub extern "C" fn make_funding_redeemscript(mut broadcaster: crate::c_types::PublicKey, mut countersignatory: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z {
658         let mut ret = lightning::ln::chan_utils::make_funding_redeemscript(&broadcaster.into_rust(), &countersignatory.into_rust());
659         ret.into_bytes().into()
660 }
661
662 /// Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC
663 /// parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the
664 /// transaction which needs signing, and can be used to construct an HTLC transaction which is
665 /// broadcastable given a counterparty HTLC signature.
666 ///
667 /// Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
668 /// commitment transaction).
669 #[no_mangle]
670 pub extern "C" fn build_htlc_transaction(commitment_txid: *const [u8; 32], mut feerate_per_kw: u32, mut contest_delay: u16, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment, mut opt_anchors: bool, mut broadcaster_delayed_payment_key: crate::c_types::PublicKey, mut revocation_key: crate::c_types::PublicKey) -> crate::c_types::Transaction {
671         let mut ret = lightning::ln::chan_utils::build_htlc_transaction(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*commitment_txid }[..]).unwrap(), feerate_per_kw, contest_delay, htlc.get_native_ref(), opt_anchors, &broadcaster_delayed_payment_key.into_rust(), &revocation_key.into_rust());
672         crate::c_types::Transaction::from_bitcoin(&ret)
673 }
674
675 /// Gets the witnessScript for an anchor output from the funding public key.
676 /// The witness in the spending input must be:
677 /// <BIP 143 funding_signature>
678 /// After 16 blocks of confirmation, an alternative satisfying witness could be:
679 /// <>
680 /// (empty vector required to satisfy compliance with MINIMALIF-standard rule)
681 #[no_mangle]
682 pub extern "C" fn get_anchor_redeemscript(mut funding_pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::CVec_u8Z {
683         let mut ret = lightning::ln::chan_utils::get_anchor_redeemscript(&funding_pubkey.into_rust());
684         ret.into_bytes().into()
685 }
686
687
688 use lightning::ln::chan_utils::ChannelTransactionParameters as nativeChannelTransactionParametersImport;
689 pub(crate) type nativeChannelTransactionParameters = nativeChannelTransactionParametersImport;
690
691 /// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction).
692 /// The fields are organized by holder/counterparty.
693 ///
694 /// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters
695 /// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions.
696 #[must_use]
697 #[repr(C)]
698 pub struct ChannelTransactionParameters {
699         /// A pointer to the opaque Rust object.
700
701         /// Nearly everywhere, inner must be non-null, however in places where
702         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
703         pub inner: *mut nativeChannelTransactionParameters,
704         /// Indicates that this is the only struct which contains the same pointer.
705
706         /// Rust functions which take ownership of an object provided via an argument require
707         /// this to be true and invalidate the object pointed to by inner.
708         pub is_owned: bool,
709 }
710
711 impl Drop for ChannelTransactionParameters {
712         fn drop(&mut self) {
713                 if self.is_owned && !<*mut nativeChannelTransactionParameters>::is_null(self.inner) {
714                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
715                 }
716         }
717 }
718 /// Frees any resources used by the ChannelTransactionParameters, if is_owned is set and inner is non-NULL.
719 #[no_mangle]
720 pub extern "C" fn ChannelTransactionParameters_free(this_obj: ChannelTransactionParameters) { }
721 #[allow(unused)]
722 /// Used only if an object of this type is returned as a trait impl by a method
723 pub(crate) extern "C" fn ChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
724         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTransactionParameters); }
725 }
726 #[allow(unused)]
727 impl ChannelTransactionParameters {
728         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelTransactionParameters {
729                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
730         }
731         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelTransactionParameters {
732                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
733         }
734         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
735         pub(crate) fn take_inner(mut self) -> *mut nativeChannelTransactionParameters {
736                 assert!(self.is_owned);
737                 let ret = ObjOps::untweak_ptr(self.inner);
738                 self.inner = core::ptr::null_mut();
739                 ret
740         }
741 }
742 /// Holder public keys
743 #[no_mangle]
744 pub extern "C" fn ChannelTransactionParameters_get_holder_pubkeys(this_ptr: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
745         let mut inner_val = &mut this_ptr.get_native_mut_ref().holder_pubkeys;
746         crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::ChannelPublicKeys<>) as *mut _) }, is_owned: false }
747 }
748 /// Holder public keys
749 #[no_mangle]
750 pub extern "C" fn ChannelTransactionParameters_set_holder_pubkeys(this_ptr: &mut ChannelTransactionParameters, mut val: crate::lightning::ln::chan_utils::ChannelPublicKeys) {
751         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.holder_pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
752 }
753 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
754 #[no_mangle]
755 pub extern "C" fn ChannelTransactionParameters_get_holder_selected_contest_delay(this_ptr: &ChannelTransactionParameters) -> u16 {
756         let mut inner_val = &mut this_ptr.get_native_mut_ref().holder_selected_contest_delay;
757         *inner_val
758 }
759 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
760 #[no_mangle]
761 pub extern "C" fn ChannelTransactionParameters_set_holder_selected_contest_delay(this_ptr: &mut ChannelTransactionParameters, mut val: u16) {
762         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.holder_selected_contest_delay = val;
763 }
764 /// Whether the holder is the initiator of this channel.
765 /// This is an input to the commitment number obscure factor computation.
766 #[no_mangle]
767 pub extern "C" fn ChannelTransactionParameters_get_is_outbound_from_holder(this_ptr: &ChannelTransactionParameters) -> bool {
768         let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound_from_holder;
769         *inner_val
770 }
771 /// Whether the holder is the initiator of this channel.
772 /// This is an input to the commitment number obscure factor computation.
773 #[no_mangle]
774 pub extern "C" fn ChannelTransactionParameters_set_is_outbound_from_holder(this_ptr: &mut ChannelTransactionParameters, mut val: bool) {
775         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound_from_holder = val;
776 }
777 /// The late-bound counterparty channel transaction parameters.
778 /// These parameters are populated at the point in the protocol where the counterparty provides them.
779 ///
780 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
781 #[no_mangle]
782 pub extern "C" fn ChannelTransactionParameters_get_counterparty_parameters(this_ptr: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters {
783         let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_parameters;
784         let mut local_inner_val = crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::chan_utils::CounterpartyChannelTransactionParameters<>) as *mut _ }, is_owned: false };
785         local_inner_val
786 }
787 /// The late-bound counterparty channel transaction parameters.
788 /// These parameters are populated at the point in the protocol where the counterparty provides them.
789 ///
790 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
791 #[no_mangle]
792 pub extern "C" fn ChannelTransactionParameters_set_counterparty_parameters(this_ptr: &mut ChannelTransactionParameters, mut val: crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters) {
793         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
794         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_parameters = local_val;
795 }
796 /// The late-bound funding outpoint
797 ///
798 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
799 #[no_mangle]
800 pub extern "C" fn ChannelTransactionParameters_get_funding_outpoint(this_ptr: &ChannelTransactionParameters) -> crate::lightning::chain::transaction::OutPoint {
801         let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_outpoint;
802         let mut local_inner_val = crate::lightning::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::chain::transaction::OutPoint<>) as *mut _ }, is_owned: false };
803         local_inner_val
804 }
805 /// The late-bound funding outpoint
806 ///
807 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
808 #[no_mangle]
809 pub extern "C" fn ChannelTransactionParameters_set_funding_outpoint(this_ptr: &mut ChannelTransactionParameters, mut val: crate::lightning::chain::transaction::OutPoint) {
810         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
811         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_outpoint = local_val;
812 }
813 /// Are anchors used for this channel.  Boolean is serialization backwards-compatible
814 #[no_mangle]
815 pub extern "C" fn ChannelTransactionParameters_get_opt_anchors(this_ptr: &ChannelTransactionParameters) -> crate::c_types::derived::COption_NoneZ {
816         let mut inner_val = &mut this_ptr.get_native_mut_ref().opt_anchors;
817         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_NoneZ::None } else { crate::c_types::derived::COption_NoneZ::Some /* { () /**/ } */};
818         local_inner_val
819 }
820 /// Are anchors used for this channel.  Boolean is serialization backwards-compatible
821 #[no_mangle]
822 pub extern "C" fn ChannelTransactionParameters_set_opt_anchors(this_ptr: &mut ChannelTransactionParameters, mut val: crate::c_types::derived::COption_NoneZ) {
823         let mut local_val = if val.is_some() { Some( { () /*val.take()*/ }) } else { None };
824         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.opt_anchors = local_val;
825 }
826 /// Constructs a new ChannelTransactionParameters given each field
827 #[must_use]
828 #[no_mangle]
829 pub extern "C" fn ChannelTransactionParameters_new(mut holder_pubkeys_arg: crate::lightning::ln::chan_utils::ChannelPublicKeys, mut holder_selected_contest_delay_arg: u16, mut is_outbound_from_holder_arg: bool, mut counterparty_parameters_arg: crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters, mut funding_outpoint_arg: crate::lightning::chain::transaction::OutPoint, mut opt_anchors_arg: crate::c_types::derived::COption_NoneZ) -> ChannelTransactionParameters {
830         let mut local_counterparty_parameters_arg = if counterparty_parameters_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(counterparty_parameters_arg.take_inner()) } }) };
831         let mut local_funding_outpoint_arg = if funding_outpoint_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(funding_outpoint_arg.take_inner()) } }) };
832         let mut local_opt_anchors_arg = if opt_anchors_arg.is_some() { Some( { () /*opt_anchors_arg.take()*/ }) } else { None };
833         ChannelTransactionParameters { inner: ObjOps::heap_alloc(nativeChannelTransactionParameters {
834                 holder_pubkeys: *unsafe { Box::from_raw(holder_pubkeys_arg.take_inner()) },
835                 holder_selected_contest_delay: holder_selected_contest_delay_arg,
836                 is_outbound_from_holder: is_outbound_from_holder_arg,
837                 counterparty_parameters: local_counterparty_parameters_arg,
838                 funding_outpoint: local_funding_outpoint_arg,
839                 opt_anchors: local_opt_anchors_arg,
840         }), is_owned: true }
841 }
842 impl Clone for ChannelTransactionParameters {
843         fn clone(&self) -> Self {
844                 Self {
845                         inner: if <*mut nativeChannelTransactionParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
846                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
847                         is_owned: true,
848                 }
849         }
850 }
851 #[allow(unused)]
852 /// Used only if an object of this type is returned as a trait impl by a method
853 pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
854         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTransactionParameters)).clone() })) as *mut c_void
855 }
856 #[no_mangle]
857 /// Creates a copy of the ChannelTransactionParameters
858 pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters {
859         orig.clone()
860 }
861
862 use lightning::ln::chan_utils::CounterpartyChannelTransactionParameters as nativeCounterpartyChannelTransactionParametersImport;
863 pub(crate) type nativeCounterpartyChannelTransactionParameters = nativeCounterpartyChannelTransactionParametersImport;
864
865 /// Late-bound per-channel counterparty data used to build transactions.
866 #[must_use]
867 #[repr(C)]
868 pub struct CounterpartyChannelTransactionParameters {
869         /// A pointer to the opaque Rust object.
870
871         /// Nearly everywhere, inner must be non-null, however in places where
872         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
873         pub inner: *mut nativeCounterpartyChannelTransactionParameters,
874         /// Indicates that this is the only struct which contains the same pointer.
875
876         /// Rust functions which take ownership of an object provided via an argument require
877         /// this to be true and invalidate the object pointed to by inner.
878         pub is_owned: bool,
879 }
880
881 impl Drop for CounterpartyChannelTransactionParameters {
882         fn drop(&mut self) {
883                 if self.is_owned && !<*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) {
884                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
885                 }
886         }
887 }
888 /// Frees any resources used by the CounterpartyChannelTransactionParameters, if is_owned is set and inner is non-NULL.
889 #[no_mangle]
890 pub extern "C" fn CounterpartyChannelTransactionParameters_free(this_obj: CounterpartyChannelTransactionParameters) { }
891 #[allow(unused)]
892 /// Used only if an object of this type is returned as a trait impl by a method
893 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
894         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyChannelTransactionParameters); }
895 }
896 #[allow(unused)]
897 impl CounterpartyChannelTransactionParameters {
898         pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyChannelTransactionParameters {
899                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
900         }
901         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyChannelTransactionParameters {
902                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
903         }
904         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
905         pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyChannelTransactionParameters {
906                 assert!(self.is_owned);
907                 let ret = ObjOps::untweak_ptr(self.inner);
908                 self.inner = core::ptr::null_mut();
909                 ret
910         }
911 }
912 /// Counter-party public keys
913 #[no_mangle]
914 pub extern "C" fn CounterpartyChannelTransactionParameters_get_pubkeys(this_ptr: &CounterpartyChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
915         let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkeys;
916         crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::chan_utils::ChannelPublicKeys<>) as *mut _) }, is_owned: false }
917 }
918 /// Counter-party public keys
919 #[no_mangle]
920 pub extern "C" fn CounterpartyChannelTransactionParameters_set_pubkeys(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: crate::lightning::ln::chan_utils::ChannelPublicKeys) {
921         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
922 }
923 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
924 #[no_mangle]
925 pub extern "C" fn CounterpartyChannelTransactionParameters_get_selected_contest_delay(this_ptr: &CounterpartyChannelTransactionParameters) -> u16 {
926         let mut inner_val = &mut this_ptr.get_native_mut_ref().selected_contest_delay;
927         *inner_val
928 }
929 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
930 #[no_mangle]
931 pub extern "C" fn CounterpartyChannelTransactionParameters_set_selected_contest_delay(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: u16) {
932         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.selected_contest_delay = val;
933 }
934 /// Constructs a new CounterpartyChannelTransactionParameters given each field
935 #[must_use]
936 #[no_mangle]
937 pub extern "C" fn CounterpartyChannelTransactionParameters_new(mut pubkeys_arg: crate::lightning::ln::chan_utils::ChannelPublicKeys, mut selected_contest_delay_arg: u16) -> CounterpartyChannelTransactionParameters {
938         CounterpartyChannelTransactionParameters { inner: ObjOps::heap_alloc(nativeCounterpartyChannelTransactionParameters {
939                 pubkeys: *unsafe { Box::from_raw(pubkeys_arg.take_inner()) },
940                 selected_contest_delay: selected_contest_delay_arg,
941         }), is_owned: true }
942 }
943 impl Clone for CounterpartyChannelTransactionParameters {
944         fn clone(&self) -> Self {
945                 Self {
946                         inner: if <*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
947                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
948                         is_owned: true,
949                 }
950         }
951 }
952 #[allow(unused)]
953 /// Used only if an object of this type is returned as a trait impl by a method
954 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
955         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void
956 }
957 #[no_mangle]
958 /// Creates a copy of the CounterpartyChannelTransactionParameters
959 pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters {
960         orig.clone()
961 }
962 /// Whether the late bound parameters are populated.
963 #[must_use]
964 #[no_mangle]
965 pub extern "C" fn ChannelTransactionParameters_is_populated(this_arg: &ChannelTransactionParameters) -> bool {
966         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_populated();
967         ret
968 }
969
970 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
971 /// given that the holder is the broadcaster.
972 ///
973 /// self.is_populated() must be true before calling this function.
974 #[must_use]
975 #[no_mangle]
976 pub extern "C" fn ChannelTransactionParameters_as_holder_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters {
977         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_holder_broadcastable();
978         crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
979 }
980
981 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
982 /// given that the counterparty is the broadcaster.
983 ///
984 /// self.is_populated() must be true before calling this function.
985 #[must_use]
986 #[no_mangle]
987 pub extern "C" fn ChannelTransactionParameters_as_counterparty_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters {
988         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_counterparty_broadcastable();
989         crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
990 }
991
992 #[no_mangle]
993 /// Serialize the CounterpartyChannelTransactionParameters object into a byte array which can be read by CounterpartyChannelTransactionParameters_read
994 pub extern "C" fn CounterpartyChannelTransactionParameters_write(obj: &CounterpartyChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
995         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
996 }
997 #[no_mangle]
998 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
999         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyChannelTransactionParameters) })
1000 }
1001 #[no_mangle]
1002 /// Read a CounterpartyChannelTransactionParameters from a byte array, created by CounterpartyChannelTransactionParameters_write
1003 pub extern "C" fn CounterpartyChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyChannelTransactionParametersDecodeErrorZ {
1004         let res: Result<lightning::ln::chan_utils::CounterpartyChannelTransactionParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1005         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters { 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() };
1006         local_res
1007 }
1008 #[no_mangle]
1009 /// Serialize the ChannelTransactionParameters object into a byte array which can be read by ChannelTransactionParameters_read
1010 pub extern "C" fn ChannelTransactionParameters_write(obj: &ChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
1011         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1012 }
1013 #[no_mangle]
1014 pub(crate) extern "C" fn ChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1015         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTransactionParameters) })
1016 }
1017 #[no_mangle]
1018 /// Read a ChannelTransactionParameters from a byte array, created by ChannelTransactionParameters_write
1019 pub extern "C" fn ChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelTransactionParametersDecodeErrorZ {
1020         let res: Result<lightning::ln::chan_utils::ChannelTransactionParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1021         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::ChannelTransactionParameters { 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() };
1022         local_res
1023 }
1024
1025 use lightning::ln::chan_utils::DirectedChannelTransactionParameters as nativeDirectedChannelTransactionParametersImport;
1026 pub(crate) type nativeDirectedChannelTransactionParameters = nativeDirectedChannelTransactionParametersImport<'static>;
1027
1028 /// Static channel fields used to build transactions given per-commitment fields, organized by
1029 /// broadcaster/countersignatory.
1030 ///
1031 /// This is derived from the holder/counterparty-organized ChannelTransactionParameters via the
1032 /// as_holder_broadcastable and as_counterparty_broadcastable functions.
1033 #[must_use]
1034 #[repr(C)]
1035 pub struct DirectedChannelTransactionParameters {
1036         /// A pointer to the opaque Rust object.
1037
1038         /// Nearly everywhere, inner must be non-null, however in places where
1039         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1040         pub inner: *mut nativeDirectedChannelTransactionParameters,
1041         /// Indicates that this is the only struct which contains the same pointer.
1042
1043         /// Rust functions which take ownership of an object provided via an argument require
1044         /// this to be true and invalidate the object pointed to by inner.
1045         pub is_owned: bool,
1046 }
1047
1048 impl Drop for DirectedChannelTransactionParameters {
1049         fn drop(&mut self) {
1050                 if self.is_owned && !<*mut nativeDirectedChannelTransactionParameters>::is_null(self.inner) {
1051                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1052                 }
1053         }
1054 }
1055 /// Frees any resources used by the DirectedChannelTransactionParameters, if is_owned is set and inner is non-NULL.
1056 #[no_mangle]
1057 pub extern "C" fn DirectedChannelTransactionParameters_free(this_obj: DirectedChannelTransactionParameters) { }
1058 #[allow(unused)]
1059 /// Used only if an object of this type is returned as a trait impl by a method
1060 pub(crate) extern "C" fn DirectedChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
1061         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelTransactionParameters); }
1062 }
1063 #[allow(unused)]
1064 impl DirectedChannelTransactionParameters {
1065         pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelTransactionParameters {
1066                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1067         }
1068         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelTransactionParameters {
1069                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1070         }
1071         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1072         pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelTransactionParameters {
1073                 assert!(self.is_owned);
1074                 let ret = ObjOps::untweak_ptr(self.inner);
1075                 self.inner = core::ptr::null_mut();
1076                 ret
1077         }
1078 }
1079 /// Get the channel pubkeys for the broadcaster
1080 #[must_use]
1081 #[no_mangle]
1082 pub extern "C" fn DirectedChannelTransactionParameters_broadcaster_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1083         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcaster_pubkeys();
1084         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 }
1085 }
1086
1087 /// Get the channel pubkeys for the countersignatory
1088 #[must_use]
1089 #[no_mangle]
1090 pub extern "C" fn DirectedChannelTransactionParameters_countersignatory_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1091         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.countersignatory_pubkeys();
1092         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 }
1093 }
1094
1095 /// Get the contest delay applicable to the transactions.
1096 /// Note that the contest delay was selected by the countersignatory.
1097 #[must_use]
1098 #[no_mangle]
1099 pub extern "C" fn DirectedChannelTransactionParameters_contest_delay(this_arg: &DirectedChannelTransactionParameters) -> u16 {
1100         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.contest_delay();
1101         ret
1102 }
1103
1104 /// Whether the channel is outbound from the broadcaster.
1105 ///
1106 /// The boolean representing the side that initiated the channel is
1107 /// an input to the commitment number obscure factor computation.
1108 #[must_use]
1109 #[no_mangle]
1110 pub extern "C" fn DirectedChannelTransactionParameters_is_outbound(this_arg: &DirectedChannelTransactionParameters) -> bool {
1111         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
1112         ret
1113 }
1114
1115 /// The funding outpoint
1116 #[must_use]
1117 #[no_mangle]
1118 pub extern "C" fn DirectedChannelTransactionParameters_funding_outpoint(this_arg: &DirectedChannelTransactionParameters) -> crate::lightning::chain::transaction::OutPoint {
1119         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
1120         crate::c_types::bitcoin_to_C_outpoint(ret)
1121 }
1122
1123 /// Whether to use anchors for this channel
1124 #[must_use]
1125 #[no_mangle]
1126 pub extern "C" fn DirectedChannelTransactionParameters_opt_anchors(this_arg: &DirectedChannelTransactionParameters) -> bool {
1127         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.opt_anchors();
1128         ret
1129 }
1130
1131
1132 use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport;
1133 pub(crate) type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport;
1134
1135 /// Information needed to build and sign a holder's commitment transaction.
1136 ///
1137 /// The transaction is only signed once we are ready to broadcast.
1138 #[must_use]
1139 #[repr(C)]
1140 pub struct HolderCommitmentTransaction {
1141         /// A pointer to the opaque Rust object.
1142
1143         /// Nearly everywhere, inner must be non-null, however in places where
1144         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1145         pub inner: *mut nativeHolderCommitmentTransaction,
1146         /// Indicates that this is the only struct which contains the same pointer.
1147
1148         /// Rust functions which take ownership of an object provided via an argument require
1149         /// this to be true and invalidate the object pointed to by inner.
1150         pub is_owned: bool,
1151 }
1152
1153 impl Drop for HolderCommitmentTransaction {
1154         fn drop(&mut self) {
1155                 if self.is_owned && !<*mut nativeHolderCommitmentTransaction>::is_null(self.inner) {
1156                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1157                 }
1158         }
1159 }
1160 /// Frees any resources used by the HolderCommitmentTransaction, if is_owned is set and inner is non-NULL.
1161 #[no_mangle]
1162 pub extern "C" fn HolderCommitmentTransaction_free(this_obj: HolderCommitmentTransaction) { }
1163 #[allow(unused)]
1164 /// Used only if an object of this type is returned as a trait impl by a method
1165 pub(crate) extern "C" fn HolderCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1166         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHolderCommitmentTransaction); }
1167 }
1168 #[allow(unused)]
1169 impl HolderCommitmentTransaction {
1170         pub(crate) fn get_native_ref(&self) -> &'static nativeHolderCommitmentTransaction {
1171                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1172         }
1173         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHolderCommitmentTransaction {
1174                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1175         }
1176         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1177         pub(crate) fn take_inner(mut self) -> *mut nativeHolderCommitmentTransaction {
1178                 assert!(self.is_owned);
1179                 let ret = ObjOps::untweak_ptr(self.inner);
1180                 self.inner = core::ptr::null_mut();
1181                 ret
1182         }
1183 }
1184 /// Our counterparty's signature for the transaction
1185 #[no_mangle]
1186 pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature {
1187         let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig;
1188         crate::c_types::Signature::from_rust(&inner_val)
1189 }
1190 /// Our counterparty's signature for the transaction
1191 #[no_mangle]
1192 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) {
1193         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust();
1194 }
1195 /// All non-dust counterparty HTLC signatures, in the order they appear in the transaction
1196 #[no_mangle]
1197 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_htlc_sigs(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_SignatureZ) {
1198         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); };
1199         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_htlc_sigs = local_val;
1200 }
1201 impl Clone for HolderCommitmentTransaction {
1202         fn clone(&self) -> Self {
1203                 Self {
1204                         inner: if <*mut nativeHolderCommitmentTransaction>::is_null(self.inner) { core::ptr::null_mut() } else {
1205                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1206                         is_owned: true,
1207                 }
1208         }
1209 }
1210 #[allow(unused)]
1211 /// Used only if an object of this type is returned as a trait impl by a method
1212 pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1213         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void
1214 }
1215 #[no_mangle]
1216 /// Creates a copy of the HolderCommitmentTransaction
1217 pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction {
1218         orig.clone()
1219 }
1220 #[no_mangle]
1221 /// Serialize the HolderCommitmentTransaction object into a byte array which can be read by HolderCommitmentTransaction_read
1222 pub extern "C" fn HolderCommitmentTransaction_write(obj: &HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1223         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1224 }
1225 #[no_mangle]
1226 pub(crate) extern "C" fn HolderCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1227         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHolderCommitmentTransaction) })
1228 }
1229 #[no_mangle]
1230 /// Read a HolderCommitmentTransaction from a byte array, created by HolderCommitmentTransaction_write
1231 pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HolderCommitmentTransactionDecodeErrorZ {
1232         let res: Result<lightning::ln::chan_utils::HolderCommitmentTransaction, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1233         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::HolderCommitmentTransaction { 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() };
1234         local_res
1235 }
1236 /// Create a new holder transaction with the given counterparty signatures.
1237 /// The funding keys are used to figure out which signature should go first when building the transaction for broadcast.
1238 #[must_use]
1239 #[no_mangle]
1240 pub extern "C" fn HolderCommitmentTransaction_new(mut commitment_tx: crate::lightning::ln::chan_utils::CommitmentTransaction, mut counterparty_sig: crate::c_types::Signature, mut counterparty_htlc_sigs: crate::c_types::derived::CVec_SignatureZ, mut holder_funding_key: crate::c_types::PublicKey, mut counterparty_funding_key: crate::c_types::PublicKey) -> HolderCommitmentTransaction {
1241         let mut local_counterparty_htlc_sigs = Vec::new(); for mut item in counterparty_htlc_sigs.into_rust().drain(..) { local_counterparty_htlc_sigs.push( { item.into_rust() }); };
1242         let mut ret = lightning::ln::chan_utils::HolderCommitmentTransaction::new(*unsafe { Box::from_raw(commitment_tx.take_inner()) }, counterparty_sig.into_rust(), local_counterparty_htlc_sigs, &holder_funding_key.into_rust(), &counterparty_funding_key.into_rust());
1243         HolderCommitmentTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1244 }
1245
1246
1247 use lightning::ln::chan_utils::BuiltCommitmentTransaction as nativeBuiltCommitmentTransactionImport;
1248 pub(crate) type nativeBuiltCommitmentTransaction = nativeBuiltCommitmentTransactionImport;
1249
1250 /// A pre-built Bitcoin commitment transaction and its txid.
1251 #[must_use]
1252 #[repr(C)]
1253 pub struct BuiltCommitmentTransaction {
1254         /// A pointer to the opaque Rust object.
1255
1256         /// Nearly everywhere, inner must be non-null, however in places where
1257         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1258         pub inner: *mut nativeBuiltCommitmentTransaction,
1259         /// Indicates that this is the only struct which contains the same pointer.
1260
1261         /// Rust functions which take ownership of an object provided via an argument require
1262         /// this to be true and invalidate the object pointed to by inner.
1263         pub is_owned: bool,
1264 }
1265
1266 impl Drop for BuiltCommitmentTransaction {
1267         fn drop(&mut self) {
1268                 if self.is_owned && !<*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) {
1269                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1270                 }
1271         }
1272 }
1273 /// Frees any resources used by the BuiltCommitmentTransaction, if is_owned is set and inner is non-NULL.
1274 #[no_mangle]
1275 pub extern "C" fn BuiltCommitmentTransaction_free(this_obj: BuiltCommitmentTransaction) { }
1276 #[allow(unused)]
1277 /// Used only if an object of this type is returned as a trait impl by a method
1278 pub(crate) extern "C" fn BuiltCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1279         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBuiltCommitmentTransaction); }
1280 }
1281 #[allow(unused)]
1282 impl BuiltCommitmentTransaction {
1283         pub(crate) fn get_native_ref(&self) -> &'static nativeBuiltCommitmentTransaction {
1284                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1285         }
1286         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBuiltCommitmentTransaction {
1287                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1288         }
1289         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1290         pub(crate) fn take_inner(mut self) -> *mut nativeBuiltCommitmentTransaction {
1291                 assert!(self.is_owned);
1292                 let ret = ObjOps::untweak_ptr(self.inner);
1293                 self.inner = core::ptr::null_mut();
1294                 ret
1295         }
1296 }
1297 /// The commitment transaction
1298 #[no_mangle]
1299 pub extern "C" fn BuiltCommitmentTransaction_get_transaction(this_ptr: &BuiltCommitmentTransaction) -> crate::c_types::Transaction {
1300         let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction;
1301         crate::c_types::Transaction::from_bitcoin(inner_val)
1302 }
1303 /// The commitment transaction
1304 #[no_mangle]
1305 pub extern "C" fn BuiltCommitmentTransaction_set_transaction(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::Transaction) {
1306         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction = val.into_bitcoin();
1307 }
1308 /// The txid for the commitment transaction.
1309 ///
1310 /// This is provided as a performance optimization, instead of calling transaction.txid()
1311 /// multiple times.
1312 #[no_mangle]
1313 pub extern "C" fn BuiltCommitmentTransaction_get_txid(this_ptr: &BuiltCommitmentTransaction) -> *const [u8; 32] {
1314         let mut inner_val = &mut this_ptr.get_native_mut_ref().txid;
1315         inner_val.as_inner()
1316 }
1317 /// The txid for the commitment transaction.
1318 ///
1319 /// This is provided as a performance optimization, instead of calling transaction.txid()
1320 /// multiple times.
1321 #[no_mangle]
1322 pub extern "C" fn BuiltCommitmentTransaction_set_txid(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::ThirtyTwoBytes) {
1323         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap();
1324 }
1325 /// Constructs a new BuiltCommitmentTransaction given each field
1326 #[must_use]
1327 #[no_mangle]
1328 pub extern "C" fn BuiltCommitmentTransaction_new(mut transaction_arg: crate::c_types::Transaction, mut txid_arg: crate::c_types::ThirtyTwoBytes) -> BuiltCommitmentTransaction {
1329         BuiltCommitmentTransaction { inner: ObjOps::heap_alloc(nativeBuiltCommitmentTransaction {
1330                 transaction: transaction_arg.into_bitcoin(),
1331                 txid: ::bitcoin::hash_types::Txid::from_slice(&txid_arg.data[..]).unwrap(),
1332         }), is_owned: true }
1333 }
1334 impl Clone for BuiltCommitmentTransaction {
1335         fn clone(&self) -> Self {
1336                 Self {
1337                         inner: if <*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) { core::ptr::null_mut() } else {
1338                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1339                         is_owned: true,
1340                 }
1341         }
1342 }
1343 #[allow(unused)]
1344 /// Used only if an object of this type is returned as a trait impl by a method
1345 pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1346         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void
1347 }
1348 #[no_mangle]
1349 /// Creates a copy of the BuiltCommitmentTransaction
1350 pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction {
1351         orig.clone()
1352 }
1353 #[no_mangle]
1354 /// Serialize the BuiltCommitmentTransaction object into a byte array which can be read by BuiltCommitmentTransaction_read
1355 pub extern "C" fn BuiltCommitmentTransaction_write(obj: &BuiltCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1356         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1357 }
1358 #[no_mangle]
1359 pub(crate) extern "C" fn BuiltCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1360         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBuiltCommitmentTransaction) })
1361 }
1362 #[no_mangle]
1363 /// Read a BuiltCommitmentTransaction from a byte array, created by BuiltCommitmentTransaction_write
1364 pub extern "C" fn BuiltCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BuiltCommitmentTransactionDecodeErrorZ {
1365         let res: Result<lightning::ln::chan_utils::BuiltCommitmentTransaction, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1366         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::BuiltCommitmentTransaction { 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() };
1367         local_res
1368 }
1369 /// Get the SIGHASH_ALL sighash value of the transaction.
1370 ///
1371 /// This can be used to verify a signature.
1372 #[must_use]
1373 #[no_mangle]
1374 pub extern "C" fn BuiltCommitmentTransaction_get_sighash_all(this_arg: &BuiltCommitmentTransaction, mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::ThirtyTwoBytes {
1375         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_sighash_all(&::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis);
1376         crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() }
1377 }
1378
1379 /// Sign a transaction, either because we are counter-signing the counterparty's transaction or
1380 /// because we are about to broadcast a holder transaction.
1381 #[must_use]
1382 #[no_mangle]
1383 pub extern "C" fn BuiltCommitmentTransaction_sign(this_arg: &BuiltCommitmentTransaction, funding_key: *const [u8; 32], mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature {
1384         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, secp256k1::SECP256K1);
1385         crate::c_types::Signature::from_rust(&ret)
1386 }
1387
1388
1389 use lightning::ln::chan_utils::ClosingTransaction as nativeClosingTransactionImport;
1390 pub(crate) type nativeClosingTransaction = nativeClosingTransactionImport;
1391
1392 /// This class tracks the per-transaction information needed to build a closing transaction and will
1393 /// actually build it and sign.
1394 ///
1395 /// This class can be used inside a signer implementation to generate a signature given the relevant
1396 /// secret key.
1397 #[must_use]
1398 #[repr(C)]
1399 pub struct ClosingTransaction {
1400         /// A pointer to the opaque Rust object.
1401
1402         /// Nearly everywhere, inner must be non-null, however in places where
1403         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1404         pub inner: *mut nativeClosingTransaction,
1405         /// Indicates that this is the only struct which contains the same pointer.
1406
1407         /// Rust functions which take ownership of an object provided via an argument require
1408         /// this to be true and invalidate the object pointed to by inner.
1409         pub is_owned: bool,
1410 }
1411
1412 impl Drop for ClosingTransaction {
1413         fn drop(&mut self) {
1414                 if self.is_owned && !<*mut nativeClosingTransaction>::is_null(self.inner) {
1415                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1416                 }
1417         }
1418 }
1419 /// Frees any resources used by the ClosingTransaction, if is_owned is set and inner is non-NULL.
1420 #[no_mangle]
1421 pub extern "C" fn ClosingTransaction_free(this_obj: ClosingTransaction) { }
1422 #[allow(unused)]
1423 /// Used only if an object of this type is returned as a trait impl by a method
1424 pub(crate) extern "C" fn ClosingTransaction_free_void(this_ptr: *mut c_void) {
1425         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeClosingTransaction); }
1426 }
1427 #[allow(unused)]
1428 impl ClosingTransaction {
1429         pub(crate) fn get_native_ref(&self) -> &'static nativeClosingTransaction {
1430                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1431         }
1432         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeClosingTransaction {
1433                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1434         }
1435         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1436         pub(crate) fn take_inner(mut self) -> *mut nativeClosingTransaction {
1437                 assert!(self.is_owned);
1438                 let ret = ObjOps::untweak_ptr(self.inner);
1439                 self.inner = core::ptr::null_mut();
1440                 ret
1441         }
1442 }
1443 impl Clone for ClosingTransaction {
1444         fn clone(&self) -> Self {
1445                 Self {
1446                         inner: if <*mut nativeClosingTransaction>::is_null(self.inner) { core::ptr::null_mut() } else {
1447                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1448                         is_owned: true,
1449                 }
1450         }
1451 }
1452 #[allow(unused)]
1453 /// Used only if an object of this type is returned as a trait impl by a method
1454 pub(crate) extern "C" fn ClosingTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1455         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeClosingTransaction)).clone() })) as *mut c_void
1456 }
1457 #[no_mangle]
1458 /// Creates a copy of the ClosingTransaction
1459 pub extern "C" fn ClosingTransaction_clone(orig: &ClosingTransaction) -> ClosingTransaction {
1460         orig.clone()
1461 }
1462 /// Checks if two ClosingTransactions contain equal inner contents.
1463 #[no_mangle]
1464 pub extern "C" fn ClosingTransaction_hash(o: &ClosingTransaction) -> u64 {
1465         if o.inner.is_null() { return 0; }
1466         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1467         #[allow(deprecated)]
1468         let mut hasher = core::hash::SipHasher::new();
1469         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1470         core::hash::Hasher::finish(&hasher)
1471 }
1472 /// Construct an object of the class
1473 #[must_use]
1474 #[no_mangle]
1475 pub extern "C" fn ClosingTransaction_new(mut to_holder_value_sat: u64, mut to_counterparty_value_sat: u64, mut to_holder_script: crate::c_types::derived::CVec_u8Z, mut to_counterparty_script: crate::c_types::derived::CVec_u8Z, mut funding_outpoint: crate::lightning::chain::transaction::OutPoint) -> ClosingTransaction {
1476         let mut ret = lightning::ln::chan_utils::ClosingTransaction::new(to_holder_value_sat, to_counterparty_value_sat, ::bitcoin::blockdata::script::Script::from(to_holder_script.into_rust()), ::bitcoin::blockdata::script::Script::from(to_counterparty_script.into_rust()), crate::c_types::C_to_bitcoin_outpoint(funding_outpoint));
1477         ClosingTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1478 }
1479
1480 /// Trust our pre-built transaction.
1481 ///
1482 /// Applies a wrapper which allows access to the transaction.
1483 ///
1484 /// This should only be used if you fully trust the builder of this object. It should not
1485 /// be used by an external signer - instead use the verify function.
1486 #[must_use]
1487 #[no_mangle]
1488 pub extern "C" fn ClosingTransaction_trust(this_arg: &ClosingTransaction) -> crate::lightning::ln::chan_utils::TrustedClosingTransaction {
1489         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.trust();
1490         crate::lightning::ln::chan_utils::TrustedClosingTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1491 }
1492
1493 /// Verify our pre-built transaction.
1494 ///
1495 /// Applies a wrapper which allows access to the transaction.
1496 ///
1497 /// An external validating signer must call this method before signing
1498 /// or using the built transaction.
1499 #[must_use]
1500 #[no_mangle]
1501 pub extern "C" fn ClosingTransaction_verify(this_arg: &ClosingTransaction, mut funding_outpoint: crate::lightning::chain::transaction::OutPoint) -> crate::c_types::derived::CResult_TrustedClosingTransactionNoneZ {
1502         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify(crate::c_types::C_to_bitcoin_outpoint(funding_outpoint));
1503         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::TrustedClosingTransaction { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1504         local_ret
1505 }
1506
1507 /// The value to be sent to the holder, or zero if the output will be omitted
1508 #[must_use]
1509 #[no_mangle]
1510 pub extern "C" fn ClosingTransaction_to_holder_value_sat(this_arg: &ClosingTransaction) -> u64 {
1511         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_holder_value_sat();
1512         ret
1513 }
1514
1515 /// The value to be sent to the counterparty, or zero if the output will be omitted
1516 #[must_use]
1517 #[no_mangle]
1518 pub extern "C" fn ClosingTransaction_to_counterparty_value_sat(this_arg: &ClosingTransaction) -> u64 {
1519         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_counterparty_value_sat();
1520         ret
1521 }
1522
1523 /// The destination of the holder's output
1524 #[must_use]
1525 #[no_mangle]
1526 pub extern "C" fn ClosingTransaction_to_holder_script(this_arg: &ClosingTransaction) -> crate::c_types::u8slice {
1527         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_holder_script();
1528         crate::c_types::u8slice::from_slice(&ret[..])
1529 }
1530
1531 /// The destination of the counterparty's output
1532 #[must_use]
1533 #[no_mangle]
1534 pub extern "C" fn ClosingTransaction_to_counterparty_script(this_arg: &ClosingTransaction) -> crate::c_types::u8slice {
1535         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_counterparty_script();
1536         crate::c_types::u8slice::from_slice(&ret[..])
1537 }
1538
1539
1540 use lightning::ln::chan_utils::TrustedClosingTransaction as nativeTrustedClosingTransactionImport;
1541 pub(crate) type nativeTrustedClosingTransaction = nativeTrustedClosingTransactionImport<'static>;
1542
1543 /// A wrapper on ClosingTransaction indicating that the built bitcoin
1544 /// transaction is trusted.
1545 ///
1546 /// See trust() and verify() functions on CommitmentTransaction.
1547 ///
1548 /// This structure implements Deref.
1549 #[must_use]
1550 #[repr(C)]
1551 pub struct TrustedClosingTransaction {
1552         /// A pointer to the opaque Rust object.
1553
1554         /// Nearly everywhere, inner must be non-null, however in places where
1555         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1556         pub inner: *mut nativeTrustedClosingTransaction,
1557         /// Indicates that this is the only struct which contains the same pointer.
1558
1559         /// Rust functions which take ownership of an object provided via an argument require
1560         /// this to be true and invalidate the object pointed to by inner.
1561         pub is_owned: bool,
1562 }
1563
1564 impl Drop for TrustedClosingTransaction {
1565         fn drop(&mut self) {
1566                 if self.is_owned && !<*mut nativeTrustedClosingTransaction>::is_null(self.inner) {
1567                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1568                 }
1569         }
1570 }
1571 /// Frees any resources used by the TrustedClosingTransaction, if is_owned is set and inner is non-NULL.
1572 #[no_mangle]
1573 pub extern "C" fn TrustedClosingTransaction_free(this_obj: TrustedClosingTransaction) { }
1574 #[allow(unused)]
1575 /// Used only if an object of this type is returned as a trait impl by a method
1576 pub(crate) extern "C" fn TrustedClosingTransaction_free_void(this_ptr: *mut c_void) {
1577         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedClosingTransaction); }
1578 }
1579 #[allow(unused)]
1580 impl TrustedClosingTransaction {
1581         pub(crate) fn get_native_ref(&self) -> &'static nativeTrustedClosingTransaction {
1582                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1583         }
1584         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeTrustedClosingTransaction {
1585                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1586         }
1587         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1588         pub(crate) fn take_inner(mut self) -> *mut nativeTrustedClosingTransaction {
1589                 assert!(self.is_owned);
1590                 let ret = ObjOps::untweak_ptr(self.inner);
1591                 self.inner = core::ptr::null_mut();
1592                 ret
1593         }
1594 }
1595 /// The pre-built Bitcoin commitment transaction
1596 #[must_use]
1597 #[no_mangle]
1598 pub extern "C" fn TrustedClosingTransaction_built_transaction(this_arg: &TrustedClosingTransaction) -> crate::c_types::Transaction {
1599         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.built_transaction();
1600         crate::c_types::Transaction::from_bitcoin(ret)
1601 }
1602
1603 /// Get the SIGHASH_ALL sighash value of the transaction.
1604 ///
1605 /// This can be used to verify a signature.
1606 #[must_use]
1607 #[no_mangle]
1608 pub extern "C" fn TrustedClosingTransaction_get_sighash_all(this_arg: &TrustedClosingTransaction, mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::ThirtyTwoBytes {
1609         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_sighash_all(&::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis);
1610         crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() }
1611 }
1612
1613 /// Sign a transaction, either because we are counter-signing the counterparty's transaction or
1614 /// because we are about to broadcast a holder transaction.
1615 #[must_use]
1616 #[no_mangle]
1617 pub extern "C" fn TrustedClosingTransaction_sign(this_arg: &TrustedClosingTransaction, funding_key: *const [u8; 32], mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature {
1618         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, secp256k1::SECP256K1);
1619         crate::c_types::Signature::from_rust(&ret)
1620 }
1621
1622
1623 use lightning::ln::chan_utils::CommitmentTransaction as nativeCommitmentTransactionImport;
1624 pub(crate) type nativeCommitmentTransaction = nativeCommitmentTransactionImport;
1625
1626 /// This class tracks the per-transaction information needed to build a commitment transaction and will
1627 /// actually build it and sign.  It is used for holder transactions that we sign only when needed
1628 /// and for transactions we sign for the counterparty.
1629 ///
1630 /// This class can be used inside a signer implementation to generate a signature given the relevant
1631 /// secret key.
1632 #[must_use]
1633 #[repr(C)]
1634 pub struct CommitmentTransaction {
1635         /// A pointer to the opaque Rust object.
1636
1637         /// Nearly everywhere, inner must be non-null, however in places where
1638         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1639         pub inner: *mut nativeCommitmentTransaction,
1640         /// Indicates that this is the only struct which contains the same pointer.
1641
1642         /// Rust functions which take ownership of an object provided via an argument require
1643         /// this to be true and invalidate the object pointed to by inner.
1644         pub is_owned: bool,
1645 }
1646
1647 impl Drop for CommitmentTransaction {
1648         fn drop(&mut self) {
1649                 if self.is_owned && !<*mut nativeCommitmentTransaction>::is_null(self.inner) {
1650                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1651                 }
1652         }
1653 }
1654 /// Frees any resources used by the CommitmentTransaction, if is_owned is set and inner is non-NULL.
1655 #[no_mangle]
1656 pub extern "C" fn CommitmentTransaction_free(this_obj: CommitmentTransaction) { }
1657 #[allow(unused)]
1658 /// Used only if an object of this type is returned as a trait impl by a method
1659 pub(crate) extern "C" fn CommitmentTransaction_free_void(this_ptr: *mut c_void) {
1660         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentTransaction); }
1661 }
1662 #[allow(unused)]
1663 impl CommitmentTransaction {
1664         pub(crate) fn get_native_ref(&self) -> &'static nativeCommitmentTransaction {
1665                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1666         }
1667         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCommitmentTransaction {
1668                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1669         }
1670         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1671         pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentTransaction {
1672                 assert!(self.is_owned);
1673                 let ret = ObjOps::untweak_ptr(self.inner);
1674                 self.inner = core::ptr::null_mut();
1675                 ret
1676         }
1677 }
1678 impl Clone for CommitmentTransaction {
1679         fn clone(&self) -> Self {
1680                 Self {
1681                         inner: if <*mut nativeCommitmentTransaction>::is_null(self.inner) { core::ptr::null_mut() } else {
1682                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1683                         is_owned: true,
1684                 }
1685         }
1686 }
1687 #[allow(unused)]
1688 /// Used only if an object of this type is returned as a trait impl by a method
1689 pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1690         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void
1691 }
1692 #[no_mangle]
1693 /// Creates a copy of the CommitmentTransaction
1694 pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction {
1695         orig.clone()
1696 }
1697 #[no_mangle]
1698 /// Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
1699 pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1700         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1701 }
1702 #[no_mangle]
1703 pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1704         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) })
1705 }
1706 #[no_mangle]
1707 /// Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
1708 pub extern "C" fn CommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentTransactionDecodeErrorZ {
1709         let res: Result<lightning::ln::chan_utils::CommitmentTransaction, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1710         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::CommitmentTransaction { 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() };
1711         local_res
1712 }
1713 /// The backwards-counting commitment number
1714 #[must_use]
1715 #[no_mangle]
1716 pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &CommitmentTransaction) -> u64 {
1717         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.commitment_number();
1718         ret
1719 }
1720
1721 /// The value to be sent to the broadcaster
1722 #[must_use]
1723 #[no_mangle]
1724 pub extern "C" fn CommitmentTransaction_to_broadcaster_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1725         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_broadcaster_value_sat();
1726         ret
1727 }
1728
1729 /// The value to be sent to the counterparty
1730 #[must_use]
1731 #[no_mangle]
1732 pub extern "C" fn CommitmentTransaction_to_countersignatory_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1733         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_countersignatory_value_sat();
1734         ret
1735 }
1736
1737 /// The feerate paid per 1000-weight-unit in this commitment transaction.
1738 #[must_use]
1739 #[no_mangle]
1740 pub extern "C" fn CommitmentTransaction_feerate_per_kw(this_arg: &CommitmentTransaction) -> u32 {
1741         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.feerate_per_kw();
1742         ret
1743 }
1744
1745 /// Trust our pre-built transaction and derived transaction creation public keys.
1746 ///
1747 /// Applies a wrapper which allows access to these fields.
1748 ///
1749 /// This should only be used if you fully trust the builder of this object.  It should not
1750 /// be used by an external signer - instead use the verify function.
1751 #[must_use]
1752 #[no_mangle]
1753 pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction) -> crate::lightning::ln::chan_utils::TrustedCommitmentTransaction {
1754         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.trust();
1755         crate::lightning::ln::chan_utils::TrustedCommitmentTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1756 }
1757
1758 /// Verify our pre-built transaction and derived transaction creation public keys.
1759 ///
1760 /// Applies a wrapper which allows access to these fields.
1761 ///
1762 /// An external validating signer must call this method before signing
1763 /// or using the built transaction.
1764 #[must_use]
1765 #[no_mangle]
1766 pub extern "C" fn CommitmentTransaction_verify(this_arg: &CommitmentTransaction, channel_parameters: &crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters, broadcaster_keys: &crate::lightning::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::lightning::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TrustedCommitmentTransactionNoneZ {
1767         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify(channel_parameters.get_native_ref(), broadcaster_keys.get_native_ref(), countersignatory_keys.get_native_ref(), secp256k1::SECP256K1);
1768         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::chan_utils::TrustedCommitmentTransaction { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1769         local_ret
1770 }
1771
1772
1773 use lightning::ln::chan_utils::TrustedCommitmentTransaction as nativeTrustedCommitmentTransactionImport;
1774 pub(crate) type nativeTrustedCommitmentTransaction = nativeTrustedCommitmentTransactionImport<'static>;
1775
1776 /// A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin
1777 /// transaction and the transaction creation keys) are trusted.
1778 ///
1779 /// See trust() and verify() functions on CommitmentTransaction.
1780 ///
1781 /// This structure implements Deref.
1782 #[must_use]
1783 #[repr(C)]
1784 pub struct TrustedCommitmentTransaction {
1785         /// A pointer to the opaque Rust object.
1786
1787         /// Nearly everywhere, inner must be non-null, however in places where
1788         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1789         pub inner: *mut nativeTrustedCommitmentTransaction,
1790         /// Indicates that this is the only struct which contains the same pointer.
1791
1792         /// Rust functions which take ownership of an object provided via an argument require
1793         /// this to be true and invalidate the object pointed to by inner.
1794         pub is_owned: bool,
1795 }
1796
1797 impl Drop for TrustedCommitmentTransaction {
1798         fn drop(&mut self) {
1799                 if self.is_owned && !<*mut nativeTrustedCommitmentTransaction>::is_null(self.inner) {
1800                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1801                 }
1802         }
1803 }
1804 /// Frees any resources used by the TrustedCommitmentTransaction, if is_owned is set and inner is non-NULL.
1805 #[no_mangle]
1806 pub extern "C" fn TrustedCommitmentTransaction_free(this_obj: TrustedCommitmentTransaction) { }
1807 #[allow(unused)]
1808 /// Used only if an object of this type is returned as a trait impl by a method
1809 pub(crate) extern "C" fn TrustedCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1810         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedCommitmentTransaction); }
1811 }
1812 #[allow(unused)]
1813 impl TrustedCommitmentTransaction {
1814         pub(crate) fn get_native_ref(&self) -> &'static nativeTrustedCommitmentTransaction {
1815                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1816         }
1817         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeTrustedCommitmentTransaction {
1818                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1819         }
1820         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1821         pub(crate) fn take_inner(mut self) -> *mut nativeTrustedCommitmentTransaction {
1822                 assert!(self.is_owned);
1823                 let ret = ObjOps::untweak_ptr(self.inner);
1824                 self.inner = core::ptr::null_mut();
1825                 ret
1826         }
1827 }
1828 /// The transaction ID of the built Bitcoin transaction
1829 #[must_use]
1830 #[no_mangle]
1831 pub extern "C" fn TrustedCommitmentTransaction_txid(this_arg: &TrustedCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
1832         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.txid();
1833         crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
1834 }
1835
1836 /// The pre-built Bitcoin commitment transaction
1837 #[must_use]
1838 #[no_mangle]
1839 pub extern "C" fn TrustedCommitmentTransaction_built_transaction(this_arg: &TrustedCommitmentTransaction) -> crate::lightning::ln::chan_utils::BuiltCommitmentTransaction {
1840         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.built_transaction();
1841         crate::lightning::ln::chan_utils::BuiltCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::chan_utils::BuiltCommitmentTransaction<>) as *mut _) }, is_owned: false }
1842 }
1843
1844 /// The pre-calculated transaction creation public keys.
1845 #[must_use]
1846 #[no_mangle]
1847 pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitmentTransaction) -> crate::lightning::ln::chan_utils::TxCreationKeys {
1848         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.keys();
1849         crate::lightning::ln::chan_utils::TxCreationKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::chan_utils::TxCreationKeys<>) as *mut _) }, is_owned: false }
1850 }
1851
1852 /// Should anchors be used.
1853 #[must_use]
1854 #[no_mangle]
1855 pub extern "C" fn TrustedCommitmentTransaction_opt_anchors(this_arg: &TrustedCommitmentTransaction) -> bool {
1856         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.opt_anchors();
1857         ret
1858 }
1859
1860 /// Get a signature for each HTLC which was included in the commitment transaction (ie for
1861 /// which HTLCOutputInCommitment::transaction_output_index.is_some()).
1862 ///
1863 /// The returned Vec has one entry for each HTLC, and in the same order.
1864 #[must_use]
1865 #[no_mangle]
1866 pub extern "C" fn TrustedCommitmentTransaction_get_htlc_sigs(this_arg: &TrustedCommitmentTransaction, htlc_base_key: *const [u8; 32], channel_parameters: &crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
1867         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), channel_parameters.get_native_ref(), secp256k1::SECP256K1);
1868         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( { crate::c_types::Signature::from_rust(&item) }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1869         local_ret
1870 }
1871
1872 /// Commitment transaction numbers which appear in the transactions themselves are XOR'd with a
1873 /// shared secret first. This prevents on-chain observers from discovering how many commitment
1874 /// transactions occurred in a channel before it was closed.
1875 ///
1876 /// This function gets the shared secret from relevant channel public keys and can be used to
1877 /// \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
1878 #[no_mangle]
1879 pub extern "C" fn get_commitment_transaction_number_obscure_factor(mut broadcaster_payment_basepoint: crate::c_types::PublicKey, mut countersignatory_payment_basepoint: crate::c_types::PublicKey, mut outbound_from_broadcaster: bool) -> u64 {
1880         let mut ret = lightning::ln::chan_utils::get_commitment_transaction_number_obscure_factor(&broadcaster_payment_basepoint.into_rust(), &countersignatory_payment_basepoint.into_rust(), outbound_from_broadcaster);
1881         ret
1882 }
1883