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