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