Skip to content

Commit

Permalink
Expose get_tx in Blockchain
Browse files Browse the repository at this point in the history
  • Loading branch information
jurvis committed Sep 24, 2024
1 parent 60f1aef commit 78a243a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ interface Blockchain {

[Throws=BdkError]
string get_block_hash(u32 height);

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

callback interface Progress {
Expand Down
10 changes: 9 additions & 1 deletion bdk-ffi/src/blockchain.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// use crate::BlockchainConfig;
use crate::Network;
use crate::{BdkError, Transaction};
use bdk::bitcoin::Txid;
use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
use bdk::blockchain::rpc::Auth as BdkAuth;
use bdk::blockchain::rpc::RpcSyncParams as BdkRpcSyncParams;
use bdk::blockchain::Blockchain as BdkBlockchain;
use bdk::blockchain::GetBlockHash;
use bdk::blockchain::GetHeight;
use bdk::blockchain::{
electrum::ElectrumBlockchainConfig, esplora::EsploraBlockchainConfig,
rpc::RpcConfig as BdkRpcConfig, ConfigurableBlockchain,
};
use bdk::blockchain::{Blockchain as BdkBlockchain, GetTx};
use bdk::FeeRate;
use std::convert::{From, TryFrom};
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::{Arc, Mutex, MutexGuard};

pub(crate) struct Blockchain {
Expand Down Expand Up @@ -80,6 +82,12 @@ impl Blockchain {
.get_block_hash(u64::from(height))
.map(|hash| hash.to_string())
}

pub(crate) fn get_tx(&self, txid: String) -> Result<Option<Arc<Transaction>>, BdkError> {
let txid = Txid::from_str(txid.as_str())?;
let tx_opt = self.get_blockchain().get_tx(&txid)?;
Ok(tx_opt.map(|inner| Arc::new(Transaction { inner })))
}
}

/// Configuration for an ElectrumBlockchain
Expand Down

0 comments on commit 78a243a

Please sign in to comment.