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