diff --git a/CHANGELOG.md b/CHANGELOG.md index cf7d727..0612f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Add `get_height()` and `get_block_hash()` methods on blockchain [#184] + +[#184]: https://github.com/bitcoindevkit/bdk-ffi/pull/184 ## [v0.8.0] - Update BDK to version 0.20.0 [#169] diff --git a/src/bdk.udl b/src/bdk.udl index d98cfec..276a9ab 100644 --- a/src/bdk.udl +++ b/src/bdk.udl @@ -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 { diff --git a/src/lib.rs b/src/lib.rs index 95243cb..77c0076 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { + self.get_blockchain().get_height() + } + + fn get_block_hash(&self, height: u32) -> Result { + self.get_blockchain() + .get_block_hash(u64::from(height)) + .map(|hash| hash.to_string()) + } } struct Wallet {