]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Support converting C `OutPoint`s to `bitcoin` `OutPoint`s
authorMatt Corallo <git@bluematt.me>
Thu, 23 Sep 2021 17:46:30 +0000 (17:46 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 23 Sep 2021 18:35:11 +0000 (18:35 +0000)
c-bindings-gen/src/types.rs
lightning-c-bindings/src/c_types/mod.rs

index 38752da2198603038aaaf67bfc8c617593fd30ea..cfa5b5f15fc0d2eacddb74cc188a4ae69bb2c908 100644 (file)
@@ -986,6 +986,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        "bitcoin::blockdata::script::Script" if !is_ref => Some("::bitcoin::blockdata::script::Script::from("),
                        "bitcoin::blockdata::transaction::Transaction" if is_ref => Some("&"),
                        "bitcoin::blockdata::transaction::Transaction" => Some(""),
+                       "bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::C_to_bitcoin_outpoint("),
                        "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(""),
                        "bitcoin::network::constants::Network" => Some(""),
                        "bitcoin::blockdata::block::BlockHeader" => Some("&::bitcoin::consensus::encode::deserialize(unsafe { &*"),
@@ -1057,6 +1058,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        "bitcoin::blockdata::script::Script" if is_ref => Some(".to_slice()))"),
                        "bitcoin::blockdata::script::Script" if !is_ref => Some(".into_rust())"),
                        "bitcoin::blockdata::transaction::Transaction" => Some(".into_bitcoin()"),
+                       "bitcoin::blockdata::transaction::OutPoint" => Some(")"),
                        "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(".into_rust()"),
                        "bitcoin::network::constants::Network" => Some(".into_bitcoin()"),
                        "bitcoin::blockdata::block::BlockHeader" => Some(" }).unwrap()"),
index 95dae8da8762437db4dbd53f456def6ac122dcab..8cbfddd469437b725c4dd2e3a04fc58e0f05e566 100644 (file)
@@ -289,6 +289,13 @@ pub extern "C" fn Transaction_free(_res: Transaction) { }
 pub(crate) fn bitcoin_to_C_outpoint(outpoint: ::bitcoin::blockdata::transaction::OutPoint) -> crate::lightning::chain::transaction::OutPoint {
        crate::lightning::chain::transaction::OutPoint_new(ThirtyTwoBytes { data: outpoint.txid.into_inner() }, outpoint.vout.try_into().unwrap())
 }
+pub(crate) fn C_to_bitcoin_outpoint(outpoint: crate::lightning::chain::transaction::OutPoint) -> ::bitcoin::blockdata::transaction::OutPoint {
+       unsafe {
+               ::bitcoin::blockdata::transaction::OutPoint {
+                       txid: (*outpoint.inner).txid, vout: (*outpoint.inner).index as u32
+               }
+       }
+}
 
 #[repr(C)]
 #[derive(Clone)]