Merge pull request #184 from thunderbiscuit/block-height-hash
Add `get_height` and `get_block_hash` methods on blockchain
This commit is contained in:
commit
eed5554551
@ -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
|
- `derive(DerivationPath)` derives and returns child DescriptorPublicKey
|
||||||
- `extend(DerivationPath)` extends and returns DescriptorPublicKey
|
- `extend(DerivationPath)` extends and returns DescriptorPublicKey
|
||||||
- `as_string()` returns DescriptorPublicKey as String
|
- `as_string()` returns DescriptorPublicKey as String
|
||||||
|
- Add to `interface Blockchain` the `get_height()` and `get_block_hash()` methods [#184]
|
||||||
- Interfaces Added [#154]
|
- Interfaces Added [#154]
|
||||||
- `DescriptorSecretKey`
|
- `DescriptorSecretKey`
|
||||||
- `DescriptorPublicKey`
|
- `DescriptorPublicKey`
|
||||||
@ -28,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- `restore_extended_key`, returned ExtendedKeyInfo
|
- `restore_extended_key`, returned ExtendedKeyInfo
|
||||||
|
|
||||||
[#154]: https://github.com/bitcoindevkit/bdk-ffi/pull/154
|
[#154]: https://github.com/bitcoindevkit/bdk-ffi/pull/154
|
||||||
|
[#184]: https://github.com/bitcoindevkit/bdk-ffi/pull/184
|
||||||
|
|
||||||
## [v0.8.0]
|
## [v0.8.0]
|
||||||
- Update BDK to version 0.20.0 [#169]
|
- Update BDK to version 0.20.0 [#169]
|
||||||
|
@ -134,6 +134,12 @@ interface Blockchain {
|
|||||||
|
|
||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
void broadcast([ByRef] PartiallySignedBitcoinTransaction psbt);
|
void broadcast([ByRef] PartiallySignedBitcoinTransaction psbt);
|
||||||
|
|
||||||
|
[Throws=BdkError]
|
||||||
|
u32 get_height();
|
||||||
|
|
||||||
|
[Throws=BdkError]
|
||||||
|
string get_block_hash(u32 height);
|
||||||
};
|
};
|
||||||
|
|
||||||
callback interface Progress {
|
callback interface Progress {
|
||||||
|
12
src/lib.rs
12
src/lib.rs
@ -4,6 +4,8 @@ use bdk::bitcoin::util::bip32::DerivationPath as BdkDerivationPath;
|
|||||||
use bdk::bitcoin::util::psbt::PartiallySignedTransaction;
|
use bdk::bitcoin::util::psbt::PartiallySignedTransaction;
|
||||||
use bdk::bitcoin::{Address, Network, OutPoint as BdkOutPoint, Script, Txid};
|
use bdk::bitcoin::{Address, Network, OutPoint as BdkOutPoint, Script, Txid};
|
||||||
use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
|
use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
|
||||||
|
use bdk::blockchain::GetBlockHash;
|
||||||
|
use bdk::blockchain::GetHeight;
|
||||||
use bdk::blockchain::{
|
use bdk::blockchain::{
|
||||||
electrum::ElectrumBlockchainConfig, esplora::EsploraBlockchainConfig, ConfigurableBlockchain,
|
electrum::ElectrumBlockchainConfig, esplora::EsploraBlockchainConfig, ConfigurableBlockchain,
|
||||||
};
|
};
|
||||||
@ -174,6 +176,16 @@ impl Blockchain {
|
|||||||
let tx = psbt.internal.lock().unwrap().clone().extract_tx();
|
let tx = psbt.internal.lock().unwrap().clone().extract_tx();
|
||||||
self.get_blockchain().broadcast(&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 {
|
struct Wallet {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user