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