From 758dba18fd4c5f6d8db8ba51e34646fbb2302042 Mon Sep 17 00:00:00 2001 From: Vladimir Fomene Date: Thu, 16 Jun 2022 20:42:02 +0100 Subject: [PATCH] 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. --- src/blockchain/esplora/reqwest.rs | 8 ++++++++ src/blockchain/esplora/ureq.rs | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/blockchain/esplora/reqwest.rs b/src/blockchain/esplora/reqwest.rs index f68bdd8..0d40506 100644 --- a/src/blockchain/esplora/reqwest.rs +++ b/src/blockchain/esplora/reqwest.rs @@ -117,6 +117,14 @@ impl GetTx for EsploraBlockchain { } } +#[maybe_async] +impl GetBlockHash for EsploraBlockchain { + fn get_block_hash(&self, height: u64) -> Result { + 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( diff --git a/src/blockchain/esplora/ureq.rs b/src/blockchain/esplora/ureq.rs index 7ce57a1..9899b90 100644 --- a/src/blockchain/esplora/ureq.rs +++ b/src/blockchain/esplora/ureq.rs @@ -112,6 +112,13 @@ impl GetTx for EsploraBlockchain { } } +impl GetBlockHash for EsploraBlockchain { + fn get_block_hash(&self, height: u64) -> Result { + let block_header = self.url_client._get_header(height as u32)?; + Ok(block_header.block_hash()) + } +} + impl WalletSync for EsploraBlockchain { fn wallet_setup( &self,