-
Notifications
You must be signed in to change notification settings - Fork 60
Query block hash by by block height #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query block hash by by block height #13
Conversation
Pull Request Test Coverage Report for Build 3227896333Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
This looks good, @tnull and @vladimirfomene are also working on examples for testing, once their stuff is in you should add a similar test for this new query also. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good. Maybe we want to reuse these methods in get_header
, since it also gets the block hash by height?
I believe we need to be careful when reusing some of these methods in other methods as it might result into doing more than one round trip to the server. |
Ah, excuse the mistake, I meant rust-esplora-client/src/blocking.rs Lines 130 to 148 in 590a01b
|
Imo reusing Looking at the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, two nits.
src/async.rs
Outdated
let bytes = resp.bytes().await?; | ||
let hash = | ||
std::str::from_utf8(&bytes).map_err(|_| Error::HeaderHeightNotFound(block_height))?; | ||
let block_hash = self.get_block_hash(block_height).await?.to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think clippy will complain otherwise since BlockHash
implements Display
.
let block_hash = self.get_block_hash(block_height).await?.to_string(); | |
let block_hash = self.get_block_hash(block_height).await?; |
src/blocking.rs
Outdated
|
||
let hash = | ||
std::str::from_utf8(&bytes).map_err(|_| Error::HeaderHeightNotFound(block_height))?; | ||
let block_hash = self.get_block_hash(block_height)?.to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Likewise.
let block_hash = self.get_block_hash(block_height)?.to_string(); | |
let block_hash = self.get_block_hash(block_height)?; |
3072fd0
to
6b2f84f
Compare
Fixed and rebased onto |
@gcomte, I think it will be cleaner if we squash these changes into one commit. |
Yeah, that could be done when merging, right? |
Hey @gcomte ! can you squash it here? It makes things easy for us. |
6b2f84f
to
05e1045
Compare
Done 👍 |
I guess I should write some tests as well, as this PR has been merged now: #10 |
@gcomte, can you add test to this so that I can merge it? |
05e1045
to
b6d663b
Compare
Do you want me to squash it into the other commit? |
let (blocking_client, async_client) = setup_clients().await; | ||
let block_hash = blocking_client.get_block_hash(21).unwrap(); | ||
let block_hash_async = async_client.get_block_hash(21).await.unwrap(); | ||
assert_eq!(block_hash, block_hash_async); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to add another check comparing the Esplora results to RPC, i.e., BITCOIND.client.get_block_hash(21)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. Added: 7c66cf1
b6d663b
to
7c66cf1
Compare
92606cc Test `get_header_by_hash` rather than `get_height` (Elias Rohrer) 6673912 Deprecate `get_height` (Elias Rohrer) 9e233ef Allow to retrieve a block header by hash (Elias Rohrer) Pull request description: ~~Based on #13 since it probably land soon.~~ This PR adds a method allowing to retrieve a `BlockHeader` via a given `BlockHash` and reuses it in `get_height`. Top commit has no ACKs. Tree-SHA512: 2be894f7e745e317b02512183e073806e90145cbde9ad89f10e5782d6bc302da6d72adb0cef0fce7cd746e4f7b93fba0844a640bc30457ccafbcf19dd5673254
Give the possibility to query a block hash by providing its corresponding block height