]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Handle transaction conversion directly instead of via a new var
authorMatt Corallo <git@bluematt.me>
Sun, 25 Apr 2021 22:30:07 +0000 (22:30 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 26 Apr 2021 16:03:41 +0000 (16:03 +0000)
new var conversion isn't supported everywhere, and there's really
no reason transaction conversion should need it.

c-bindings-gen/src/types.rs
lightning-c-bindings/src/c_types/mod.rs

index 74379b843b9f67e751bb4a1b0ed7576a509e61e7..e88133818cca6ae1a8584c3ef417a5c7d90983af 100644 (file)
@@ -949,8 +949,6 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        "[u8]" if is_ref => Some(("crate::c_types::u8slice::from_slice(", ")")),
                        "[usize]" if is_ref => Some(("crate::c_types::usizeslice::from_slice(", ")")),
 
-                       "bitcoin::blockdata::transaction::Transaction" if is_ref => Some(("::bitcoin::consensus::encode::serialize(", ")")),
-                       "bitcoin::blockdata::transaction::Transaction" if !is_ref => Some(("::bitcoin::consensus::encode::serialize(&", ")")),
                        "bitcoin::blockdata::block::BlockHeader" if is_ref => Some(("{ let mut s = [0u8; 80]; s[..].copy_from_slice(&::bitcoin::consensus::encode::serialize(", ")); s }")),
                        "bitcoin::blockdata::block::Block" if is_ref => Some(("::bitcoin::consensus::encode::serialize(", ")")),
                        "bitcoin::hash_types::Txid" => None,
@@ -996,7 +994,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        "bitcoin::secp256k1::Error" if !is_ref => Some("crate::c_types::Secp256k1Error::from_rust("),
                        "bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice::from_slice(&"),
                        "bitcoin::blockdata::script::Script" if !is_ref => Some(""),
-                       "bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction::from_vec(local_"),
+                       "bitcoin::blockdata::transaction::Transaction" if is_ref => Some("crate::c_types::Transaction::from_bitcoin("),
+                       "bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction::from_bitcoin(&"),
                        "bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("),
                        "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("),
                        "bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network::from_bitcoin("),
index ee7660cd09bc6cb0f11fbaae1922cb466676c88b..c4113a9647cf20f64b09d11881a626992d884d55 100644 (file)
@@ -187,9 +187,10 @@ impl Transaction {
                if self.datalen == 0 { panic!("0-length buffer can never represent a valid Transaction"); }
                ::bitcoin::consensus::encode::deserialize(unsafe { std::slice::from_raw_parts(self.data, self.datalen) }).unwrap()
        }
-       pub(crate) fn from_vec(v: Vec<u8>) -> Self {
-               let datalen = v.len();
-               let data = Box::into_raw(v.into_boxed_slice());
+       pub(crate) fn from_bitcoin(btc: &BitcoinTransaction) -> Self {
+               let vec = ::bitcoin::consensus::encode::serialize(btc);
+               let datalen = vec.len();
+               let data = Box::into_raw(vec.into_boxed_slice());
                Self {
                        data: unsafe { (*data).as_mut_ptr() },
                        datalen,