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