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