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