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