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 bitcoin::hashes::Hash;
15 use crate::c_types::*;
17 /// Build the commitment secret from the seed and the commitment number
19 pub extern "C" fn build_commitment_secret(commitment_seed: *const [u8; 32], mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
20 let mut ret = lightning::ln::chan_utils::build_commitment_secret(unsafe { &*commitment_seed}, idx);
21 crate::c_types::ThirtyTwoBytes { data: ret }
24 /// Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
25 /// from the base secret and the per_commitment_point.
27 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
28 /// generated (ie our own).
30 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 {
31 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());
32 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() };
36 /// Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
37 /// from the base point and the per_commitment_key. This is the public equivalent of
38 /// derive_private_key - using only public keys to derive a public key instead of private keys.
40 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
41 /// generated (ie our own).
43 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 {
44 let mut ret = lightning::ln::chan_utils::derive_public_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &base_point.into_rust());
45 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() };
49 /// Derives a per-commitment-transaction revocation key from its constituent parts.
51 /// Only the cheating participant owns a valid witness to propagate a revoked
52 /// commitment transaction, thus per_commitment_secret always come from cheater
53 /// and revocation_base_secret always come from punisher, which is the broadcaster
54 /// of the transaction spending with this key knowledge.
56 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
57 /// generated (ie our own).
59 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 {
60 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());
61 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() };
65 /// Derives a per-commitment-transaction revocation public key from its constituent parts. This is
66 /// the public equivalend of derive_private_revocation_key - using only public keys to derive a
67 /// public key instead of private keys.
69 /// Only the cheating participant owns a valid witness to propagate a revoked
70 /// commitment transaction, thus per_commitment_point always come from cheater
71 /// and revocation_base_point always come from punisher, which is the broadcaster
72 /// of the transaction spending with this key knowledge.
74 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
75 /// generated (ie our own).
77 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 {
78 let mut ret = lightning::ln::chan_utils::derive_public_revocation_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &countersignatory_revocation_base_point.into_rust());
79 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() };
84 use lightning::ln::chan_utils::TxCreationKeys as nativeTxCreationKeysImport;
85 type nativeTxCreationKeys = nativeTxCreationKeysImport;
87 /// The set of public keys which are used in the creation of one commitment transaction.
88 /// These are derived from the channel base keys and per-commitment data.
90 /// A broadcaster key is provided from potential broadcaster of the computed transaction.
91 /// A countersignatory key is coming from a protocol participant unable to broadcast the
94 /// These keys are assumed to be good, either because the code derived them from
95 /// channel basepoints via the new function, or they were obtained via
96 /// CommitmentTransaction.trust().keys() because we trusted the source of the
97 /// pre-calculated keys.
100 pub struct TxCreationKeys {
101 /// A pointer to the opaque Rust object.
103 /// Nearly everywhere, inner must be non-null, however in places where
104 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
105 pub inner: *mut nativeTxCreationKeys,
106 /// Indicates that this is the only struct which contains the same pointer.
108 /// Rust functions which take ownership of an object provided via an argument require
109 /// this to be true and invalidate the object pointed to by inner.
113 impl Drop for TxCreationKeys {
115 if self.is_owned && !<*mut nativeTxCreationKeys>::is_null(self.inner) {
116 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
120 /// Frees any resources used by the TxCreationKeys, if is_owned is set and inner is non-NULL.
122 pub extern "C" fn TxCreationKeys_free(this_obj: TxCreationKeys) { }
124 /// Used only if an object of this type is returned as a trait impl by a method
125 extern "C" fn TxCreationKeys_free_void(this_ptr: *mut c_void) {
126 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTxCreationKeys); }
129 impl TxCreationKeys {
130 pub(crate) fn get_native_ref(&self) -> &'static nativeTxCreationKeys {
131 unsafe { &*ObjOps::untweak_ptr(self.inner) }
133 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeTxCreationKeys {
134 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
136 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
137 pub(crate) fn take_inner(mut self) -> *mut nativeTxCreationKeys {
138 assert!(self.is_owned);
139 let ret = ObjOps::untweak_ptr(self.inner);
140 self.inner = std::ptr::null_mut();
144 /// The broadcaster's per-commitment public key which was used to derive the other keys.
146 pub extern "C" fn TxCreationKeys_get_per_commitment_point(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
147 let mut inner_val = &mut this_ptr.get_native_mut_ref().per_commitment_point;
148 crate::c_types::PublicKey::from_rust(&inner_val)
150 /// The broadcaster's per-commitment public key which was used to derive the other keys.
152 pub extern "C" fn TxCreationKeys_set_per_commitment_point(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
153 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.per_commitment_point = val.into_rust();
155 /// The revocation key which is used to allow the broadcaster of the commitment
156 /// transaction to provide their counterparty the ability to punish them if they broadcast
159 pub extern "C" fn TxCreationKeys_get_revocation_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
160 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_key;
161 crate::c_types::PublicKey::from_rust(&inner_val)
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_set_revocation_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
168 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_key = val.into_rust();
170 /// Broadcaster's HTLC Key
172 pub extern "C" fn TxCreationKeys_get_broadcaster_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
173 let mut inner_val = &mut this_ptr.get_native_mut_ref().broadcaster_htlc_key;
174 crate::c_types::PublicKey::from_rust(&inner_val)
176 /// Broadcaster's HTLC Key
178 pub extern "C" fn TxCreationKeys_set_broadcaster_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
179 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.broadcaster_htlc_key = val.into_rust();
181 /// Countersignatory's HTLC Key
183 pub extern "C" fn TxCreationKeys_get_countersignatory_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
184 let mut inner_val = &mut this_ptr.get_native_mut_ref().countersignatory_htlc_key;
185 crate::c_types::PublicKey::from_rust(&inner_val)
187 /// Countersignatory's HTLC Key
189 pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
190 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.countersignatory_htlc_key = val.into_rust();
192 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
194 pub extern "C" fn TxCreationKeys_get_broadcaster_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
195 let mut inner_val = &mut this_ptr.get_native_mut_ref().broadcaster_delayed_payment_key;
196 crate::c_types::PublicKey::from_rust(&inner_val)
198 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
200 pub extern "C" fn TxCreationKeys_set_broadcaster_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
201 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.broadcaster_delayed_payment_key = val.into_rust();
203 /// Constructs a new TxCreationKeys given each field
206 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 {
207 TxCreationKeys { inner: ObjOps::heap_alloc(nativeTxCreationKeys {
208 per_commitment_point: per_commitment_point_arg.into_rust(),
209 revocation_key: revocation_key_arg.into_rust(),
210 broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(),
211 countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(),
212 broadcaster_delayed_payment_key: broadcaster_delayed_payment_key_arg.into_rust(),
215 impl Clone for TxCreationKeys {
216 fn clone(&self) -> Self {
218 inner: if <*mut nativeTxCreationKeys>::is_null(self.inner) { std::ptr::null_mut() } else {
219 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
225 /// Used only if an object of this type is returned as a trait impl by a method
226 pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
227 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxCreationKeys)).clone() })) as *mut c_void
230 /// Creates a copy of the TxCreationKeys
231 pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys {
235 /// Serialize the TxCreationKeys object into a byte array which can be read by TxCreationKeys_read
236 pub extern "C" fn TxCreationKeys_write(obj: &TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
237 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
240 pub(crate) extern "C" fn TxCreationKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
241 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxCreationKeys) })
244 /// Read a TxCreationKeys from a byte array, created by TxCreationKeys_write
245 pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_TxCreationKeysDecodeErrorZ {
246 let res = crate::c_types::deserialize_obj(ser);
247 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() };
251 use lightning::ln::chan_utils::ChannelPublicKeys as nativeChannelPublicKeysImport;
252 type nativeChannelPublicKeys = nativeChannelPublicKeysImport;
254 /// One counterparty's public keys which do not change over the life of a channel.
257 pub struct ChannelPublicKeys {
258 /// A pointer to the opaque Rust object.
260 /// Nearly everywhere, inner must be non-null, however in places where
261 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
262 pub inner: *mut nativeChannelPublicKeys,
263 /// Indicates that this is the only struct which contains the same pointer.
265 /// Rust functions which take ownership of an object provided via an argument require
266 /// this to be true and invalidate the object pointed to by inner.
270 impl Drop for ChannelPublicKeys {
272 if self.is_owned && !<*mut nativeChannelPublicKeys>::is_null(self.inner) {
273 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
277 /// Frees any resources used by the ChannelPublicKeys, if is_owned is set and inner is non-NULL.
279 pub extern "C" fn ChannelPublicKeys_free(this_obj: ChannelPublicKeys) { }
281 /// Used only if an object of this type is returned as a trait impl by a method
282 extern "C" fn ChannelPublicKeys_free_void(this_ptr: *mut c_void) {
283 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelPublicKeys); }
286 impl ChannelPublicKeys {
287 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelPublicKeys {
288 unsafe { &*ObjOps::untweak_ptr(self.inner) }
290 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelPublicKeys {
291 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
293 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
294 pub(crate) fn take_inner(mut self) -> *mut nativeChannelPublicKeys {
295 assert!(self.is_owned);
296 let ret = ObjOps::untweak_ptr(self.inner);
297 self.inner = std::ptr::null_mut();
301 /// The public key which is used to sign all commitment transactions, as it appears in the
302 /// on-chain channel lock-in 2-of-2 multisig output.
304 pub extern "C" fn ChannelPublicKeys_get_funding_pubkey(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
305 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_pubkey;
306 crate::c_types::PublicKey::from_rust(&inner_val)
308 /// The public key which is used to sign all commitment transactions, as it appears in the
309 /// on-chain channel lock-in 2-of-2 multisig output.
311 pub extern "C" fn ChannelPublicKeys_set_funding_pubkey(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
312 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_pubkey = val.into_rust();
314 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
315 /// revocation keys. This is combined with the per-commitment-secret generated by the
316 /// counterparty to create a secret which the counterparty can reveal to revoke previous
319 pub extern "C" fn ChannelPublicKeys_get_revocation_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
320 let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_basepoint;
321 crate::c_types::PublicKey::from_rust(&inner_val)
323 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
324 /// revocation keys. This is combined with the per-commitment-secret generated by the
325 /// counterparty to create a secret which the counterparty can reveal to revoke previous
328 pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
329 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_basepoint = val.into_rust();
331 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
332 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
333 /// static across every commitment transaction.
335 pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
336 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_point;
337 crate::c_types::PublicKey::from_rust(&inner_val)
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_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
344 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_point = val.into_rust();
346 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
347 /// public key which receives non-HTLC-encumbered funds which are only available for spending
348 /// after some delay (or can be claimed via the revocation path).
350 pub extern "C" fn ChannelPublicKeys_get_delayed_payment_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
351 let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_basepoint;
352 crate::c_types::PublicKey::from_rust(&inner_val)
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_set_delayed_payment_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
359 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_basepoint = val.into_rust();
361 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
362 /// which is used to encumber HTLC-in-flight outputs.
364 pub extern "C" fn ChannelPublicKeys_get_htlc_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
365 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_basepoint;
366 crate::c_types::PublicKey::from_rust(&inner_val)
368 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
369 /// which is used to encumber HTLC-in-flight outputs.
371 pub extern "C" fn ChannelPublicKeys_set_htlc_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
372 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_basepoint = val.into_rust();
374 /// Constructs a new ChannelPublicKeys given each field
377 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 {
378 ChannelPublicKeys { inner: ObjOps::heap_alloc(nativeChannelPublicKeys {
379 funding_pubkey: funding_pubkey_arg.into_rust(),
380 revocation_basepoint: revocation_basepoint_arg.into_rust(),
381 payment_point: payment_point_arg.into_rust(),
382 delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(),
383 htlc_basepoint: htlc_basepoint_arg.into_rust(),
386 impl Clone for ChannelPublicKeys {
387 fn clone(&self) -> Self {
389 inner: if <*mut nativeChannelPublicKeys>::is_null(self.inner) { std::ptr::null_mut() } else {
390 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
396 /// Used only if an object of this type is returned as a trait impl by a method
397 pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
398 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelPublicKeys)).clone() })) as *mut c_void
401 /// Creates a copy of the ChannelPublicKeys
402 pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys {
406 /// Serialize the ChannelPublicKeys object into a byte array which can be read by ChannelPublicKeys_read
407 pub extern "C" fn ChannelPublicKeys_write(obj: &ChannelPublicKeys) -> crate::c_types::derived::CVec_u8Z {
408 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
411 pub(crate) extern "C" fn ChannelPublicKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
412 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelPublicKeys) })
415 /// Read a ChannelPublicKeys from a byte array, created by ChannelPublicKeys_write
416 pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelPublicKeysDecodeErrorZ {
417 let res = crate::c_types::deserialize_obj(ser);
418 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() };
421 /// Create per-state keys from channel base points and the per-commitment point.
422 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
425 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 {
426 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());
427 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() };
431 /// Generate per-state keys from channel static keys.
432 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
435 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 {
436 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);
437 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() };
441 /// The maximum length of a script returned by get_revokeable_redeemscript.
444 pub static REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH: usize = lightning::ln::chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH;
445 /// A script either spendable by the revocation
446 /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
447 /// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
449 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 {
450 let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), contest_delay, &broadcaster_delayed_payment_key.into_rust());
451 ret.into_bytes().into()
455 use lightning::ln::chan_utils::HTLCOutputInCommitment as nativeHTLCOutputInCommitmentImport;
456 type nativeHTLCOutputInCommitment = nativeHTLCOutputInCommitmentImport;
458 /// Information about an HTLC as it appears in a commitment transaction
461 pub struct HTLCOutputInCommitment {
462 /// A pointer to the opaque Rust object.
464 /// Nearly everywhere, inner must be non-null, however in places where
465 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
466 pub inner: *mut nativeHTLCOutputInCommitment,
467 /// Indicates that this is the only struct which contains the same pointer.
469 /// Rust functions which take ownership of an object provided via an argument require
470 /// this to be true and invalidate the object pointed to by inner.
474 impl Drop for HTLCOutputInCommitment {
476 if self.is_owned && !<*mut nativeHTLCOutputInCommitment>::is_null(self.inner) {
477 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
481 /// Frees any resources used by the HTLCOutputInCommitment, if is_owned is set and inner is non-NULL.
483 pub extern "C" fn HTLCOutputInCommitment_free(this_obj: HTLCOutputInCommitment) { }
485 /// Used only if an object of this type is returned as a trait impl by a method
486 extern "C" fn HTLCOutputInCommitment_free_void(this_ptr: *mut c_void) {
487 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCOutputInCommitment); }
490 impl HTLCOutputInCommitment {
491 pub(crate) fn get_native_ref(&self) -> &'static nativeHTLCOutputInCommitment {
492 unsafe { &*ObjOps::untweak_ptr(self.inner) }
494 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHTLCOutputInCommitment {
495 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
497 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
498 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCOutputInCommitment {
499 assert!(self.is_owned);
500 let ret = ObjOps::untweak_ptr(self.inner);
501 self.inner = std::ptr::null_mut();
505 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
506 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
507 /// need to compare this value to whether the commitment transaction in question is that of
508 /// the counterparty or our own.
510 pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool {
511 let mut inner_val = &mut this_ptr.get_native_mut_ref().offered;
514 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
515 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
516 /// need to compare this value to whether the commitment transaction in question is that of
517 /// the counterparty or our own.
519 pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) {
520 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.offered = val;
522 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
523 /// this divided by 1000.
525 pub extern "C" fn HTLCOutputInCommitment_get_amount_msat(this_ptr: &HTLCOutputInCommitment) -> u64 {
526 let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_msat;
529 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
530 /// this divided by 1000.
532 pub extern "C" fn HTLCOutputInCommitment_set_amount_msat(this_ptr: &mut HTLCOutputInCommitment, mut val: u64) {
533 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_msat = val;
535 /// The CLTV lock-time at which this HTLC expires.
537 pub extern "C" fn HTLCOutputInCommitment_get_cltv_expiry(this_ptr: &HTLCOutputInCommitment) -> u32 {
538 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry;
541 /// The CLTV lock-time at which this HTLC expires.
543 pub extern "C" fn HTLCOutputInCommitment_set_cltv_expiry(this_ptr: &mut HTLCOutputInCommitment, mut val: u32) {
544 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry = val;
546 /// The hash of the preimage which unlocks this HTLC.
548 pub extern "C" fn HTLCOutputInCommitment_get_payment_hash(this_ptr: &HTLCOutputInCommitment) -> *const [u8; 32] {
549 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_hash;
552 /// The hash of the preimage which unlocks this HTLC.
554 pub extern "C" fn HTLCOutputInCommitment_set_payment_hash(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::ThirtyTwoBytes) {
555 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_hash = ::lightning::ln::PaymentHash(val.data);
557 /// The position within the commitment transactions' outputs. This may be None if the value is
558 /// below the dust limit (in which case no output appears in the commitment transaction and the
559 /// value is spent to additional transaction fees).
561 pub extern "C" fn HTLCOutputInCommitment_get_transaction_output_index(this_ptr: &HTLCOutputInCommitment) -> crate::c_types::derived::COption_u32Z {
562 let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction_output_index;
563 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()) } };
566 /// The position within the commitment transactions' outputs. This may be None if the value is
567 /// below the dust limit (in which case no output appears in the commitment transaction and the
568 /// value is spent to additional transaction fees).
570 pub extern "C" fn HTLCOutputInCommitment_set_transaction_output_index(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::derived::COption_u32Z) {
571 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
572 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction_output_index = local_val;
574 /// Constructs a new HTLCOutputInCommitment given each field
577 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 {
578 let mut local_transaction_output_index_arg = if transaction_output_index_arg.is_some() { Some( { transaction_output_index_arg.take() }) } else { None };
579 HTLCOutputInCommitment { inner: ObjOps::heap_alloc(nativeHTLCOutputInCommitment {
580 offered: offered_arg,
581 amount_msat: amount_msat_arg,
582 cltv_expiry: cltv_expiry_arg,
583 payment_hash: ::lightning::ln::PaymentHash(payment_hash_arg.data),
584 transaction_output_index: local_transaction_output_index_arg,
587 impl Clone for HTLCOutputInCommitment {
588 fn clone(&self) -> Self {
590 inner: if <*mut nativeHTLCOutputInCommitment>::is_null(self.inner) { std::ptr::null_mut() } else {
591 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
597 /// Used only if an object of this type is returned as a trait impl by a method
598 pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_void) -> *mut c_void {
599 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCOutputInCommitment)).clone() })) as *mut c_void
602 /// Creates a copy of the HTLCOutputInCommitment
603 pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment {
607 /// Serialize the HTLCOutputInCommitment object into a byte array which can be read by HTLCOutputInCommitment_read
608 pub extern "C" fn HTLCOutputInCommitment_write(obj: &HTLCOutputInCommitment) -> crate::c_types::derived::CVec_u8Z {
609 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
612 pub(crate) extern "C" fn HTLCOutputInCommitment_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
613 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCOutputInCommitment) })
616 /// Read a HTLCOutputInCommitment from a byte array, created by HTLCOutputInCommitment_write
617 pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCOutputInCommitmentDecodeErrorZ {
618 let res = crate::c_types::deserialize_obj(ser);
619 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() };
622 /// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
623 /// does not need to have its previous_output_index filled.
625 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 {
626 let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(htlc.get_native_ref(), keys.get_native_ref());
627 ret.into_bytes().into()
630 /// Gets the redeemscript for a funding output from the two funding public keys.
631 /// Note that the order of funding public keys does not matter.
633 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 {
634 let mut ret = lightning::ln::chan_utils::make_funding_redeemscript(&broadcaster.into_rust(), &countersignatory.into_rust());
635 ret.into_bytes().into()
638 /// Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC
639 /// parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the
640 /// transaction which needs signing, and can be used to construct an HTLC transaction which is
641 /// broadcastable given a counterparty HTLC signature.
643 /// Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
644 /// commitment transaction).
646 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 {
647 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());
648 crate::c_types::Transaction::from_bitcoin(&ret)
652 use lightning::ln::chan_utils::ChannelTransactionParameters as nativeChannelTransactionParametersImport;
653 type nativeChannelTransactionParameters = nativeChannelTransactionParametersImport;
655 /// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction).
656 /// The fields are organized by holder/counterparty.
658 /// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters
659 /// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions.
662 pub struct ChannelTransactionParameters {
663 /// A pointer to the opaque Rust object.
665 /// Nearly everywhere, inner must be non-null, however in places where
666 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
667 pub inner: *mut nativeChannelTransactionParameters,
668 /// Indicates that this is the only struct which contains the same pointer.
670 /// Rust functions which take ownership of an object provided via an argument require
671 /// this to be true and invalidate the object pointed to by inner.
675 impl Drop for ChannelTransactionParameters {
677 if self.is_owned && !<*mut nativeChannelTransactionParameters>::is_null(self.inner) {
678 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
682 /// Frees any resources used by the ChannelTransactionParameters, if is_owned is set and inner is non-NULL.
684 pub extern "C" fn ChannelTransactionParameters_free(this_obj: ChannelTransactionParameters) { }
686 /// Used only if an object of this type is returned as a trait impl by a method
687 extern "C" fn ChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
688 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTransactionParameters); }
691 impl ChannelTransactionParameters {
692 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelTransactionParameters {
693 unsafe { &*ObjOps::untweak_ptr(self.inner) }
695 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelTransactionParameters {
696 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
698 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
699 pub(crate) fn take_inner(mut self) -> *mut nativeChannelTransactionParameters {
700 assert!(self.is_owned);
701 let ret = ObjOps::untweak_ptr(self.inner);
702 self.inner = std::ptr::null_mut();
706 /// Holder public keys
708 pub extern "C" fn ChannelTransactionParameters_get_holder_pubkeys(this_ptr: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
709 let mut inner_val = &mut this_ptr.get_native_mut_ref().holder_pubkeys;
710 crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
712 /// Holder public keys
714 pub extern "C" fn ChannelTransactionParameters_set_holder_pubkeys(this_ptr: &mut ChannelTransactionParameters, mut val: crate::lightning::ln::chan_utils::ChannelPublicKeys) {
715 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.holder_pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
717 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
719 pub extern "C" fn ChannelTransactionParameters_get_holder_selected_contest_delay(this_ptr: &ChannelTransactionParameters) -> u16 {
720 let mut inner_val = &mut this_ptr.get_native_mut_ref().holder_selected_contest_delay;
723 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
725 pub extern "C" fn ChannelTransactionParameters_set_holder_selected_contest_delay(this_ptr: &mut ChannelTransactionParameters, mut val: u16) {
726 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.holder_selected_contest_delay = val;
728 /// Whether the holder is the initiator of this channel.
729 /// This is an input to the commitment number obscure factor computation.
731 pub extern "C" fn ChannelTransactionParameters_get_is_outbound_from_holder(this_ptr: &ChannelTransactionParameters) -> bool {
732 let mut inner_val = &mut this_ptr.get_native_mut_ref().is_outbound_from_holder;
735 /// Whether the holder is the initiator of this channel.
736 /// This is an input to the commitment number obscure factor computation.
738 pub extern "C" fn ChannelTransactionParameters_set_is_outbound_from_holder(this_ptr: &mut ChannelTransactionParameters, mut val: bool) {
739 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.is_outbound_from_holder = val;
741 /// The late-bound counterparty channel transaction parameters.
742 /// These parameters are populated at the point in the protocol where the counterparty provides them.
744 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
746 pub extern "C" fn ChannelTransactionParameters_get_counterparty_parameters(this_ptr: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters {
747 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_parameters;
748 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 _) as *mut _ }, is_owned: false };
751 /// The late-bound counterparty channel transaction parameters.
752 /// These parameters are populated at the point in the protocol where the counterparty provides them.
754 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
756 pub extern "C" fn ChannelTransactionParameters_set_counterparty_parameters(this_ptr: &mut ChannelTransactionParameters, mut val: crate::lightning::ln::chan_utils::CounterpartyChannelTransactionParameters) {
757 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
758 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_parameters = local_val;
760 /// The late-bound funding outpoint
762 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
764 pub extern "C" fn ChannelTransactionParameters_get_funding_outpoint(this_ptr: &ChannelTransactionParameters) -> crate::lightning::chain::transaction::OutPoint {
765 let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_outpoint;
766 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 _) as *mut _ }, is_owned: false };
769 /// The late-bound funding outpoint
771 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
773 pub extern "C" fn ChannelTransactionParameters_set_funding_outpoint(this_ptr: &mut ChannelTransactionParameters, mut val: crate::lightning::chain::transaction::OutPoint) {
774 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
775 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_outpoint = local_val;
777 /// Constructs a new ChannelTransactionParameters given each field
780 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 {
781 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()) } }) };
782 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()) } }) };
783 ChannelTransactionParameters { inner: ObjOps::heap_alloc(nativeChannelTransactionParameters {
784 holder_pubkeys: *unsafe { Box::from_raw(holder_pubkeys_arg.take_inner()) },
785 holder_selected_contest_delay: holder_selected_contest_delay_arg,
786 is_outbound_from_holder: is_outbound_from_holder_arg,
787 counterparty_parameters: local_counterparty_parameters_arg,
788 funding_outpoint: local_funding_outpoint_arg,
791 impl Clone for ChannelTransactionParameters {
792 fn clone(&self) -> Self {
794 inner: if <*mut nativeChannelTransactionParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
795 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
801 /// Used only if an object of this type is returned as a trait impl by a method
802 pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
803 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTransactionParameters)).clone() })) as *mut c_void
806 /// Creates a copy of the ChannelTransactionParameters
807 pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters {
811 use lightning::ln::chan_utils::CounterpartyChannelTransactionParameters as nativeCounterpartyChannelTransactionParametersImport;
812 type nativeCounterpartyChannelTransactionParameters = nativeCounterpartyChannelTransactionParametersImport;
814 /// Late-bound per-channel counterparty data used to build transactions.
817 pub struct CounterpartyChannelTransactionParameters {
818 /// A pointer to the opaque Rust object.
820 /// Nearly everywhere, inner must be non-null, however in places where
821 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
822 pub inner: *mut nativeCounterpartyChannelTransactionParameters,
823 /// Indicates that this is the only struct which contains the same pointer.
825 /// Rust functions which take ownership of an object provided via an argument require
826 /// this to be true and invalidate the object pointed to by inner.
830 impl Drop for CounterpartyChannelTransactionParameters {
832 if self.is_owned && !<*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) {
833 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
837 /// Frees any resources used by the CounterpartyChannelTransactionParameters, if is_owned is set and inner is non-NULL.
839 pub extern "C" fn CounterpartyChannelTransactionParameters_free(this_obj: CounterpartyChannelTransactionParameters) { }
841 /// Used only if an object of this type is returned as a trait impl by a method
842 extern "C" fn CounterpartyChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
843 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyChannelTransactionParameters); }
846 impl CounterpartyChannelTransactionParameters {
847 pub(crate) fn get_native_ref(&self) -> &'static nativeCounterpartyChannelTransactionParameters {
848 unsafe { &*ObjOps::untweak_ptr(self.inner) }
850 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCounterpartyChannelTransactionParameters {
851 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
853 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
854 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyChannelTransactionParameters {
855 assert!(self.is_owned);
856 let ret = ObjOps::untweak_ptr(self.inner);
857 self.inner = std::ptr::null_mut();
861 /// Counter-party public keys
863 pub extern "C" fn CounterpartyChannelTransactionParameters_get_pubkeys(this_ptr: &CounterpartyChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
864 let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkeys;
865 crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
867 /// Counter-party public keys
869 pub extern "C" fn CounterpartyChannelTransactionParameters_set_pubkeys(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: crate::lightning::ln::chan_utils::ChannelPublicKeys) {
870 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
872 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
874 pub extern "C" fn CounterpartyChannelTransactionParameters_get_selected_contest_delay(this_ptr: &CounterpartyChannelTransactionParameters) -> u16 {
875 let mut inner_val = &mut this_ptr.get_native_mut_ref().selected_contest_delay;
878 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
880 pub extern "C" fn CounterpartyChannelTransactionParameters_set_selected_contest_delay(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: u16) {
881 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.selected_contest_delay = val;
883 /// Constructs a new CounterpartyChannelTransactionParameters given each field
886 pub extern "C" fn CounterpartyChannelTransactionParameters_new(mut pubkeys_arg: crate::lightning::ln::chan_utils::ChannelPublicKeys, mut selected_contest_delay_arg: u16) -> CounterpartyChannelTransactionParameters {
887 CounterpartyChannelTransactionParameters { inner: ObjOps::heap_alloc(nativeCounterpartyChannelTransactionParameters {
888 pubkeys: *unsafe { Box::from_raw(pubkeys_arg.take_inner()) },
889 selected_contest_delay: selected_contest_delay_arg,
892 impl Clone for CounterpartyChannelTransactionParameters {
893 fn clone(&self) -> Self {
895 inner: if <*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
896 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
902 /// Used only if an object of this type is returned as a trait impl by a method
903 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
904 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void
907 /// Creates a copy of the CounterpartyChannelTransactionParameters
908 pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters {
911 /// Whether the late bound parameters are populated.
914 pub extern "C" fn ChannelTransactionParameters_is_populated(this_arg: &ChannelTransactionParameters) -> bool {
915 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_populated();
919 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
920 /// given that the holder is the broadcaster.
922 /// self.is_populated() must be true before calling this function.
925 pub extern "C" fn ChannelTransactionParameters_as_holder_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters {
926 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_holder_broadcastable();
927 crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
930 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
931 /// given that the counterparty is the broadcaster.
933 /// self.is_populated() must be true before calling this function.
936 pub extern "C" fn ChannelTransactionParameters_as_counterparty_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters {
937 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_counterparty_broadcastable();
938 crate::lightning::ln::chan_utils::DirectedChannelTransactionParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
942 /// Serialize the CounterpartyChannelTransactionParameters object into a byte array which can be read by CounterpartyChannelTransactionParameters_read
943 pub extern "C" fn CounterpartyChannelTransactionParameters_write(obj: &CounterpartyChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
944 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
947 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
948 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyChannelTransactionParameters) })
951 /// Read a CounterpartyChannelTransactionParameters from a byte array, created by CounterpartyChannelTransactionParameters_write
952 pub extern "C" fn CounterpartyChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyChannelTransactionParametersDecodeErrorZ {
953 let res = crate::c_types::deserialize_obj(ser);
954 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() };
958 /// Serialize the ChannelTransactionParameters object into a byte array which can be read by ChannelTransactionParameters_read
959 pub extern "C" fn ChannelTransactionParameters_write(obj: &ChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
960 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
963 pub(crate) extern "C" fn ChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
964 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTransactionParameters) })
967 /// Read a ChannelTransactionParameters from a byte array, created by ChannelTransactionParameters_write
968 pub extern "C" fn ChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelTransactionParametersDecodeErrorZ {
969 let res = crate::c_types::deserialize_obj(ser);
970 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() };
974 use lightning::ln::chan_utils::DirectedChannelTransactionParameters as nativeDirectedChannelTransactionParametersImport;
975 type nativeDirectedChannelTransactionParameters = nativeDirectedChannelTransactionParametersImport<'static>;
977 /// Static channel fields used to build transactions given per-commitment fields, organized by
978 /// broadcaster/countersignatory.
980 /// This is derived from the holder/counterparty-organized ChannelTransactionParameters via the
981 /// as_holder_broadcastable and as_counterparty_broadcastable functions.
984 pub struct DirectedChannelTransactionParameters {
985 /// A pointer to the opaque Rust object.
987 /// Nearly everywhere, inner must be non-null, however in places where
988 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
989 pub inner: *mut nativeDirectedChannelTransactionParameters,
990 /// Indicates that this is the only struct which contains the same pointer.
992 /// Rust functions which take ownership of an object provided via an argument require
993 /// this to be true and invalidate the object pointed to by inner.
997 impl Drop for DirectedChannelTransactionParameters {
999 if self.is_owned && !<*mut nativeDirectedChannelTransactionParameters>::is_null(self.inner) {
1000 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1004 /// Frees any resources used by the DirectedChannelTransactionParameters, if is_owned is set and inner is non-NULL.
1006 pub extern "C" fn DirectedChannelTransactionParameters_free(this_obj: DirectedChannelTransactionParameters) { }
1008 /// Used only if an object of this type is returned as a trait impl by a method
1009 extern "C" fn DirectedChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
1010 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelTransactionParameters); }
1013 impl DirectedChannelTransactionParameters {
1014 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelTransactionParameters {
1015 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1017 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelTransactionParameters {
1018 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1020 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1021 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelTransactionParameters {
1022 assert!(self.is_owned);
1023 let ret = ObjOps::untweak_ptr(self.inner);
1024 self.inner = std::ptr::null_mut();
1028 /// Get the channel pubkeys for the broadcaster
1031 pub extern "C" fn DirectedChannelTransactionParameters_broadcaster_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1032 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.broadcaster_pubkeys();
1033 crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1036 /// Get the channel pubkeys for the countersignatory
1039 pub extern "C" fn DirectedChannelTransactionParameters_countersignatory_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::lightning::ln::chan_utils::ChannelPublicKeys {
1040 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.countersignatory_pubkeys();
1041 crate::lightning::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1044 /// Get the contest delay applicable to the transactions.
1045 /// Note that the contest delay was selected by the countersignatory.
1048 pub extern "C" fn DirectedChannelTransactionParameters_contest_delay(this_arg: &DirectedChannelTransactionParameters) -> u16 {
1049 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.contest_delay();
1053 /// Whether the channel is outbound from the broadcaster.
1055 /// The boolean representing the side that initiated the channel is
1056 /// an input to the commitment number obscure factor computation.
1059 pub extern "C" fn DirectedChannelTransactionParameters_is_outbound(this_arg: &DirectedChannelTransactionParameters) -> bool {
1060 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_outbound();
1064 /// The funding outpoint
1067 pub extern "C" fn DirectedChannelTransactionParameters_funding_outpoint(this_arg: &DirectedChannelTransactionParameters) -> crate::lightning::chain::transaction::OutPoint {
1068 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.funding_outpoint();
1069 crate::c_types::bitcoin_to_C_outpoint(ret)
1073 use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport;
1074 type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport;
1076 /// Information needed to build and sign a holder's commitment transaction.
1078 /// The transaction is only signed once we are ready to broadcast.
1081 pub struct HolderCommitmentTransaction {
1082 /// A pointer to the opaque Rust object.
1084 /// Nearly everywhere, inner must be non-null, however in places where
1085 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1086 pub inner: *mut nativeHolderCommitmentTransaction,
1087 /// Indicates that this is the only struct which contains the same pointer.
1089 /// Rust functions which take ownership of an object provided via an argument require
1090 /// this to be true and invalidate the object pointed to by inner.
1094 impl Drop for HolderCommitmentTransaction {
1095 fn drop(&mut self) {
1096 if self.is_owned && !<*mut nativeHolderCommitmentTransaction>::is_null(self.inner) {
1097 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1101 /// Frees any resources used by the HolderCommitmentTransaction, if is_owned is set and inner is non-NULL.
1103 pub extern "C" fn HolderCommitmentTransaction_free(this_obj: HolderCommitmentTransaction) { }
1105 /// Used only if an object of this type is returned as a trait impl by a method
1106 extern "C" fn HolderCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1107 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHolderCommitmentTransaction); }
1110 impl HolderCommitmentTransaction {
1111 pub(crate) fn get_native_ref(&self) -> &'static nativeHolderCommitmentTransaction {
1112 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1114 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHolderCommitmentTransaction {
1115 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1117 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1118 pub(crate) fn take_inner(mut self) -> *mut nativeHolderCommitmentTransaction {
1119 assert!(self.is_owned);
1120 let ret = ObjOps::untweak_ptr(self.inner);
1121 self.inner = std::ptr::null_mut();
1125 /// Our counterparty's signature for the transaction
1127 pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature {
1128 let mut inner_val = &mut this_ptr.get_native_mut_ref().counterparty_sig;
1129 crate::c_types::Signature::from_rust(&inner_val)
1131 /// Our counterparty's signature for the transaction
1133 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) {
1134 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_sig = val.into_rust();
1136 /// All non-dust counterparty HTLC signatures, in the order they appear in the transaction
1138 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_htlc_sigs(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_SignatureZ) {
1139 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); };
1140 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.counterparty_htlc_sigs = local_val;
1142 impl Clone for HolderCommitmentTransaction {
1143 fn clone(&self) -> Self {
1145 inner: if <*mut nativeHolderCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else {
1146 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1152 /// Used only if an object of this type is returned as a trait impl by a method
1153 pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1154 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void
1157 /// Creates a copy of the HolderCommitmentTransaction
1158 pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction {
1162 /// Serialize the HolderCommitmentTransaction object into a byte array which can be read by HolderCommitmentTransaction_read
1163 pub extern "C" fn HolderCommitmentTransaction_write(obj: &HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1164 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1167 pub(crate) extern "C" fn HolderCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1168 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHolderCommitmentTransaction) })
1171 /// Read a HolderCommitmentTransaction from a byte array, created by HolderCommitmentTransaction_write
1172 pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HolderCommitmentTransactionDecodeErrorZ {
1173 let res = crate::c_types::deserialize_obj(ser);
1174 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() };
1177 /// Create a new holder transaction with the given counterparty signatures.
1178 /// The funding keys are used to figure out which signature should go first when building the transaction for broadcast.
1181 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 {
1182 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() }); };
1183 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());
1184 HolderCommitmentTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1188 use lightning::ln::chan_utils::BuiltCommitmentTransaction as nativeBuiltCommitmentTransactionImport;
1189 type nativeBuiltCommitmentTransaction = nativeBuiltCommitmentTransactionImport;
1191 /// A pre-built Bitcoin commitment transaction and its txid.
1194 pub struct BuiltCommitmentTransaction {
1195 /// A pointer to the opaque Rust object.
1197 /// Nearly everywhere, inner must be non-null, however in places where
1198 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1199 pub inner: *mut nativeBuiltCommitmentTransaction,
1200 /// Indicates that this is the only struct which contains the same pointer.
1202 /// Rust functions which take ownership of an object provided via an argument require
1203 /// this to be true and invalidate the object pointed to by inner.
1207 impl Drop for BuiltCommitmentTransaction {
1208 fn drop(&mut self) {
1209 if self.is_owned && !<*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) {
1210 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1214 /// Frees any resources used by the BuiltCommitmentTransaction, if is_owned is set and inner is non-NULL.
1216 pub extern "C" fn BuiltCommitmentTransaction_free(this_obj: BuiltCommitmentTransaction) { }
1218 /// Used only if an object of this type is returned as a trait impl by a method
1219 extern "C" fn BuiltCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1220 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBuiltCommitmentTransaction); }
1223 impl BuiltCommitmentTransaction {
1224 pub(crate) fn get_native_ref(&self) -> &'static nativeBuiltCommitmentTransaction {
1225 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1227 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBuiltCommitmentTransaction {
1228 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1230 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1231 pub(crate) fn take_inner(mut self) -> *mut nativeBuiltCommitmentTransaction {
1232 assert!(self.is_owned);
1233 let ret = ObjOps::untweak_ptr(self.inner);
1234 self.inner = std::ptr::null_mut();
1238 /// The commitment transaction
1240 pub extern "C" fn BuiltCommitmentTransaction_get_transaction(this_ptr: &BuiltCommitmentTransaction) -> crate::c_types::Transaction {
1241 let mut inner_val = &mut this_ptr.get_native_mut_ref().transaction;
1242 crate::c_types::Transaction::from_bitcoin(inner_val)
1244 /// The commitment transaction
1246 pub extern "C" fn BuiltCommitmentTransaction_set_transaction(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::Transaction) {
1247 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.transaction = val.into_bitcoin();
1249 /// The txid for the commitment transaction.
1251 /// This is provided as a performance optimization, instead of calling transaction.txid()
1254 pub extern "C" fn BuiltCommitmentTransaction_get_txid(this_ptr: &BuiltCommitmentTransaction) -> *const [u8; 32] {
1255 let mut inner_val = &mut this_ptr.get_native_mut_ref().txid;
1256 inner_val.as_inner()
1258 /// The txid for the commitment transaction.
1260 /// This is provided as a performance optimization, instead of calling transaction.txid()
1263 pub extern "C" fn BuiltCommitmentTransaction_set_txid(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::ThirtyTwoBytes) {
1264 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap();
1266 /// Constructs a new BuiltCommitmentTransaction given each field
1269 pub extern "C" fn BuiltCommitmentTransaction_new(mut transaction_arg: crate::c_types::Transaction, mut txid_arg: crate::c_types::ThirtyTwoBytes) -> BuiltCommitmentTransaction {
1270 BuiltCommitmentTransaction { inner: ObjOps::heap_alloc(nativeBuiltCommitmentTransaction {
1271 transaction: transaction_arg.into_bitcoin(),
1272 txid: ::bitcoin::hash_types::Txid::from_slice(&txid_arg.data[..]).unwrap(),
1273 }), is_owned: true }
1275 impl Clone for BuiltCommitmentTransaction {
1276 fn clone(&self) -> Self {
1278 inner: if <*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else {
1279 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1285 /// Used only if an object of this type is returned as a trait impl by a method
1286 pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1287 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void
1290 /// Creates a copy of the BuiltCommitmentTransaction
1291 pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction {
1295 /// Serialize the BuiltCommitmentTransaction object into a byte array which can be read by BuiltCommitmentTransaction_read
1296 pub extern "C" fn BuiltCommitmentTransaction_write(obj: &BuiltCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1297 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1300 pub(crate) extern "C" fn BuiltCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1301 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBuiltCommitmentTransaction) })
1304 /// Read a BuiltCommitmentTransaction from a byte array, created by BuiltCommitmentTransaction_write
1305 pub extern "C" fn BuiltCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BuiltCommitmentTransactionDecodeErrorZ {
1306 let res = crate::c_types::deserialize_obj(ser);
1307 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() };
1310 /// Get the SIGHASH_ALL sighash value of the transaction.
1312 /// This can be used to verify a signature.
1315 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 {
1316 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);
1317 crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() }
1320 /// Sign a transaction, either because we are counter-signing the counterparty's transaction or
1321 /// because we are about to broadcast a holder transaction.
1324 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 {
1325 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);
1326 crate::c_types::Signature::from_rust(&ret)
1330 use lightning::ln::chan_utils::CommitmentTransaction as nativeCommitmentTransactionImport;
1331 type nativeCommitmentTransaction = nativeCommitmentTransactionImport;
1333 /// This class tracks the per-transaction information needed to build a commitment transaction and to
1334 /// actually build it and sign. It is used for holder transactions that we sign only when needed
1335 /// and for transactions we sign for the counterparty.
1337 /// This class can be used inside a signer implementation to generate a signature given the relevant
1341 pub struct CommitmentTransaction {
1342 /// A pointer to the opaque Rust object.
1344 /// Nearly everywhere, inner must be non-null, however in places where
1345 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1346 pub inner: *mut nativeCommitmentTransaction,
1347 /// Indicates that this is the only struct which contains the same pointer.
1349 /// Rust functions which take ownership of an object provided via an argument require
1350 /// this to be true and invalidate the object pointed to by inner.
1354 impl Drop for CommitmentTransaction {
1355 fn drop(&mut self) {
1356 if self.is_owned && !<*mut nativeCommitmentTransaction>::is_null(self.inner) {
1357 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1361 /// Frees any resources used by the CommitmentTransaction, if is_owned is set and inner is non-NULL.
1363 pub extern "C" fn CommitmentTransaction_free(this_obj: CommitmentTransaction) { }
1365 /// Used only if an object of this type is returned as a trait impl by a method
1366 extern "C" fn CommitmentTransaction_free_void(this_ptr: *mut c_void) {
1367 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentTransaction); }
1370 impl CommitmentTransaction {
1371 pub(crate) fn get_native_ref(&self) -> &'static nativeCommitmentTransaction {
1372 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1374 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCommitmentTransaction {
1375 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1377 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1378 pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentTransaction {
1379 assert!(self.is_owned);
1380 let ret = ObjOps::untweak_ptr(self.inner);
1381 self.inner = std::ptr::null_mut();
1385 impl Clone for CommitmentTransaction {
1386 fn clone(&self) -> Self {
1388 inner: if <*mut nativeCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else {
1389 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1395 /// Used only if an object of this type is returned as a trait impl by a method
1396 pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1397 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void
1400 /// Creates a copy of the CommitmentTransaction
1401 pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction {
1405 /// Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
1406 pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1407 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1410 pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1411 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) })
1414 /// Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
1415 pub extern "C" fn CommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentTransactionDecodeErrorZ {
1416 let res = crate::c_types::deserialize_obj(ser);
1417 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() };
1420 /// The backwards-counting commitment number
1423 pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &CommitmentTransaction) -> u64 {
1424 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.commitment_number();
1428 /// The value to be sent to the broadcaster
1431 pub extern "C" fn CommitmentTransaction_to_broadcaster_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1432 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_broadcaster_value_sat();
1436 /// The value to be sent to the counterparty
1439 pub extern "C" fn CommitmentTransaction_to_countersignatory_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1440 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_countersignatory_value_sat();
1444 /// The feerate paid per 1000-weight-unit in this commitment transaction.
1447 pub extern "C" fn CommitmentTransaction_feerate_per_kw(this_arg: &CommitmentTransaction) -> u32 {
1448 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.feerate_per_kw();
1452 /// Trust our pre-built transaction and derived transaction creation public keys.
1454 /// Applies a wrapper which allows access to these fields.
1456 /// This should only be used if you fully trust the builder of this object. It should not
1457 ///\tbe used by an external signer - instead use the verify function.
1460 pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction) -> crate::lightning::ln::chan_utils::TrustedCommitmentTransaction {
1461 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.trust();
1462 crate::lightning::ln::chan_utils::TrustedCommitmentTransaction { inner: ObjOps::heap_alloc(ret), is_owned: true }
1465 /// Verify our pre-built transaction and derived transaction creation public keys.
1467 /// Applies a wrapper which allows access to these fields.
1469 /// An external validating signer must call this method before signing
1470 /// or using the built transaction.
1473 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 {
1474 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);
1475 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() };
1480 use lightning::ln::chan_utils::TrustedCommitmentTransaction as nativeTrustedCommitmentTransactionImport;
1481 type nativeTrustedCommitmentTransaction = nativeTrustedCommitmentTransactionImport<'static>;
1483 /// A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin
1484 /// transaction and the transaction creation keys) are trusted.
1486 /// See trust() and verify() functions on CommitmentTransaction.
1488 /// This structure implements Deref.
1491 pub struct TrustedCommitmentTransaction {
1492 /// A pointer to the opaque Rust object.
1494 /// Nearly everywhere, inner must be non-null, however in places where
1495 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1496 pub inner: *mut nativeTrustedCommitmentTransaction,
1497 /// Indicates that this is the only struct which contains the same pointer.
1499 /// Rust functions which take ownership of an object provided via an argument require
1500 /// this to be true and invalidate the object pointed to by inner.
1504 impl Drop for TrustedCommitmentTransaction {
1505 fn drop(&mut self) {
1506 if self.is_owned && !<*mut nativeTrustedCommitmentTransaction>::is_null(self.inner) {
1507 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1511 /// Frees any resources used by the TrustedCommitmentTransaction, if is_owned is set and inner is non-NULL.
1513 pub extern "C" fn TrustedCommitmentTransaction_free(this_obj: TrustedCommitmentTransaction) { }
1515 /// Used only if an object of this type is returned as a trait impl by a method
1516 extern "C" fn TrustedCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1517 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedCommitmentTransaction); }
1520 impl TrustedCommitmentTransaction {
1521 pub(crate) fn get_native_ref(&self) -> &'static nativeTrustedCommitmentTransaction {
1522 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1524 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeTrustedCommitmentTransaction {
1525 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1527 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1528 pub(crate) fn take_inner(mut self) -> *mut nativeTrustedCommitmentTransaction {
1529 assert!(self.is_owned);
1530 let ret = ObjOps::untweak_ptr(self.inner);
1531 self.inner = std::ptr::null_mut();
1535 /// The transaction ID of the built Bitcoin transaction
1538 pub extern "C" fn TrustedCommitmentTransaction_txid(this_arg: &TrustedCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
1539 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.txid();
1540 crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
1543 /// The pre-built Bitcoin commitment transaction
1546 pub extern "C" fn TrustedCommitmentTransaction_built_transaction(this_arg: &TrustedCommitmentTransaction) -> crate::lightning::ln::chan_utils::BuiltCommitmentTransaction {
1547 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.built_transaction();
1548 crate::lightning::ln::chan_utils::BuiltCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1551 /// The pre-calculated transaction creation public keys.
1554 pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitmentTransaction) -> crate::lightning::ln::chan_utils::TxCreationKeys {
1555 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.keys();
1556 crate::lightning::ln::chan_utils::TxCreationKeys { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const _) as *mut _) }, is_owned: false }
1559 /// Get a signature for each HTLC which was included in the commitment transaction (ie for
1560 /// which HTLCOutputInCommitment::transaction_output_index.is_some()).
1562 /// The returned Vec has one entry for each HTLC, and in the same order.
1565 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 {
1566 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);
1567 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() };
1571 /// Commitment transaction numbers which appear in the transactions themselves are XOR'd with a
1572 /// shared secret first. This prevents on-chain observers from discovering how many commitment
1573 /// transactions occurred in a channel before it was closed.
1575 /// This function gets the shared secret from relevant channel public keys and can be used to
1576 /// \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
1578 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 {
1579 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);