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