1 //! Various utilities for building scripts and deriving keys related to channels. These are
2 //! largely of interest for those implementing chain::keysinterface::Sign message signing by hand.
5 use bitcoin::hashes::Hash;
8 /// Build the commitment secret from the seed and the commitment number
10 pub extern "C" fn build_commitment_secret(commitment_seed: *const [u8; 32], mut idx: u64) -> crate::c_types::ThirtyTwoBytes {
11 let mut ret = lightning::ln::chan_utils::build_commitment_secret(unsafe { &*commitment_seed}, idx);
12 crate::c_types::ThirtyTwoBytes { data: ret }
15 /// Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
16 /// from the base secret and the per_commitment_point.
18 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
19 /// generated (ie our own).
21 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 {
22 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());
23 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() };
27 /// Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
28 /// from the base point and the per_commitment_key. This is the public equivalent of
29 /// derive_private_key - using only public keys to derive a public key instead of private keys.
31 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
32 /// generated (ie our own).
34 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 {
35 let mut ret = lightning::ln::chan_utils::derive_public_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &base_point.into_rust());
36 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() };
40 /// Derives a per-commitment-transaction revocation key from its constituent parts.
42 /// Only the cheating participant owns a valid witness to propagate a revoked
43 /// commitment transaction, thus per_commitment_secret always come from cheater
44 /// and revocation_base_secret always come from punisher, which is the broadcaster
45 /// of the transaction spending with this key knowledge.
47 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
48 /// generated (ie our own).
50 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 {
51 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());
52 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() };
56 /// Derives a per-commitment-transaction revocation public key from its constituent parts. This is
57 /// the public equivalend of derive_private_revocation_key - using only public keys to derive a
58 /// public key instead of private keys.
60 /// Only the cheating participant owns a valid witness to propagate a revoked
61 /// commitment transaction, thus per_commitment_point always come from cheater
62 /// and revocation_base_point always come from punisher, which is the broadcaster
63 /// of the transaction spending with this key knowledge.
65 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
66 /// generated (ie our own).
68 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 {
69 let mut ret = lightning::ln::chan_utils::derive_public_revocation_key(secp256k1::SECP256K1, &per_commitment_point.into_rust(), &countersignatory_revocation_base_point.into_rust());
70 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() };
75 use lightning::ln::chan_utils::TxCreationKeys as nativeTxCreationKeysImport;
76 type nativeTxCreationKeys = nativeTxCreationKeysImport;
78 /// The set of public keys which are used in the creation of one commitment transaction.
79 /// These are derived from the channel base keys and per-commitment data.
81 /// A broadcaster key is provided from potential broadcaster of the computed transaction.
82 /// A countersignatory key is coming from a protocol participant unable to broadcast the
85 /// These keys are assumed to be good, either because the code derived them from
86 /// channel basepoints via the new function, or they were obtained via
87 /// CommitmentTransaction.trust().keys() because we trusted the source of the
88 /// pre-calculated keys.
91 pub struct TxCreationKeys {
92 /// Nearly everywhere, inner must be non-null, however in places where
93 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
94 pub inner: *mut nativeTxCreationKeys,
98 impl Drop for TxCreationKeys {
100 if self.is_owned && !self.inner.is_null() {
101 let _ = unsafe { Box::from_raw(self.inner) };
106 pub extern "C" fn TxCreationKeys_free(this_ptr: TxCreationKeys) { }
108 /// Used only if an object of this type is returned as a trait impl by a method
109 extern "C" fn TxCreationKeys_free_void(this_ptr: *mut c_void) {
110 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTxCreationKeys); }
113 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
114 impl TxCreationKeys {
115 pub(crate) fn take_inner(mut self) -> *mut nativeTxCreationKeys {
116 assert!(self.is_owned);
117 let ret = self.inner;
118 self.inner = std::ptr::null_mut();
122 /// The broadcaster's per-commitment public key which was used to derive the other keys.
124 pub extern "C" fn TxCreationKeys_get_per_commitment_point(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
125 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.per_commitment_point;
126 crate::c_types::PublicKey::from_rust(&(*inner_val))
128 /// The broadcaster's per-commitment public key which was used to derive the other keys.
130 pub extern "C" fn TxCreationKeys_set_per_commitment_point(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
131 unsafe { &mut *this_ptr.inner }.per_commitment_point = val.into_rust();
133 /// The revocation key which is used to allow the broadcaster of the commitment
134 /// transaction to provide their counterparty the ability to punish them if they broadcast
137 pub extern "C" fn TxCreationKeys_get_revocation_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
138 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_key;
139 crate::c_types::PublicKey::from_rust(&(*inner_val))
141 /// The revocation key which is used to allow the broadcaster of the commitment
142 /// transaction to provide their counterparty the ability to punish them if they broadcast
145 pub extern "C" fn TxCreationKeys_set_revocation_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
146 unsafe { &mut *this_ptr.inner }.revocation_key = val.into_rust();
148 /// Broadcaster's HTLC Key
150 pub extern "C" fn TxCreationKeys_get_broadcaster_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
151 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key;
152 crate::c_types::PublicKey::from_rust(&(*inner_val))
154 /// Broadcaster's HTLC Key
156 pub extern "C" fn TxCreationKeys_set_broadcaster_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
157 unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key = val.into_rust();
159 /// Countersignatory's HTLC Key
161 pub extern "C" fn TxCreationKeys_get_countersignatory_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
162 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key;
163 crate::c_types::PublicKey::from_rust(&(*inner_val))
165 /// Countersignatory's HTLC Key
167 pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
168 unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key = val.into_rust();
170 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
172 pub extern "C" fn TxCreationKeys_get_broadcaster_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
173 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key;
174 crate::c_types::PublicKey::from_rust(&(*inner_val))
176 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
178 pub extern "C" fn TxCreationKeys_set_broadcaster_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
179 unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key = val.into_rust();
183 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 {
184 TxCreationKeys { inner: Box::into_raw(Box::new(nativeTxCreationKeys {
185 per_commitment_point: per_commitment_point_arg.into_rust(),
186 revocation_key: revocation_key_arg.into_rust(),
187 broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(),
188 countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(),
189 broadcaster_delayed_payment_key: broadcaster_delayed_payment_key_arg.into_rust(),
190 })), is_owned: true }
192 impl Clone for TxCreationKeys {
193 fn clone(&self) -> Self {
195 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
196 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
202 /// Used only if an object of this type is returned as a trait impl by a method
203 pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
204 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxCreationKeys)).clone() })) as *mut c_void
207 pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys {
211 pub extern "C" fn TxCreationKeys_write(obj: &TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
212 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
215 pub(crate) extern "C" fn TxCreationKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
216 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxCreationKeys) })
219 pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_TxCreationKeysDecodeErrorZ {
220 let res = crate::c_types::deserialize_obj(ser);
221 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() };
225 use lightning::ln::chan_utils::ChannelPublicKeys as nativeChannelPublicKeysImport;
226 type nativeChannelPublicKeys = nativeChannelPublicKeysImport;
228 /// One counterparty's public keys which do not change over the life of a channel.
231 pub struct ChannelPublicKeys {
232 /// Nearly everywhere, inner must be non-null, however in places where
233 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
234 pub inner: *mut nativeChannelPublicKeys,
238 impl Drop for ChannelPublicKeys {
240 if self.is_owned && !self.inner.is_null() {
241 let _ = unsafe { Box::from_raw(self.inner) };
246 pub extern "C" fn ChannelPublicKeys_free(this_ptr: ChannelPublicKeys) { }
248 /// Used only if an object of this type is returned as a trait impl by a method
249 extern "C" fn ChannelPublicKeys_free_void(this_ptr: *mut c_void) {
250 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelPublicKeys); }
253 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
254 impl ChannelPublicKeys {
255 pub(crate) fn take_inner(mut self) -> *mut nativeChannelPublicKeys {
256 assert!(self.is_owned);
257 let ret = self.inner;
258 self.inner = std::ptr::null_mut();
262 /// The public key which is used to sign all commitment transactions, as it appears in the
263 /// on-chain channel lock-in 2-of-2 multisig output.
265 pub extern "C" fn ChannelPublicKeys_get_funding_pubkey(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
266 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_pubkey;
267 crate::c_types::PublicKey::from_rust(&(*inner_val))
269 /// The public key which is used to sign all commitment transactions, as it appears in the
270 /// on-chain channel lock-in 2-of-2 multisig output.
272 pub extern "C" fn ChannelPublicKeys_set_funding_pubkey(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
273 unsafe { &mut *this_ptr.inner }.funding_pubkey = val.into_rust();
275 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
276 /// revocation keys. This is combined with the per-commitment-secret generated by the
277 /// counterparty to create a secret which the counterparty can reveal to revoke previous
280 pub extern "C" fn ChannelPublicKeys_get_revocation_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
281 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_basepoint;
282 crate::c_types::PublicKey::from_rust(&(*inner_val))
284 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
285 /// revocation keys. This is combined with the per-commitment-secret generated by the
286 /// counterparty to create a secret which the counterparty can reveal to revoke previous
289 pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
290 unsafe { &mut *this_ptr.inner }.revocation_basepoint = val.into_rust();
292 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
293 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
294 /// static across every commitment transaction.
296 pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
297 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_point;
298 crate::c_types::PublicKey::from_rust(&(*inner_val))
300 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
301 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
302 /// static across every commitment transaction.
304 pub extern "C" fn ChannelPublicKeys_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
305 unsafe { &mut *this_ptr.inner }.payment_point = val.into_rust();
307 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
308 /// public key which receives non-HTLC-encumbered funds which are only available for spending
309 /// after some delay (or can be claimed via the revocation path).
311 pub extern "C" fn ChannelPublicKeys_get_delayed_payment_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
312 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint;
313 crate::c_types::PublicKey::from_rust(&(*inner_val))
315 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
316 /// public key which receives non-HTLC-encumbered funds which are only available for spending
317 /// after some delay (or can be claimed via the revocation path).
319 pub extern "C" fn ChannelPublicKeys_set_delayed_payment_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
320 unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint = val.into_rust();
322 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
323 /// which is used to encumber HTLC-in-flight outputs.
325 pub extern "C" fn ChannelPublicKeys_get_htlc_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
326 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_basepoint;
327 crate::c_types::PublicKey::from_rust(&(*inner_val))
329 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
330 /// which is used to encumber HTLC-in-flight outputs.
332 pub extern "C" fn ChannelPublicKeys_set_htlc_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
333 unsafe { &mut *this_ptr.inner }.htlc_basepoint = val.into_rust();
337 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 {
338 ChannelPublicKeys { inner: Box::into_raw(Box::new(nativeChannelPublicKeys {
339 funding_pubkey: funding_pubkey_arg.into_rust(),
340 revocation_basepoint: revocation_basepoint_arg.into_rust(),
341 payment_point: payment_point_arg.into_rust(),
342 delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(),
343 htlc_basepoint: htlc_basepoint_arg.into_rust(),
344 })), is_owned: true }
346 impl Clone for ChannelPublicKeys {
347 fn clone(&self) -> Self {
349 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
350 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
356 /// Used only if an object of this type is returned as a trait impl by a method
357 pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
358 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelPublicKeys)).clone() })) as *mut c_void
361 pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys {
365 pub extern "C" fn ChannelPublicKeys_write(obj: &ChannelPublicKeys) -> crate::c_types::derived::CVec_u8Z {
366 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
369 pub(crate) extern "C" fn ChannelPublicKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
370 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelPublicKeys) })
373 pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelPublicKeysDecodeErrorZ {
374 let res = crate::c_types::deserialize_obj(ser);
375 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() };
378 /// Create per-state keys from channel base points and the per-commitment point.
379 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
382 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 {
383 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());
384 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() };
388 /// Generate per-state keys from channel static keys.
389 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
392 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 {
393 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 }, secp256k1::SECP256K1);
394 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() };
400 pub static REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH: usize = lightning::ln::chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH;
401 /// A script either spendable by the revocation
402 /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
403 /// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
405 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 {
406 let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), contest_delay, &broadcaster_delayed_payment_key.into_rust());
407 ret.into_bytes().into()
411 use lightning::ln::chan_utils::HTLCOutputInCommitment as nativeHTLCOutputInCommitmentImport;
412 type nativeHTLCOutputInCommitment = nativeHTLCOutputInCommitmentImport;
414 /// Information about an HTLC as it appears in a commitment transaction
417 pub struct HTLCOutputInCommitment {
418 /// Nearly everywhere, inner must be non-null, however in places where
419 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
420 pub inner: *mut nativeHTLCOutputInCommitment,
424 impl Drop for HTLCOutputInCommitment {
426 if self.is_owned && !self.inner.is_null() {
427 let _ = unsafe { Box::from_raw(self.inner) };
432 pub extern "C" fn HTLCOutputInCommitment_free(this_ptr: HTLCOutputInCommitment) { }
434 /// Used only if an object of this type is returned as a trait impl by a method
435 extern "C" fn HTLCOutputInCommitment_free_void(this_ptr: *mut c_void) {
436 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCOutputInCommitment); }
439 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
440 impl HTLCOutputInCommitment {
441 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCOutputInCommitment {
442 assert!(self.is_owned);
443 let ret = self.inner;
444 self.inner = std::ptr::null_mut();
448 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
449 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
450 /// need to compare this value to whether the commitment transaction in question is that of
451 /// the counterparty or our own.
453 pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool {
454 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.offered;
457 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
458 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
459 /// need to compare this value to whether the commitment transaction in question is that of
460 /// the counterparty or our own.
462 pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) {
463 unsafe { &mut *this_ptr.inner }.offered = val;
465 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
466 /// this divided by 1000.
468 pub extern "C" fn HTLCOutputInCommitment_get_amount_msat(this_ptr: &HTLCOutputInCommitment) -> u64 {
469 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.amount_msat;
472 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
473 /// this divided by 1000.
475 pub extern "C" fn HTLCOutputInCommitment_set_amount_msat(this_ptr: &mut HTLCOutputInCommitment, mut val: u64) {
476 unsafe { &mut *this_ptr.inner }.amount_msat = val;
478 /// The CLTV lock-time at which this HTLC expires.
480 pub extern "C" fn HTLCOutputInCommitment_get_cltv_expiry(this_ptr: &HTLCOutputInCommitment) -> u32 {
481 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry;
484 /// The CLTV lock-time at which this HTLC expires.
486 pub extern "C" fn HTLCOutputInCommitment_set_cltv_expiry(this_ptr: &mut HTLCOutputInCommitment, mut val: u32) {
487 unsafe { &mut *this_ptr.inner }.cltv_expiry = val;
489 /// The hash of the preimage which unlocks this HTLC.
491 pub extern "C" fn HTLCOutputInCommitment_get_payment_hash(this_ptr: &HTLCOutputInCommitment) -> *const [u8; 32] {
492 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_hash;
495 /// The hash of the preimage which unlocks this HTLC.
497 pub extern "C" fn HTLCOutputInCommitment_set_payment_hash(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::ThirtyTwoBytes) {
498 unsafe { &mut *this_ptr.inner }.payment_hash = ::lightning::ln::channelmanager::PaymentHash(val.data);
500 impl Clone for HTLCOutputInCommitment {
501 fn clone(&self) -> Self {
503 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
504 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
510 /// Used only if an object of this type is returned as a trait impl by a method
511 pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_void) -> *mut c_void {
512 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCOutputInCommitment)).clone() })) as *mut c_void
515 pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment {
519 pub extern "C" fn HTLCOutputInCommitment_write(obj: &HTLCOutputInCommitment) -> crate::c_types::derived::CVec_u8Z {
520 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
523 pub(crate) extern "C" fn HTLCOutputInCommitment_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
524 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCOutputInCommitment) })
527 pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCOutputInCommitmentDecodeErrorZ {
528 let res = crate::c_types::deserialize_obj(ser);
529 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() };
532 /// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
533 /// does not need to have its previous_output_index filled.
535 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 {
536 let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(unsafe { &*htlc.inner }, unsafe { &*keys.inner });
537 ret.into_bytes().into()
540 /// Gets the redeemscript for a funding output from the two funding public keys.
541 /// Note that the order of funding public keys does not matter.
543 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 {
544 let mut ret = lightning::ln::chan_utils::make_funding_redeemscript(&broadcaster.into_rust(), &countersignatory.into_rust());
545 ret.into_bytes().into()
548 /// panics if htlc.transaction_output_index.is_none()!
550 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 {
551 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());
552 let mut local_ret = ::bitcoin::consensus::encode::serialize(&ret);
553 crate::c_types::Transaction::from_vec(local_ret)
557 use lightning::ln::chan_utils::ChannelTransactionParameters as nativeChannelTransactionParametersImport;
558 type nativeChannelTransactionParameters = nativeChannelTransactionParametersImport;
560 /// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction).
561 /// The fields are organized by holder/counterparty.
563 /// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters
564 /// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions.
567 pub struct ChannelTransactionParameters {
568 /// Nearly everywhere, inner must be non-null, however in places where
569 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
570 pub inner: *mut nativeChannelTransactionParameters,
574 impl Drop for ChannelTransactionParameters {
576 if self.is_owned && !self.inner.is_null() {
577 let _ = unsafe { Box::from_raw(self.inner) };
582 pub extern "C" fn ChannelTransactionParameters_free(this_ptr: ChannelTransactionParameters) { }
584 /// Used only if an object of this type is returned as a trait impl by a method
585 extern "C" fn ChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
586 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTransactionParameters); }
589 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
590 impl ChannelTransactionParameters {
591 pub(crate) fn take_inner(mut self) -> *mut nativeChannelTransactionParameters {
592 assert!(self.is_owned);
593 let ret = self.inner;
594 self.inner = std::ptr::null_mut();
598 /// Holder public keys
600 pub extern "C" fn ChannelTransactionParameters_get_holder_pubkeys(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
601 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_pubkeys;
602 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
604 /// Holder public keys
606 pub extern "C" fn ChannelTransactionParameters_set_holder_pubkeys(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) {
607 unsafe { &mut *this_ptr.inner }.holder_pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
609 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
611 pub extern "C" fn ChannelTransactionParameters_get_holder_selected_contest_delay(this_ptr: &ChannelTransactionParameters) -> u16 {
612 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay;
615 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
617 pub extern "C" fn ChannelTransactionParameters_set_holder_selected_contest_delay(this_ptr: &mut ChannelTransactionParameters, mut val: u16) {
618 unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay = val;
620 /// Whether the holder is the initiator of this channel.
621 /// This is an input to the commitment number obscure factor computation.
623 pub extern "C" fn ChannelTransactionParameters_get_is_outbound_from_holder(this_ptr: &ChannelTransactionParameters) -> bool {
624 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_outbound_from_holder;
627 /// Whether the holder is the initiator of this channel.
628 /// This is an input to the commitment number obscure factor computation.
630 pub extern "C" fn ChannelTransactionParameters_set_is_outbound_from_holder(this_ptr: &mut ChannelTransactionParameters, mut val: bool) {
631 unsafe { &mut *this_ptr.inner }.is_outbound_from_holder = val;
633 /// The late-bound counterparty channel transaction parameters.
634 /// These parameters are populated at the point in the protocol where the counterparty provides them.
636 pub extern "C" fn ChannelTransactionParameters_get_counterparty_parameters(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::CounterpartyChannelTransactionParameters {
637 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_parameters;
638 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 };
641 /// The late-bound counterparty channel transaction parameters.
642 /// These parameters are populated at the point in the protocol where the counterparty provides them.
644 pub extern "C" fn ChannelTransactionParameters_set_counterparty_parameters(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::CounterpartyChannelTransactionParameters) {
645 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
646 unsafe { &mut *this_ptr.inner }.counterparty_parameters = local_val;
648 /// The late-bound funding outpoint
650 pub extern "C" fn ChannelTransactionParameters_get_funding_outpoint(this_ptr: &ChannelTransactionParameters) -> crate::chain::transaction::OutPoint {
651 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_outpoint;
652 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 };
655 /// The late-bound funding outpoint
657 pub extern "C" fn ChannelTransactionParameters_set_funding_outpoint(this_ptr: &mut ChannelTransactionParameters, mut val: crate::chain::transaction::OutPoint) {
658 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
659 unsafe { &mut *this_ptr.inner }.funding_outpoint = local_val;
663 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 {
664 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()) } }) };
665 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()) } }) };
666 ChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeChannelTransactionParameters {
667 holder_pubkeys: *unsafe { Box::from_raw(holder_pubkeys_arg.take_inner()) },
668 holder_selected_contest_delay: holder_selected_contest_delay_arg,
669 is_outbound_from_holder: is_outbound_from_holder_arg,
670 counterparty_parameters: local_counterparty_parameters_arg,
671 funding_outpoint: local_funding_outpoint_arg,
672 })), is_owned: true }
674 impl Clone for ChannelTransactionParameters {
675 fn clone(&self) -> Self {
677 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
678 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
684 /// Used only if an object of this type is returned as a trait impl by a method
685 pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
686 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTransactionParameters)).clone() })) as *mut c_void
689 pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters {
693 use lightning::ln::chan_utils::CounterpartyChannelTransactionParameters as nativeCounterpartyChannelTransactionParametersImport;
694 type nativeCounterpartyChannelTransactionParameters = nativeCounterpartyChannelTransactionParametersImport;
696 /// Late-bound per-channel counterparty data used to build transactions.
699 pub struct CounterpartyChannelTransactionParameters {
700 /// Nearly everywhere, inner must be non-null, however in places where
701 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
702 pub inner: *mut nativeCounterpartyChannelTransactionParameters,
706 impl Drop for CounterpartyChannelTransactionParameters {
708 if self.is_owned && !self.inner.is_null() {
709 let _ = unsafe { Box::from_raw(self.inner) };
714 pub extern "C" fn CounterpartyChannelTransactionParameters_free(this_ptr: CounterpartyChannelTransactionParameters) { }
716 /// Used only if an object of this type is returned as a trait impl by a method
717 extern "C" fn CounterpartyChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
718 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyChannelTransactionParameters); }
721 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
722 impl CounterpartyChannelTransactionParameters {
723 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyChannelTransactionParameters {
724 assert!(self.is_owned);
725 let ret = self.inner;
726 self.inner = std::ptr::null_mut();
730 /// Counter-party public keys
732 pub extern "C" fn CounterpartyChannelTransactionParameters_get_pubkeys(this_ptr: &CounterpartyChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
733 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.pubkeys;
734 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
736 /// Counter-party public keys
738 pub extern "C" fn CounterpartyChannelTransactionParameters_set_pubkeys(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) {
739 unsafe { &mut *this_ptr.inner }.pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
741 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
743 pub extern "C" fn CounterpartyChannelTransactionParameters_get_selected_contest_delay(this_ptr: &CounterpartyChannelTransactionParameters) -> u16 {
744 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.selected_contest_delay;
747 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
749 pub extern "C" fn CounterpartyChannelTransactionParameters_set_selected_contest_delay(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: u16) {
750 unsafe { &mut *this_ptr.inner }.selected_contest_delay = val;
754 pub extern "C" fn CounterpartyChannelTransactionParameters_new(mut pubkeys_arg: crate::ln::chan_utils::ChannelPublicKeys, mut selected_contest_delay_arg: u16) -> CounterpartyChannelTransactionParameters {
755 CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeCounterpartyChannelTransactionParameters {
756 pubkeys: *unsafe { Box::from_raw(pubkeys_arg.take_inner()) },
757 selected_contest_delay: selected_contest_delay_arg,
758 })), is_owned: true }
760 impl Clone for CounterpartyChannelTransactionParameters {
761 fn clone(&self) -> Self {
763 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
764 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
770 /// Used only if an object of this type is returned as a trait impl by a method
771 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
772 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void
775 pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters {
778 /// Whether the late bound parameters are populated.
781 pub extern "C" fn ChannelTransactionParameters_is_populated(this_arg: &ChannelTransactionParameters) -> bool {
782 let mut ret = unsafe { &*this_arg.inner }.is_populated();
786 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
787 /// given that the holder is the broadcaster.
789 /// self.is_populated() must be true before calling this function.
792 pub extern "C" fn ChannelTransactionParameters_as_holder_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters {
793 let mut ret = unsafe { &*this_arg.inner }.as_holder_broadcastable();
794 crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true }
797 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
798 /// given that the counterparty is the broadcaster.
800 /// self.is_populated() must be true before calling this function.
803 pub extern "C" fn ChannelTransactionParameters_as_counterparty_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters {
804 let mut ret = unsafe { &*this_arg.inner }.as_counterparty_broadcastable();
805 crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true }
809 pub extern "C" fn CounterpartyChannelTransactionParameters_write(obj: &CounterpartyChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
810 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
813 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
814 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyChannelTransactionParameters) })
817 pub extern "C" fn CounterpartyChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyChannelTransactionParametersDecodeErrorZ {
818 let res = crate::c_types::deserialize_obj(ser);
819 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() };
823 pub extern "C" fn ChannelTransactionParameters_write(obj: &ChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
824 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
827 pub(crate) extern "C" fn ChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
828 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTransactionParameters) })
831 pub extern "C" fn ChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelTransactionParametersDecodeErrorZ {
832 let res = crate::c_types::deserialize_obj(ser);
833 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() };
837 use lightning::ln::chan_utils::DirectedChannelTransactionParameters as nativeDirectedChannelTransactionParametersImport;
838 type nativeDirectedChannelTransactionParameters = nativeDirectedChannelTransactionParametersImport<'static>;
840 /// Static channel fields used to build transactions given per-commitment fields, organized by
841 /// broadcaster/countersignatory.
843 /// This is derived from the holder/counterparty-organized ChannelTransactionParameters via the
844 /// as_holder_broadcastable and as_counterparty_broadcastable functions.
847 pub struct DirectedChannelTransactionParameters {
848 /// Nearly everywhere, inner must be non-null, however in places where
849 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
850 pub inner: *mut nativeDirectedChannelTransactionParameters,
854 impl Drop for DirectedChannelTransactionParameters {
856 if self.is_owned && !self.inner.is_null() {
857 let _ = unsafe { Box::from_raw(self.inner) };
862 pub extern "C" fn DirectedChannelTransactionParameters_free(this_ptr: DirectedChannelTransactionParameters) { }
864 /// Used only if an object of this type is returned as a trait impl by a method
865 extern "C" fn DirectedChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
866 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelTransactionParameters); }
869 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
870 impl DirectedChannelTransactionParameters {
871 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelTransactionParameters {
872 assert!(self.is_owned);
873 let ret = self.inner;
874 self.inner = std::ptr::null_mut();
878 /// Get the channel pubkeys for the broadcaster
881 pub extern "C" fn DirectedChannelTransactionParameters_broadcaster_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
882 let mut ret = unsafe { &*this_arg.inner }.broadcaster_pubkeys();
883 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
886 /// Get the channel pubkeys for the countersignatory
889 pub extern "C" fn DirectedChannelTransactionParameters_countersignatory_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
890 let mut ret = unsafe { &*this_arg.inner }.countersignatory_pubkeys();
891 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
894 /// Get the contest delay applicable to the transactions.
895 /// Note that the contest delay was selected by the countersignatory.
898 pub extern "C" fn DirectedChannelTransactionParameters_contest_delay(this_arg: &DirectedChannelTransactionParameters) -> u16 {
899 let mut ret = unsafe { &*this_arg.inner }.contest_delay();
903 /// Whether the channel is outbound from the broadcaster.
905 /// The boolean representing the side that initiated the channel is
906 /// an input to the commitment number obscure factor computation.
909 pub extern "C" fn DirectedChannelTransactionParameters_is_outbound(this_arg: &DirectedChannelTransactionParameters) -> bool {
910 let mut ret = unsafe { &*this_arg.inner }.is_outbound();
914 /// The funding outpoint
917 pub extern "C" fn DirectedChannelTransactionParameters_funding_outpoint(this_arg: &DirectedChannelTransactionParameters) -> crate::chain::transaction::OutPoint {
918 let mut ret = unsafe { &*this_arg.inner }.funding_outpoint();
919 crate::c_types::bitcoin_to_C_outpoint(ret)
923 use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport;
924 type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport;
926 /// Information needed to build and sign a holder's commitment transaction.
928 /// The transaction is only signed once we are ready to broadcast.
931 pub struct HolderCommitmentTransaction {
932 /// Nearly everywhere, inner must be non-null, however in places where
933 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
934 pub inner: *mut nativeHolderCommitmentTransaction,
938 impl Drop for HolderCommitmentTransaction {
940 if self.is_owned && !self.inner.is_null() {
941 let _ = unsafe { Box::from_raw(self.inner) };
946 pub extern "C" fn HolderCommitmentTransaction_free(this_ptr: HolderCommitmentTransaction) { }
948 /// Used only if an object of this type is returned as a trait impl by a method
949 extern "C" fn HolderCommitmentTransaction_free_void(this_ptr: *mut c_void) {
950 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHolderCommitmentTransaction); }
953 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
954 impl HolderCommitmentTransaction {
955 pub(crate) fn take_inner(mut self) -> *mut nativeHolderCommitmentTransaction {
956 assert!(self.is_owned);
957 let ret = self.inner;
958 self.inner = std::ptr::null_mut();
962 /// Our counterparty's signature for the transaction
964 pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature {
965 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_sig;
966 crate::c_types::Signature::from_rust(&(*inner_val))
968 /// Our counterparty's signature for the transaction
970 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) {
971 unsafe { &mut *this_ptr.inner }.counterparty_sig = val.into_rust();
973 /// All non-dust counterparty HTLC signatures, in the order they appear in the transaction
975 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_htlc_sigs(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_SignatureZ) {
976 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); };
977 unsafe { &mut *this_ptr.inner }.counterparty_htlc_sigs = local_val;
979 impl Clone for HolderCommitmentTransaction {
980 fn clone(&self) -> Self {
982 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
983 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
989 /// Used only if an object of this type is returned as a trait impl by a method
990 pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
991 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void
994 pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction {
998 pub extern "C" fn HolderCommitmentTransaction_write(obj: &HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
999 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1002 pub(crate) extern "C" fn HolderCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1003 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHolderCommitmentTransaction) })
1006 pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HolderCommitmentTransactionDecodeErrorZ {
1007 let res = crate::c_types::deserialize_obj(ser);
1008 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() };
1011 /// Create a new holder transaction with the given counterparty signatures.
1012 /// The funding keys are used to figure out which signature should go first when building the transaction for broadcast.
1015 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 {
1016 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() }); };
1017 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());
1018 HolderCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1022 use lightning::ln::chan_utils::BuiltCommitmentTransaction as nativeBuiltCommitmentTransactionImport;
1023 type nativeBuiltCommitmentTransaction = nativeBuiltCommitmentTransactionImport;
1025 /// A pre-built Bitcoin commitment transaction and its txid.
1028 pub struct BuiltCommitmentTransaction {
1029 /// Nearly everywhere, inner must be non-null, however in places where
1030 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1031 pub inner: *mut nativeBuiltCommitmentTransaction,
1035 impl Drop for BuiltCommitmentTransaction {
1036 fn drop(&mut self) {
1037 if self.is_owned && !self.inner.is_null() {
1038 let _ = unsafe { Box::from_raw(self.inner) };
1043 pub extern "C" fn BuiltCommitmentTransaction_free(this_ptr: BuiltCommitmentTransaction) { }
1045 /// Used only if an object of this type is returned as a trait impl by a method
1046 extern "C" fn BuiltCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1047 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBuiltCommitmentTransaction); }
1050 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1051 impl BuiltCommitmentTransaction {
1052 pub(crate) fn take_inner(mut self) -> *mut nativeBuiltCommitmentTransaction {
1053 assert!(self.is_owned);
1054 let ret = self.inner;
1055 self.inner = std::ptr::null_mut();
1059 /// The commitment transaction
1061 pub extern "C" fn BuiltCommitmentTransaction_get_transaction(this_ptr: &BuiltCommitmentTransaction) -> crate::c_types::Transaction {
1062 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.transaction;
1063 let mut local_inner_val = ::bitcoin::consensus::encode::serialize(inner_val);
1064 crate::c_types::Transaction::from_vec(local_inner_val)
1066 /// The commitment transaction
1068 pub extern "C" fn BuiltCommitmentTransaction_set_transaction(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::Transaction) {
1069 unsafe { &mut *this_ptr.inner }.transaction = val.into_bitcoin();
1071 /// The txid for the commitment transaction.
1073 /// This is provided as a performance optimization, instead of calling transaction.txid()
1076 pub extern "C" fn BuiltCommitmentTransaction_get_txid(this_ptr: &BuiltCommitmentTransaction) -> *const [u8; 32] {
1077 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.txid;
1078 (*inner_val).as_inner()
1080 /// The txid for the commitment transaction.
1082 /// This is provided as a performance optimization, instead of calling transaction.txid()
1085 pub extern "C" fn BuiltCommitmentTransaction_set_txid(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::ThirtyTwoBytes) {
1086 unsafe { &mut *this_ptr.inner }.txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap();
1090 pub extern "C" fn BuiltCommitmentTransaction_new(mut transaction_arg: crate::c_types::Transaction, mut txid_arg: crate::c_types::ThirtyTwoBytes) -> BuiltCommitmentTransaction {
1091 BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(nativeBuiltCommitmentTransaction {
1092 transaction: transaction_arg.into_bitcoin(),
1093 txid: ::bitcoin::hash_types::Txid::from_slice(&txid_arg.data[..]).unwrap(),
1094 })), is_owned: true }
1096 impl Clone for BuiltCommitmentTransaction {
1097 fn clone(&self) -> Self {
1099 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
1100 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1106 /// Used only if an object of this type is returned as a trait impl by a method
1107 pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1108 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void
1111 pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction {
1115 pub extern "C" fn BuiltCommitmentTransaction_write(obj: &BuiltCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1116 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1119 pub(crate) extern "C" fn BuiltCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1120 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBuiltCommitmentTransaction) })
1123 pub extern "C" fn BuiltCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BuiltCommitmentTransactionDecodeErrorZ {
1124 let res = crate::c_types::deserialize_obj(ser);
1125 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() };
1128 /// Get the SIGHASH_ALL sighash value of the transaction.
1130 /// This can be used to verify a signature.
1133 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 {
1134 let mut ret = unsafe { &*this_arg.inner }.get_sighash_all(&::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis);
1135 crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() }
1138 /// Sign a transaction, either because we are counter-signing the counterparty's transaction or
1139 /// because we are about to broadcast a holder transaction.
1142 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 {
1143 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, secp256k1::SECP256K1);
1144 crate::c_types::Signature::from_rust(&ret)
1148 use lightning::ln::chan_utils::CommitmentTransaction as nativeCommitmentTransactionImport;
1149 type nativeCommitmentTransaction = nativeCommitmentTransactionImport;
1151 /// This class tracks the per-transaction information needed to build a commitment transaction and to
1152 /// actually build it and sign. It is used for holder transactions that we sign only when needed
1153 /// and for transactions we sign for the counterparty.
1155 /// This class can be used inside a signer implementation to generate a signature given the relevant
1159 pub struct CommitmentTransaction {
1160 /// Nearly everywhere, inner must be non-null, however in places where
1161 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1162 pub inner: *mut nativeCommitmentTransaction,
1166 impl Drop for CommitmentTransaction {
1167 fn drop(&mut self) {
1168 if self.is_owned && !self.inner.is_null() {
1169 let _ = unsafe { Box::from_raw(self.inner) };
1174 pub extern "C" fn CommitmentTransaction_free(this_ptr: CommitmentTransaction) { }
1176 /// Used only if an object of this type is returned as a trait impl by a method
1177 extern "C" fn CommitmentTransaction_free_void(this_ptr: *mut c_void) {
1178 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentTransaction); }
1181 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1182 impl CommitmentTransaction {
1183 pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentTransaction {
1184 assert!(self.is_owned);
1185 let ret = self.inner;
1186 self.inner = std::ptr::null_mut();
1190 impl Clone for CommitmentTransaction {
1191 fn clone(&self) -> Self {
1193 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
1194 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1200 /// Used only if an object of this type is returned as a trait impl by a method
1201 pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1202 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void
1205 pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction {
1209 pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1210 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1213 pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1214 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) })
1217 pub extern "C" fn CommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentTransactionDecodeErrorZ {
1218 let res = crate::c_types::deserialize_obj(ser);
1219 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() };
1222 /// The backwards-counting commitment number
1225 pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &CommitmentTransaction) -> u64 {
1226 let mut ret = unsafe { &*this_arg.inner }.commitment_number();
1230 /// The value to be sent to the broadcaster
1233 pub extern "C" fn CommitmentTransaction_to_broadcaster_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1234 let mut ret = unsafe { &*this_arg.inner }.to_broadcaster_value_sat();
1238 /// The value to be sent to the counterparty
1241 pub extern "C" fn CommitmentTransaction_to_countersignatory_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1242 let mut ret = unsafe { &*this_arg.inner }.to_countersignatory_value_sat();
1246 /// The feerate paid per 1000-weight-unit in this commitment transaction.
1249 pub extern "C" fn CommitmentTransaction_feerate_per_kw(this_arg: &CommitmentTransaction) -> u32 {
1250 let mut ret = unsafe { &*this_arg.inner }.feerate_per_kw();
1254 /// Trust our pre-built transaction and derived transaction creation public keys.
1256 /// Applies a wrapper which allows access to these fields.
1258 /// This should only be used if you fully trust the builder of this object. It should not
1259 ///\tbe used by an external signer - instead use the verify function.
1262 pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction) -> crate::ln::chan_utils::TrustedCommitmentTransaction {
1263 let mut ret = unsafe { &*this_arg.inner }.trust();
1264 crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1267 /// Verify our pre-built transaction and derived transaction creation public keys.
1269 /// Applies a wrapper which allows access to these fields.
1271 /// An external validating signer must call this method before signing
1272 /// or using the built transaction.
1275 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 {
1276 let mut ret = unsafe { &*this_arg.inner }.verify(unsafe { &*channel_parameters.inner }, unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, secp256k1::SECP256K1);
1277 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() };
1282 use lightning::ln::chan_utils::TrustedCommitmentTransaction as nativeTrustedCommitmentTransactionImport;
1283 type nativeTrustedCommitmentTransaction = nativeTrustedCommitmentTransactionImport<'static>;
1285 /// A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin
1286 /// transaction and the transaction creation keys) are trusted.
1288 /// See trust() and verify() functions on CommitmentTransaction.
1290 /// This structure implements Deref.
1293 pub struct TrustedCommitmentTransaction {
1294 /// Nearly everywhere, inner must be non-null, however in places where
1295 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1296 pub inner: *mut nativeTrustedCommitmentTransaction,
1300 impl Drop for TrustedCommitmentTransaction {
1301 fn drop(&mut self) {
1302 if self.is_owned && !self.inner.is_null() {
1303 let _ = unsafe { Box::from_raw(self.inner) };
1308 pub extern "C" fn TrustedCommitmentTransaction_free(this_ptr: TrustedCommitmentTransaction) { }
1310 /// Used only if an object of this type is returned as a trait impl by a method
1311 extern "C" fn TrustedCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1312 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedCommitmentTransaction); }
1315 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1316 impl TrustedCommitmentTransaction {
1317 pub(crate) fn take_inner(mut self) -> *mut nativeTrustedCommitmentTransaction {
1318 assert!(self.is_owned);
1319 let ret = self.inner;
1320 self.inner = std::ptr::null_mut();
1324 /// The transaction ID of the built Bitcoin transaction
1327 pub extern "C" fn TrustedCommitmentTransaction_txid(this_arg: &TrustedCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
1328 let mut ret = unsafe { &*this_arg.inner }.txid();
1329 crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
1332 /// The pre-built Bitcoin commitment transaction
1335 pub extern "C" fn TrustedCommitmentTransaction_built_transaction(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::BuiltCommitmentTransaction {
1336 let mut ret = unsafe { &*this_arg.inner }.built_transaction();
1337 crate::ln::chan_utils::BuiltCommitmentTransaction { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1340 /// The pre-calculated transaction creation public keys.
1343 pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys {
1344 let mut ret = unsafe { &*this_arg.inner }.keys();
1345 crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1348 /// Get a signature for each HTLC which was included in the commitment transaction (ie for
1349 /// which HTLCOutputInCommitment::transaction_output_index.is_some()).
1351 /// The returned Vec has one entry for each HTLC, and in the same order.
1354 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 {
1355 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 }, secp256k1::SECP256K1);
1356 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( { 0u8 /*e*/ }).into() };
1360 /// Get the transaction number obscure factor
1362 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 {
1363 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);