Skip to content

Commit 9e233ef

Browse files
committed
Allow to retrieve a block header by hash
1 parent 8364d05 commit 9e233ef

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/async.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ impl AsyncClient {
116116
/// Get a [`BlockHeader`] given a particular block height.
117117
pub async fn get_header(&self, block_height: u32) -> Result<BlockHeader, Error> {
118118
let block_hash = self.get_block_hash(block_height).await?;
119+
self.get_header_by_hash(&block_hash).await
120+
}
119121

122+
/// Get a [`BlockHeader`] given a particular block hash.
123+
pub async fn get_header_by_hash(&self, block_hash: &BlockHash) -> Result<BlockHeader, Error> {
120124
let resp = self
121125
.client
122126
.get(&format!("{}/block/{}/header", self.url, block_hash))

src/blocking.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ impl BlockingClient {
129129
/// Get a [`BlockHeader`] given a particular block height.
130130
pub fn get_header(&self, block_height: u32) -> Result<BlockHeader, Error> {
131131
let block_hash = self.get_block_hash(block_height)?;
132+
self.get_header_by_hash(&block_hash)
133+
}
132134

135+
/// Get a [`BlockHeader`] given a particular block hash.
136+
pub fn get_header_by_hash(&self, block_hash: &BlockHash) -> Result<BlockHeader, Error> {
133137
let resp = self
134138
.agent
135139
.get(&format!("{}/block/{}/header", self.url, block_hash))

0 commit comments

Comments
 (0)