From 87fd113c9f2f8c9f694434ef1898289b29fc657f Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 26 Sep 2024 11:54:48 -0500 Subject: [PATCH] feat: esplora client get_tx --- bdk-ffi/src/bdk.udl | 3 +++ bdk-ffi/src/error.rs | 9 +++++++++ bdk-ffi/src/esplora.rs | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 2c8876e4..f593982c 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -580,6 +580,9 @@ interface EsploraClient { [Throws=EsploraError] void broadcast([ByRef] Transaction transaction); + + [Throws=EsploraError] + Transaction? get_tx(string txid); }; // ------------------------------------------------------------------------ diff --git a/bdk-ffi/src/error.rs b/bdk-ffi/src/error.rs index af9e3f0c..6707c0be 100644 --- a/bdk-ffi/src/error.rs +++ b/bdk-ffi/src/error.rs @@ -7,6 +7,7 @@ use bdk_wallet::bitcoin::address::FromScriptError as BdkFromScriptError; use bdk_wallet::bitcoin::address::ParseError as BdkParseError; use bdk_wallet::bitcoin::bip32::Error as BdkBip32Error; use bdk_wallet::bitcoin::consensus::encode::Error as BdkEncodeError; +use bdk_wallet::bitcoin::hashes::hex::HexToArrayError as BdkHexToArrayError; use bdk_wallet::bitcoin::hex::DisplayHex; use bdk_wallet::bitcoin::psbt::Error as BdkPsbtError; use bdk_wallet::bitcoin::psbt::ExtractTxError as BdkExtractTxError; @@ -1013,6 +1014,14 @@ impl From> for EsploraError { } } +impl From for EsploraError { + fn from(error: BdkHexToArrayError) -> Self { + EsploraError::Parsing { + error_message: error.to_string(), + } + } +} + impl From for ExtractTxError { fn from(error: BdkExtractTxError) -> Self { match error { diff --git a/bdk-ffi/src/esplora.rs b/bdk-ffi/src/esplora.rs index 76d1d77e..934a9079 100644 --- a/bdk-ffi/src/esplora.rs +++ b/bdk-ffi/src/esplora.rs @@ -6,6 +6,7 @@ use crate::types::{FullScanRequest, SyncRequest}; use bdk_esplora::esplora_client::{BlockingClient, Builder}; use bdk_esplora::EsploraExt; use bdk_wallet::bitcoin::Transaction as BdkTransaction; +use bdk_wallet::bitcoin::Txid; use bdk_wallet::chain::spk_client::FullScanRequest as BdkFullScanRequest; use bdk_wallet::chain::spk_client::FullScanResult as BdkFullScanResult; use bdk_wallet::chain::spk_client::SyncRequest as BdkSyncRequest; @@ -14,6 +15,7 @@ use bdk_wallet::KeychainKind; use bdk_wallet::Update as BdkUpdate; use std::collections::BTreeMap; +use std::str::FromStr; use std::sync::Arc; pub struct EsploraClient(BlockingClient); @@ -81,4 +83,10 @@ impl EsploraClient { .broadcast(&bdk_transaction) .map_err(EsploraError::from) } + + pub fn get_tx(&self, txid: String) -> Result>, EsploraError> { + let txid = Txid::from_str(&txid)?; + let tx_opt = self.0.get_tx(&txid)?; + Ok(tx_opt.map(|inner| Arc::new(Transaction::from(inner)))) + } }