1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! Various utilities for building scripts and deriving keys related to channels. These are
10 //! largely of interest for those implementing chain::keysinterface::Sign message signing by hand.
12 use std::str::FromStr;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
18 /// Build the commitment secret from the seed and the commitment number
20 pub extern "C" fn build_commitment_secret(commitment_seed: *const [u8; 32], mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
21 let mut ret = lightning::ln::chan_utils::build_commitment_secret(unsafe { &*commitment_seed}, idx);
22 crate::c_types::ThirtyTwoBytes { data: ret }
25 /// Build a closing transaction
27 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 {
28 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));
29 crate::c_types::Transaction::from_bitcoin(&ret)
32 /// Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
33 /// from the base secret and the per_commitment_point.
35 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
36 /// generated (ie our own).
38 pub extern "C" fn derive_private_key(mut per_commitment_point: crate::c_types::PublicKey, base_secret: *const [u8; 32]) -> crate::c_types::derived::CResult_SecretKeyErrorZ {
39 let mut ret = lightning::ln::chan_utils::derive_private_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *base_secret}[..]).unwrap());
40 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SecretKey::from_rust(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
44 /// Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
45 /// from the base point and the per_commitment_key. This is the public equivalent of
46 /// derive_private_key - using only public keys to derive a public key instead of private keys.
48 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
49 /// generated (ie our own).
51 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::derived::CResult_PublicKeyErrorZ {
52 let mut ret = lightning::ln::chan_utils::derive_public_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &base_point.into_rust());
53 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
57 /// Derives a per-commitment-transaction revocation key from its constituent parts.
59 /// Only the cheating participant owns a valid witness to propagate a revoked
60 /// commitment transaction, thus per_commitment_secret always come from cheater
61 /// and revocation_base_secret always come from punisher, which is the broadcaster
62 /// of the transaction spending with this key knowledge.
64 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
65 /// generated (ie our own).
67 pub extern "C" fn derive_private_revocation_key(per_commitment_secret: *const [u8; 32], countersignatory_revocation_base_secret: *const [u8; 32]) -> crate::c_types::derived::CResult_SecretKeyErrorZ {
68 let mut ret = lightning::ln::chan_utils::derive_private_revocation_key(secp256k1::SECP256K1, &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *per_commitment_secret}[..]).unwrap(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *countersignatory_revocation_base_secret}[..]).unwrap());
69 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::SecretKey::from_rust(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
73 /// Derives a per-commitment-transaction revocation public key from its constituent parts. This is
74 /// the public equivalend of derive_private_revocation_key - using only public keys to derive a
75 /// public key instead of private keys.
77 /// Only the cheating participant owns a valid witness to propagate a revoked
78 /// commitment transaction, thus per_commitment_point always come from cheater
79 /// and revocation_base_point always come from punisher, which is the broadcaster
80 /// of the transaction spending with this key knowledge.
82 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
83 /// generated (ie our own).
85 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::derived::CResult_PublicKeyErrorZ {
86 let mut ret = lightning::ln::chan_utils::derive_public_revocation_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &countersignatory_revocation_base_point.into_rust());
87 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
92 use lightning::ln::chan_utils::TxCreationKeys as nativeTxCreationKeysImport;
93 pub(crate) type nativeTxCreationKeys = nativeTxCreationKeysImport;
95 /// The set of public keys which are used in the creation of one commitment transaction.
96 /// These are derived from the channel base keys and per-commitment data.
98 /// A broadcaster key is provided from potential broadcaster of the computed transaction.
99 /// A countersignatory key is coming from a protocol participant unable to broadcast the
102 /// These keys are assumed to be good, either because the code derived them from
103 /// channel basepoints via the new function, or they were obtained via
104 /// CommitmentTransaction.trust().keys() because we trusted the source of the
105 /// pre-calculated keys.
108 pub struct TxCreationKeys {
109 /// A pointer to the opaque Rust object.
111 /// Nearly everywhere, inner must be non-null, however in places where
112 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
113 pub inner: *mut nativeTxCreationKeys,
114 /// Indicates that this is the only struct which contains the same pointer.
116 /// Rust functions which take ownership of an object provided via an argument require
117 /// this to be true and invalidate the object pointed to by inner.
121 impl Drop for TxCreationKeys {
123 if self.is_owned && !<*mut nativeTxCreationKeys>::is_null(self.inner) {
124 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
128 /// Frees any resources used by the TxCreationKeys, if is_owned is set and inner is non-NULL.
130 pub extern "C" fn TxCreationKeys_free(this_obj: TxCreationKeys) { }
132 /// Used only if an object of this type is returned as a trait impl by a method
133 pub(crate) extern "C" fn TxCreationKeys_free_void(this_ptr: *mut c_void) {
134 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTxCreationKeys); }
137 impl TxCreationKeys {
138 pub(crate) fn get_native_ref(&self) -> &'static nativeTxCreationKeys {
139 unsafe { &*ObjOps::untweak_ptr(self.inner) }
141 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeTxCreationKeys {
142 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
144 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
145 pub(crate) fn take_inner(mut self) -> *mut nativeTxCreationKeys {
146 assert!(self.is_owned);
147 let ret = ObjOps::untweak_ptr(self.inner);
148 self.inner = std::ptr::null_mut();
152 /// The broadcaster's per-commitment public key which was used to derive the other keys.
154 pub extern "C" fn TxCreationKeys_get_per_commitment_point(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
155 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
156 crate::c_types::PublicKey::from_rust(&inner_val)
158 /// The broadcaster's per-commitment public key which was used to derive the other keys.
160 pub extern "C" fn TxCreationKeys_set_per_commitment_point(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
161 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
163 /// The revocation key which is used to allow the broadcaster of the commitment
164 /// transaction to provide their counterparty the ability to punish them if they broadcast
167 pub extern "C" fn TxCreationKeys_get_revocation_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
168 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_key;
169 crate::c_types::PublicKey::from_rust(&inner_val)
171 /// The revocation key which is used to allow the broadcaster of the commitment
172 /// transaction to provide their counterparty the ability to punish them if they broadcast
175 pub extern "C" fn TxCreationKeys_set_revocation_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
176 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_key = val.into_rust();
178 /// Broadcaster's HTLC Key
180 pub extern "C" fn TxCreationKeys_get_broadcaster_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
181 let mut inner_val = &mut this_ptr.get_native_mut_ref().broadcaster_htlc_key;
182 crate::c_types::PublicKey::from_rust(&inner_val)
184 /// Broadcaster's HTLC Key
186 pub extern "C" fn TxCreationKeys_set_broadcaster_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
187 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.broadcaster_htlc_key = val.into_rust();
189 /// Countersignatory's HTLC Key
191 pub extern "C" fn TxCreationKeys_get_countersignatory_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
192 let mut inner_val = &mut this_ptr.get_native_mut_ref().countersignatory_htlc_key;
193 crate::c_types::PublicKey::from_rust(&inner_val)
195 /// Countersignatory's HTLC Key
197 pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
198 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.countersignatory_htlc_key = val.into_rust();
200 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
202 pub extern "C" fn TxCreationKeys_get_broadcaster_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
203 let mut inner_val = &mut this_ptr.get_native_mut_ref().broadcaster_delayed_payment_key;
204 crate::c_types::PublicKey::from_rust(&inner_val)
206 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
208 pub extern "C" fn TxCreationKeys_set_broadcaster_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
209 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.broadcaster_delayed_payment_key = val.into_rust();
211 /// Constructs a new TxCreationKeys given each field
214 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 {
215 TxCreationKeys { inner: ObjOps::heap_alloc(nativeTxCreationKeys {
216 per_commitment_point: per_commitment_point_arg.into_rust(),
217 revocation_key: revocation_key_arg.into_rust(),
218 broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(),
219 countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(),
220 broadcaster_delayed_payment_key: broadcaster_delayed_payment_key_arg.into_rust(),
223 impl Clone for TxCreationKeys {
224 fn clone(&self) -> Self {
226 inner: if <*mut nativeTxCreationKeys>::is_null(self.inner) { std::ptr::null_mut() } else {
227 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
233 /// Used only if an object of this type is returned as a trait impl by a method
234 pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
235 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxCreationKeys)).clone() })) as *mut c_void
238 /// Creates a copy of the TxCreationKeys
239 pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys {
243 /// Serialize the TxCreationKeys object into a byte array which can be read by TxCreationKeys_read
244 pub extern "C" fn TxCreationKeys_write(obj: &TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
245 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
248 pub(crate) extern "C" fn TxCreationKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
249 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxCreationKeys) })
252 /// Read a TxCreationKeys from a byte array, created by TxCreationKeys_write
253 pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_TxCreationKeysDecodeErrorZ {
254 let res: Result<lightning::ln::chan_utils::TxCreationKeys, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
255 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
259 use lightning::ln::chan_utils::ChannelPublicKeys as nativeChannelPublicKeysImport;
260 pub(crate) type nativeChannelPublicKeys = nativeChannelPublicKeysImport;
262 /// One counterparty's public keys which do not change over the life of a channel.
265 pub struct ChannelPublicKeys {
266 /// A pointer to the opaque Rust object.
268 /// Nearly everywhere, inner must be non-null, however in places where
269 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
270 pub inner: *mut nativeChannelPublicKeys,
271 /// Indicates that this is the only struct which contains the same pointer.
273 /// Rust functions which take ownership of an object provided via an argument require
274 /// this to be true and invalidate the object pointed to by inner.
278 impl Drop for ChannelPublicKeys {
280 if self.is_owned && !<*mut nativeChannelPublicKeys>::is_null(self.inner) {
281 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
285 /// Frees any resources used by the ChannelPublicKeys, if is_owned is set and inner is non-NULL.
287 pub extern "C" fn ChannelPublicKeys_free(this_obj: ChannelPublicKeys) { }
289 /// Used only if an object of this type is returned as a trait impl by a method
290 pub(crate) extern "C" fn ChannelPublicKeys_free_void(this_ptr: *mut c_void) {
291 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelPublicKeys); }
294 impl ChannelPublicKeys {
295 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelPublicKeys {
296 unsafe { &*ObjOps::untweak_ptr(self.inner) }
298 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelPublicKeys {
299 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
301 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
302 pub(crate) fn take_inner(mut self) -> *mut nativeChannelPublicKeys {
303 assert!(self.is_owned);
304 let ret = ObjOps::untweak_ptr(self.inner);
305 self.inner = std::ptr::null_mut();
309 /// The public key which is used to sign all commitment transactions, as it appears in the
310 /// on-chain channel lock-in 2-of-2 multisig output.
312 pub extern "C" fn ChannelPublicKeys_get_funding_pubkey(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
313 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_pubkey;
314 crate::c_types::PublicKey::from_rust(&inner_val)
316 /// The public key which is used to sign all commitment transactions, as it appears in the
317 /// on-chain channel lock-in 2-of-2 multisig output.
319 pub extern "C" fn ChannelPublicKeys_set_funding_pubkey(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
320 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_pubkey = val.into_rust();
322 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
323 /// revocation keys. This is combined with the per-commitment-secret generated by the
324 /// counterparty to create a secret which the counterparty can reveal to revoke previous
327 pub extern "C" fn ChannelPublicKeys_get_revocation_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
328 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_basepoint;
329 crate::c_types::PublicKey::from_rust(&inner_val)
331 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
332 /// revocation keys. This is combined with the per-commitment-secret generated by the
333 /// counterparty to create a secret which the counterparty can reveal to revoke previous
336 pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
337 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_basepoint = val.into_rust();
339 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
340 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
341 /// static across every commitment transaction.
343 pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
344 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_point;
345 crate::c_types::PublicKey::from_rust(&inner_val)
347 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
348 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
349 /// static across every commitment transaction.
351 pub extern "C" fn ChannelPublicKeys_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
352 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_point = val.into_rust();
354 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
355 /// public key which receives non-HTLC-encumbered funds which are only available for spending
356 /// after some delay (or can be claimed via the revocation path).
358 pub extern "C" fn ChannelPublicKeys_get_delayed_payment_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
359 let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_basepoint;
360 crate::c_types::PublicKey::from_rust(&inner_val)
362 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
363 /// public key which receives non-HTLC-encumbered funds which are only available for spending
364 /// after some delay (or can be claimed via the revocation path).
366 pub extern "C" fn ChannelPublicKeys_set_delayed_payment_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
367 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_basepoint = val.into_rust();
369 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
370 /// which is used to encumber HTLC-in-flight outputs.
372 pub extern "C" fn ChannelPublicKeys_get_htlc_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
373 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_basepoint;
374 crate::c_types::PublicKey::from_rust(&inner_val)
376 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
377 /// which is used to encumber HTLC-in-flight outputs.
379 pub extern "C" fn ChannelPublicKeys_set_htlc_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
380 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_basepoint = val.into_rust();
382 /// Constructs a new ChannelPublicKeys given each field
385 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 {
386 ChannelPublicKeys { inner: ObjOps::heap_alloc(nativeChannelPublicKeys {
387 funding_pubkey: funding_pubkey_arg.into_rust(),
388 revocation_basepoint: revocation_basepoint_arg.into_rust(),
389 payment_point: payment_point_arg.into_rust(),
390 delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(),
391 htlc_basepoint: htlc_basepoint_arg.into_rust(),
394 impl Clone for ChannelPublicKeys {
395 fn clone(&self) -> Self {
397 inner: if <*mut nativeChannelPublicKeys>::is_null(self.inner) { std::ptr::null_mut() } else {
398 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
404 /// Used only if an object of this type is returned as a trait impl by a method
405 pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
406 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelPublicKeys)).clone() })) as *mut c_void
409 /// Creates a copy of the ChannelPublicKeys
410 pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys {
414 /// Serialize the ChannelPublicKeys object into a byte array which can be read by ChannelPublicKeys_read
415 pub extern "C" fn ChannelPublicKeys_write(obj: &ChannelPublicKeys) -> crate::c_types::derived::CVec_u8Z {
416 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
419 pub(crate) extern "C" fn ChannelPublicKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
420 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelPublicKeys) })
423 /// Read a ChannelPublicKeys from a byte array, created by ChannelPublicKeys_write
424 pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelPublicKeysDecodeErrorZ {
425 let res: Result<lightning::ln::chan_utils::ChannelPublicKeys, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
426 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
429 /// Create per-state keys from channel base points and the per-commitment point.
430 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
433 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::c_types::derived::CResult_TxCreationKeysErrorZ {
434 let mut ret = lightning::ln::chan_utils::TxCreationKeys::derive_new(secp256k1::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());
435 let mut local_ret = match ret { 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::c_types::Secp256k1Error::from_rust(e) }).into() };
439 /// Generate per-state keys from channel static keys.
440 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
443 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::c_types::derived::CResult_TxCreationKeysErrorZ {
444 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::SECP256K1);
445 let mut local_ret = match ret { 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::c_types::Secp256k1Error::from_rust(e) }).into() };
449 /// The maximum length of a script returned by get_revokeable_redeemscript.
452 pub static REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH: usize = lightning::ln::chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH;
453 /// A script either spendable by the revocation
454 /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
455 /// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
457 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 {
458 let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), contest_delay, &broadcaster_delayed_payment_key.into_rust());
459 ret.into_bytes().into()
463 use lightning::ln::chan_utils::HTLCOutputInCommitment as nativeHTLCOutputInCommitmentImport;
464 pub(crate) type nativeHTLCOutputInCommitment = nativeHTLCOutputInCommitmentImport;
466 /// Information about an HTLC as it appears in a commitment transaction
469 pub struct HTLCOutputInCommitment {
470 /// A pointer to the opaque Rust object.
472 /// Nearly everywhere, inner must be non-null, however in places where
473 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
474 pub inner: *mut nativeHTLCOutputInCommitment,
475 /// Indicates that this is the only struct which contains the same pointer.
477 /// Rust functions which take ownership of an object provided via an argument require
478 /// this to be true and invalidate the object pointed to by inner.
482 impl Drop for HTLCOutputInCommitment {
484 if self.is_owned && !<*mut nativeHTLCOutputInCommitment>::is_null(self.inner) {
485 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
489 /// Frees any resources used by the HTLCOutputInCommitment, if is_owned is set and inner is non-NULL.
491 pub extern "C" fn HTLCOutputInCommitment_free(this_obj: HTLCOutputInCommitment) { }
493 /// Used only if an object of this type is returned as a trait impl by a method
494 pub(crate) extern "C" fn HTLCOutputInCommitment_free_void(this_ptr: *mut c_void) {
495 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCOutputInCommitment); }
498 impl HTLCOutputInCommitment {
499 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCOutputInCommitment {
500 unsafe { &*ObjOps::untweak_ptr(self.inner) }
502 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCOutputInCommitment {
503 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
505 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
506 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCOutputInCommitment {
507 assert!(self.is_owned);
508 let ret = ObjOps::untweak_ptr(self.inner);
509 self.inner = std::ptr::null_mut();
513 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
514 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
515 /// need to compare this value to whether the commitment transaction in question is that of
516 /// the counterparty or our own.
518 pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool {
519 let mut inner_val = &mut this_ptr.get_native_mut_ref().offered;
522 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
523 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
524 /// need to compare this value to whether the commitment transaction in question is that of
525 /// the counterparty or our own.
527 pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) {
528 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.offered = val;
530 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
531 /// this divided by 1000.
533 pub extern "C" fn HTLCOutputInCommitment_get_amount_msat(this_ptr: &HTLCOutputInCommitment) -> u64 {
534 let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_msat;
537 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
538 /// this divided by 1000.
540 pub extern "C" fn HTLCOutputInCommitment_set_amount_msat(this_ptr: &mut HTLCOutputInCommitment, mut val: u64) {
541 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_msat = val;
543 /// The CLTV lock-time at which this HTLC expires.
545 pub extern "C" fn HTLCOutputInCommitment_get_cltv_expiry(this_ptr: &HTLCOutputInCommitment) -> u32 {
546 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry;
549 /// The CLTV lock-time at which this HTLC expires.
551 pub extern "C" fn HTLCOutputInCommitment_set_cltv_expiry(this_ptr: &mut HTLCOutputInCommitment, mut val: u32) {
552 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry = val;
554 /// The hash of the preimage which unlocks this HTLC.
556 pub extern "C" fn HTLCOutputInCommitment_get_payment_hash(this_ptr: &HTLCOutputInCommitment) -> *const [u8; 32] {
557 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_hash;
560 /// The hash of the preimage which unlocks this HTLC.
562 pub extern "C" fn HTLCOutputInCommitment_set_payment_hash(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::ThirtyTwoBytes) {
563 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_hash = ::lightning::ln::PaymentHash(val.data);
565 /// The position within the commitment transactions' outputs. This may be None if the value is
566 /// below the dust limit (in which case no output appears in the commitment transaction and the
567 /// value is spent to additional transaction fees).
569 pub extern "C" fn HTLCOutputInCommitment_get_transaction_output_index(this_ptr: &HTLCOutputInCommitment) -> crate::c_types::derived::COption_u32Z {
570 let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_output_index;
571 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() }) };
574 /// The position within the commitment transactions' outputs. This may be None if the value is
575 /// below the dust limit (in which case no output appears in the commitment transaction and the
576 /// value is spent to additional transaction fees).
578 pub extern "C" fn HTLCOutputInCommitment_set_transaction_output_index(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::derived::COption_u32Z) {
579 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
580 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_output_index = local_val;
582 /// Constructs a new HTLCOutputInCommitment given each field
585 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 {
586 let mut local_transaction_output_index_arg = if transaction_output_index_arg.is_some() { Some( { transaction_output_index_arg.take() }) } else { None };
587 HTLCOutputInCommitment { inner: ObjOps::heap_alloc(nativeHTLCOutputInCommitment {
588 offered: offered_arg,
589 amount_msat: amount_msat_arg,
590 cltv_expiry: cltv_expiry_arg,
591 payment_hash: ::lightning::ln::PaymentHash(payment_hash_arg.data),
592 transaction_output_index: local_transaction_output_index_arg,
595 impl Clone for HTLCOutputInCommitment {
596 fn clone(&self) -> Self {
598 inner: if <*mut nativeHTLCOutputInCommitment>::is_null(self.inner) { std::ptr::null_mut() } else {
599 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
605 /// Used only if an object of this type is returned as a trait impl by a method
606 pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_void) -> *mut c_void {
607 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCOutputInCommitment)).clone() })) as *mut c_void
610 /// Creates a copy of the HTLCOutputInCommitment
611 pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment {
615 /// Serialize the HTLCOutputInCommitment object into a byte array which can be read by HTLCOutputInCommitment_read
616 pub extern "C" fn HTLCOutputInCommitment_write(obj: &HTLCOutputInCommitment) -> crate::c_types::derived::CVec_u8Z {
617 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
620 pub(crate) extern "C" fn HTLCOutputInCommitment_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
621 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCOutputInCommitment) })
624 /// Read a HTLCOutputInCommitment from a byte array, created by HTLCOutputInCommitment_write
625 pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCOutputInCommitmentDecodeErrorZ {
626 let res: Result<lightning::ln::chan_utils::HTLCOutputInCommitment, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
627 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
630 /// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
631 /// does not need to have its previous_output_index filled.
633 pub extern "C" fn get_htlc_redeemscript(htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment, keys: &crate::lightning::ln::chan_utils::TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
634 let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(htlc.get_native_ref(), keys.get_native_ref());
635 ret.into_bytes().into()
638 /// Gets the redeemscript for a funding output from the two funding public keys.
639 /// Note that the order of funding public keys does not matter.
641 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 {
642 let mut ret = lightning::ln::chan_utils::make_funding_redeemscript(&broadcaster.into_rust(), &countersignatory.into_rust());
643 ret.into_bytes().into()
646 /// Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC
647 /// parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the
648 /// transaction which needs signing, and can be used to construct an HTLC transaction which is
649 /// broadcastable given a counterparty HTLC signature.
651 /// Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
652 /// commitment transaction).
654 pub extern "C" fn build_htlc_transaction(commitment_txid: *const [u8; 32], mut feerate_per_kw: u32, mut contest_delay: u16, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment, mut broadcaster_delayed_payment_key: crate::c_types::PublicKey, mut revocation_key: crate::c_types::PublicKey) -> crate::c_types::Transaction {
655 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(), &broadcaster_delayed_payment_key.into_rust(), &revocation_key.into_rust());
656 crate::c_types::Transaction::from_bitcoin(&ret)
660 use lightning::ln::chan_utils::ChannelTransactionParameters as nativeChannelTransactionParametersImport;
661 pub(crate) type nativeChannelTransactionParameters = nativeChannelTransactionParametersImport;
663 /// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction).
664 /// The fields are organized by holder/counterparty.
666 /// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters
667 /// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions.
670 pub struct ChannelTransactionParameters {
671 /// A pointer to the opaque Rust object.
673 /// Nearly everywhere, inner must be non-null, however in places where
674 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
675 pub inner: *mut nativeChannelTransactionParameters,
676 /// Indicates that this is the only struct which contains the same pointer.
678 /// Rust functions which take ownership of an object provided via an argument require
679 /// this to be true and invalidate the object pointed to by inner.
683 impl Drop for ChannelTransactionParameters {
685 if self.is_owned && !<*mut nativeChannelTransactionParameters>::is_null(self.inner) {
686 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
690 /// Frees any resources used by the ChannelTransactionParameters, if is_owned is set and inner is non-NULL.
692 pub extern "C" fn ChannelTransactionParameters_free(this_obj: ChannelTransactionParameters) { }
694 /// Used only if an object of this type is returned as a trait impl by a method
695 pub(crate) extern "C" fn ChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
696 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTransactionParameters); }
699 impl ChannelTransactionParameters {
700 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelTransactionParameters {
701 unsafe { &*ObjOps::untweak_ptr(self.inner) }
703 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelTransactionParameters {
704 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
706 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
707 pub(crate) fn take_inner(mut self) -> *mut nativeChannelTransactionParameters {
708 assert!(self.is_owned);
709 let ret = ObjOps::untweak_ptr(self.inner);
710 self.inner = std::ptr::null_mut();
714 /// Holder public keys
716 pub extern "C" fn ChannelTransactionParameters_get_holder_pubkeys(this_ptr: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
717 let mut inner_val = &mut this_ptr.get_native_mut_ref().holder_pubkeys;
718 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 }
720 /// Holder public keys
722 pub extern "C" fn ChannelTransactionParameters_set_holder_pubkeys(this_ptr: &mut ChannelTransactionParameters, mut val: crate::lightning::ln::chan_utils::ChannelPublicKeys) {
723 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.holder_pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
725 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
727 pub extern "C" fn ChannelTransactionParameters_get_holder_selected_contest_delay(this_ptr: &ChannelTransactionParameters) -> u16 {
728 let mut inner_val = &mut this_ptr.get_native_mut_ref().holder_selected_contest_delay;
731 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
733 pub extern "C" fn ChannelTransactionParameters_set_holder_selected_contest_delay(this_ptr: &mut ChannelTransactionParameters, mut val: u16) {
734 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.holder_selected_contest_delay = val;
736 /// Whether the holder is the initiator of this channel.
737 /// This is an input to the commitment number obscure factor computation.
739 pub extern "C" fn ChannelTransactionParameters_get_is_outbound_from_holder(this_ptr: &ChannelTransactionParameters) -> bool {
740 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound_from_holder;
743 /// Whether the holder is the initiator of this channel.
744 /// This is an input to the commitment number obscure factor computation.
746 pub extern "C" fn ChannelTransactionParameters_set_is_outbound_from_holder(this_ptr: &mut ChannelTransactionParameters, mut val: bool) {
747 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound_from_holder = val;
749 /// The late-bound counterparty channel transaction parameters.
750 /// These parameters are populated at the point in the protocol where the counterparty provides them.
752 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
754 pub extern "C" fn ChannelTransactionParameters_get_counterparty_parameters(this_ptr: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters {
755 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_parameters;
756 let mut local_inner_val = crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters { inner: unsafe { (if inner_val.is_none() { std::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 };
759 /// The late-bound counterparty channel transaction parameters.
760 /// These parameters are populated at the point in the protocol where the counterparty provides them.
762 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
764 pub extern "C" fn ChannelTransactionParameters_set_counterparty_parameters(this_ptr: &mut ChannelTransactionParameters, mut val: crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters) {
765 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
766 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_parameters = local_val;
768 /// The late-bound funding outpoint
770 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
772 pub extern "C" fn ChannelTransactionParameters_get_funding_outpoint(this_ptr: &ChannelTransactionParameters) -> crate::lightning::chain::transaction::OutPoint {
773 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_outpoint;
774 let mut local_inner_val = crate::lightning::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::chain::transaction::OutPoint<>) as *mut _ }, is_owned: false };
777 /// The late-bound funding outpoint
779 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
781 pub extern "C" fn ChannelTransactionParameters_set_funding_outpoint(this_ptr: &mut ChannelTransactionParameters, mut val: crate::lightning::chain::transaction::OutPoint) {
782 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
783 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_outpoint = local_val;
785 /// Constructs a new ChannelTransactionParameters given each field
788 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) -> ChannelTransactionParameters {
789 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()) } }) };
790 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()) } }) };
791 ChannelTransactionParameters { inner: ObjOps::heap_alloc(nativeChannelTransactionParameters {
792 holder_pubkeys: *unsafe { Box::from_raw(holder_pubkeys_arg.take_inner()) },
793 holder_selected_contest_delay: holder_selected_contest_delay_arg,
794 is_outbound_from_holder: is_outbound_from_holder_arg,
795 counterparty_parameters: local_counterparty_parameters_arg,
796 funding_outpoint: local_funding_outpoint_arg,
799 impl Clone for ChannelTransactionParameters {
800 fn clone(&self) -> Self {
802 inner: if <*mut nativeChannelTransactionParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
803 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
809 /// Used only if an object of this type is returned as a trait impl by a method
810 pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
811 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTransactionParameters)).clone() })) as *mut c_void
814 /// Creates a copy of the ChannelTransactionParameters
815 pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters {
819 use lightning::ln::chan_utils::CounterpartyChannelTransactionParameters as nativeCounterpartyChannelTransactionParametersImport;
820 pub(crate) type nativeCounterpartyChannelTransactionParameters = nativeCounterpartyChannelTransactionParametersImport;
822 /// Late-bound per-channel counterparty data used to build transactions.
825 pub struct CounterpartyChannelTransactionParameters {
826 /// A pointer to the opaque Rust object.
828 /// Nearly everywhere, inner must be non-null, however in places where
829 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
830 pub inner: *mut nativeCounterpartyChannelTransactionParameters,
831 /// Indicates that this is the only struct which contains the same pointer.
833 /// Rust functions which take ownership of an object provided via an argument require
834 /// this to be true and invalidate the object pointed to by inner.
838 impl Drop for CounterpartyChannelTransactionParameters {
840 if self.is_owned && !<*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) {
841 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
845 /// Frees any resources used by the CounterpartyChannelTransactionParameters, if is_owned is set and inner is non-NULL.
847 pub extern "C" fn CounterpartyChannelTransactionParameters_free(this_obj: CounterpartyChannelTransactionParameters) { }
849 /// Used only if an object of this type is returned as a trait impl by a method
850 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
851 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyChannelTransactionParameters); }
854 impl CounterpartyChannelTransactionParameters {
855 pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyChannelTransactionParameters {
856 unsafe { &*ObjOps::untweak_ptr(self.inner) }
858 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyChannelTransactionParameters {
859 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
861 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
862 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyChannelTransactionParameters {
863 assert!(self.is_owned);
864 let ret = ObjOps::untweak_ptr(self.inner);
865 self.inner = std::ptr::null_mut();
869 /// Counter-party public keys
871 pub extern "C" fn CounterpartyChannelTransactionParameters_get_pubkeys(this_ptr: &CounterpartyChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
872 let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkeys;
873 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 }
875 /// Counter-party public keys
877 pub extern "C" fn CounterpartyChannelTransactionParameters_set_pubkeys(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: crate::lightning::ln::chan_utils::ChannelPublicKeys) {
878 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
880 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
882 pub extern "C" fn CounterpartyChannelTransactionParameters_get_selected_contest_delay(this_ptr: &CounterpartyChannelTransactionParameters) -> u16 {
883 let mut inner_val = &mut this_ptr.get_native_mut_ref().selected_contest_delay;
886 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
888 pub extern "C" fn CounterpartyChannelTransactionParameters_set_selected_contest_delay(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: u16) {
889 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.selected_contest_delay = val;
891 /// Constructs a new CounterpartyChannelTransactionParameters given each field
894 pub extern "C" fn CounterpartyChannelTransactionParameters_new(mut pubkeys_arg: crate::lightning::ln::chan_utils::ChannelPublicKeys, mut selected_contest_delay_arg: u16) -> CounterpartyChannelTransactionParameters {
895 CounterpartyChannelTransactionParameters { inner: ObjOps::heap_alloc(nativeCounterpartyChannelTransactionParameters {
896 pubkeys: *unsafe { Box::from_raw(pubkeys_arg.take_inner()) },
897 selected_contest_delay: selected_contest_delay_arg,
900 impl Clone for CounterpartyChannelTransactionParameters {
901 fn clone(&self) -> Self {
903 inner: if <*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
904 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
910 /// Used only if an object of this type is returned as a trait impl by a method
911 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
912 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void
915 /// Creates a copy of the CounterpartyChannelTransactionParameters
916 pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters {
919 /// Whether the late bound parameters are populated.
922 pub extern "C" fn ChannelTransactionParameters_is_populated(this_arg: &ChannelTransactionParameters) -> bool {
923 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_populated();
927 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
928 /// given that the holder is the broadcaster.
930 /// self.is_populated() must be true before calling this function.
933 pub extern "C" fn ChannelTransactionParameters_as_holder_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters {
934 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_holder_broadcastable();
935 crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
938 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
939 /// given that the counterparty is the broadcaster.
941 /// self.is_populated() must be true before calling this function.
944 pub extern "C" fn ChannelTransactionParameters_as_counterparty_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters {
945 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_counterparty_broadcastable();
946 crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
950 /// Serialize the CounterpartyChannelTransactionParameters object into a byte array which can be read by CounterpartyChannelTransactionParameters_read
951 pub extern "C" fn CounterpartyChannelTransactionParameters_write(obj: &CounterpartyChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
952 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
955 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
956 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyChannelTransactionParameters) })
959 /// Read a CounterpartyChannelTransactionParameters from a byte array, created by CounterpartyChannelTransactionParameters_write
960 pub extern "C" fn CounterpartyChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyChannelTransactionParametersDecodeErrorZ {
961 let res: Result<lightning::ln::chan_utils::CounterpartyChannelTransactionParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
962 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
966 /// Serialize the ChannelTransactionParameters object into a byte array which can be read by ChannelTransactionParameters_read
967 pub extern "C" fn ChannelTransactionParameters_write(obj: &ChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
968 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
971 pub(crate) extern "C" fn ChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
972 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTransactionParameters) })
975 /// Read a ChannelTransactionParameters from a byte array, created by ChannelTransactionParameters_write
976 pub extern "C" fn ChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelTransactionParametersDecodeErrorZ {
977 let res: Result<lightning::ln::chan_utils::ChannelTransactionParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
978 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
982 use lightning::ln::chan_utils::DirectedChannelTransactionParameters as nativeDirectedChannelTransactionParametersImport;
983 pub(crate) type nativeDirectedChannelTransactionParameters = nativeDirectedChannelTransactionParametersImport<'static>;
985 /// Static channel fields used to build transactions given per-commitment fields, organized by
986 /// broadcaster/countersignatory.
988 /// This is derived from the holder/counterparty-organized ChannelTransactionParameters via the
989 /// as_holder_broadcastable and as_counterparty_broadcastable functions.
992 pub struct DirectedChannelTransactionParameters {
993 /// A pointer to the opaque Rust object.
995 /// Nearly everywhere, inner must be non-null, however in places where
996 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
997 pub inner: *mut nativeDirectedChannelTransactionParameters,
998 /// Indicates that this is the only struct which contains the same pointer.
1000 /// Rust functions which take ownership of an object provided via an argument require
1001 /// this to be true and invalidate the object pointed to by inner.
1005 impl Drop for DirectedChannelTransactionParameters {
1006 fn drop(&mut self) {
1007 if self.is_owned && !<*mut nativeDirectedChannelTransactionParameters>::is_null(self.inner) {
1008 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1012 /// Frees any resources used by the DirectedChannelTransactionParameters, if is_owned is set and inner is non-NULL.
1014 pub extern "C" fn DirectedChannelTransactionParameters_free(this_obj: DirectedChannelTransactionParameters) { }
1016 /// Used only if an object of this type is returned as a trait impl by a method
1017 pub(crate) extern "C" fn DirectedChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
1018 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelTransactionParameters); }
1021 impl DirectedChannelTransactionParameters {
1022 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelTransactionParameters {
1023 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1025 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelTransactionParameters {
1026 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1028 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1029 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelTransactionParameters {
1030 assert!(self.is_owned);
1031 let ret = ObjOps::untweak_ptr(self.inner);
1032 self.inner = std::ptr::null_mut();
1036 /// Get the channel pubkeys for the broadcaster
1039 pub extern "C" fn DirectedChannelTransactionParameters_broadcaster_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1040 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcaster_pubkeys();
1041 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 }
1044 /// Get the channel pubkeys for the countersignatory
1047 pub extern "C" fn DirectedChannelTransactionParameters_countersignatory_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1048 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.countersignatory_pubkeys();
1049 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 }
1052 /// Get the contest delay applicable to the transactions.
1053 /// Note that the contest delay was selected by the countersignatory.
1056 pub extern "C" fn DirectedChannelTransactionParameters_contest_delay(this_arg: &DirectedChannelTransactionParameters) -> u16 {
1057 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.contest_delay();
1061 /// Whether the channel is outbound from the broadcaster.
1063 /// The boolean representing the side that initiated the channel is
1064 /// an input to the commitment number obscure factor computation.
1067 pub extern "C" fn DirectedChannelTransactionParameters_is_outbound(this_arg: &DirectedChannelTransactionParameters) -> bool {
1068 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
1072 /// The funding outpoint
1075 pub extern "C" fn DirectedChannelTransactionParameters_funding_outpoint(this_arg: &DirectedChannelTransactionParameters) -> crate::lightning::chain::transaction::OutPoint {
1076 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
1077 crate::c_types::bitcoin_to_C_outpoint(ret)
1081 use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport;
1082 pub(crate) type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport;
1084 /// Information needed to build and sign a holder's commitment transaction.
1086 /// The transaction is only signed once we are ready to broadcast.
1089 pub struct HolderCommitmentTransaction {
1090 /// A pointer to the opaque Rust object.
1092 /// Nearly everywhere, inner must be non-null, however in places where
1093 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1094 pub inner: *mut nativeHolderCommitmentTransaction,
1095 /// Indicates that this is the only struct which contains the same pointer.
1097 /// Rust functions which take ownership of an object provided via an argument require
1098 /// this to be true and invalidate the object pointed to by inner.
1102 impl Drop for HolderCommitmentTransaction {
1103 fn drop(&mut self) {
1104 if self.is_owned && !<*mut nativeHolderCommitmentTransaction>::is_null(self.inner) {
1105 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1109 /// Frees any resources used by the HolderCommitmentTransaction, if is_owned is set and inner is non-NULL.
1111 pub extern "C" fn HolderCommitmentTransaction_free(this_obj: HolderCommitmentTransaction) { }
1113 /// Used only if an object of this type is returned as a trait impl by a method
1114 pub(crate) extern "C" fn HolderCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1115 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHolderCommitmentTransaction); }
1118 impl HolderCommitmentTransaction {
1119 pub(crate) fn get_native_ref(&self) -> &'static nativeHolderCommitmentTransaction {
1120 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1122 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHolderCommitmentTransaction {
1123 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1125 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1126 pub(crate) fn take_inner(mut self) -> *mut nativeHolderCommitmentTransaction {
1127 assert!(self.is_owned);
1128 let ret = ObjOps::untweak_ptr(self.inner);
1129 self.inner = std::ptr::null_mut();
1133 /// Our counterparty's signature for the transaction
1135 pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature {
1136 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig;
1137 crate::c_types::Signature::from_rust(&inner_val)
1139 /// Our counterparty's signature for the transaction
1141 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) {
1142 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust();
1144 /// All non-dust counterparty HTLC signatures, in the order they appear in the transaction
1146 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_htlc_sigs(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_SignatureZ) {
1147 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); };
1148 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_htlc_sigs = local_val;
1150 impl Clone for HolderCommitmentTransaction {
1151 fn clone(&self) -> Self {
1153 inner: if <*mut nativeHolderCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else {
1154 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1160 /// Used only if an object of this type is returned as a trait impl by a method
1161 pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1162 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void
1165 /// Creates a copy of the HolderCommitmentTransaction
1166 pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction {
1170 /// Serialize the HolderCommitmentTransaction object into a byte array which can be read by HolderCommitmentTransaction_read
1171 pub extern "C" fn HolderCommitmentTransaction_write(obj: &HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1172 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1175 pub(crate) extern "C" fn HolderCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1176 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHolderCommitmentTransaction) })
1179 /// Read a HolderCommitmentTransaction from a byte array, created by HolderCommitmentTransaction_write
1180 pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HolderCommitmentTransactionDecodeErrorZ {
1181 let res: Result<lightning::ln::chan_utils::HolderCommitmentTransaction, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1182 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1185 /// Create a new holder transaction with the given counterparty signatures.
1186 /// The funding keys are used to figure out which signature should go first when building the transaction for broadcast.
1189 pub extern "C" fn HolderCommitmentTransaction_new(mut commitment_tx: crate::lightning::ln::chan_utils::CommitmentTransaction, mut counterparty_sig: crate::c_types::Signature, mut counterparty_htlc_sigs: crate::c_types::derived::CVec_SignatureZ, mut holder_funding_key: crate::c_types::PublicKey, mut counterparty_funding_key: crate::c_types::PublicKey) -> HolderCommitmentTransaction {
1190 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() }); };
1191 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());
1192 HolderCommitmentTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1196 use lightning::ln::chan_utils::BuiltCommitmentTransaction as nativeBuiltCommitmentTransactionImport;
1197 pub(crate) type nativeBuiltCommitmentTransaction = nativeBuiltCommitmentTransactionImport;
1199 /// A pre-built Bitcoin commitment transaction and its txid.
1202 pub struct BuiltCommitmentTransaction {
1203 /// A pointer to the opaque Rust object.
1205 /// Nearly everywhere, inner must be non-null, however in places where
1206 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1207 pub inner: *mut nativeBuiltCommitmentTransaction,
1208 /// Indicates that this is the only struct which contains the same pointer.
1210 /// Rust functions which take ownership of an object provided via an argument require
1211 /// this to be true and invalidate the object pointed to by inner.
1215 impl Drop for BuiltCommitmentTransaction {
1216 fn drop(&mut self) {
1217 if self.is_owned && !<*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) {
1218 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1222 /// Frees any resources used by the BuiltCommitmentTransaction, if is_owned is set and inner is non-NULL.
1224 pub extern "C" fn BuiltCommitmentTransaction_free(this_obj: BuiltCommitmentTransaction) { }
1226 /// Used only if an object of this type is returned as a trait impl by a method
1227 pub(crate) extern "C" fn BuiltCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1228 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBuiltCommitmentTransaction); }
1231 impl BuiltCommitmentTransaction {
1232 pub(crate) fn get_native_ref(&self) -> &'static nativeBuiltCommitmentTransaction {
1233 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1235 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBuiltCommitmentTransaction {
1236 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1238 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1239 pub(crate) fn take_inner(mut self) -> *mut nativeBuiltCommitmentTransaction {
1240 assert!(self.is_owned);
1241 let ret = ObjOps::untweak_ptr(self.inner);
1242 self.inner = std::ptr::null_mut();
1246 /// The commitment transaction
1248 pub extern "C" fn BuiltCommitmentTransaction_get_transaction(this_ptr: &BuiltCommitmentTransaction) -> crate::c_types::Transaction {
1249 let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction;
1250 crate::c_types::Transaction::from_bitcoin(inner_val)
1252 /// The commitment transaction
1254 pub extern "C" fn BuiltCommitmentTransaction_set_transaction(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::Transaction) {
1255 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction = val.into_bitcoin();
1257 /// The txid for the commitment transaction.
1259 /// This is provided as a performance optimization, instead of calling transaction.txid()
1262 pub extern "C" fn BuiltCommitmentTransaction_get_txid(this_ptr: &BuiltCommitmentTransaction) -> *const [u8; 32] {
1263 let mut inner_val = &mut this_ptr.get_native_mut_ref().txid;
1264 inner_val.as_inner()
1266 /// The txid for the commitment transaction.
1268 /// This is provided as a performance optimization, instead of calling transaction.txid()
1271 pub extern "C" fn BuiltCommitmentTransaction_set_txid(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::ThirtyTwoBytes) {
1272 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap();
1274 /// Constructs a new BuiltCommitmentTransaction given each field
1277 pub extern "C" fn BuiltCommitmentTransaction_new(mut transaction_arg: crate::c_types::Transaction, mut txid_arg: crate::c_types::ThirtyTwoBytes) -> BuiltCommitmentTransaction {
1278 BuiltCommitmentTransaction { inner: ObjOps::heap_alloc(nativeBuiltCommitmentTransaction {
1279 transaction: transaction_arg.into_bitcoin(),
1280 txid: ::bitcoin::hash_types::Txid::from_slice(&txid_arg.data[..]).unwrap(),
1281 }), is_owned: true }
1283 impl Clone for BuiltCommitmentTransaction {
1284 fn clone(&self) -> Self {
1286 inner: if <*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else {
1287 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1293 /// Used only if an object of this type is returned as a trait impl by a method
1294 pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1295 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void
1298 /// Creates a copy of the BuiltCommitmentTransaction
1299 pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction {
1303 /// Serialize the BuiltCommitmentTransaction object into a byte array which can be read by BuiltCommitmentTransaction_read
1304 pub extern "C" fn BuiltCommitmentTransaction_write(obj: &BuiltCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1305 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1308 pub(crate) extern "C" fn BuiltCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1309 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBuiltCommitmentTransaction) })
1312 /// Read a BuiltCommitmentTransaction from a byte array, created by BuiltCommitmentTransaction_write
1313 pub extern "C" fn BuiltCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BuiltCommitmentTransactionDecodeErrorZ {
1314 let res: Result<lightning::ln::chan_utils::BuiltCommitmentTransaction, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1315 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1318 /// Get the SIGHASH_ALL sighash value of the transaction.
1320 /// This can be used to verify a signature.
1323 pub extern "C" fn BuiltCommitmentTransaction_get_sighash_all(this_arg: &BuiltCommitmentTransaction, mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::ThirtyTwoBytes {
1324 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);
1325 crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() }
1328 /// Sign a transaction, either because we are counter-signing the counterparty's transaction or
1329 /// because we are about to broadcast a holder transaction.
1332 pub extern "C" fn BuiltCommitmentTransaction_sign(this_arg: &BuiltCommitmentTransaction, funding_key: *const [u8; 32], mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature {
1333 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, secp256k1::SECP256K1);
1334 crate::c_types::Signature::from_rust(&ret)
1338 use lightning::ln::chan_utils::ClosingTransaction as nativeClosingTransactionImport;
1339 pub(crate) type nativeClosingTransaction = nativeClosingTransactionImport;
1341 /// This class tracks the per-transaction information needed to build a closing transaction and will
1342 /// actually build it and sign.
1344 /// This class can be used inside a signer implementation to generate a signature given the relevant
1348 pub struct ClosingTransaction {
1349 /// A pointer to the opaque Rust object.
1351 /// Nearly everywhere, inner must be non-null, however in places where
1352 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1353 pub inner: *mut nativeClosingTransaction,
1354 /// Indicates that this is the only struct which contains the same pointer.
1356 /// Rust functions which take ownership of an object provided via an argument require
1357 /// this to be true and invalidate the object pointed to by inner.
1361 impl Drop for ClosingTransaction {
1362 fn drop(&mut self) {
1363 if self.is_owned && !<*mut nativeClosingTransaction>::is_null(self.inner) {
1364 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1368 /// Frees any resources used by the ClosingTransaction, if is_owned is set and inner is non-NULL.
1370 pub extern "C" fn ClosingTransaction_free(this_obj: ClosingTransaction) { }
1372 /// Used only if an object of this type is returned as a trait impl by a method
1373 pub(crate) extern "C" fn ClosingTransaction_free_void(this_ptr: *mut c_void) {
1374 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeClosingTransaction); }
1377 impl ClosingTransaction {
1378 pub(crate) fn get_native_ref(&self) -> &'static nativeClosingTransaction {
1379 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1381 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeClosingTransaction {
1382 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1384 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1385 pub(crate) fn take_inner(mut self) -> *mut nativeClosingTransaction {
1386 assert!(self.is_owned);
1387 let ret = ObjOps::untweak_ptr(self.inner);
1388 self.inner = std::ptr::null_mut();
1392 /// Construct an object of the class
1395 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) -> ClosingTransaction {
1396 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));
1397 ClosingTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1400 /// Trust our pre-built transaction.
1402 /// Applies a wrapper which allows access to the transaction.
1404 /// This should only be used if you fully trust the builder of this object. It should not
1405 /// be used by an external signer - instead use the verify function.
1408 pub extern "C" fn ClosingTransaction_trust(this_arg: &ClosingTransaction) -> crate::lightning::ln::chan_utils::TrustedClosingTransaction {
1409 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.trust();
1410 crate::lightning::ln::chan_utils::TrustedClosingTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1413 /// Verify our pre-built transaction.
1415 /// Applies a wrapper which allows access to the transaction.
1417 /// An external validating signer must call this method before signing
1418 /// or using the built transaction.
1421 pub extern "C" fn ClosingTransaction_verify(this_arg: &ClosingTransaction, mut funding_outpoint: crate::lightning::chain::transaction::OutPoint) -> crate::c_types::derived::CResult_TrustedClosingTransactionNoneZ {
1422 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify(crate::c_types::C_to_bitcoin_outpoint(funding_outpoint));
1423 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() };
1427 /// The value to be sent to the holder, or zero if the output will be omitted
1430 pub extern "C" fn ClosingTransaction_to_holder_value_sat(this_arg: &ClosingTransaction) -> u64 {
1431 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_holder_value_sat();
1435 /// The value to be sent to the counterparty, or zero if the output will be omitted
1438 pub extern "C" fn ClosingTransaction_to_counterparty_value_sat(this_arg: &ClosingTransaction) -> u64 {
1439 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_counterparty_value_sat();
1443 /// The destination of the holder's output
1446 pub extern "C" fn ClosingTransaction_to_holder_script(this_arg: &ClosingTransaction) -> crate::c_types::u8slice {
1447 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_holder_script();
1448 crate::c_types::u8slice::from_slice(&ret[..])
1451 /// The destination of the counterparty's output
1454 pub extern "C" fn ClosingTransaction_to_counterparty_script(this_arg: &ClosingTransaction) -> crate::c_types::u8slice {
1455 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_counterparty_script();
1456 crate::c_types::u8slice::from_slice(&ret[..])
1460 use lightning::ln::chan_utils::TrustedClosingTransaction as nativeTrustedClosingTransactionImport;
1461 pub(crate) type nativeTrustedClosingTransaction = nativeTrustedClosingTransactionImport<'static>;
1463 /// A wrapper on ClosingTransaction indicating that the built bitcoin
1464 /// transaction is trusted.
1466 /// See trust() and verify() functions on CommitmentTransaction.
1468 /// This structure implements Deref.
1471 pub struct TrustedClosingTransaction {
1472 /// A pointer to the opaque Rust object.
1474 /// Nearly everywhere, inner must be non-null, however in places where
1475 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1476 pub inner: *mut nativeTrustedClosingTransaction,
1477 /// Indicates that this is the only struct which contains the same pointer.
1479 /// Rust functions which take ownership of an object provided via an argument require
1480 /// this to be true and invalidate the object pointed to by inner.
1484 impl Drop for TrustedClosingTransaction {
1485 fn drop(&mut self) {
1486 if self.is_owned && !<*mut nativeTrustedClosingTransaction>::is_null(self.inner) {
1487 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1491 /// Frees any resources used by the TrustedClosingTransaction, if is_owned is set and inner is non-NULL.
1493 pub extern "C" fn TrustedClosingTransaction_free(this_obj: TrustedClosingTransaction) { }
1495 /// Used only if an object of this type is returned as a trait impl by a method
1496 pub(crate) extern "C" fn TrustedClosingTransaction_free_void(this_ptr: *mut c_void) {
1497 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedClosingTransaction); }
1500 impl TrustedClosingTransaction {
1501 pub(crate) fn get_native_ref(&self) -> &'static nativeTrustedClosingTransaction {
1502 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1504 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeTrustedClosingTransaction {
1505 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1507 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1508 pub(crate) fn take_inner(mut self) -> *mut nativeTrustedClosingTransaction {
1509 assert!(self.is_owned);
1510 let ret = ObjOps::untweak_ptr(self.inner);
1511 self.inner = std::ptr::null_mut();
1515 /// The pre-built Bitcoin commitment transaction
1518 pub extern "C" fn TrustedClosingTransaction_built_transaction(this_arg: &TrustedClosingTransaction) -> crate::c_types::Transaction {
1519 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.built_transaction();
1520 crate::c_types::Transaction::from_bitcoin(ret)
1523 /// Get the SIGHASH_ALL sighash value of the transaction.
1525 /// This can be used to verify a signature.
1528 pub extern "C" fn TrustedClosingTransaction_get_sighash_all(this_arg: &TrustedClosingTransaction, mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::ThirtyTwoBytes {
1529 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);
1530 crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() }
1533 /// Sign a transaction, either because we are counter-signing the counterparty's transaction or
1534 /// because we are about to broadcast a holder transaction.
1537 pub extern "C" fn TrustedClosingTransaction_sign(this_arg: &TrustedClosingTransaction, funding_key: *const [u8; 32], mut funding_redeemscript: crate::c_types::u8slice, mut channel_value_satoshis: u64) -> crate::c_types::Signature {
1538 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.sign(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, secp256k1::SECP256K1);
1539 crate::c_types::Signature::from_rust(&ret)
1543 use lightning::ln::chan_utils::CommitmentTransaction as nativeCommitmentTransactionImport;
1544 pub(crate) type nativeCommitmentTransaction = nativeCommitmentTransactionImport;
1546 /// This class tracks the per-transaction information needed to build a commitment transaction and will
1547 /// actually build it and sign. It is used for holder transactions that we sign only when needed
1548 /// and for transactions we sign for the counterparty.
1550 /// This class can be used inside a signer implementation to generate a signature given the relevant
1554 pub struct CommitmentTransaction {
1555 /// A pointer to the opaque Rust object.
1557 /// Nearly everywhere, inner must be non-null, however in places where
1558 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1559 pub inner: *mut nativeCommitmentTransaction,
1560 /// Indicates that this is the only struct which contains the same pointer.
1562 /// Rust functions which take ownership of an object provided via an argument require
1563 /// this to be true and invalidate the object pointed to by inner.
1567 impl Drop for CommitmentTransaction {
1568 fn drop(&mut self) {
1569 if self.is_owned && !<*mut nativeCommitmentTransaction>::is_null(self.inner) {
1570 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1574 /// Frees any resources used by the CommitmentTransaction, if is_owned is set and inner is non-NULL.
1576 pub extern "C" fn CommitmentTransaction_free(this_obj: CommitmentTransaction) { }
1578 /// Used only if an object of this type is returned as a trait impl by a method
1579 pub(crate) extern "C" fn CommitmentTransaction_free_void(this_ptr: *mut c_void) {
1580 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentTransaction); }
1583 impl CommitmentTransaction {
1584 pub(crate) fn get_native_ref(&self) -> &'static nativeCommitmentTransaction {
1585 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1587 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCommitmentTransaction {
1588 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1590 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1591 pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentTransaction {
1592 assert!(self.is_owned);
1593 let ret = ObjOps::untweak_ptr(self.inner);
1594 self.inner = std::ptr::null_mut();
1598 impl Clone for CommitmentTransaction {
1599 fn clone(&self) -> Self {
1601 inner: if <*mut nativeCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else {
1602 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1608 /// Used only if an object of this type is returned as a trait impl by a method
1609 pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1610 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void
1613 /// Creates a copy of the CommitmentTransaction
1614 pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction {
1618 /// Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
1619 pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1620 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1623 pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1624 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) })
1627 /// Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
1628 pub extern "C" fn CommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentTransactionDecodeErrorZ {
1629 let res: Result<lightning::ln::chan_utils::CommitmentTransaction, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1630 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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1633 /// The backwards-counting commitment number
1636 pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &CommitmentTransaction) -> u64 {
1637 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.commitment_number();
1641 /// The value to be sent to the broadcaster
1644 pub extern "C" fn CommitmentTransaction_to_broadcaster_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1645 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_broadcaster_value_sat();
1649 /// The value to be sent to the counterparty
1652 pub extern "C" fn CommitmentTransaction_to_countersignatory_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1653 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_countersignatory_value_sat();
1657 /// The feerate paid per 1000-weight-unit in this commitment transaction.
1660 pub extern "C" fn CommitmentTransaction_feerate_per_kw(this_arg: &CommitmentTransaction) -> u32 {
1661 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.feerate_per_kw();
1665 /// Trust our pre-built transaction and derived transaction creation public keys.
1667 /// Applies a wrapper which allows access to these fields.
1669 /// This should only be used if you fully trust the builder of this object. It should not
1670 /// be used by an external signer - instead use the verify function.
1673 pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction) -> crate::lightning::ln::chan_utils::TrustedCommitmentTransaction {
1674 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.trust();
1675 crate::lightning::ln::chan_utils::TrustedCommitmentTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1678 /// Verify our pre-built transaction and derived transaction creation public keys.
1680 /// Applies a wrapper which allows access to these fields.
1682 /// An external validating signer must call this method before signing
1683 /// or using the built transaction.
1686 pub extern "C" fn CommitmentTransaction_verify(this_arg: &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 {
1687 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::SECP256K1);
1688 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() };
1693 use lightning::ln::chan_utils::TrustedCommitmentTransaction as nativeTrustedCommitmentTransactionImport;
1694 pub(crate) type nativeTrustedCommitmentTransaction = nativeTrustedCommitmentTransactionImport<'static>;
1696 /// A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin
1697 /// transaction and the transaction creation keys) are trusted.
1699 /// See trust() and verify() functions on CommitmentTransaction.
1701 /// This structure implements Deref.
1704 pub struct TrustedCommitmentTransaction {
1705 /// A pointer to the opaque Rust object.
1707 /// Nearly everywhere, inner must be non-null, however in places where
1708 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1709 pub inner: *mut nativeTrustedCommitmentTransaction,
1710 /// Indicates that this is the only struct which contains the same pointer.
1712 /// Rust functions which take ownership of an object provided via an argument require
1713 /// this to be true and invalidate the object pointed to by inner.
1717 impl Drop for TrustedCommitmentTransaction {
1718 fn drop(&mut self) {
1719 if self.is_owned && !<*mut nativeTrustedCommitmentTransaction>::is_null(self.inner) {
1720 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1724 /// Frees any resources used by the TrustedCommitmentTransaction, if is_owned is set and inner is non-NULL.
1726 pub extern "C" fn TrustedCommitmentTransaction_free(this_obj: TrustedCommitmentTransaction) { }
1728 /// Used only if an object of this type is returned as a trait impl by a method
1729 pub(crate) extern "C" fn TrustedCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1730 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedCommitmentTransaction); }
1733 impl TrustedCommitmentTransaction {
1734 pub(crate) fn get_native_ref(&self) -> &'static nativeTrustedCommitmentTransaction {
1735 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1737 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeTrustedCommitmentTransaction {
1738 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1740 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1741 pub(crate) fn take_inner(mut self) -> *mut nativeTrustedCommitmentTransaction {
1742 assert!(self.is_owned);
1743 let ret = ObjOps::untweak_ptr(self.inner);
1744 self.inner = std::ptr::null_mut();
1748 /// The transaction ID of the built Bitcoin transaction
1751 pub extern "C" fn TrustedCommitmentTransaction_txid(this_arg: &TrustedCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
1752 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.txid();
1753 crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
1756 /// The pre-built Bitcoin commitment transaction
1759 pub extern "C" fn TrustedCommitmentTransaction_built_transaction(this_arg: &TrustedCommitmentTransaction) -> crate::lightning::ln::chan_utils::BuiltCommitmentTransaction {
1760 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.built_transaction();
1761 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 }
1764 /// The pre-calculated transaction creation public keys.
1767 pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitmentTransaction) -> crate::lightning::ln::chan_utils::TxCreationKeys {
1768 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.keys();
1769 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 }
1772 /// Get a signature for each HTLC which was included in the commitment transaction (ie for
1773 /// which HTLCOutputInCommitment::transaction_output_index.is_some()).
1775 /// The returned Vec has one entry for each HTLC, and in the same order.
1778 pub extern "C" fn TrustedCommitmentTransaction_get_htlc_sigs(this_arg: &TrustedCommitmentTransaction, htlc_base_key: *const [u8; 32], channel_parameters: &crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
1779 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), channel_parameters.get_native_ref(), secp256k1::SECP256K1);
1780 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { crate::c_types::Signature::from_rust(&item) }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
1784 /// Commitment transaction numbers which appear in the transactions themselves are XOR'd with a
1785 /// shared secret first. This prevents on-chain observers from discovering how many commitment
1786 /// transactions occurred in a channel before it was closed.
1788 /// This function gets the shared secret from relevant channel public keys and can be used to
1789 /// \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
1791 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 {
1792 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);