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-Tag: v0.0.13~38^2~6 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=78c2c48ea30e5d933c0a29c5a9e4dea47eeabf04;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 ac3efb627..e85729481 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -401,10 +401,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"), @@ -615,6 +614,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_"), @@ -679,6 +679,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.