diff --git a/CHANGELOG.md b/CHANGELOG.md index f319934..e34d6e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `derive(DerivationPath)` derives and returns child DescriptorPublicKey - `extend(DerivationPath)` extends and returns DescriptorPublicKey - `as_string()` returns DescriptorPublicKey as String + - Add to `interface Blockchain` the `get_height()` and `get_block_hash()` methods [#184] - Interfaces Added [#154] - `DescriptorSecretKey` - `DescriptorPublicKey` @@ -28,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `restore_extended_key`, returned ExtendedKeyInfo [#154]: https://github.com/bitcoindevkit/bdk-ffi/pull/154 +[#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 03b874b..b8b7529 100644 --- a/src/bdk.udl +++ b/src/bdk.udl @@ -134,6 +134,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 d7ba6be..181f537 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,8 @@ use bdk::bitcoin::util::bip32::DerivationPath as BdkDerivationPath; 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, }; @@ -174,6 +176,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 {