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