Add get_height and get_block_hash methods on blockchain

This commit is contained in:
thunderbiscuit committed 2022-08-18 13:39:00 -04:00
1 parent d38737669d
commit 25963ec982
3 files changed
+22

No files matched your search

+6
View File
@@ -143,6 +143,12 @@ interface Blockchain {
[Throws=BdkError]
void broadcast([ByRef] PartiallySignedBitcoinTransaction psbt);
[Throws=BdkError]
u32 get_height();
[Throws=BdkError]
string get_block_hash(u32 height);
};
callback interface Progress {
+12
View File
@@ -3,6 +3,8 @@ use bdk::bitcoin::secp256k1::Secp256k1;
use bdk::bitcoin::util::psbt::PartiallySignedTransaction;
use bdk::bitcoin::{Address, Network, OutPoint as BdkOutPoint, Script, Txid};
use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
use bdk::blockchain::GetBlockHash;
use bdk::blockchain::GetHeight;
use bdk::blockchain::{
electrum::ElectrumBlockchainConfig, esplora::EsploraBlockchainConfig, ConfigurableBlockchain,
};
@@ -169,6 +171,16 @@ impl Blockchain {
let tx = psbt.internal.lock().unwrap().clone().extract_tx();
self.get_blockchain().broadcast(&tx)
}
fn get_height(&self) -> Result<u32, Error> {
self.get_blockchain().get_height()
}
fn get_block_hash(&self, height: u32) -> Result<String, Error> {
self.get_blockchain()
.get_block_hash(u64::from(height))
.map(|hash| hash.to_string())
}
}
struct Wallet {