From: Matt Corallo Date: Mon, 4 Jan 2021 20:12:37 +0000 (-0500) Subject: [bindings] Support exposing `bitcoin::OutPoint`s as our common type X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=941d9997e687ef0fd41608651c4308745df8f157;p=rust-lightning [bindings] Support exposing `bitcoin::OutPoint`s as our common type --- diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 7108e10f7..a077d311b 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -393,10 +393,9 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "bitcoin::secp256k1::Error" if !is_ref => Some("crate::c_types::Secp256k1Error"), "bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice"), "bitcoin::blockdata::script::Script" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"), - "bitcoin::blockdata::transaction::OutPoint" if is_ref => Some("crate::chain::transaction::OutPoint"), + "bitcoin::blockdata::transaction::OutPoint" => Some("crate::chain::transaction::OutPoint"), "bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction"), "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut"), - "bitcoin::OutPoint" => Some("crate::chain::transaction::OutPoint"), "bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network"), "bitcoin::blockdata::block::BlockHeader" if is_ref => Some("*const [u8; 80]"), "bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice"), @@ -607,6 +606,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "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::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("), "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("), "bitcoin::blockdata::block::BlockHeader" if is_ref => Some("&local_"), "bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice::from_slice(&local_"), @@ -671,6 +671,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { "bitcoin::blockdata::script::Script" if is_ref => Some("[..])"), "bitcoin::blockdata::script::Script" if !is_ref => Some(".into_bytes().into()"), "bitcoin::blockdata::transaction::Transaction" => Some(")"), + "bitcoin::blockdata::transaction::OutPoint" => Some(")"), "bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"), "bitcoin::blockdata::block::BlockHeader" if is_ref => Some(""), "bitcoin::blockdata::block::Block" if is_ref => Some(")"), diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 191927790..0e41b64b0 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -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 { @@ -130,6 +133,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.