Skip to content

Commit

Permalink
Get block hash by its height
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vladimirfomene committed Jul 6, 2022
1 parent c5c3c61 commit 758dba1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/blockchain/esplora/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ impl GetTx for EsploraBlockchain {
}
}

#[maybe_async]
impl GetBlockHash for EsploraBlockchain {
fn get_block_hash(&self, height: u64) -> Result<BlockHash, Error> {
let block_header = await_or_block!(self.url_client._get_header(height as u32))?;
Ok(block_header.block_hash())
}
}

#[maybe_async]
impl WalletSync for EsploraBlockchain {
fn wallet_setup<D: BatchDatabase>(
Expand Down
7 changes: 7 additions & 0 deletions src/blockchain/esplora/ureq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ impl GetTx for EsploraBlockchain {
}
}

impl GetBlockHash for EsploraBlockchain {
fn get_block_hash(&self, height: u64) -> Result<BlockHash, Error> {
let block_header = self.url_client._get_header(height as u32)?;
Ok(block_header.block_hash())
}
}

impl WalletSync for EsploraBlockchain {
fn wallet_setup<D: BatchDatabase>(
&self,
Expand Down

0 comments on commit 758dba1

Please sign in to comment.