From: Matt Corallo Date: Thu, 23 Sep 2021 17:46:30 +0000 (+0000) Subject: Support converting C `OutPoint`s to `bitcoin` `OutPoint`s X-Git-Tag: v0.0.101.1~1^2~11 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=7613eb0c40d726769bfc2b43e84421017858c532;p=ldk-c-bindings Support converting C `OutPoint`s to `bitcoin` `OutPoint`s --- diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 38752da..cfa5b5f 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -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()"), diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 95dae8d..8cbfddd 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -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)]