Skip to content

Commit

Permalink
feat: esplora client get_tx
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Sep 27, 2024
1 parent 1b00bd1 commit 87fd113
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ interface EsploraClient {

[Throws=EsploraError]
void broadcast([ByRef] Transaction transaction);

[Throws=EsploraError]
Transaction? get_tx(string txid);
};

// ------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions bdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1013,6 +1014,14 @@ impl From<Box<BdkEsploraError>> for EsploraError {
}
}

impl From<BdkHexToArrayError> for EsploraError {
fn from(error: BdkHexToArrayError) -> Self {
EsploraError::Parsing {
error_message: error.to_string(),
}
}
}

impl From<BdkExtractTxError> for ExtractTxError {
fn from(error: BdkExtractTxError) -> Self {
match error {
Expand Down
8 changes: 8 additions & 0 deletions bdk-ffi/src/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -81,4 +83,10 @@ impl EsploraClient {
.broadcast(&bdk_transaction)
.map_err(EsploraError::from)
}

pub fn get_tx(&self, txid: String) -> Result<Option<Arc<Transaction>>, 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))))
}
}

0 comments on commit 87fd113

Please sign in to comment.