Skip to content

Commit 6bf7878

Browse files
committed
Merge bitcoindevkit/bdk#634: Get block hash by its height
758dba1 Get block hash by its height (Vladimir Fomene) Pull request description: ### Description This PR create a new trait `blockchain::GetBlockHash` with a `get_block_hash` method which returns a block hash given the block height. This has been implemented for all blockchain backends. Fixes #603 ### Notes to the reviewers I haven't updated the `CHANGELOG.md` and docs. Am I suppose to update it for this change? ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [x] I've added tests for the new feature * [ ] I've added docs for the new feature * [ ] I've updated `CHANGELOG.md` ACKs for top commit: notmandatory: ACK 758dba1 Tree-SHA512: 9c084a6665ecbf27ee8170fdb06e0dc8373d6a901ce29e5f5a1bec111d1507cb3bee6b03a653a55fd20e0fabe7a5eada3353e24a1e21f3a11f01bb9881ae99e5
2 parents c5c3c61 + 758dba1 commit 6bf7878

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/blockchain/esplora/reqwest.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ impl GetTx for EsploraBlockchain {
117117
}
118118
}
119119

120+
#[maybe_async]
121+
impl GetBlockHash for EsploraBlockchain {
122+
fn get_block_hash(&self, height: u64) -> Result<BlockHash, Error> {
123+
let block_header = await_or_block!(self.url_client._get_header(height as u32))?;
124+
Ok(block_header.block_hash())
125+
}
126+
}
127+
120128
#[maybe_async]
121129
impl WalletSync for EsploraBlockchain {
122130
fn wallet_setup<D: BatchDatabase>(

src/blockchain/esplora/ureq.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ impl GetTx for EsploraBlockchain {
112112
}
113113
}
114114

115+
impl GetBlockHash for EsploraBlockchain {
116+
fn get_block_hash(&self, height: u64) -> Result<BlockHash, Error> {
117+
let block_header = self.url_client._get_header(height as u32)?;
118+
Ok(block_header.block_hash())
119+
}
120+
}
121+
115122
impl WalletSync for EsploraBlockchain {
116123
fn wallet_setup<D: BatchDatabase>(
117124
&self,

0 commit comments

Comments
 (0)