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