Add get_height and get_block_hash methods on blockchain
This commit is contained in:
parent
d38737669d
commit
25963ec982
@ -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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [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]
|
## [v0.8.0]
|
||||||
- Update BDK to version 0.20.0 [#169]
|
- Update BDK to version 0.20.0 [#169]
|
||||||
|
@ -143,6 +143,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
@ -3,6 +3,8 @@ use bdk::bitcoin::secp256k1::Secp256k1;
|
|||||||
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,
|
||||||
};
|
};
|
||||||
@ -169,6 +171,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