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 /// A pointer to the opaque Rust object.
94 /// Nearly everywhere, inner must be non-null, however in places where
95 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
96 pub inner: *mut nativeTxCreationKeys,
97 /// Indicates that this is the only struct which contains the same pointer.
99 /// Rust functions which take ownership of an object provided via an argument require
100 /// this to be true and invalidate the object pointed to by inner.
104 impl Drop for TxCreationKeys {
106 if self.is_owned && !<*mut nativeTxCreationKeys>::is_null(self.inner) {
107 let _ = unsafe { Box::from_raw(self.inner) };
111 /// Frees any resources used by the TxCreationKeys, if is_owned is set and inner is non-NULL.
113 pub extern "C" fn TxCreationKeys_free(this_obj: TxCreationKeys) { }
115 /// Used only if an object of this type is returned as a trait impl by a method
116 extern "C" fn TxCreationKeys_free_void(this_ptr: *mut c_void) {
117 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTxCreationKeys); }
120 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
121 impl TxCreationKeys {
122 pub(crate) fn take_inner(mut self) -> *mut nativeTxCreationKeys {
123 assert!(self.is_owned);
124 let ret = self.inner;
125 self.inner = std::ptr::null_mut();
129 /// The broadcaster's per-commitment public key which was used to derive the other keys.
131 pub extern "C" fn TxCreationKeys_get_per_commitment_point(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
132 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.per_commitment_point;
133 crate::c_types::PublicKey::from_rust(&(*inner_val))
135 /// The broadcaster's per-commitment public key which was used to derive the other keys.
137 pub extern "C" fn TxCreationKeys_set_per_commitment_point(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
138 unsafe { &mut *this_ptr.inner }.per_commitment_point = val.into_rust();
140 /// The revocation key which is used to allow the broadcaster of the commitment
141 /// transaction to provide their counterparty the ability to punish them if they broadcast
144 pub extern "C" fn TxCreationKeys_get_revocation_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
145 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_key;
146 crate::c_types::PublicKey::from_rust(&(*inner_val))
148 /// The revocation key which is used to allow the broadcaster of the commitment
149 /// transaction to provide their counterparty the ability to punish them if they broadcast
152 pub extern "C" fn TxCreationKeys_set_revocation_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
153 unsafe { &mut *this_ptr.inner }.revocation_key = val.into_rust();
155 /// Broadcaster's HTLC Key
157 pub extern "C" fn TxCreationKeys_get_broadcaster_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
158 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key;
159 crate::c_types::PublicKey::from_rust(&(*inner_val))
161 /// Broadcaster's HTLC Key
163 pub extern "C" fn TxCreationKeys_set_broadcaster_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
164 unsafe { &mut *this_ptr.inner }.broadcaster_htlc_key = val.into_rust();
166 /// Countersignatory's HTLC Key
168 pub extern "C" fn TxCreationKeys_get_countersignatory_htlc_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
169 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key;
170 crate::c_types::PublicKey::from_rust(&(*inner_val))
172 /// Countersignatory's HTLC Key
174 pub extern "C" fn TxCreationKeys_set_countersignatory_htlc_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
175 unsafe { &mut *this_ptr.inner }.countersignatory_htlc_key = val.into_rust();
177 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
179 pub extern "C" fn TxCreationKeys_get_broadcaster_delayed_payment_key(this_ptr: &TxCreationKeys) -> crate::c_types::PublicKey {
180 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key;
181 crate::c_types::PublicKey::from_rust(&(*inner_val))
183 /// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
185 pub extern "C" fn TxCreationKeys_set_broadcaster_delayed_payment_key(this_ptr: &mut TxCreationKeys, mut val: crate::c_types::PublicKey) {
186 unsafe { &mut *this_ptr.inner }.broadcaster_delayed_payment_key = val.into_rust();
188 /// Constructs a new TxCreationKeys given each field
191 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 {
192 TxCreationKeys { inner: Box::into_raw(Box::new(nativeTxCreationKeys {
193 per_commitment_point: per_commitment_point_arg.into_rust(),
194 revocation_key: revocation_key_arg.into_rust(),
195 broadcaster_htlc_key: broadcaster_htlc_key_arg.into_rust(),
196 countersignatory_htlc_key: countersignatory_htlc_key_arg.into_rust(),
197 broadcaster_delayed_payment_key: broadcaster_delayed_payment_key_arg.into_rust(),
198 })), is_owned: true }
200 impl Clone for TxCreationKeys {
201 fn clone(&self) -> Self {
203 inner: if <*mut nativeTxCreationKeys>::is_null(self.inner) { std::ptr::null_mut() } else {
204 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
210 /// Used only if an object of this type is returned as a trait impl by a method
211 pub(crate) extern "C" fn TxCreationKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
212 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxCreationKeys)).clone() })) as *mut c_void
215 /// Creates a copy of the TxCreationKeys
216 pub extern "C" fn TxCreationKeys_clone(orig: &TxCreationKeys) -> TxCreationKeys {
220 /// Serialize the TxCreationKeys object into a byte array which can be read by TxCreationKeys_read
221 pub extern "C" fn TxCreationKeys_write(obj: &TxCreationKeys) -> crate::c_types::derived::CVec_u8Z {
222 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
225 pub(crate) extern "C" fn TxCreationKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
226 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxCreationKeys) })
229 /// Read a TxCreationKeys from a byte array, created by TxCreationKeys_write
230 pub extern "C" fn TxCreationKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_TxCreationKeysDecodeErrorZ {
231 let res = crate::c_types::deserialize_obj(ser);
232 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() };
236 use lightning::ln::chan_utils::ChannelPublicKeys as nativeChannelPublicKeysImport;
237 type nativeChannelPublicKeys = nativeChannelPublicKeysImport;
239 /// One counterparty's public keys which do not change over the life of a channel.
242 pub struct ChannelPublicKeys {
243 /// A pointer to the opaque Rust object.
245 /// Nearly everywhere, inner must be non-null, however in places where
246 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
247 pub inner: *mut nativeChannelPublicKeys,
248 /// Indicates that this is the only struct which contains the same pointer.
250 /// Rust functions which take ownership of an object provided via an argument require
251 /// this to be true and invalidate the object pointed to by inner.
255 impl Drop for ChannelPublicKeys {
257 if self.is_owned && !<*mut nativeChannelPublicKeys>::is_null(self.inner) {
258 let _ = unsafe { Box::from_raw(self.inner) };
262 /// Frees any resources used by the ChannelPublicKeys, if is_owned is set and inner is non-NULL.
264 pub extern "C" fn ChannelPublicKeys_free(this_obj: ChannelPublicKeys) { }
266 /// Used only if an object of this type is returned as a trait impl by a method
267 extern "C" fn ChannelPublicKeys_free_void(this_ptr: *mut c_void) {
268 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelPublicKeys); }
271 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
272 impl ChannelPublicKeys {
273 pub(crate) fn take_inner(mut self) -> *mut nativeChannelPublicKeys {
274 assert!(self.is_owned);
275 let ret = self.inner;
276 self.inner = std::ptr::null_mut();
280 /// The public key which is used to sign all commitment transactions, as it appears in the
281 /// on-chain channel lock-in 2-of-2 multisig output.
283 pub extern "C" fn ChannelPublicKeys_get_funding_pubkey(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
284 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_pubkey;
285 crate::c_types::PublicKey::from_rust(&(*inner_val))
287 /// The public key which is used to sign all commitment transactions, as it appears in the
288 /// on-chain channel lock-in 2-of-2 multisig output.
290 pub extern "C" fn ChannelPublicKeys_set_funding_pubkey(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
291 unsafe { &mut *this_ptr.inner }.funding_pubkey = val.into_rust();
293 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
294 /// revocation keys. This is combined with the per-commitment-secret generated by the
295 /// counterparty to create a secret which the counterparty can reveal to revoke previous
298 pub extern "C" fn ChannelPublicKeys_get_revocation_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
299 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.revocation_basepoint;
300 crate::c_types::PublicKey::from_rust(&(*inner_val))
302 /// The base point which is used (with derive_public_revocation_key) to derive per-commitment
303 /// revocation keys. This is combined with the per-commitment-secret generated by the
304 /// counterparty to create a secret which the counterparty can reveal to revoke previous
307 pub extern "C" fn ChannelPublicKeys_set_revocation_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
308 unsafe { &mut *this_ptr.inner }.revocation_basepoint = val.into_rust();
310 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
311 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
312 /// static across every commitment transaction.
314 pub extern "C" fn ChannelPublicKeys_get_payment_point(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
315 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_point;
316 crate::c_types::PublicKey::from_rust(&(*inner_val))
318 /// The public key on which the non-broadcaster (ie the countersignatory) receives an immediately
319 /// spendable primary channel balance on the broadcaster's commitment transaction. This key is
320 /// static across every commitment transaction.
322 pub extern "C" fn ChannelPublicKeys_set_payment_point(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
323 unsafe { &mut *this_ptr.inner }.payment_point = val.into_rust();
325 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
326 /// public key which receives non-HTLC-encumbered funds which are only available for spending
327 /// after some delay (or can be claimed via the revocation path).
329 pub extern "C" fn ChannelPublicKeys_get_delayed_payment_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
330 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint;
331 crate::c_types::PublicKey::from_rust(&(*inner_val))
333 /// The base point which is used (with derive_public_key) to derive a per-commitment payment
334 /// public key which receives non-HTLC-encumbered funds which are only available for spending
335 /// after some delay (or can be claimed via the revocation path).
337 pub extern "C" fn ChannelPublicKeys_set_delayed_payment_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
338 unsafe { &mut *this_ptr.inner }.delayed_payment_basepoint = val.into_rust();
340 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
341 /// which is used to encumber HTLC-in-flight outputs.
343 pub extern "C" fn ChannelPublicKeys_get_htlc_basepoint(this_ptr: &ChannelPublicKeys) -> crate::c_types::PublicKey {
344 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_basepoint;
345 crate::c_types::PublicKey::from_rust(&(*inner_val))
347 /// The base point which is used (with derive_public_key) to derive a per-commitment public key
348 /// which is used to encumber HTLC-in-flight outputs.
350 pub extern "C" fn ChannelPublicKeys_set_htlc_basepoint(this_ptr: &mut ChannelPublicKeys, mut val: crate::c_types::PublicKey) {
351 unsafe { &mut *this_ptr.inner }.htlc_basepoint = val.into_rust();
353 /// Constructs a new ChannelPublicKeys given each field
356 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 {
357 ChannelPublicKeys { inner: Box::into_raw(Box::new(nativeChannelPublicKeys {
358 funding_pubkey: funding_pubkey_arg.into_rust(),
359 revocation_basepoint: revocation_basepoint_arg.into_rust(),
360 payment_point: payment_point_arg.into_rust(),
361 delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(),
362 htlc_basepoint: htlc_basepoint_arg.into_rust(),
363 })), is_owned: true }
365 impl Clone for ChannelPublicKeys {
366 fn clone(&self) -> Self {
368 inner: if <*mut nativeChannelPublicKeys>::is_null(self.inner) { std::ptr::null_mut() } else {
369 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
375 /// Used only if an object of this type is returned as a trait impl by a method
376 pub(crate) extern "C" fn ChannelPublicKeys_clone_void(this_ptr: *const c_void) -> *mut c_void {
377 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelPublicKeys)).clone() })) as *mut c_void
380 /// Creates a copy of the ChannelPublicKeys
381 pub extern "C" fn ChannelPublicKeys_clone(orig: &ChannelPublicKeys) -> ChannelPublicKeys {
385 /// Serialize the ChannelPublicKeys object into a byte array which can be read by ChannelPublicKeys_read
386 pub extern "C" fn ChannelPublicKeys_write(obj: &ChannelPublicKeys) -> crate::c_types::derived::CVec_u8Z {
387 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
390 pub(crate) extern "C" fn ChannelPublicKeys_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
391 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelPublicKeys) })
394 /// Read a ChannelPublicKeys from a byte array, created by ChannelPublicKeys_write
395 pub extern "C" fn ChannelPublicKeys_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelPublicKeysDecodeErrorZ {
396 let res = crate::c_types::deserialize_obj(ser);
397 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() };
400 /// Create per-state keys from channel base points and the per-commitment point.
401 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
404 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 {
405 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());
406 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() };
410 /// Generate per-state keys from channel static keys.
411 /// Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
414 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 {
415 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);
416 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() };
420 /// The maximum length of a script returned by get_revokeable_redeemscript.
423 pub static REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH: usize = lightning::ln::chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH;
424 /// A script either spendable by the revocation
425 /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
426 /// Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
428 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 {
429 let mut ret = lightning::ln::chan_utils::get_revokeable_redeemscript(&revocation_key.into_rust(), contest_delay, &broadcaster_delayed_payment_key.into_rust());
430 ret.into_bytes().into()
434 use lightning::ln::chan_utils::HTLCOutputInCommitment as nativeHTLCOutputInCommitmentImport;
435 type nativeHTLCOutputInCommitment = nativeHTLCOutputInCommitmentImport;
437 /// Information about an HTLC as it appears in a commitment transaction
440 pub struct HTLCOutputInCommitment {
441 /// A pointer to the opaque Rust object.
443 /// Nearly everywhere, inner must be non-null, however in places where
444 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
445 pub inner: *mut nativeHTLCOutputInCommitment,
446 /// Indicates that this is the only struct which contains the same pointer.
448 /// Rust functions which take ownership of an object provided via an argument require
449 /// this to be true and invalidate the object pointed to by inner.
453 impl Drop for HTLCOutputInCommitment {
455 if self.is_owned && !<*mut nativeHTLCOutputInCommitment>::is_null(self.inner) {
456 let _ = unsafe { Box::from_raw(self.inner) };
460 /// Frees any resources used by the HTLCOutputInCommitment, if is_owned is set and inner is non-NULL.
462 pub extern "C" fn HTLCOutputInCommitment_free(this_obj: HTLCOutputInCommitment) { }
464 /// Used only if an object of this type is returned as a trait impl by a method
465 extern "C" fn HTLCOutputInCommitment_free_void(this_ptr: *mut c_void) {
466 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHTLCOutputInCommitment); }
469 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
470 impl HTLCOutputInCommitment {
471 pub(crate) fn take_inner(mut self) -> *mut nativeHTLCOutputInCommitment {
472 assert!(self.is_owned);
473 let ret = self.inner;
474 self.inner = std::ptr::null_mut();
478 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
479 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
480 /// need to compare this value to whether the commitment transaction in question is that of
481 /// the counterparty or our own.
483 pub extern "C" fn HTLCOutputInCommitment_get_offered(this_ptr: &HTLCOutputInCommitment) -> bool {
484 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.offered;
487 /// Whether the HTLC was \"offered\" (ie outbound in relation to this commitment transaction).
488 /// Note that this is not the same as whether it is ountbound *from us*. To determine that you
489 /// need to compare this value to whether the commitment transaction in question is that of
490 /// the counterparty or our own.
492 pub extern "C" fn HTLCOutputInCommitment_set_offered(this_ptr: &mut HTLCOutputInCommitment, mut val: bool) {
493 unsafe { &mut *this_ptr.inner }.offered = val;
495 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
496 /// this divided by 1000.
498 pub extern "C" fn HTLCOutputInCommitment_get_amount_msat(this_ptr: &HTLCOutputInCommitment) -> u64 {
499 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.amount_msat;
502 /// The value, in msat, of the HTLC. The value as it appears in the commitment transaction is
503 /// this divided by 1000.
505 pub extern "C" fn HTLCOutputInCommitment_set_amount_msat(this_ptr: &mut HTLCOutputInCommitment, mut val: u64) {
506 unsafe { &mut *this_ptr.inner }.amount_msat = val;
508 /// The CLTV lock-time at which this HTLC expires.
510 pub extern "C" fn HTLCOutputInCommitment_get_cltv_expiry(this_ptr: &HTLCOutputInCommitment) -> u32 {
511 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry;
514 /// The CLTV lock-time at which this HTLC expires.
516 pub extern "C" fn HTLCOutputInCommitment_set_cltv_expiry(this_ptr: &mut HTLCOutputInCommitment, mut val: u32) {
517 unsafe { &mut *this_ptr.inner }.cltv_expiry = val;
519 /// The hash of the preimage which unlocks this HTLC.
521 pub extern "C" fn HTLCOutputInCommitment_get_payment_hash(this_ptr: &HTLCOutputInCommitment) -> *const [u8; 32] {
522 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.payment_hash;
525 /// The hash of the preimage which unlocks this HTLC.
527 pub extern "C" fn HTLCOutputInCommitment_set_payment_hash(this_ptr: &mut HTLCOutputInCommitment, mut val: crate::c_types::ThirtyTwoBytes) {
528 unsafe { &mut *this_ptr.inner }.payment_hash = ::lightning::ln::channelmanager::PaymentHash(val.data);
530 impl Clone for HTLCOutputInCommitment {
531 fn clone(&self) -> Self {
533 inner: if <*mut nativeHTLCOutputInCommitment>::is_null(self.inner) { std::ptr::null_mut() } else {
534 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
540 /// Used only if an object of this type is returned as a trait impl by a method
541 pub(crate) extern "C" fn HTLCOutputInCommitment_clone_void(this_ptr: *const c_void) -> *mut c_void {
542 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHTLCOutputInCommitment)).clone() })) as *mut c_void
545 /// Creates a copy of the HTLCOutputInCommitment
546 pub extern "C" fn HTLCOutputInCommitment_clone(orig: &HTLCOutputInCommitment) -> HTLCOutputInCommitment {
550 /// Serialize the HTLCOutputInCommitment object into a byte array which can be read by HTLCOutputInCommitment_read
551 pub extern "C" fn HTLCOutputInCommitment_write(obj: &HTLCOutputInCommitment) -> crate::c_types::derived::CVec_u8Z {
552 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
555 pub(crate) extern "C" fn HTLCOutputInCommitment_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
556 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHTLCOutputInCommitment) })
559 /// Read a HTLCOutputInCommitment from a byte array, created by HTLCOutputInCommitment_write
560 pub extern "C" fn HTLCOutputInCommitment_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HTLCOutputInCommitmentDecodeErrorZ {
561 let res = crate::c_types::deserialize_obj(ser);
562 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() };
565 /// Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
566 /// does not need to have its previous_output_index filled.
568 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 {
569 let mut ret = lightning::ln::chan_utils::get_htlc_redeemscript(unsafe { &*htlc.inner }, unsafe { &*keys.inner });
570 ret.into_bytes().into()
573 /// Gets the redeemscript for a funding output from the two funding public keys.
574 /// Note that the order of funding public keys does not matter.
576 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 {
577 let mut ret = lightning::ln::chan_utils::make_funding_redeemscript(&broadcaster.into_rust(), &countersignatory.into_rust());
578 ret.into_bytes().into()
581 /// panics if htlc.transaction_output_index.is_none()!
583 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 {
584 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());
585 let mut local_ret = ::bitcoin::consensus::encode::serialize(&ret);
586 crate::c_types::Transaction::from_vec(local_ret)
590 use lightning::ln::chan_utils::ChannelTransactionParameters as nativeChannelTransactionParametersImport;
591 type nativeChannelTransactionParameters = nativeChannelTransactionParametersImport;
593 /// Per-channel data used to build transactions in conjunction with the per-commitment data (CommitmentTransaction).
594 /// The fields are organized by holder/counterparty.
596 /// Normally, this is converted to the broadcaster/countersignatory-organized DirectedChannelTransactionParameters
597 /// before use, via the as_holder_broadcastable and as_counterparty_broadcastable functions.
600 pub struct ChannelTransactionParameters {
601 /// A pointer to the opaque Rust object.
603 /// Nearly everywhere, inner must be non-null, however in places where
604 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
605 pub inner: *mut nativeChannelTransactionParameters,
606 /// Indicates that this is the only struct which contains the same pointer.
608 /// Rust functions which take ownership of an object provided via an argument require
609 /// this to be true and invalidate the object pointed to by inner.
613 impl Drop for ChannelTransactionParameters {
615 if self.is_owned && !<*mut nativeChannelTransactionParameters>::is_null(self.inner) {
616 let _ = unsafe { Box::from_raw(self.inner) };
620 /// Frees any resources used by the ChannelTransactionParameters, if is_owned is set and inner is non-NULL.
622 pub extern "C" fn ChannelTransactionParameters_free(this_obj: ChannelTransactionParameters) { }
624 /// Used only if an object of this type is returned as a trait impl by a method
625 extern "C" fn ChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
626 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTransactionParameters); }
629 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
630 impl ChannelTransactionParameters {
631 pub(crate) fn take_inner(mut self) -> *mut nativeChannelTransactionParameters {
632 assert!(self.is_owned);
633 let ret = self.inner;
634 self.inner = std::ptr::null_mut();
638 /// Holder public keys
640 pub extern "C" fn ChannelTransactionParameters_get_holder_pubkeys(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
641 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_pubkeys;
642 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
644 /// Holder public keys
646 pub extern "C" fn ChannelTransactionParameters_set_holder_pubkeys(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) {
647 unsafe { &mut *this_ptr.inner }.holder_pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
649 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
651 pub extern "C" fn ChannelTransactionParameters_get_holder_selected_contest_delay(this_ptr: &ChannelTransactionParameters) -> u16 {
652 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay;
655 /// The contest delay selected by the holder, which applies to counterparty-broadcast transactions
657 pub extern "C" fn ChannelTransactionParameters_set_holder_selected_contest_delay(this_ptr: &mut ChannelTransactionParameters, mut val: u16) {
658 unsafe { &mut *this_ptr.inner }.holder_selected_contest_delay = val;
660 /// Whether the holder is the initiator of this channel.
661 /// This is an input to the commitment number obscure factor computation.
663 pub extern "C" fn ChannelTransactionParameters_get_is_outbound_from_holder(this_ptr: &ChannelTransactionParameters) -> bool {
664 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.is_outbound_from_holder;
667 /// Whether the holder is the initiator of this channel.
668 /// This is an input to the commitment number obscure factor computation.
670 pub extern "C" fn ChannelTransactionParameters_set_is_outbound_from_holder(this_ptr: &mut ChannelTransactionParameters, mut val: bool) {
671 unsafe { &mut *this_ptr.inner }.is_outbound_from_holder = val;
673 /// The late-bound counterparty channel transaction parameters.
674 /// These parameters are populated at the point in the protocol where the counterparty provides them.
676 pub extern "C" fn ChannelTransactionParameters_get_counterparty_parameters(this_ptr: &ChannelTransactionParameters) -> crate::ln::chan_utils::CounterpartyChannelTransactionParameters {
677 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_parameters;
678 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 };
681 /// The late-bound counterparty channel transaction parameters.
682 /// These parameters are populated at the point in the protocol where the counterparty provides them.
684 pub extern "C" fn ChannelTransactionParameters_set_counterparty_parameters(this_ptr: &mut ChannelTransactionParameters, mut val: crate::ln::chan_utils::CounterpartyChannelTransactionParameters) {
685 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
686 unsafe { &mut *this_ptr.inner }.counterparty_parameters = local_val;
688 /// The late-bound funding outpoint
690 pub extern "C" fn ChannelTransactionParameters_get_funding_outpoint(this_ptr: &ChannelTransactionParameters) -> crate::chain::transaction::OutPoint {
691 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.funding_outpoint;
692 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 };
695 /// The late-bound funding outpoint
697 pub extern "C" fn ChannelTransactionParameters_set_funding_outpoint(this_ptr: &mut ChannelTransactionParameters, mut val: crate::chain::transaction::OutPoint) {
698 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
699 unsafe { &mut *this_ptr.inner }.funding_outpoint = local_val;
701 /// Constructs a new ChannelTransactionParameters given each field
704 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 {
705 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()) } }) };
706 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()) } }) };
707 ChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeChannelTransactionParameters {
708 holder_pubkeys: *unsafe { Box::from_raw(holder_pubkeys_arg.take_inner()) },
709 holder_selected_contest_delay: holder_selected_contest_delay_arg,
710 is_outbound_from_holder: is_outbound_from_holder_arg,
711 counterparty_parameters: local_counterparty_parameters_arg,
712 funding_outpoint: local_funding_outpoint_arg,
713 })), is_owned: true }
715 impl Clone for ChannelTransactionParameters {
716 fn clone(&self) -> Self {
718 inner: if <*mut nativeChannelTransactionParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
719 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
725 /// Used only if an object of this type is returned as a trait impl by a method
726 pub(crate) extern "C" fn ChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
727 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTransactionParameters)).clone() })) as *mut c_void
730 /// Creates a copy of the ChannelTransactionParameters
731 pub extern "C" fn ChannelTransactionParameters_clone(orig: &ChannelTransactionParameters) -> ChannelTransactionParameters {
735 use lightning::ln::chan_utils::CounterpartyChannelTransactionParameters as nativeCounterpartyChannelTransactionParametersImport;
736 type nativeCounterpartyChannelTransactionParameters = nativeCounterpartyChannelTransactionParametersImport;
738 /// Late-bound per-channel counterparty data used to build transactions.
741 pub struct CounterpartyChannelTransactionParameters {
742 /// A pointer to the opaque Rust object.
744 /// Nearly everywhere, inner must be non-null, however in places where
745 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
746 pub inner: *mut nativeCounterpartyChannelTransactionParameters,
747 /// Indicates that this is the only struct which contains the same pointer.
749 /// Rust functions which take ownership of an object provided via an argument require
750 /// this to be true and invalidate the object pointed to by inner.
754 impl Drop for CounterpartyChannelTransactionParameters {
756 if self.is_owned && !<*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) {
757 let _ = unsafe { Box::from_raw(self.inner) };
761 /// Frees any resources used by the CounterpartyChannelTransactionParameters, if is_owned is set and inner is non-NULL.
763 pub extern "C" fn CounterpartyChannelTransactionParameters_free(this_obj: CounterpartyChannelTransactionParameters) { }
765 /// Used only if an object of this type is returned as a trait impl by a method
766 extern "C" fn CounterpartyChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
767 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCounterpartyChannelTransactionParameters); }
770 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
771 impl CounterpartyChannelTransactionParameters {
772 pub(crate) fn take_inner(mut self) -> *mut nativeCounterpartyChannelTransactionParameters {
773 assert!(self.is_owned);
774 let ret = self.inner;
775 self.inner = std::ptr::null_mut();
779 /// Counter-party public keys
781 pub extern "C" fn CounterpartyChannelTransactionParameters_get_pubkeys(this_ptr: &CounterpartyChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
782 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.pubkeys;
783 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
785 /// Counter-party public keys
787 pub extern "C" fn CounterpartyChannelTransactionParameters_set_pubkeys(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: crate::ln::chan_utils::ChannelPublicKeys) {
788 unsafe { &mut *this_ptr.inner }.pubkeys = *unsafe { Box::from_raw(val.take_inner()) };
790 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
792 pub extern "C" fn CounterpartyChannelTransactionParameters_get_selected_contest_delay(this_ptr: &CounterpartyChannelTransactionParameters) -> u16 {
793 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.selected_contest_delay;
796 /// The contest delay selected by the counterparty, which applies to holder-broadcast transactions
798 pub extern "C" fn CounterpartyChannelTransactionParameters_set_selected_contest_delay(this_ptr: &mut CounterpartyChannelTransactionParameters, mut val: u16) {
799 unsafe { &mut *this_ptr.inner }.selected_contest_delay = val;
801 /// Constructs a new CounterpartyChannelTransactionParameters given each field
804 pub extern "C" fn CounterpartyChannelTransactionParameters_new(mut pubkeys_arg: crate::ln::chan_utils::ChannelPublicKeys, mut selected_contest_delay_arg: u16) -> CounterpartyChannelTransactionParameters {
805 CounterpartyChannelTransactionParameters { inner: Box::into_raw(Box::new(nativeCounterpartyChannelTransactionParameters {
806 pubkeys: *unsafe { Box::from_raw(pubkeys_arg.take_inner()) },
807 selected_contest_delay: selected_contest_delay_arg,
808 })), is_owned: true }
810 impl Clone for CounterpartyChannelTransactionParameters {
811 fn clone(&self) -> Self {
813 inner: if <*mut nativeCounterpartyChannelTransactionParameters>::is_null(self.inner) { std::ptr::null_mut() } else {
814 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
820 /// Used only if an object of this type is returned as a trait impl by a method
821 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
822 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCounterpartyChannelTransactionParameters)).clone() })) as *mut c_void
825 /// Creates a copy of the CounterpartyChannelTransactionParameters
826 pub extern "C" fn CounterpartyChannelTransactionParameters_clone(orig: &CounterpartyChannelTransactionParameters) -> CounterpartyChannelTransactionParameters {
829 /// Whether the late bound parameters are populated.
832 pub extern "C" fn ChannelTransactionParameters_is_populated(this_arg: &ChannelTransactionParameters) -> bool {
833 let mut ret = unsafe { &*this_arg.inner }.is_populated();
837 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
838 /// given that the holder is the broadcaster.
840 /// self.is_populated() must be true before calling this function.
843 pub extern "C" fn ChannelTransactionParameters_as_holder_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters {
844 let mut ret = unsafe { &*this_arg.inner }.as_holder_broadcastable();
845 crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true }
848 /// Convert the holder/counterparty parameters to broadcaster/countersignatory-organized parameters,
849 /// given that the counterparty is the broadcaster.
851 /// self.is_populated() must be true before calling this function.
854 pub extern "C" fn ChannelTransactionParameters_as_counterparty_broadcastable(this_arg: &ChannelTransactionParameters) -> crate::ln::chan_utils::DirectedChannelTransactionParameters {
855 let mut ret = unsafe { &*this_arg.inner }.as_counterparty_broadcastable();
856 crate::ln::chan_utils::DirectedChannelTransactionParameters { inner: Box::into_raw(Box::new(ret)), is_owned: true }
860 /// Serialize the CounterpartyChannelTransactionParameters object into a byte array which can be read by CounterpartyChannelTransactionParameters_read
861 pub extern "C" fn CounterpartyChannelTransactionParameters_write(obj: &CounterpartyChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
862 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
865 pub(crate) extern "C" fn CounterpartyChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
866 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCounterpartyChannelTransactionParameters) })
869 /// Read a CounterpartyChannelTransactionParameters from a byte array, created by CounterpartyChannelTransactionParameters_write
870 pub extern "C" fn CounterpartyChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CounterpartyChannelTransactionParametersDecodeErrorZ {
871 let res = crate::c_types::deserialize_obj(ser);
872 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() };
876 /// Serialize the ChannelTransactionParameters object into a byte array which can be read by ChannelTransactionParameters_read
877 pub extern "C" fn ChannelTransactionParameters_write(obj: &ChannelTransactionParameters) -> crate::c_types::derived::CVec_u8Z {
878 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
881 pub(crate) extern "C" fn ChannelTransactionParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
882 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTransactionParameters) })
885 /// Read a ChannelTransactionParameters from a byte array, created by ChannelTransactionParameters_write
886 pub extern "C" fn ChannelTransactionParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelTransactionParametersDecodeErrorZ {
887 let res = crate::c_types::deserialize_obj(ser);
888 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() };
892 use lightning::ln::chan_utils::DirectedChannelTransactionParameters as nativeDirectedChannelTransactionParametersImport;
893 type nativeDirectedChannelTransactionParameters = nativeDirectedChannelTransactionParametersImport<'static>;
895 /// Static channel fields used to build transactions given per-commitment fields, organized by
896 /// broadcaster/countersignatory.
898 /// This is derived from the holder/counterparty-organized ChannelTransactionParameters via the
899 /// as_holder_broadcastable and as_counterparty_broadcastable functions.
902 pub struct DirectedChannelTransactionParameters {
903 /// A pointer to the opaque Rust object.
905 /// Nearly everywhere, inner must be non-null, however in places where
906 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
907 pub inner: *mut nativeDirectedChannelTransactionParameters,
908 /// Indicates that this is the only struct which contains the same pointer.
910 /// Rust functions which take ownership of an object provided via an argument require
911 /// this to be true and invalidate the object pointed to by inner.
915 impl Drop for DirectedChannelTransactionParameters {
917 if self.is_owned && !<*mut nativeDirectedChannelTransactionParameters>::is_null(self.inner) {
918 let _ = unsafe { Box::from_raw(self.inner) };
922 /// Frees any resources used by the DirectedChannelTransactionParameters, if is_owned is set and inner is non-NULL.
924 pub extern "C" fn DirectedChannelTransactionParameters_free(this_obj: DirectedChannelTransactionParameters) { }
926 /// Used only if an object of this type is returned as a trait impl by a method
927 extern "C" fn DirectedChannelTransactionParameters_free_void(this_ptr: *mut c_void) {
928 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelTransactionParameters); }
931 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
932 impl DirectedChannelTransactionParameters {
933 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelTransactionParameters {
934 assert!(self.is_owned);
935 let ret = self.inner;
936 self.inner = std::ptr::null_mut();
940 /// Get the channel pubkeys for the broadcaster
943 pub extern "C" fn DirectedChannelTransactionParameters_broadcaster_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
944 let mut ret = unsafe { &*this_arg.inner }.broadcaster_pubkeys();
945 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
948 /// Get the channel pubkeys for the countersignatory
951 pub extern "C" fn DirectedChannelTransactionParameters_countersignatory_pubkeys(this_arg: &DirectedChannelTransactionParameters) -> crate::ln::chan_utils::ChannelPublicKeys {
952 let mut ret = unsafe { &*this_arg.inner }.countersignatory_pubkeys();
953 crate::ln::chan_utils::ChannelPublicKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
956 /// Get the contest delay applicable to the transactions.
957 /// Note that the contest delay was selected by the countersignatory.
960 pub extern "C" fn DirectedChannelTransactionParameters_contest_delay(this_arg: &DirectedChannelTransactionParameters) -> u16 {
961 let mut ret = unsafe { &*this_arg.inner }.contest_delay();
965 /// Whether the channel is outbound from the broadcaster.
967 /// The boolean representing the side that initiated the channel is
968 /// an input to the commitment number obscure factor computation.
971 pub extern "C" fn DirectedChannelTransactionParameters_is_outbound(this_arg: &DirectedChannelTransactionParameters) -> bool {
972 let mut ret = unsafe { &*this_arg.inner }.is_outbound();
976 /// The funding outpoint
979 pub extern "C" fn DirectedChannelTransactionParameters_funding_outpoint(this_arg: &DirectedChannelTransactionParameters) -> crate::chain::transaction::OutPoint {
980 let mut ret = unsafe { &*this_arg.inner }.funding_outpoint();
981 crate::c_types::bitcoin_to_C_outpoint(ret)
985 use lightning::ln::chan_utils::HolderCommitmentTransaction as nativeHolderCommitmentTransactionImport;
986 type nativeHolderCommitmentTransaction = nativeHolderCommitmentTransactionImport;
988 /// Information needed to build and sign a holder's commitment transaction.
990 /// The transaction is only signed once we are ready to broadcast.
993 pub struct HolderCommitmentTransaction {
994 /// A pointer to the opaque Rust object.
996 /// Nearly everywhere, inner must be non-null, however in places where
997 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
998 pub inner: *mut nativeHolderCommitmentTransaction,
999 /// Indicates that this is the only struct which contains the same pointer.
1001 /// Rust functions which take ownership of an object provided via an argument require
1002 /// this to be true and invalidate the object pointed to by inner.
1006 impl Drop for HolderCommitmentTransaction {
1007 fn drop(&mut self) {
1008 if self.is_owned && !<*mut nativeHolderCommitmentTransaction>::is_null(self.inner) {
1009 let _ = unsafe { Box::from_raw(self.inner) };
1013 /// Frees any resources used by the HolderCommitmentTransaction, if is_owned is set and inner is non-NULL.
1015 pub extern "C" fn HolderCommitmentTransaction_free(this_obj: HolderCommitmentTransaction) { }
1017 /// Used only if an object of this type is returned as a trait impl by a method
1018 extern "C" fn HolderCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1019 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHolderCommitmentTransaction); }
1022 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1023 impl HolderCommitmentTransaction {
1024 pub(crate) fn take_inner(mut self) -> *mut nativeHolderCommitmentTransaction {
1025 assert!(self.is_owned);
1026 let ret = self.inner;
1027 self.inner = std::ptr::null_mut();
1031 /// Our counterparty's signature for the transaction
1033 pub extern "C" fn HolderCommitmentTransaction_get_counterparty_sig(this_ptr: &HolderCommitmentTransaction) -> crate::c_types::Signature {
1034 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.counterparty_sig;
1035 crate::c_types::Signature::from_rust(&(*inner_val))
1037 /// Our counterparty's signature for the transaction
1039 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_sig(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::Signature) {
1040 unsafe { &mut *this_ptr.inner }.counterparty_sig = val.into_rust();
1042 /// All non-dust counterparty HTLC signatures, in the order they appear in the transaction
1044 pub extern "C" fn HolderCommitmentTransaction_set_counterparty_htlc_sigs(this_ptr: &mut HolderCommitmentTransaction, mut val: crate::c_types::derived::CVec_SignatureZ) {
1045 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); };
1046 unsafe { &mut *this_ptr.inner }.counterparty_htlc_sigs = local_val;
1048 impl Clone for HolderCommitmentTransaction {
1049 fn clone(&self) -> Self {
1051 inner: if <*mut nativeHolderCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else {
1052 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1058 /// Used only if an object of this type is returned as a trait impl by a method
1059 pub(crate) extern "C" fn HolderCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1060 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHolderCommitmentTransaction)).clone() })) as *mut c_void
1063 /// Creates a copy of the HolderCommitmentTransaction
1064 pub extern "C" fn HolderCommitmentTransaction_clone(orig: &HolderCommitmentTransaction) -> HolderCommitmentTransaction {
1068 /// Serialize the HolderCommitmentTransaction object into a byte array which can be read by HolderCommitmentTransaction_read
1069 pub extern "C" fn HolderCommitmentTransaction_write(obj: &HolderCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1070 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1073 pub(crate) extern "C" fn HolderCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1074 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHolderCommitmentTransaction) })
1077 /// Read a HolderCommitmentTransaction from a byte array, created by HolderCommitmentTransaction_write
1078 pub extern "C" fn HolderCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HolderCommitmentTransactionDecodeErrorZ {
1079 let res = crate::c_types::deserialize_obj(ser);
1080 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() };
1083 /// Create a new holder transaction with the given counterparty signatures.
1084 /// The funding keys are used to figure out which signature should go first when building the transaction for broadcast.
1087 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 {
1088 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() }); };
1089 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());
1090 HolderCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1094 use lightning::ln::chan_utils::BuiltCommitmentTransaction as nativeBuiltCommitmentTransactionImport;
1095 type nativeBuiltCommitmentTransaction = nativeBuiltCommitmentTransactionImport;
1097 /// A pre-built Bitcoin commitment transaction and its txid.
1100 pub struct BuiltCommitmentTransaction {
1101 /// A pointer to the opaque Rust object.
1103 /// Nearly everywhere, inner must be non-null, however in places where
1104 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1105 pub inner: *mut nativeBuiltCommitmentTransaction,
1106 /// Indicates that this is the only struct which contains the same pointer.
1108 /// Rust functions which take ownership of an object provided via an argument require
1109 /// this to be true and invalidate the object pointed to by inner.
1113 impl Drop for BuiltCommitmentTransaction {
1114 fn drop(&mut self) {
1115 if self.is_owned && !<*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) {
1116 let _ = unsafe { Box::from_raw(self.inner) };
1120 /// Frees any resources used by the BuiltCommitmentTransaction, if is_owned is set and inner is non-NULL.
1122 pub extern "C" fn BuiltCommitmentTransaction_free(this_obj: BuiltCommitmentTransaction) { }
1124 /// Used only if an object of this type is returned as a trait impl by a method
1125 extern "C" fn BuiltCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1126 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBuiltCommitmentTransaction); }
1129 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1130 impl BuiltCommitmentTransaction {
1131 pub(crate) fn take_inner(mut self) -> *mut nativeBuiltCommitmentTransaction {
1132 assert!(self.is_owned);
1133 let ret = self.inner;
1134 self.inner = std::ptr::null_mut();
1138 /// The commitment transaction
1140 pub extern "C" fn BuiltCommitmentTransaction_get_transaction(this_ptr: &BuiltCommitmentTransaction) -> crate::c_types::Transaction {
1141 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.transaction;
1142 let mut local_inner_val = ::bitcoin::consensus::encode::serialize(inner_val);
1143 crate::c_types::Transaction::from_vec(local_inner_val)
1145 /// The commitment transaction
1147 pub extern "C" fn BuiltCommitmentTransaction_set_transaction(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::Transaction) {
1148 unsafe { &mut *this_ptr.inner }.transaction = val.into_bitcoin();
1150 /// The txid for the commitment transaction.
1152 /// This is provided as a performance optimization, instead of calling transaction.txid()
1155 pub extern "C" fn BuiltCommitmentTransaction_get_txid(this_ptr: &BuiltCommitmentTransaction) -> *const [u8; 32] {
1156 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.txid;
1157 (*inner_val).as_inner()
1159 /// The txid for the commitment transaction.
1161 /// This is provided as a performance optimization, instead of calling transaction.txid()
1164 pub extern "C" fn BuiltCommitmentTransaction_set_txid(this_ptr: &mut BuiltCommitmentTransaction, mut val: crate::c_types::ThirtyTwoBytes) {
1165 unsafe { &mut *this_ptr.inner }.txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap();
1167 /// Constructs a new BuiltCommitmentTransaction given each field
1170 pub extern "C" fn BuiltCommitmentTransaction_new(mut transaction_arg: crate::c_types::Transaction, mut txid_arg: crate::c_types::ThirtyTwoBytes) -> BuiltCommitmentTransaction {
1171 BuiltCommitmentTransaction { inner: Box::into_raw(Box::new(nativeBuiltCommitmentTransaction {
1172 transaction: transaction_arg.into_bitcoin(),
1173 txid: ::bitcoin::hash_types::Txid::from_slice(&txid_arg.data[..]).unwrap(),
1174 })), is_owned: true }
1176 impl Clone for BuiltCommitmentTransaction {
1177 fn clone(&self) -> Self {
1179 inner: if <*mut nativeBuiltCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else {
1180 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1186 /// Used only if an object of this type is returned as a trait impl by a method
1187 pub(crate) extern "C" fn BuiltCommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1188 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBuiltCommitmentTransaction)).clone() })) as *mut c_void
1191 /// Creates a copy of the BuiltCommitmentTransaction
1192 pub extern "C" fn BuiltCommitmentTransaction_clone(orig: &BuiltCommitmentTransaction) -> BuiltCommitmentTransaction {
1196 /// Serialize the BuiltCommitmentTransaction object into a byte array which can be read by BuiltCommitmentTransaction_read
1197 pub extern "C" fn BuiltCommitmentTransaction_write(obj: &BuiltCommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1198 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1201 pub(crate) extern "C" fn BuiltCommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1202 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBuiltCommitmentTransaction) })
1205 /// Read a BuiltCommitmentTransaction from a byte array, created by BuiltCommitmentTransaction_write
1206 pub extern "C" fn BuiltCommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BuiltCommitmentTransactionDecodeErrorZ {
1207 let res = crate::c_types::deserialize_obj(ser);
1208 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() };
1211 /// Get the SIGHASH_ALL sighash value of the transaction.
1213 /// This can be used to verify a signature.
1216 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 {
1217 let mut ret = unsafe { &*this_arg.inner }.get_sighash_all(&::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis);
1218 crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() }
1221 /// Sign a transaction, either because we are counter-signing the counterparty's transaction or
1222 /// because we are about to broadcast a holder transaction.
1225 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 {
1226 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);
1227 crate::c_types::Signature::from_rust(&ret)
1231 use lightning::ln::chan_utils::CommitmentTransaction as nativeCommitmentTransactionImport;
1232 type nativeCommitmentTransaction = nativeCommitmentTransactionImport;
1234 /// This class tracks the per-transaction information needed to build a commitment transaction and to
1235 /// actually build it and sign. It is used for holder transactions that we sign only when needed
1236 /// and for transactions we sign for the counterparty.
1238 /// This class can be used inside a signer implementation to generate a signature given the relevant
1242 pub struct CommitmentTransaction {
1243 /// A pointer to the opaque Rust object.
1245 /// Nearly everywhere, inner must be non-null, however in places where
1246 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1247 pub inner: *mut nativeCommitmentTransaction,
1248 /// Indicates that this is the only struct which contains the same pointer.
1250 /// Rust functions which take ownership of an object provided via an argument require
1251 /// this to be true and invalidate the object pointed to by inner.
1255 impl Drop for CommitmentTransaction {
1256 fn drop(&mut self) {
1257 if self.is_owned && !<*mut nativeCommitmentTransaction>::is_null(self.inner) {
1258 let _ = unsafe { Box::from_raw(self.inner) };
1262 /// Frees any resources used by the CommitmentTransaction, if is_owned is set and inner is non-NULL.
1264 pub extern "C" fn CommitmentTransaction_free(this_obj: CommitmentTransaction) { }
1266 /// Used only if an object of this type is returned as a trait impl by a method
1267 extern "C" fn CommitmentTransaction_free_void(this_ptr: *mut c_void) {
1268 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentTransaction); }
1271 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1272 impl CommitmentTransaction {
1273 pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentTransaction {
1274 assert!(self.is_owned);
1275 let ret = self.inner;
1276 self.inner = std::ptr::null_mut();
1280 impl Clone for CommitmentTransaction {
1281 fn clone(&self) -> Self {
1283 inner: if <*mut nativeCommitmentTransaction>::is_null(self.inner) { std::ptr::null_mut() } else {
1284 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1290 /// Used only if an object of this type is returned as a trait impl by a method
1291 pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
1292 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void
1295 /// Creates a copy of the CommitmentTransaction
1296 pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction {
1300 /// Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
1301 pub extern "C" fn CommitmentTransaction_write(obj: &CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
1302 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1305 pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1306 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) })
1309 /// Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
1310 pub extern "C" fn CommitmentTransaction_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentTransactionDecodeErrorZ {
1311 let res = crate::c_types::deserialize_obj(ser);
1312 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() };
1315 /// The backwards-counting commitment number
1318 pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &CommitmentTransaction) -> u64 {
1319 let mut ret = unsafe { &*this_arg.inner }.commitment_number();
1323 /// The value to be sent to the broadcaster
1326 pub extern "C" fn CommitmentTransaction_to_broadcaster_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1327 let mut ret = unsafe { &*this_arg.inner }.to_broadcaster_value_sat();
1331 /// The value to be sent to the counterparty
1334 pub extern "C" fn CommitmentTransaction_to_countersignatory_value_sat(this_arg: &CommitmentTransaction) -> u64 {
1335 let mut ret = unsafe { &*this_arg.inner }.to_countersignatory_value_sat();
1339 /// The feerate paid per 1000-weight-unit in this commitment transaction.
1342 pub extern "C" fn CommitmentTransaction_feerate_per_kw(this_arg: &CommitmentTransaction) -> u32 {
1343 let mut ret = unsafe { &*this_arg.inner }.feerate_per_kw();
1347 /// Trust our pre-built transaction and derived transaction creation public keys.
1349 /// Applies a wrapper which allows access to these fields.
1351 /// This should only be used if you fully trust the builder of this object. It should not
1352 ///\tbe used by an external signer - instead use the verify function.
1355 pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction) -> crate::ln::chan_utils::TrustedCommitmentTransaction {
1356 let mut ret = unsafe { &*this_arg.inner }.trust();
1357 crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1360 /// Verify our pre-built transaction and derived transaction creation public keys.
1362 /// Applies a wrapper which allows access to these fields.
1364 /// An external validating signer must call this method before signing
1365 /// or using the built transaction.
1368 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 {
1369 let mut ret = unsafe { &*this_arg.inner }.verify(unsafe { &*channel_parameters.inner }, unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, secp256k1::SECP256K1);
1370 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() };
1375 use lightning::ln::chan_utils::TrustedCommitmentTransaction as nativeTrustedCommitmentTransactionImport;
1376 type nativeTrustedCommitmentTransaction = nativeTrustedCommitmentTransactionImport<'static>;
1378 /// A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin
1379 /// transaction and the transaction creation keys) are trusted.
1381 /// See trust() and verify() functions on CommitmentTransaction.
1383 /// This structure implements Deref.
1386 pub struct TrustedCommitmentTransaction {
1387 /// A pointer to the opaque Rust object.
1389 /// Nearly everywhere, inner must be non-null, however in places where
1390 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1391 pub inner: *mut nativeTrustedCommitmentTransaction,
1392 /// Indicates that this is the only struct which contains the same pointer.
1394 /// Rust functions which take ownership of an object provided via an argument require
1395 /// this to be true and invalidate the object pointed to by inner.
1399 impl Drop for TrustedCommitmentTransaction {
1400 fn drop(&mut self) {
1401 if self.is_owned && !<*mut nativeTrustedCommitmentTransaction>::is_null(self.inner) {
1402 let _ = unsafe { Box::from_raw(self.inner) };
1406 /// Frees any resources used by the TrustedCommitmentTransaction, if is_owned is set and inner is non-NULL.
1408 pub extern "C" fn TrustedCommitmentTransaction_free(this_obj: TrustedCommitmentTransaction) { }
1410 /// Used only if an object of this type is returned as a trait impl by a method
1411 extern "C" fn TrustedCommitmentTransaction_free_void(this_ptr: *mut c_void) {
1412 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedCommitmentTransaction); }
1415 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1416 impl TrustedCommitmentTransaction {
1417 pub(crate) fn take_inner(mut self) -> *mut nativeTrustedCommitmentTransaction {
1418 assert!(self.is_owned);
1419 let ret = self.inner;
1420 self.inner = std::ptr::null_mut();
1424 /// The transaction ID of the built Bitcoin transaction
1427 pub extern "C" fn TrustedCommitmentTransaction_txid(this_arg: &TrustedCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
1428 let mut ret = unsafe { &*this_arg.inner }.txid();
1429 crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
1432 /// The pre-built Bitcoin commitment transaction
1435 pub extern "C" fn TrustedCommitmentTransaction_built_transaction(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::BuiltCommitmentTransaction {
1436 let mut ret = unsafe { &*this_arg.inner }.built_transaction();
1437 crate::ln::chan_utils::BuiltCommitmentTransaction { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1440 /// The pre-calculated transaction creation public keys.
1443 pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys {
1444 let mut ret = unsafe { &*this_arg.inner }.keys();
1445 crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
1448 /// Get a signature for each HTLC which was included in the commitment transaction (ie for
1449 /// which HTLCOutputInCommitment::transaction_output_index.is_some()).
1451 /// The returned Vec has one entry for each HTLC, and in the same order.
1454 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 {
1455 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);
1456 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() };
1460 /// Get the transaction number obscure factor
1462 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 {
1463 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);