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