Merge pull request #767 from TheBlueMatt/2020-12-chansigner-read-bindings
[rust-lightning] / lightning-c-bindings / src / c_types / mod.rs
index 840bd7a4446a5b07c59658e66686d734f680de38..20c49a6d92b30f0c96ad2ac6e394fbfbbcfa2c31 100644 (file)
@@ -2,11 +2,14 @@ pub mod derived;
 
 use bitcoin::Script as BitcoinScript;
 use bitcoin::Transaction as BitcoinTransaction;
+use bitcoin::hashes::Hash;
 use bitcoin::secp256k1::key::PublicKey as SecpPublicKey;
 use bitcoin::secp256k1::key::SecretKey as SecpSecretKey;
 use bitcoin::secp256k1::Signature as SecpSignature;
 use bitcoin::secp256k1::Error as SecpError;
 
+use std::convert::TryInto; // Bindings need at least rustc 1.34
+
 #[derive(Clone)]
 #[repr(C)]
 pub struct PublicKey {
@@ -54,8 +57,9 @@ impl Signature {
        pub(crate) fn into_rust(&self) -> SecpSignature {
                SecpSignature::from_compact(&self.compact_form).unwrap()
        }
-       pub(crate) fn is_null(&self) -> bool { self.compact_form[..] == [0; 64][..] }
-       pub(crate) fn null() -> Self { Self { compact_form: [0; 64] } }
+       // The following are used for Option<Signature> which we support, but don't use anymore
+       #[allow(unused)] pub(crate) fn is_null(&self) -> bool { self.compact_form[..] == [0; 64][..] }
+       #[allow(unused)] pub(crate) fn null() -> Self { Self { compact_form: [0; 64] } }
 }
 
 #[repr(C)]
@@ -130,6 +134,10 @@ impl Drop for Transaction {
 #[no_mangle]
 pub extern "C" fn Transaction_free(_res: Transaction) { }
 
+pub(crate) fn bitcoin_to_C_outpoint(outpoint: ::bitcoin::blockdata::transaction::OutPoint) -> crate::chain::transaction::OutPoint {
+       crate::chain::transaction::OutPoint_new(ThirtyTwoBytes { data: outpoint.txid.into_inner() }, outpoint.vout.try_into().unwrap())
+}
+
 #[repr(C)]
 #[derive(Clone)]
 /// A transaction output including a scriptPubKey and value.
@@ -320,7 +328,7 @@ impl<T: Clone> Clone for CVecTempl<T> {
        fn clone(&self) -> Self {
                let mut res = Vec::new();
                if self.datalen == 0 { return Self::from(res); }
-               res.clone_from_slice(unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) });
+               res.extend_from_slice(unsafe { std::slice::from_raw_parts_mut(self.data, self.datalen) });
                Self::from(res)
        }
 }