Skip to content

Commit 758dba1

Browse files
Get block hash by its height
Create blockchain::GetBlockHash trait with a method to get block hash given a block height. Then, implement this trait for all backends (Electrum, RPC , Esplora, CBF). Referenced in issue 603.
1 parent c5c3c61 commit 758dba1

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)