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