+/// Get the SIGHASH_ALL sighash value of the transaction.
+///
+/// This can be used to verify a signature.
+#[must_use]
+#[no_mangle]
+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 {
+ let mut ret = unsafe { &*this_arg.inner }.get_sighash_all(&::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis);
+ crate::c_types::ThirtyTwoBytes { data: ret.as_ref().clone() }
+}
+
+/// Sign a transaction, either because we are counter-signing the counterparty's transaction or
+/// because we are about to broadcast a holder transaction.
+#[must_use]
+#[no_mangle]
+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 {
+ let mut ret = unsafe { &*this_arg.inner }.sign(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *funding_key}[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(funding_redeemscript.to_slice())), channel_value_satoshis, &bitcoin::secp256k1::Secp256k1::new());
+ crate::c_types::Signature::from_rust(&ret)
+}
+
+
+use lightning::ln::chan_utils::CommitmentTransaction as nativeCommitmentTransactionImport;
+type nativeCommitmentTransaction = nativeCommitmentTransactionImport;
+
+/// This class tracks the per-transaction information needed to build a commitment transaction and to
+/// actually build it and sign. It is used for holder transactions that we sign only when needed
+/// and for transactions we sign for the counterparty.
+///
+/// This class can be used inside a signer implementation to generate a signature given the relevant
+/// secret key.
+#[must_use]
+#[repr(C)]
+pub struct CommitmentTransaction {
+ /// Nearly everywhere, inner must be non-null, however in places where
+ /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+ pub inner: *mut nativeCommitmentTransaction,
+ pub is_owned: bool,
+}
+
+impl Drop for CommitmentTransaction {
+ fn drop(&mut self) {
+ if self.is_owned && !self.inner.is_null() {
+ let _ = unsafe { Box::from_raw(self.inner) };
+ }
+ }
+}
+#[no_mangle]
+pub extern "C" fn CommitmentTransaction_free(this_ptr: CommitmentTransaction) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+extern "C" fn CommitmentTransaction_free_void(this_ptr: *mut c_void) {
+ unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentTransaction); }
+}
+#[allow(unused)]
+/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+impl CommitmentTransaction {
+ pub(crate) fn take_inner(mut self) -> *mut nativeCommitmentTransaction {
+ assert!(self.is_owned);
+ let ret = self.inner;
+ self.inner = std::ptr::null_mut();
+ ret
+ }
+}
+impl Clone for CommitmentTransaction {
+ fn clone(&self) -> Self {
+ Self {
+ inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
+ is_owned: true,
+ }
+ }
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn CommitmentTransaction_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentTransaction)).clone() })) as *mut c_void
+}
+#[no_mangle]
+pub extern "C" fn CommitmentTransaction_clone(orig: &CommitmentTransaction) -> CommitmentTransaction {
+ CommitmentTransaction { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
+}
+#[no_mangle]
+pub extern "C" fn CommitmentTransaction_write(obj: *const CommitmentTransaction) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
+}
+#[no_mangle]
+pub(crate) extern "C" fn CommitmentTransaction_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentTransaction) })
+}
+#[no_mangle]
+pub extern "C" fn CommitmentTransaction_read(ser: crate::c_types::u8slice) -> CommitmentTransaction {
+ if let Ok(res) = crate::c_types::deserialize_obj(ser) {
+ CommitmentTransaction { inner: Box::into_raw(Box::new(res)), is_owned: true }
+ } else {
+ CommitmentTransaction { inner: std::ptr::null_mut(), is_owned: true }
+ }
+}
+/// The backwards-counting commitment number
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CommitmentTransaction_commitment_number(this_arg: &CommitmentTransaction) -> u64 {
+ let mut ret = unsafe { &*this_arg.inner }.commitment_number();
+ ret
+}
+
+/// The value to be sent to the broadcaster
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CommitmentTransaction_to_broadcaster_value_sat(this_arg: &CommitmentTransaction) -> u64 {
+ let mut ret = unsafe { &*this_arg.inner }.to_broadcaster_value_sat();
+ ret
+}
+
+/// The value to be sent to the counterparty
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CommitmentTransaction_to_countersignatory_value_sat(this_arg: &CommitmentTransaction) -> u64 {
+ let mut ret = unsafe { &*this_arg.inner }.to_countersignatory_value_sat();
+ ret
+}
+
+/// The feerate paid per 1000-weight-unit in this commitment transaction.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CommitmentTransaction_feerate_per_kw(this_arg: &CommitmentTransaction) -> u32 {
+ let mut ret = unsafe { &*this_arg.inner }.feerate_per_kw();
+ ret
+}
+
+/// Trust our pre-built transaction and derived transaction creation public keys.
+///
+/// Applies a wrapper which allows access to these fields.
+///
+/// This should only be used if you fully trust the builder of this object. It should not
+///\tbe used by an external signer - instead use the verify function.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CommitmentTransaction_trust(this_arg: &CommitmentTransaction) -> crate::ln::chan_utils::TrustedCommitmentTransaction {
+ let mut ret = unsafe { &*this_arg.inner }.trust();
+ crate::ln::chan_utils::TrustedCommitmentTransaction { inner: Box::into_raw(Box::new(ret)), is_owned: true }
+}
+
+/// Verify our pre-built transaction and derived transaction creation public keys.
+///
+/// Applies a wrapper which allows access to these fields.
+///
+/// An external validating signer must call this method before signing
+/// or using the built transaction.
+#[must_use]
+#[no_mangle]
+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 {
+ let mut ret = unsafe { &*this_arg.inner }.verify(unsafe { &*channel_parameters.inner }, unsafe { &*broadcaster_keys.inner }, unsafe { &*countersignatory_keys.inner }, &bitcoin::secp256k1::Secp256k1::new());
+ 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 } }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
+ local_ret
+}
+
+
+use lightning::ln::chan_utils::TrustedCommitmentTransaction as nativeTrustedCommitmentTransactionImport;
+type nativeTrustedCommitmentTransaction = nativeTrustedCommitmentTransactionImport<'static>;
+
+/// A wrapper on CommitmentTransaction indicating that the derived fields (the built bitcoin
+/// transaction and the transaction creation keys) are trusted.
+///
+/// See trust() and verify() functions on CommitmentTransaction.
+///
+/// This structure implements Deref.
+#[must_use]
+#[repr(C)]
+pub struct TrustedCommitmentTransaction {
+ /// Nearly everywhere, inner must be non-null, however in places where
+ /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+ pub inner: *mut nativeTrustedCommitmentTransaction,
+ pub is_owned: bool,
+}
+
+impl Drop for TrustedCommitmentTransaction {
+ fn drop(&mut self) {
+ if self.is_owned && !self.inner.is_null() {
+ let _ = unsafe { Box::from_raw(self.inner) };
+ }
+ }
+}
+#[no_mangle]
+pub extern "C" fn TrustedCommitmentTransaction_free(this_ptr: TrustedCommitmentTransaction) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+extern "C" fn TrustedCommitmentTransaction_free_void(this_ptr: *mut c_void) {
+ unsafe { let _ = Box::from_raw(this_ptr as *mut nativeTrustedCommitmentTransaction); }
+}
+#[allow(unused)]
+/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+impl TrustedCommitmentTransaction {
+ pub(crate) fn take_inner(mut self) -> *mut nativeTrustedCommitmentTransaction {
+ assert!(self.is_owned);
+ let ret = self.inner;
+ self.inner = std::ptr::null_mut();
+ ret
+ }
+}
+/// The transaction ID of the built Bitcoin transaction
+#[must_use]
+#[no_mangle]
+pub extern "C" fn TrustedCommitmentTransaction_txid(this_arg: &TrustedCommitmentTransaction) -> crate::c_types::ThirtyTwoBytes {
+ let mut ret = unsafe { &*this_arg.inner }.txid();
+ crate::c_types::ThirtyTwoBytes { data: ret.into_inner() }
+}
+
+/// The pre-built Bitcoin commitment transaction
+#[must_use]
+#[no_mangle]
+pub extern "C" fn TrustedCommitmentTransaction_built_transaction(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::BuiltCommitmentTransaction {
+ let mut ret = unsafe { &*this_arg.inner }.built_transaction();
+ crate::ln::chan_utils::BuiltCommitmentTransaction { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
+}
+
+/// The pre-calculated transaction creation public keys.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn TrustedCommitmentTransaction_keys(this_arg: &TrustedCommitmentTransaction) -> crate::ln::chan_utils::TxCreationKeys {
+ let mut ret = unsafe { &*this_arg.inner }.keys();
+ crate::ln::chan_utils::TxCreationKeys { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
+}
+
+/// Get a signature for each HTLC which was included in the commitment transaction (ie for
+/// which HTLCOutputInCommitment::transaction_output_index.is_some()).
+///
+/// The returned Vec has one entry for each HTLC, and in the same order.
+#[must_use]
+#[no_mangle]
+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 {
+ let mut ret = unsafe { &*this_arg.inner }.get_htlc_sigs(&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *htlc_base_key}[..]).unwrap(), unsafe { &*channel_parameters.inner }, &bitcoin::secp256k1::Secp256k1::new());
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for item in o.drain(..) { local_ret_0.push( { crate::c_types::Signature::from_rust(&item) }); }; local_ret_0.into() }), Err(mut e) => crate::c_types::CResultTempl::err( { 0u8 /*e*/ }) };
+ local_ret
+}
+
+/// Get the transaction number obscure factor
+#[no_mangle]
+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 {
+ 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);
+ ret
+}
+