1 //! Various utilities for building scripts and deriving keys related to channels. These are
2 //! largely of interest for those implementing chain::keysinterface::ChannelKeys message signing
6 use bitcoin::hashes::Hash;
9 /// Build the commitment secret from the seed and the commitment number
11 pub extern "C" fn build_commitment_secret(commitment_seed: *const [u8; 32], mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
12 let mut ret = lightning::ln::chan_utils::build_commitment_secret(unsafe { &*commitment_seed}, idx);
13 crate::c_types::ThirtyTwoBytes { data: ret }
16 /// Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
17 /// from the base secret and the per_commitment_point.
19 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
20 /// generated (ie our own).
22 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 {
23 let mut ret = lightning::ln::chan_utils::derive_private_key(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *base_secret}[..]).unwrap());
24 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() };
28 /// Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
29 /// from the base point and the per_commitment_key. This is the public equivalent of
30 /// derive_private_key - using only public keys to derive a public key instead of private keys.
32 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
33 /// generated (ie our own).
35 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 {
36 let mut ret = lightning::ln::chan_utils::derive_public_key(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &base_point.into_rust());
37 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() };
41 /// Derives a per-commitment-transaction revocation key from its constituent parts.
43 /// Only the cheating participant owns a valid witness to propagate a revoked
44 /// commitment transaction, thus per_commitment_secret always come from cheater
45 /// and revocation_base_secret always come from punisher, which is the broadcaster
46 /// of the transaction spending with this key knowledge.
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_private_revocation_key(per_commitment_secret: *const [u8; 32], countersignatory_revocation_base_secret: *const [u8; 32]) -> crate::c_types::derived::CResult_SecretKeyErrorZ {
52 let mut ret = lightning::ln::chan_utils::derive_private_revocation_key(&bitcoin::secp256k1::Secp256k1::new(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *per_commitment_secret}[..]).unwrap(), &::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *countersignatory_revocation_base_secret}[..]).unwrap());
53 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() };
57 /// Derives a per-commitment-transaction revocation public key from its constituent parts. This is
58 /// the public equivalend of derive_private_revocation_key - using only public keys to derive a
59 /// public key instead of private keys.
61 /// Only the cheating participant owns a valid witness to propagate a revoked
62 /// commitment transaction, thus per_commitment_point always come from cheater
63 /// and revocation_base_point always come from punisher, which is the broadcaster
64 /// of the transaction spending with this key knowledge.
66 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
67 /// generated (ie our own).
69 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 {
70 let mut ret = lightning::ln::chan_utils::derive_public_revocation_key(&bitcoin::secp256k1::Secp256k1::new(), &per_commitment_point.into_rust(), &countersignatory_revocation_base_point.into_rust());
71 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() };
76 use lightning::ln::chan_utils::TxCreationKeys as nativeTxCreationKeysImport;
77 type nativeTxCreationKeys = nativeTxCreationKeysImport;
79 /// The set of public keys which are used in the creation of one commitment transaction.
80 /// These are derived from the channel base keys and per-commitment data.
82 /// A broadcaster key is provided from potential broadcaster of the computed transaction.
83 /// A countersignatory key is coming from a protocol participant unable to broadcast the
86 /// These keys are assumed to be good, either because the code derived them from
87 /// channel basepoints via the new function, or they were obtained via
88 /// CommitmentTransaction.trust().keys() because we trusted the source of the
89 /// pre-calculated keys.
92 pub struct TxCreationKeys {
93 /// Nearly everywhere, inner must be non-null, however in places where
94 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
95 pub inner: *mut nativeTxCreationKeys,
99 impl Drop for TxCreationKeys {
101 if self.is_owned && !self.inner.is_null() {
102 let _ = unsafe { Box::from_raw(self.inner) };
107 pub extern "C" fn TxCreationKeys_free(this_ptr: TxCreationKeys) { }
109 /// Used only if an object of this type is returned as a trait impl by a method
110 extern "C" fn TxCreationKeys_free_void(this_ptr: *mut c_void) {
111 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTxCreationKeys); }
114 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
115 impl TxCreationKeys {
116 pub(crate) fn take_inner(mut self) -> *mut nativeTxCreationKeys {
117 assert!(self.is_owned);
118 let ret = self.inner;
119 self.inner = std::ptr::null_mut();
123 /// The broadcaster's per-commitment public key which was used to derive the other keys.
125 pub extern "C" fn TxCreationKeys_get_per_commitment_point(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
126 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.per_commitment_point;
127 crate::c_types::PublicKey::from_rust(&(*inner_val))
129 /// The broadcaster's per-commitment public key which was used to derive the other keys.
131 pub extern "C" fn TxCreationKeys_set_per_commitment_point(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
132 unsafe { &mut *this_ptr.inner }.per_commitment_point = val.into_rust();
134 /// The revocation key which is used to allow the broadcaster of the commitment
135 /// transaction to provide their counterparty the ability to punish them if they broadcast
138 pub extern "C" fn TxCreationKeys_get_revocation_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
139 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_key;
140 crate::c_types::PublicKey::from_rust(&(*inner_val))
142 /// The revocation key which is used to allow the broadcaster of the commitment
143 /// transaction to provide their counterparty the ability to punish them if they broadcast
146 pub extern "C" fn TxCreationKeys_set_revocation_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
147 unsafe { &mut *this_ptr.inner }.revocation_key = val.into_rust();
149 /// Broadcaster's HTLC Key
151 pub extern "C" fn TxCreationKeys_get_broadcaster_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
152 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key;
153 crate::c_types::PublicKey::from_rust(&(*inner_val))
155 /// Broadcaster's HTLC Key
157 pub extern "C" fn TxCreationKeys_set_broadcaster_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
158 unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key = val.into_rust();
160 /// Countersignatory's HTLC Key
162 pub extern "C" fn TxCreationKeys_get_countersignatory_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
163 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key;
164 crate::c_types::PublicKey::from_rust(&(*inner_val))
166 /// Countersignatory's HTLC Key
168 pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
169 unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key = val.into_rust();
171 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
173 pub extern "C" fn TxCreationKeys_get_broadcaster_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
174 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key;
175 crate::c_types::PublicKey::from_rust(&(*inner_val))
177 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
179 pub extern "C" fn TxCreationKeys_set_broadcaster_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
180 unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key = val.into_rust();
184 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 {
185 TxCreationKeys { inner: Box::into_raw(Box::new(nativeTxCreationKeys {
186 per_commitment_point: per_commitment_point_arg.into_rust(),
187 revocation_key: revocation_key_arg.into_rust(),
188 broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(),
189 countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(),
190 broadcaster_delayed_payment_key: broadcaster_delayed_payment_key_arg.into_rust(),
191 })), is_owned: true }
193 impl Clone for TxCreationKeys {
194 fn clone(&self) -> Self {
196 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
197 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
203 /// Used only if an object of this type is returned as a trait impl by a method
204 pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
205 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxCreationKeys)).clone() })) as *mut c_void
208 pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys {
212 pub extern "C" fn TxCreationKeys_write(obj: &TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
213 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
216 pub(crate) extern "C" fn TxCreationKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
217 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxCreationKeys) })
220 pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_TxCreationKeysDecodeErrorZ {
221 let res = crate::c_types::deserialize_obj(ser);
222 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TxCreationKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
226 use lightning::ln::chan_utils::ChannelPublicKeys as nativeChannelPublicKeysImport;
227 type nativeChannelPublicKeys = nativeChannelPublicKeysImport;
229 /// One counterparty's public keys which do not change over the life of a channel.
232 pub struct ChannelPublicKeys {
233 /// Nearly everywhere, inner must be non-null, however in places where
234 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
235 pub inner: *mut nativeChannelPublicKeys,
239 impl Drop for ChannelPublicKeys {
241 if self.is_owned && !self.inner.is_null() {
242 let _ = unsafe { Box::from_raw(self.inner) };
247 pub extern "C" fn ChannelPublicKeys_free(this_ptr: ChannelPublicKeys) { }
249 /// Used only if an object of this type is returned as a trait impl by a method
250 extern "C" fn ChannelPublicKeys_free_void(this_ptr: *mut c_void) {
251 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelPublicKeys); }
254 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
255 impl ChannelPublicKeys {
256 pub(crate) fn take_inner(mut self) -> *mut nativeChannelPublicKeys {
257 assert!(self.is_owned);
258 let ret = self.inner;
259 self.inner = std::ptr::null_mut();
263 /// The public key which is used to sign all commitment transactions, as it appears in the
264 /// on-chain channel lock-in 2-of-2 multisig output.
266 pub extern "C" fn ChannelPublicKeys_get_funding_pubkey(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
267 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_pubkey;
268 crate::c_types::PublicKey::from_rust(&(*inner_val))
270 /// The public key which is used to sign all commitment transactions, as it appears in the
271 /// on-chain channel lock-in 2-of-2 multisig output.
273 pub extern "C" fn ChannelPublicKeys_set_funding_pubkey(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
274 unsafe { &mut *this_ptr.inner }.funding_pubkey = val.into_rust();
276 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
277 /// revocation keys. This is combined with the per-commitment-secret generated by the
278 /// counterparty to create a secret which the counterparty can reveal to revoke previous
281 pub extern "C" fn ChannelPublicKeys_get_revocation_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
282 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_basepoint;
283 crate::c_types::PublicKey::from_rust(&(*inner_val))
285 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
286 /// revocation keys. This is combined with the per-commitment-secret generated by the
287 /// counterparty to create a secret which the counterparty can reveal to revoke previous
290 pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
291 unsafe { &mut *this_ptr.inner }.revocation_basepoint = val.into_rust();
293 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
294 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
295 /// static across every commitment transaction.
297 pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
298 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_point;
299 crate::c_types::PublicKey::from_rust(&(*inner_val))
301 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
302 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
303 /// static across every commitment transaction.
305 pub extern "C" fn ChannelPublicKeys_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
306 unsafe { &mut *this_ptr.inner }.payment_point = val.into_rust();
308 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
309 /// public key which receives non-HTLC-encumbered funds which are only available for spending
310 /// after some delay (or can be claimed via the revocation path).
312 pub extern "C" fn ChannelPublicKeys_get_delayed_payment_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
313 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint;
314 crate::c_types::PublicKey::from_rust(&(*inner_val))
316 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
317 /// public key which receives non-HTLC-encumbered funds which are only available for spending
318 /// after some delay (or can be claimed via the revocation path).
320 pub extern "C" fn ChannelPublicKeys_set_delayed_payment_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
321 unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint = val.into_rust();
323 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
324 /// which is used to encumber HTLC-in-flight outputs.
326 pub extern "C" fn ChannelPublicKeys_get_htlc_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
327 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_basepoint;
328 crate::c_types::PublicKey::from_rust(&(*inner_val))
330 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
331 /// which is used to encumber HTLC-in-flight outputs.
333 pub extern "C" fn ChannelPublicKeys_set_htlc_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
334 unsafe { &mut *this_ptr.inner }.htlc_basepoint = val.into_rust();
338 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 {
339 ChannelPublicKeys { inner: Box::into_raw(Box::new(nativeChannelPublicKeys {
340 funding_pubkey: funding_pubkey_arg.into_rust(),
341 revocation_basepoint: revocation_basepoint_arg.into_rust(),
342 payment_point: payment_point_arg.into_rust(),
343 delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(),
344 htlc_basepoint: htlc_basepoint_arg.into_rust(),
345 })), is_owned: true }
347 impl Clone for ChannelPublicKeys {
348 fn clone(&self) -> Self {
350 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
351 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
357 /// Used only if an object of this type is returned as a trait impl by a method
358 pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
359 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelPublicKeys)).clone() })) as *mut c_void
362 pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys {
366 pub extern "C" fn ChannelPublicKeys_write(obj: &ChannelPublicKeys) -> crate::c_types::derived::CVec_u8Z {
367 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
370 pub(crate) extern "C" fn ChannelPublicKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
371 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelPublicKeys) })
374 pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelPublicKeysDecodeErrorZ {
375 let res = crate::c_types::deserialize_obj(ser);
376 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::ChannelPublicKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
379 /// Create per-state keys from channel base points and the per-commitment point.
380 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
383 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 {
384 let mut ret = lightning::ln::chan_utils::TxCreationKeys::derive_new(&bitcoin::secp256k1::Secp256k1::new(), &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());
385 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TxCreationKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
389 /// Generate per-state keys from channel static keys.
390 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
393 pub extern "C" fn TxCreationKeys_from_channel_static_keys(mut per_commitment_point: crate::c_types::PublicKey, broadcaster_keys: &crate::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TxCreationKeysErrorZ {
394 let mut ret = lightning::ln::chan_utils::TxCreationKeys::from_channel_static_keys(&per_commitment_point.into_rust(), unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, &bitcoin::secp256k1::Secp256k1::new());
395 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TxCreationKeys { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
399 /// A script either spendable by the revocation
400 /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
401 /// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
403 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 {
404 let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), contest_delay, &broadcaster_delayed_payment_key.into_rust());
405 ret.into_bytes().into()
409 use lightning::ln::chan_utils::HTLCOutputInCommitment as nativeHTLCOutputInCommitmentImport;
410 type nativeHTLCOutputInCommitment = nativeHTLCOutputInCommitmentImport;
412 /// Information about an HTLC as it appears in a commitment transaction
415 pub struct HTLCOutputInCommitment {
416 /// Nearly everywhere, inner must be non-null, however in places where
417 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
418 pub inner: *mut nativeHTLCOutputInCommitment,
422 impl Drop for HTLCOutputInCommitment {
424 if self.is_owned && !self.inner.is_null() {
425 let _ = unsafe { Box::from_raw(self.inner) };
430 pub extern "C" fn HTLCOutputInCommitment_free(this_ptr: HTLCOutputInCommitment) { }
432 /// Used only if an object of this type is returned as a trait impl by a method
433 extern "C" fn HTLCOutputInCommitment_free_void(this_ptr: *mut c_void) {
434 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCOutputInCommitment); }
437 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
438 impl HTLCOutputInCommitment {
439 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCOutputInCommitment {
440 assert!(self.is_owned);
441 let ret = self.inner;
442 self.inner = std::ptr::null_mut();
446 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
447 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
448 /// need to compare this value to whether the commitment transaction in question is that of
449 /// the counterparty or our own.
451 pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool {
452 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.offered;
455 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
456 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
457 /// need to compare this value to whether the commitment transaction in question is that of
458 /// the counterparty or our own.
460 pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) {
461 unsafe { &mut *this_ptr.inner }.offered = val;
463 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
464 /// this divided by 1000.
466 pub extern "C" fn HTLCOutputInCommitment_get_amount_msat(this_ptr: &HTLCOutputInCommitment) -> u64 {
467 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.amount_msat;
470 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
471 /// this divided by 1000.
473 pub extern "C" fn HTLCOutputInCommitment_set_amount_msat(this_ptr: &mut HTLCOutputInCommitment, mut val: u64) {
474 unsafe { &mut *this_ptr.inner }.amount_msat = val;
476 /// The CLTV lock-time at which this HTLC expires.
478 pub extern "C" fn HTLCOutputInCommitment_get_cltv_expiry(this_ptr: &HTLCOutputInCommitment) -> u32 {
479 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry;
482 /// The CLTV lock-time at which this HTLC expires.
484 pub extern "C" fn HTLCOutputInCommitment_set_cltv_expiry(this_ptr: &mut HTLCOutputInCommitment, mut val: u32) {
485 unsafe { &mut *this_ptr.inner }.cltv_expiry = val;
487 /// The hash of the preimage which unlocks this HTLC.
489 pub extern "C" fn HTLCOutputInCommitment_get_payment_hash(this_ptr: &HTLCOutputInCommitment) -> *const [u8; 32] {
490 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_hash;
493 /// The hash of the preimage which unlocks this HTLC.
495 pub extern "C" fn HTLCOutputInCommitment_set_payment_hash(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::ThirtyTwoBytes) {
496 unsafe { &mut *this_ptr.inner }.payment_hash = ::lightning::ln::channelmanager::PaymentHash(val.data);
498 impl Clone for HTLCOutputInCommitment {
499 fn clone(&self) -> Self {
501 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
502 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
508 /// Used only if an object of this type is returned as a trait impl by a method
509 pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_void) -> *mut c_void {
510 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCOutputInCommitment)).clone() })) as *mut c_void
513 pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment {
517 pub extern "C" fn HTLCOutputInCommitment_write(obj: &HTLCOutputInCommitment) -> crate::c_types::derived::CVec_u8Z {
518 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
521 pub(crate) extern "C" fn HTLCOutputInCommitment_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
522 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCOutputInCommitment) })
525 pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCOutputInCommitmentDecodeErrorZ {
526 let res = crate::c_types::deserialize_obj(ser);
527 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::HTLCOutputInCommitment { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
530 /// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
531 /// does not need to have its previous_output_index filled.
533 pub extern "C" fn get_htlc_redeemscript(htlc: &crate::ln::chan_utils::HTLCOutputInCommitment, keys: &crate::ln::chan_utils::TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
534 let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(unsafe { &*htlc.inner }, unsafe { &*keys.inner });
535 ret.into_bytes().into()
538 /// Gets the redeemscript for a funding output from the two funding public keys.
539 /// Note that the order of funding public keys does not matter.
541 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 {
542 let mut ret = lightning::ln::chan_utils::make_funding_redeemscript(&broadcaster.into_rust(), &countersignatory.into_rust());
543 ret.into_bytes().into()
546 /// panics if htlc.transaction_output_index.is_none()!
548 pub extern "C" fn build_htlc_transaction(prev_hash: *const [u8; 32], mut feerate_per_kw: u32, mut contest_delay: u16, htlc: &crate::ln::chan_utils::HTLCOutputInCommitment, mut broadcaster_delayed_payment_key: crate::c_types::PublicKey, mut revocation_key: crate::c_types::PublicKey) -> crate::c_types::Transaction {
549 let mut ret = lightning::ln::chan_utils::build_htlc_transaction(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*prev_hash }[..]).unwrap(), feerate_per_kw, contest_delay, unsafe { &*htlc.inner }, &broadcaster_delayed_payment_key.into_rust(), &revocation_key.into_rust());
550 let mut local_ret = ::bitcoin::consensus::encode::serialize(&ret);
551 crate::c_types::Transaction::from_vec(local_ret)
555 use lightning::ln::chan_utils::ChannelTransactionParameters as nativeChannelTransactionParametersImport;
556 type nativeChannelTransactionParameters = nativeChannelTransactionParametersImport;
558 /// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction).
559 /// The fields are organized by holder/counterparty.
561 /// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters
562 /// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions.
565 pub struct ChannelTransactionParameters {
566 /// Nearly everywhere, inner must be non-null, however in places where
567 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
568 pub inner: *mut nativeChannelTransactionParameters,
572 impl Drop for ChannelTransactionParameters {
574 if self.is_owned && !self.inner.is_null() {
575 let _ = unsafe { Box::from_raw(self.inner) };
580 pub extern "C" fn ChannelTransactionParameters_free(this_ptr: ChannelTransactionParameters) { }
582 /// Used only if an object of this type is returned as a trait impl by a method
583 extern "C" fn ChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
584 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTransactionParameters); }
587 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
588 impl ChannelTransactionParameters {
589 pub(crate) fn take_inner(mut self) -> *mut nativeChannelTransactionParameters {
590 assert!(self.is_owned);
591 let ret = self.inner;
592 self.inner = std::ptr::null_mut();
596 /// Holder public keys
598 pub extern "C" fn ChannelTransactionParameters_get_holder_pubkeys(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
599 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_pubkeys;
600 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
602 /// Holder public keys
604 pub extern "C" fn ChannelTransactionParameters_set_holder_pubkeys(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) {
605 unsafe { &mut *this_ptr.inner }.holder_pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
607 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
609 pub extern "C" fn ChannelTransactionParameters_get_holder_selected_contest_delay(this_ptr: &ChannelTransactionParameters) -> u16 {
610 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay;
613 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
615 pub extern "C" fn ChannelTransactionParameters_set_holder_selected_contest_delay(this_ptr: &mut ChannelTransactionParameters, mut val: u16) {
616 unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay = val;
618 /// Whether the holder is the initiator of this channel.
619 /// This is an input to the commitment number obscure factor computation.
621 pub extern "C" fn ChannelTransactionParameters_get_is_outbound_from_holder(this_ptr: &ChannelTransactionParameters) -> bool {
622 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_outbound_from_holder;
625 /// Whether the holder is the initiator of this channel.
626 /// This is an input to the commitment number obscure factor computation.
628 pub extern "C" fn ChannelTransactionParameters_set_is_outbound_from_holder(this_ptr: &mut ChannelTransactionParameters, mut val: bool) {
629 unsafe { &mut *this_ptr.inner }.is_outbound_from_holder = val;
631 /// The late-bound counterparty channel transaction parameters.
632 /// These parameters are populated at the point in the protocol where the counterparty provides them.
634 pub extern "C" fn ChannelTransactionParameters_get_counterparty_parameters(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::CounterpartyChannelTransactionParameters {
635 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_parameters;
636 let mut local_inner_val = crate::ln::chan_utils::CounterpartyChannelTransactionParameters { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
639 /// The late-bound counterparty channel transaction parameters.
640 /// These parameters are populated at the point in the protocol where the counterparty provides them.
642 pub extern "C" fn ChannelTransactionParameters_set_counterparty_parameters(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::CounterpartyChannelTransactionParameters) {
643 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
644 unsafe { &mut *this_ptr.inner }.counterparty_parameters = local_val;
646 /// The late-bound funding outpoint
648 pub extern "C" fn ChannelTransactionParameters_get_funding_outpoint(this_ptr: &ChannelTransactionParameters) -> crate::chain::transaction::OutPoint {
649 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_outpoint;
650 let mut local_inner_val = crate::chain::transaction::OutPoint { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
653 /// The late-bound funding outpoint
655 pub extern "C" fn ChannelTransactionParameters_set_funding_outpoint(this_ptr: &mut ChannelTransactionParameters, mut val: crate::chain::transaction::OutPoint) {
656 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
657 unsafe { &mut *this_ptr.inner }.funding_outpoint = local_val;
661 pub extern "C" fn ChannelTransactionParameters_new(mut holder_pubkeys_arg: crate::ln::chan_utils::ChannelPublicKeys, mut holder_selected_contest_delay_arg: u16, mut is_outbound_from_holder_arg: bool, mut counterparty_parameters_arg: crate::ln::chan_utils::CounterpartyChannelTransactionParameters, mut funding_outpoint_arg: crate::chain::transaction::OutPoint) -> ChannelTransactionParameters {
662 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()) } }) };
663 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()) } }) };
664 ChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeChannelTransactionParameters {
665 holder_pubkeys: *unsafe { Box::from_raw(holder_pubkeys_arg.take_inner()) },
666 holder_selected_contest_delay: holder_selected_contest_delay_arg,
667 is_outbound_from_holder: is_outbound_from_holder_arg,
668 counterparty_parameters: local_counterparty_parameters_arg,
669 funding_outpoint: local_funding_outpoint_arg,
670 })), is_owned: true }
672 impl Clone for ChannelTransactionParameters {
673 fn clone(&self) -> Self {
675 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
676 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
682 /// Used only if an object of this type is returned as a trait impl by a method
683 pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
684 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTransactionParameters)).clone() })) as *mut c_void
687 pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters {
691 use lightning::ln::chan_utils::CounterpartyChannelTransactionParameters as nativeCounterpartyChannelTransactionParametersImport;
692 type nativeCounterpartyChannelTransactionParameters = nativeCounterpartyChannelTransactionParametersImport;
694 /// Late-bound per-channel counterparty data used to build transactions.
697 pub struct CounterpartyChannelTransactionParameters {
698 /// Nearly everywhere, inner must be non-null, however in places where
699 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
700 pub inner: *mut nativeCounterpartyChannelTransactionParameters,
704 impl Drop for CounterpartyChannelTransactionParameters {
706 if self.is_owned && !self.inner.is_null() {
707 let _ = unsafe { Box::from_raw(self.inner) };
712 pub extern "C" fn CounterpartyChannelTransactionParameters_free(this_ptr: CounterpartyChannelTransactionParameters) { }
714 /// Used only if an object of this type is returned as a trait impl by a method
715 extern "C" fn CounterpartyChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
716 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyChannelTransactionParameters); }
719 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
720 impl CounterpartyChannelTransactionParameters {
721 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyChannelTransactionParameters {
722 assert!(self.is_owned);
723 let ret = self.inner;
724 self.inner = std::ptr::null_mut();
728 /// Counter-party public keys
730 pub extern "C" fn CounterpartyChannelTransactionParameters_get_pubkeys(this_ptr: &CounterpartyChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
731 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.pubkeys;
732 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
734 /// Counter-party public keys
736 pub extern "C" fn CounterpartyChannelTransactionParameters_set_pubkeys(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) {
737 unsafe { &mut *this_ptr.inner }.pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
739 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
741 pub extern "C" fn CounterpartyChannelTransactionParameters_get_selected_contest_delay(this_ptr: &CounterpartyChannelTransactionParameters) -> u16 {
742 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.selected_contest_delay;
745 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
747 pub extern "C" fn CounterpartyChannelTransactionParameters_set_selected_contest_delay(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: u16) {
748 unsafe { &mut *this_ptr.inner }.selected_contest_delay = val;
752 pub extern "C" fn CounterpartyChannelTransactionParameters_new(mut pubkeys_arg: crate::ln::chan_utils::ChannelPublicKeys, mut selected_contest_delay_arg: u16) -> CounterpartyChannelTransactionParameters {
753 CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeCounterpartyChannelTransactionParameters {
754 pubkeys: *unsafe { Box::from_raw(pubkeys_arg.take_inner()) },
755 selected_contest_delay: selected_contest_delay_arg,
756 })), is_owned: true }
758 impl Clone for CounterpartyChannelTransactionParameters {
759 fn clone(&self) -> Self {
761 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
762 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
768 /// Used only if an object of this type is returned as a trait impl by a method
769 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
770 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void
773 pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters {
776 /// Whether the late bound parameters are populated.
779 pub extern "C" fn ChannelTransactionParameters_is_populated(this_arg: &ChannelTransactionParameters) -> bool {
780 let mut ret = unsafe { &*this_arg.inner }.is_populated();
784 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
785 /// given that the holder is the broadcaster.
787 /// self.is_populated() must be true before calling this function.
790 pub extern "C" fn ChannelTransactionParameters_as_holder_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters {
791 let mut ret = unsafe { &*this_arg.inner }.as_holder_broadcastable();
792 crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true }
795 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
796 /// given that the counterparty is the broadcaster.
798 /// self.is_populated() must be true before calling this function.
801 pub extern "C" fn ChannelTransactionParameters_as_counterparty_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters {
802 let mut ret = unsafe { &*this_arg.inner }.as_counterparty_broadcastable();
803 crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true }
807 pub extern "C" fn CounterpartyChannelTransactionParameters_write(obj: &CounterpartyChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
808 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
811 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
812 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyChannelTransactionParameters) })
815 pub extern "C" fn CounterpartyChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyChannelTransactionParametersDecodeErrorZ {
816 let res = crate::c_types::deserialize_obj(ser);
817 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
821 pub extern "C" fn ChannelTransactionParameters_write(obj: &ChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
822 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
825 pub(crate) extern "C" fn ChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
826 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTransactionParameters) })
829 pub extern "C" fn ChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelTransactionParametersDecodeErrorZ {
830 let res = crate::c_types::deserialize_obj(ser);
831 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::ChannelTransactionParameters { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
835 use lightning::ln::chan_utils::DirectedChannelTransactionParameters as nativeDirectedChannelTransactionParametersImport;
836 type nativeDirectedChannelTransactionParameters = nativeDirectedChannelTransactionParametersImport<'static>;
838 /// Static channel fields used to build transactions given per-commitment fields, organized by
839 /// broadcaster/countersignatory.
841 /// This is derived from the holder/counterparty-organized ChannelTransactionParameters via the
842 /// as_holder_broadcastable and as_counterparty_broadcastable functions.
845 pub struct DirectedChannelTransactionParameters {
846 /// Nearly everywhere, inner must be non-null, however in places where
847 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
848 pub inner: *mut nativeDirectedChannelTransactionParameters,
852 impl Drop for DirectedChannelTransactionParameters {
854 if self.is_owned && !self.inner.is_null() {
855 let _ = unsafe { Box::from_raw(self.inner) };
860 pub extern "C" fn DirectedChannelTransactionParameters_free(this_ptr: DirectedChannelTransactionParameters) { }
862 /// Used only if an object of this type is returned as a trait impl by a method
863 extern "C" fn DirectedChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
864 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelTransactionParameters); }
867 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
868 impl DirectedChannelTransactionParameters {
869 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelTransactionParameters {
870 assert!(self.is_owned);
871 let ret = self.inner;
872 self.inner = std::ptr::null_mut();
876 /// Get the channel pubkeys for the broadcaster
879 pub extern "C" fn DirectedChannelTransactionParameters_broadcaster_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
880 let mut ret = unsafe { &*this_arg.inner }.broadcaster_pubkeys();
881 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
884 /// Get the channel pubkeys for the countersignatory
887 pub extern "C" fn DirectedChannelTransactionParameters_countersignatory_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
888 let mut ret = unsafe { &*this_arg.inner }.countersignatory_pubkeys();
889 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
892 /// Get the contest delay applicable to the transactions.
893 /// Note that the contest delay was selected by the countersignatory.
896 pub extern "C" fn DirectedChannelTransactionParameters_contest_delay(this_arg: &DirectedChannelTransactionParameters) -> u16 {
897 let mut ret = unsafe { &*this_arg.inner }.contest_delay();
901 /// Whether the channel is outbound from the broadcaster.
903 /// The boolean representing the side that initiated the channel is
904 /// an input to the commitment number obscure factor computation.
907 pub extern "C" fn DirectedChannelTransactionParameters_is_outbound(this_arg: &DirectedChannelTransactionParameters) -> bool {
908 let mut ret = unsafe { &*this_arg.inner }.is_outbound();
912 /// The funding outpoint
915 pub extern "C" fn DirectedChannelTransactionParameters_funding_outpoint(this_arg: &DirectedChannelTransactionParameters) -> crate::chain::transaction::OutPoint {
916 let mut ret = unsafe { &*this_arg.inner }.funding_outpoint();
917 crate::c_types::bitcoin_to_C_outpoint(ret)
921 use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport;
922 type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport;
924 /// Information needed to build and sign a holder's commitment transaction.
926 /// The transaction is only signed once we are ready to broadcast.
929 pub struct HolderCommitmentTransaction {
930 /// Nearly everywhere, inner must be non-null, however in places where
931 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
932 pub inner: *mut nativeHolderCommitmentTransaction,
936 impl Drop for HolderCommitmentTransaction {
938 if self.is_owned && !self.inner.is_null() {
939 let _ = unsafe { Box::from_raw(self.inner) };
944 pub extern "C" fn HolderCommitmentTransaction_free(this_ptr: HolderCommitmentTransaction) { }
946 /// Used only if an object of this type is returned as a trait impl by a method
947 extern "C" fn HolderCommitmentTransaction_free_void(this_ptr: *mut c_void) {
948 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHolderCommitmentTransaction); }
951 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
952 impl HolderCommitmentTransaction {
953 pub(crate) fn take_inner(mut self) -> *mut nativeHolderCommitmentTransaction {
954 assert!(self.is_owned);
955 let ret = self.inner;
956 self.inner = std::ptr::null_mut();
960 /// Our counterparty's signature for the transaction
962 pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature {
963 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_sig;
964 crate::c_types::Signature::from_rust(&(*inner_val))
966 /// Our counterparty's signature for the transaction
968 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) {
969 unsafe { &mut *this_ptr.inner }.counterparty_sig = val.into_rust();
971 /// All non-dust counterparty HTLC signatures, in the order they appear in the transaction
973 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_htlc_sigs(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_SignatureZ) {
974 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); };
975 unsafe { &mut *this_ptr.inner }.counterparty_htlc_sigs = local_val;
977 impl Clone for HolderCommitmentTransaction {
978 fn clone(&self) -> Self {
980 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
981 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
987 /// Used only if an object of this type is returned as a trait impl by a method
988 pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
989 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void
992 pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction {
996 pub extern "C" fn HolderCommitmentTransaction_write(obj: &HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
997 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1000 pub(crate) extern "C" fn HolderCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1001 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHolderCommitmentTransaction) })
1004 pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HolderCommitmentTransactionDecodeErrorZ {
1005 let res = crate::c_types::deserialize_obj(ser);
1006 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::HolderCommitmentTransaction { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1009 /// Create a new holder transaction with the given counterparty signatures.
1010 /// The funding keys are used to figure out which signature should go first when building the transaction for broadcast.
1013 pub extern "C" fn HolderCommitmentTransaction_new(mut commitment_tx: crate::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 {
1014 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() }); };
1015 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());
1016 HolderCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1020 use lightning::ln::chan_utils::BuiltCommitmentTransaction as nativeBuiltCommitmentTransactionImport;
1021 type nativeBuiltCommitmentTransaction = nativeBuiltCommitmentTransactionImport;
1023 /// A pre-built Bitcoin commitment transaction and its txid.
1026 pub struct BuiltCommitmentTransaction {
1027 /// Nearly everywhere, inner must be non-null, however in places where
1028 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1029 pub inner: *mut nativeBuiltCommitmentTransaction,
1033 impl Drop for BuiltCommitmentTransaction {
1034 fn drop(&mut self) {
1035 if self.is_owned && !self.inner.is_null() {
1036 let _ = unsafe { Box::from_raw(self.inner) };
1041 pub extern "C" fn BuiltCommitmentTransaction_free(this_ptr: BuiltCommitmentTransaction) { }
1043 /// Used only if an object of this type is returned as a trait impl by a method
1044 extern "C" fn BuiltCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1045 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBuiltCommitmentTransaction); }
1048 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1049 impl BuiltCommitmentTransaction {
1050 pub(crate) fn take_inner(mut self) -> *mut nativeBuiltCommitmentTransaction {
1051 assert!(self.is_owned);
1052 let ret = self.inner;
1053 self.inner = std::ptr::null_mut();
1057 /// The commitment transaction
1059 pub extern "C" fn BuiltCommitmentTransaction_get_transaction(this_ptr: &BuiltCommitmentTransaction) -> crate::c_types::Transaction {
1060 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.transaction;
1061 let mut local_inner_val = ::bitcoin::consensus::encode::serialize(inner_val);
1062 crate::c_types::Transaction::from_vec(local_inner_val)
1064 /// The commitment transaction
1066 pub extern "C" fn BuiltCommitmentTransaction_set_transaction(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::Transaction) {
1067 unsafe { &mut *this_ptr.inner }.transaction = val.into_bitcoin();
1069 /// The txid for the commitment transaction.
1071 /// This is provided as a performance optimization, instead of calling transaction.txid()
1074 pub extern "C" fn BuiltCommitmentTransaction_get_txid(this_ptr: &BuiltCommitmentTransaction) -> *const [u8; 32] {
1075 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.txid;
1076 (*inner_val).as_inner()
1078 /// The txid for the commitment transaction.
1080 /// This is provided as a performance optimization, instead of calling transaction.txid()
1083 pub extern "C" fn BuiltCommitmentTransaction_set_txid(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::ThirtyTwoBytes) {
1084 unsafe { &mut *this_ptr.inner }.txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap();
1088 pub extern "C" fn BuiltCommitmentTransaction_new(mut transaction_arg: crate::c_types::Transaction, mut txid_arg: crate::c_types::ThirtyTwoBytes) -> BuiltCommitmentTransaction {
1089 BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(nativeBuiltCommitmentTransaction {
1090 transaction: transaction_arg.into_bitcoin(),
1091 txid: ::bitcoin::hash_types::Txid::from_slice(&txid_arg.data[..]).unwrap(),
1092 })), is_owned: true }
1094 impl Clone for BuiltCommitmentTransaction {
1095 fn clone(&self) -> Self {
1097 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
1098 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1104 /// Used only if an object of this type is returned as a trait impl by a method
1105 pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1106 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void
1109 pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction {
1113 pub extern "C" fn BuiltCommitmentTransaction_write(obj: &BuiltCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1114 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1117 pub(crate) extern "C" fn BuiltCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1118 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBuiltCommitmentTransaction) })
1121 pub extern "C" fn BuiltCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BuiltCommitmentTransactionDecodeErrorZ {
1122 let res = crate::c_types::deserialize_obj(ser);
1123 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1126 /// Get the SIGHASH_ALL sighash value of the transaction.
1128 /// This can be used to verify a signature.
1131 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 {
1132 let mut ret = unsafe { &*this_arg.inner }.get_sighash_all(&::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis);
1133 crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() }
1136 /// Sign a transaction, either because we are counter-signing the counterparty's transaction or
1137 /// because we are about to broadcast a holder transaction.
1140 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 {
1141 let mut ret = unsafe { &*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, &bitcoin::secp256k1::Secp256k1::new());
1142 crate::c_types::Signature::from_rust(&ret)
1146 use lightning::ln::chan_utils::CommitmentTransaction as nativeCommitmentTransactionImport;
1147 type nativeCommitmentTransaction = nativeCommitmentTransactionImport;
1149 /// This class tracks the per-transaction information needed to build a commitment transaction and to
1150 /// actually build it and sign. It is used for holder transactions that we sign only when needed
1151 /// and for transactions we sign for the counterparty.
1153 /// This class can be used inside a signer implementation to generate a signature given the relevant
1157 pub struct CommitmentTransaction {
1158 /// Nearly everywhere, inner must be non-null, however in places where
1159 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1160 pub inner: *mut nativeCommitmentTransaction,
1164 impl Drop for CommitmentTransaction {
1165 fn drop(&mut self) {
1166 if self.is_owned && !self.inner.is_null() {
1167 let _ = unsafe { Box::from_raw(self.inner) };
1172 pub extern "C" fn CommitmentTransaction_free(this_ptr: CommitmentTransaction) { }
1174 /// Used only if an object of this type is returned as a trait impl by a method
1175 extern "C" fn CommitmentTransaction_free_void(this_ptr: *mut c_void) {
1176 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentTransaction); }
1179 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1180 impl CommitmentTransaction {
1181 pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentTransaction {
1182 assert!(self.is_owned);
1183 let ret = self.inner;
1184 self.inner = std::ptr::null_mut();
1188 impl Clone for CommitmentTransaction {
1189 fn clone(&self) -> Self {
1191 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
1192 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1198 /// Used only if an object of this type is returned as a trait impl by a method
1199 pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1200 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void
1203 pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction {
1207 pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1208 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1211 pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1212 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) })
1215 pub extern "C" fn CommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentTransactionDecodeErrorZ {
1216 let res = crate::c_types::deserialize_obj(ser);
1217 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::CommitmentTransaction { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1220 /// The backwards-counting commitment number
1223 pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &CommitmentTransaction) -> u64 {
1224 let mut ret = unsafe { &*this_arg.inner }.commitment_number();
1228 /// The value to be sent to the broadcaster
1231 pub extern "C" fn CommitmentTransaction_to_broadcaster_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1232 let mut ret = unsafe { &*this_arg.inner }.to_broadcaster_value_sat();
1236 /// The value to be sent to the counterparty
1239 pub extern "C" fn CommitmentTransaction_to_countersignatory_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1240 let mut ret = unsafe { &*this_arg.inner }.to_countersignatory_value_sat();
1244 /// The feerate paid per 1000-weight-unit in this commitment transaction.
1247 pub extern "C" fn CommitmentTransaction_feerate_per_kw(this_arg: &CommitmentTransaction) -> u32 {
1248 let mut ret = unsafe { &*this_arg.inner }.feerate_per_kw();
1252 /// Trust our pre-built transaction and derived transaction creation public keys.
1254 /// Applies a wrapper which allows access to these fields.
1256 /// This should only be used if you fully trust the builder of this object. It should not
1257 ///\tbe used by an external signer - instead use the verify function.
1260 pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction) -> crate::ln::chan_utils::TrustedCommitmentTransaction {
1261 let mut ret = unsafe { &*this_arg.inner }.trust();
1262 crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1265 /// Verify our pre-built transaction and derived transaction creation public keys.
1267 /// Applies a wrapper which allows access to these fields.
1269 /// An external validating signer must call this method before signing
1270 /// or using the built transaction.
1273 pub extern "C" fn CommitmentTransaction_verify(this_arg: &CommitmentTransaction, channel_parameters: &crate::ln::chan_utils::DirectedChannelTransactionParameters, broadcaster_keys: &crate::ln::chan_utils::ChannelPublicKeys, countersignatory_keys: &crate::ln::chan_utils::ChannelPublicKeys) -> crate::c_types::derived::CResult_TrustedCommitmentTransactionNoneZ {
1274 let mut ret = unsafe { &*this_arg.inner }.verify(unsafe { &*channel_parameters.inner }, unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, &bitcoin::secp256k1::Secp256k1::new());
1275 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }).into() };
1280 use lightning::ln::chan_utils::TrustedCommitmentTransaction as nativeTrustedCommitmentTransactionImport;
1281 type nativeTrustedCommitmentTransaction = nativeTrustedCommitmentTransactionImport<'static>;
1283 /// A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin
1284 /// transaction and the transaction creation keys) are trusted.
1286 /// See trust() and verify() functions on CommitmentTransaction.
1288 /// This structure implements Deref.
1291 pub struct TrustedCommitmentTransaction {
1292 /// Nearly everywhere, inner must be non-null, however in places where
1293 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1294 pub inner: *mut nativeTrustedCommitmentTransaction,
1298 impl Drop for TrustedCommitmentTransaction {
1299 fn drop(&mut self) {
1300 if self.is_owned && !self.inner.is_null() {
1301 let _ = unsafe { Box::from_raw(self.inner) };
1306 pub extern "C" fn TrustedCommitmentTransaction_free(this_ptr: TrustedCommitmentTransaction) { }
1308 /// Used only if an object of this type is returned as a trait impl by a method
1309 extern "C" fn TrustedCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1310 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedCommitmentTransaction); }
1313 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1314 impl TrustedCommitmentTransaction {
1315 pub(crate) fn take_inner(mut self) -> *mut nativeTrustedCommitmentTransaction {
1316 assert!(self.is_owned);
1317 let ret = self.inner;
1318 self.inner = std::ptr::null_mut();
1322 /// The transaction ID of the built Bitcoin transaction
1325 pub extern "C" fn TrustedCommitmentTransaction_txid(this_arg: &TrustedCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
1326 let mut ret = unsafe { &*this_arg.inner }.txid();
1327 crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
1330 /// The pre-built Bitcoin commitment transaction
1333 pub extern "C" fn TrustedCommitmentTransaction_built_transaction(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::BuiltCommitmentTransaction {
1334 let mut ret = unsafe { &*this_arg.inner }.built_transaction();
1335 crate::ln::chan_utils::BuiltCommitmentTransaction { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1338 /// The pre-calculated transaction creation public keys.
1341 pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys {
1342 let mut ret = unsafe { &*this_arg.inner }.keys();
1343 crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1346 /// Get a signature for each HTLC which was included in the commitment transaction (ie for
1347 /// which HTLCOutputInCommitment::transaction_output_index.is_some()).
1349 /// The returned Vec has one entry for each HTLC, and in the same order.
1352 pub extern "C" fn TrustedCommitmentTransaction_get_htlc_sigs(this_arg: &TrustedCommitmentTransaction, htlc_base_key: *const [u8; 32], channel_parameters: &crate::ln::chan_utils::DirectedChannelTransactionParameters) -> crate::c_types::derived::CResult_CVec_SignatureZNoneZ {
1353 let mut ret = unsafe { &*this_arg.inner }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), unsafe { &*channel_parameters.inner }, &bitcoin::secp256k1::Secp256k1::new());
1354 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for 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( { 0u8 /*e*/ }).into() };
1358 /// Get the transaction number obscure factor
1360 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 {
1361 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);