Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: esplora client get_tx #598

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))))
}
}
Loading