Merge pull request #750 from TheBlueMatt/2020-11-dup-chan-id-crash
[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 /// PreCalculatedTxCreationKeys.trust_key_derivation 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_ptr(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: *const TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
212         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
213 }
214 #[no_mangle]
215 pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> TxCreationKeys {
216         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
217                 TxCreationKeys { inner: Box::into_raw(Box::new(res)), is_owned: true }
218         } else {
219                 TxCreationKeys { inner: std::ptr::null_mut(), is_owned: true }
220         }
221 }
222
223 use lightning::ln::chan_utils::PreCalculatedTxCreationKeys as nativePreCalculatedTxCreationKeysImport;
224 type nativePreCalculatedTxCreationKeys = nativePreCalculatedTxCreationKeysImport;
225
226 /// The per-commitment point and a set of pre-calculated public keys used for transaction creation
227 /// in the signer.
228 /// The pre-calculated keys are an optimization, because ChannelKeys has enough
229 /// information to re-derive them.
230 #[must_use]
231 #[repr(C)]
232 pub struct PreCalculatedTxCreationKeys {
233         /// Nearly everywhere, inner must be non-null, however in places where
234         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
235         pub inner: *mut nativePreCalculatedTxCreationKeys,
236         pub is_owned: bool,
237 }
238
239 impl Drop for PreCalculatedTxCreationKeys {
240         fn drop(&mut self) {
241                 if self.is_owned && !self.inner.is_null() {
242                         let _ = unsafe { Box::from_raw(self.inner) };
243                 }
244         }
245 }
246 #[no_mangle]
247 pub extern "C" fn PreCalculatedTxCreationKeys_free(this_ptr: PreCalculatedTxCreationKeys) { }
248 #[allow(unused)]
249 /// Used only if an object of this type is returned as a trait impl by a method
250 extern "C" fn PreCalculatedTxCreationKeys_free_void(this_ptr: *mut c_void) {
251         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePreCalculatedTxCreationKeys); }
252 }
253 #[allow(unused)]
254 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
255 impl PreCalculatedTxCreationKeys {
256         pub(crate) fn take_ptr(mut self) -> *mut nativePreCalculatedTxCreationKeys {
257                 assert!(self.is_owned);
258                 let ret = self.inner;
259                 self.inner = std::ptr::null_mut();
260                 ret
261         }
262 }
263 impl Clone for PreCalculatedTxCreationKeys {
264         fn clone(&self) -> Self {
265                 Self {
266                         inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
267                         is_owned: true,
268                 }
269         }
270 }
271 #[allow(unused)]
272 /// Used only if an object of this type is returned as a trait impl by a method
273 pub(crate) extern "C" fn PreCalculatedTxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
274         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePreCalculatedTxCreationKeys)).clone() })) as *mut c_void
275 }
276 #[no_mangle]
277 pub extern "C" fn PreCalculatedTxCreationKeys_clone(orig: &PreCalculatedTxCreationKeys) -> PreCalculatedTxCreationKeys {
278         PreCalculatedTxCreationKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
279 }
280 /// Create a new PreCalculatedTxCreationKeys from TxCreationKeys
281 #[must_use]
282 #[no_mangle]
283 pub extern "C" fn PreCalculatedTxCreationKeys_new(mut keys: crate::ln::chan_utils::TxCreationKeys) -> PreCalculatedTxCreationKeys {
284         let mut ret = lightning::ln::chan_utils::PreCalculatedTxCreationKeys::new(*unsafe { Box::from_raw(keys.take_ptr()) });
285         PreCalculatedTxCreationKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true }
286 }
287
288 /// The pre-calculated transaction creation public keys.
289 /// An external validating signer should not trust these keys.
290 #[must_use]
291 #[no_mangle]
292 pub extern "C" fn PreCalculatedTxCreationKeys_trust_key_derivation(this_arg: &PreCalculatedTxCreationKeys) -> crate::ln::chan_utils::TxCreationKeys {
293         let mut ret = unsafe { &*this_arg.inner }.trust_key_derivation();
294         crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
295 }
296
297 /// The transaction per-commitment point
298 #[must_use]
299 #[no_mangle]
300 pub extern "C" fn PreCalculatedTxCreationKeys_per_commitment_point(this_arg: &PreCalculatedTxCreationKeys) -> crate::c_types::PublicKey {
301         let mut ret = unsafe { &*this_arg.inner }.per_commitment_point();
302         crate::c_types::PublicKey::from_rust(&*ret)
303 }
304
305
306 use lightning::ln::chan_utils::ChannelPublicKeys as nativeChannelPublicKeysImport;
307 type nativeChannelPublicKeys = nativeChannelPublicKeysImport;
308
309 /// One counterparty's public keys which do not change over the life of a channel.
310 #[must_use]
311 #[repr(C)]
312 pub struct ChannelPublicKeys {
313         /// Nearly everywhere, inner must be non-null, however in places where
314         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
315         pub inner: *mut nativeChannelPublicKeys,
316         pub is_owned: bool,
317 }
318
319 impl Drop for ChannelPublicKeys {
320         fn drop(&mut self) {
321                 if self.is_owned && !self.inner.is_null() {
322                         let _ = unsafe { Box::from_raw(self.inner) };
323                 }
324         }
325 }
326 #[no_mangle]
327 pub extern "C" fn ChannelPublicKeys_free(this_ptr: ChannelPublicKeys) { }
328 #[allow(unused)]
329 /// Used only if an object of this type is returned as a trait impl by a method
330 extern "C" fn ChannelPublicKeys_free_void(this_ptr: *mut c_void) {
331         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelPublicKeys); }
332 }
333 #[allow(unused)]
334 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
335 impl ChannelPublicKeys {
336         pub(crate) fn take_ptr(mut self) -> *mut nativeChannelPublicKeys {
337                 assert!(self.is_owned);
338                 let ret = self.inner;
339                 self.inner = std::ptr::null_mut();
340                 ret
341         }
342 }
343 impl Clone for ChannelPublicKeys {
344         fn clone(&self) -> Self {
345                 Self {
346                         inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
347                         is_owned: true,
348                 }
349         }
350 }
351 #[allow(unused)]
352 /// Used only if an object of this type is returned as a trait impl by a method
353 pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
354         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelPublicKeys)).clone() })) as *mut c_void
355 }
356 #[no_mangle]
357 pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys {
358         ChannelPublicKeys { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
359 }
360 /// The public key which is used to sign all commitment transactions, as it appears in the
361 /// on-chain channel lock-in 2-of-2 multisig output.
362 #[no_mangle]
363 pub extern "C" fn ChannelPublicKeys_get_funding_pubkey(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
364         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_pubkey;
365         crate::c_types::PublicKey::from_rust(&(*inner_val))
366 }
367 /// The public key which is used to sign all commitment transactions, as it appears in the
368 /// on-chain channel lock-in 2-of-2 multisig output.
369 #[no_mangle]
370 pub extern "C" fn ChannelPublicKeys_set_funding_pubkey(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
371         unsafe { &mut *this_ptr.inner }.funding_pubkey = val.into_rust();
372 }
373 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
374 /// revocation keys. This is combined with the per-commitment-secret generated by the
375 /// counterparty to create a secret which the counterparty can reveal to revoke previous
376 /// states.
377 #[no_mangle]
378 pub extern "C" fn ChannelPublicKeys_get_revocation_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
379         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_basepoint;
380         crate::c_types::PublicKey::from_rust(&(*inner_val))
381 }
382 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
383 /// revocation keys. This is combined with the per-commitment-secret generated by the
384 /// counterparty to create a secret which the counterparty can reveal to revoke previous
385 /// states.
386 #[no_mangle]
387 pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
388         unsafe { &mut *this_ptr.inner }.revocation_basepoint = val.into_rust();
389 }
390 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
391 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
392 /// static across every commitment transaction.
393 #[no_mangle]
394 pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
395         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_point;
396         crate::c_types::PublicKey::from_rust(&(*inner_val))
397 }
398 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
399 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
400 /// static across every commitment transaction.
401 #[no_mangle]
402 pub extern "C" fn ChannelPublicKeys_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
403         unsafe { &mut *this_ptr.inner }.payment_point = val.into_rust();
404 }
405 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
406 /// public key which receives non-HTLC-encumbered funds which are only available for spending
407 /// after some delay (or can be claimed via the revocation path).
408 #[no_mangle]
409 pub extern "C" fn ChannelPublicKeys_get_delayed_payment_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
410         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint;
411         crate::c_types::PublicKey::from_rust(&(*inner_val))
412 }
413 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
414 /// public key which receives non-HTLC-encumbered funds which are only available for spending
415 /// after some delay (or can be claimed via the revocation path).
416 #[no_mangle]
417 pub extern "C" fn ChannelPublicKeys_set_delayed_payment_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
418         unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint = val.into_rust();
419 }
420 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
421 /// which is used to encumber HTLC-in-flight outputs.
422 #[no_mangle]
423 pub extern "C" fn ChannelPublicKeys_get_htlc_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
424         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_basepoint;
425         crate::c_types::PublicKey::from_rust(&(*inner_val))
426 }
427 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
428 /// which is used to encumber HTLC-in-flight outputs.
429 #[no_mangle]
430 pub extern "C" fn ChannelPublicKeys_set_htlc_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
431         unsafe { &mut *this_ptr.inner }.htlc_basepoint = val.into_rust();
432 }
433 #[must_use]
434 #[no_mangle]
435 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 {
436         ChannelPublicKeys { inner: Box::into_raw(Box::new(nativeChannelPublicKeys {
437                 funding_pubkey: funding_pubkey_arg.into_rust(),
438                 revocation_basepoint: revocation_basepoint_arg.into_rust(),
439                 payment_point: payment_point_arg.into_rust(),
440                 delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(),
441                 htlc_basepoint: htlc_basepoint_arg.into_rust(),
442         })), is_owned: true }
443 }
444 #[no_mangle]
445 pub extern "C" fn ChannelPublicKeys_write(obj: *const ChannelPublicKeys) -> crate::c_types::derived::CVec_u8Z {
446         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
447 }
448 #[no_mangle]
449 pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> ChannelPublicKeys {
450         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
451                 ChannelPublicKeys { inner: Box::into_raw(Box::new(res)), is_owned: true }
452         } else {
453                 ChannelPublicKeys { inner: std::ptr::null_mut(), is_owned: true }
454         }
455 }
456 /// Create a new TxCreationKeys from channel base points and the per-commitment point
457 #[must_use]
458 #[no_mangle]
459 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 {
460         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());
461         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) }) };
462         local_ret
463 }
464
465 /// A script either spendable by the revocation
466 /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
467 /// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
468 #[no_mangle]
469 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 {
470         let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), contest_delay, &broadcaster_delayed_payment_key.into_rust());
471         ret.into_bytes().into()
472 }
473
474
475 use lightning::ln::chan_utils::HTLCOutputInCommitment as nativeHTLCOutputInCommitmentImport;
476 type nativeHTLCOutputInCommitment = nativeHTLCOutputInCommitmentImport;
477
478 /// Information about an HTLC as it appears in a commitment transaction
479 #[must_use]
480 #[repr(C)]
481 pub struct HTLCOutputInCommitment {
482         /// Nearly everywhere, inner must be non-null, however in places where
483         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
484         pub inner: *mut nativeHTLCOutputInCommitment,
485         pub is_owned: bool,
486 }
487
488 impl Drop for HTLCOutputInCommitment {
489         fn drop(&mut self) {
490                 if self.is_owned && !self.inner.is_null() {
491                         let _ = unsafe { Box::from_raw(self.inner) };
492                 }
493         }
494 }
495 #[no_mangle]
496 pub extern "C" fn HTLCOutputInCommitment_free(this_ptr: HTLCOutputInCommitment) { }
497 #[allow(unused)]
498 /// Used only if an object of this type is returned as a trait impl by a method
499 extern "C" fn HTLCOutputInCommitment_free_void(this_ptr: *mut c_void) {
500         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCOutputInCommitment); }
501 }
502 #[allow(unused)]
503 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
504 impl HTLCOutputInCommitment {
505         pub(crate) fn take_ptr(mut self) -> *mut nativeHTLCOutputInCommitment {
506                 assert!(self.is_owned);
507                 let ret = self.inner;
508                 self.inner = std::ptr::null_mut();
509                 ret
510         }
511 }
512 impl Clone for HTLCOutputInCommitment {
513         fn clone(&self) -> Self {
514                 Self {
515                         inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
516                         is_owned: true,
517                 }
518         }
519 }
520 #[allow(unused)]
521 /// Used only if an object of this type is returned as a trait impl by a method
522 pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_void) -> *mut c_void {
523         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCOutputInCommitment)).clone() })) as *mut c_void
524 }
525 #[no_mangle]
526 pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment {
527         HTLCOutputInCommitment { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
528 }
529 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
530 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
531 /// need to compare this value to whether the commitment transaction in question is that of
532 /// the counterparty or our own.
533 #[no_mangle]
534 pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool {
535         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.offered;
536         (*inner_val)
537 }
538 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
539 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
540 /// need to compare this value to whether the commitment transaction in question is that of
541 /// the counterparty or our own.
542 #[no_mangle]
543 pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) {
544         unsafe { &mut *this_ptr.inner }.offered = val;
545 }
546 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
547 /// this divided by 1000.
548 #[no_mangle]
549 pub extern "C" fn HTLCOutputInCommitment_get_amount_msat(this_ptr: &HTLCOutputInCommitment) -> u64 {
550         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.amount_msat;
551         (*inner_val)
552 }
553 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
554 /// this divided by 1000.
555 #[no_mangle]
556 pub extern "C" fn HTLCOutputInCommitment_set_amount_msat(this_ptr: &mut HTLCOutputInCommitment, mut val: u64) {
557         unsafe { &mut *this_ptr.inner }.amount_msat = val;
558 }
559 /// The CLTV lock-time at which this HTLC expires.
560 #[no_mangle]
561 pub extern "C" fn HTLCOutputInCommitment_get_cltv_expiry(this_ptr: &HTLCOutputInCommitment) -> u32 {
562         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry;
563         (*inner_val)
564 }
565 /// The CLTV lock-time at which this HTLC expires.
566 #[no_mangle]
567 pub extern "C" fn HTLCOutputInCommitment_set_cltv_expiry(this_ptr: &mut HTLCOutputInCommitment, mut val: u32) {
568         unsafe { &mut *this_ptr.inner }.cltv_expiry = val;
569 }
570 /// The hash of the preimage which unlocks this HTLC.
571 #[no_mangle]
572 pub extern "C" fn HTLCOutputInCommitment_get_payment_hash(this_ptr: &HTLCOutputInCommitment) -> *const [u8; 32] {
573         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_hash;
574         &(*inner_val).0
575 }
576 /// The hash of the preimage which unlocks this HTLC.
577 #[no_mangle]
578 pub extern "C" fn HTLCOutputInCommitment_set_payment_hash(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::ThirtyTwoBytes) {
579         unsafe { &mut *this_ptr.inner }.payment_hash = ::lightning::ln::channelmanager::PaymentHash(val.data);
580 }
581 #[no_mangle]
582 pub extern "C" fn HTLCOutputInCommitment_write(obj: *const HTLCOutputInCommitment) -> crate::c_types::derived::CVec_u8Z {
583         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
584 }
585 #[no_mangle]
586 pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> HTLCOutputInCommitment {
587         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
588                 HTLCOutputInCommitment { inner: Box::into_raw(Box::new(res)), is_owned: true }
589         } else {
590                 HTLCOutputInCommitment { inner: std::ptr::null_mut(), is_owned: true }
591         }
592 }
593 /// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
594 /// does not need to have its previous_output_index filled.
595 #[no_mangle]
596 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 {
597         let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(unsafe { &*htlc.inner }, unsafe { &*keys.inner });
598         ret.into_bytes().into()
599 }
600
601 /// Gets the redeemscript for a funding output from the two funding public keys.
602 /// Note that the order of funding public keys does not matter.
603 #[no_mangle]
604 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 {
605         let mut ret = lightning::ln::chan_utils::make_funding_redeemscript(&broadcaster.into_rust(), &countersignatory.into_rust());
606         ret.into_bytes().into()
607 }
608
609 /// panics if htlc.transaction_output_index.is_none()!
610 #[no_mangle]
611 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 {
612         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());
613         let mut local_ret = ::bitcoin::consensus::encode::serialize(&ret);
614         crate::c_types::Transaction::from_vec(local_ret)
615 }
616
617
618 use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport;
619 type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport;
620
621 /// We use this to track holder commitment transactions and put off signing them until we are ready
622 /// to broadcast. This class can be used inside a signer implementation to generate a signature
623 /// given the relevant secret key.
624 #[must_use]
625 #[repr(C)]
626 pub struct HolderCommitmentTransaction {
627         /// Nearly everywhere, inner must be non-null, however in places where
628         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
629         pub inner: *mut nativeHolderCommitmentTransaction,
630         pub is_owned: bool,
631 }
632
633 impl Drop for HolderCommitmentTransaction {
634         fn drop(&mut self) {
635                 if self.is_owned && !self.inner.is_null() {
636                         let _ = unsafe { Box::from_raw(self.inner) };
637                 }
638         }
639 }
640 #[no_mangle]
641 pub extern "C" fn HolderCommitmentTransaction_free(this_ptr: HolderCommitmentTransaction) { }
642 #[allow(unused)]
643 /// Used only if an object of this type is returned as a trait impl by a method
644 extern "C" fn HolderCommitmentTransaction_free_void(this_ptr: *mut c_void) {
645         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHolderCommitmentTransaction); }
646 }
647 #[allow(unused)]
648 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
649 impl HolderCommitmentTransaction {
650         pub(crate) fn take_ptr(mut self) -> *mut nativeHolderCommitmentTransaction {
651                 assert!(self.is_owned);
652                 let ret = self.inner;
653                 self.inner = std::ptr::null_mut();
654                 ret
655         }
656 }
657 impl Clone for HolderCommitmentTransaction {
658         fn clone(&self) -> Self {
659                 Self {
660                         inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
661                         is_owned: true,
662                 }
663         }
664 }
665 #[allow(unused)]
666 /// Used only if an object of this type is returned as a trait impl by a method
667 pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
668         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void
669 }
670 #[no_mangle]
671 pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction {
672         HolderCommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
673 }
674 /// The commitment transaction itself, in unsigned form.
675 #[no_mangle]
676 pub extern "C" fn HolderCommitmentTransaction_get_unsigned_tx(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Transaction {
677         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.unsigned_tx;
678         let mut local_inner_val = ::bitcoin::consensus::encode::serialize(inner_val);
679         crate::c_types::Transaction::from_vec(local_inner_val)
680 }
681 /// The commitment transaction itself, in unsigned form.
682 #[no_mangle]
683 pub extern "C" fn HolderCommitmentTransaction_set_unsigned_tx(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Transaction) {
684         unsafe { &mut *this_ptr.inner }.unsigned_tx = val.into_bitcoin();
685 }
686 /// Our counterparty's signature for the transaction, above.
687 #[no_mangle]
688 pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature {
689         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_sig;
690         crate::c_types::Signature::from_rust(&(*inner_val))
691 }
692 /// Our counterparty's signature for the transaction, above.
693 #[no_mangle]
694 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) {
695         unsafe { &mut *this_ptr.inner }.counterparty_sig = val.into_rust();
696 }
697 /// The feerate paid per 1000-weight-unit in this commitment transaction. This value is
698 /// controlled by the channel initiator.
699 #[no_mangle]
700 pub extern "C" fn HolderCommitmentTransaction_get_feerate_per_kw(this_ptr: &HolderCommitmentTransaction) -> u32 {
701         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.feerate_per_kw;
702         (*inner_val)
703 }
704 /// The feerate paid per 1000-weight-unit in this commitment transaction. This value is
705 /// controlled by the channel initiator.
706 #[no_mangle]
707 pub extern "C" fn HolderCommitmentTransaction_set_feerate_per_kw(this_ptr: &mut HolderCommitmentTransaction, mut val: u32) {
708         unsafe { &mut *this_ptr.inner }.feerate_per_kw = val;
709 }
710 /// The HTLCs and counterparty htlc signatures which were included in this commitment transaction.
711 ///
712 /// Note that this includes all HTLCs, including ones which were considered dust and not
713 /// actually included in the transaction as it appears on-chain, but who's value is burned as
714 /// fees and not included in the to_holder or to_counterparty outputs.
715 ///
716 /// The counterparty HTLC signatures in the second element will always be set for non-dust HTLCs, ie
717 /// those for which transaction_output_index.is_some().
718 #[no_mangle]
719 pub extern "C" fn HolderCommitmentTransaction_set_per_htlc(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) {
720         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { let (mut orig_val_0_0, mut orig_val_0_1) = item.to_rust(); let mut local_orig_val_0_1 = if orig_val_0_1.is_null() { None } else { Some( { orig_val_0_1.into_rust() }) }; let mut local_val_0 = (*unsafe { Box::from_raw(orig_val_0_0.take_ptr()) }, local_orig_val_0_1); local_val_0 }); };
721         unsafe { &mut *this_ptr.inner }.per_htlc = local_val;
722 }
723 /// Generate a new HolderCommitmentTransaction based on a raw commitment transaction,
724 /// counterparty signature and both parties keys.
725 ///
726 /// The unsigned transaction outputs must be consistent with htlc_data.  This function
727 /// only checks that the shape and amounts are consistent, but does not check the scriptPubkey.
728 #[must_use]
729 #[no_mangle]
730 pub extern "C" fn HolderCommitmentTransaction_new_missing_holder_sig(mut unsigned_tx: crate::c_types::Transaction, mut counterparty_sig: crate::c_types::Signature, mut holder_funding_key: crate::c_types::PublicKey, mut counterparty_funding_key: crate::c_types::PublicKey, mut keys: crate::ln::chan_utils::TxCreationKeys, mut feerate_per_kw: u32, mut htlc_data: crate::c_types::derived::CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ) -> crate::ln::chan_utils::HolderCommitmentTransaction {
731         let mut local_htlc_data = Vec::new(); for mut item in htlc_data.into_rust().drain(..) { local_htlc_data.push( { let (mut orig_htlc_data_0_0, mut orig_htlc_data_0_1) = item.to_rust(); let mut local_orig_htlc_data_0_1 = if orig_htlc_data_0_1.is_null() { None } else { Some( { orig_htlc_data_0_1.into_rust() }) }; let mut local_htlc_data_0 = (*unsafe { Box::from_raw(orig_htlc_data_0_0.take_ptr()) }, local_orig_htlc_data_0_1); local_htlc_data_0 }); };
732         let mut ret = lightning::ln::chan_utils::HolderCommitmentTransaction::new_missing_holder_sig(unsigned_tx.into_bitcoin(), counterparty_sig.into_rust(), &holder_funding_key.into_rust(), &counterparty_funding_key.into_rust(), *unsafe { Box::from_raw(keys.take_ptr()) }, feerate_per_kw, local_htlc_data);
733         crate::ln::chan_utils::HolderCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
734 }
735
736 /// The pre-calculated transaction creation public keys.
737 /// An external validating signer should not trust these keys.
738 #[must_use]
739 #[no_mangle]
740 pub extern "C" fn HolderCommitmentTransaction_trust_key_derivation(this_arg: &HolderCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys {
741         let mut ret = unsafe { &*this_arg.inner }.trust_key_derivation();
742         crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
743 }
744
745 /// Get the txid of the holder commitment transaction contained in this
746 /// HolderCommitmentTransaction
747 #[must_use]
748 #[no_mangle]
749 pub extern "C" fn HolderCommitmentTransaction_txid(this_arg: &HolderCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
750         let mut ret = unsafe { &*this_arg.inner }.txid();
751         crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
752 }
753
754 /// Gets holder signature for the contained commitment transaction given holder funding private key.
755 ///
756 /// Funding key is your key included in the 2-2 funding_outpoint lock. Should be provided
757 /// by your ChannelKeys.
758 /// Funding redeemscript is script locking funding_outpoint. This is the mutlsig script
759 /// between your own funding key and your counterparty's. Currently, this is provided in
760 /// ChannelKeys::sign_holder_commitment() calls directly.
761 /// Channel value is amount locked in funding_outpoint.
762 #[must_use]
763 #[no_mangle]
764 pub extern "C" fn HolderCommitmentTransaction_get_holder_sig(this_arg: &HolderCommitmentTransaction, funding_key: *const [u8; 32], mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature {
765         let mut ret = unsafe { &*this_arg.inner }.get_holder_sig(&::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());
766         crate::c_types::Signature::from_rust(&ret)
767 }
768
769 /// Get a signature for each HTLC which was included in the commitment transaction (ie for
770 /// which HTLCOutputInCommitment::transaction_output_index.is_some()).
771 ///
772 /// The returned Vec has one entry for each HTLC, and in the same order. For HTLCs which were
773 /// considered dust and not included, a None entry exists, for all others a signature is
774 /// included.
775 #[must_use]
776 #[no_mangle]
777 pub extern "C" fn HolderCommitmentTransaction_get_htlc_sigs(this_arg: &HolderCommitmentTransaction, htlc_base_key: *const [u8; 32], mut counterparty_selected_contest_delay: u16) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
778         let mut ret = unsafe { &*this_arg.inner }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), counterparty_selected_contest_delay, &bitcoin::secp256k1::Secp256k1::new());
779         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( { let mut local_ret_0_0 = if item.is_none() { crate::c_types::Signature::null() } else {  { crate::c_types::Signature::from_rust(&(item.unwrap())) } }; local_ret_0_0 }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
780         local_ret
781 }
782
783 #[no_mangle]
784 pub extern "C" fn HolderCommitmentTransaction_write(obj: *const HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
785         crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
786 }
787 #[no_mangle]
788 pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> HolderCommitmentTransaction {
789         if let Ok(res) = crate::c_types::deserialize_obj(ser) {
790                 HolderCommitmentTransaction { inner: Box::into_raw(Box::new(res)), is_owned: true }
791         } else {
792                 HolderCommitmentTransaction { inner: std::ptr::null_mut(), is_owned: true }
793         }
794 }