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