bitcoindevkit / rust-esplora-client

Bitcoin Esplora API client library. Supports plaintext, TLS and Onion servers. Blocking or async.
MIT License
29 stars 44 forks source link

Add `get_tip_hash` API call #6

Closed tnull closed 2 years ago

tnull commented 2 years ago

This PR adds support for getting the BlockHash of the current blockchain tip.

While this is currently not strictly necessary for LDK integration, it might be nice to have in the future.

vladimirfomene commented 2 years ago

@tnull , is it not better to have a method for getting the block hash given a particular block height? I think it will provide a more general API. This is what we currently do here: https://github.com/bitcoindevkit/bdk/blob/master/src/blockchain/esplora/reqwest.rs#L121

tnull commented 2 years ago

@tnull , is it not better to have a method for getting the block hash given a particular block height? I think it will provide a more general API. This is what we currently do here: https://github.com/bitcoindevkit/bdk/blob/master/src/blockchain/esplora/reqwest.rs#L121

Well, we already have that API, but it may have some drawbacks in certain scenarios: as it is currently implemented, it requires to make two requests (one to get current tip height, one to get the hash), and could even be a bit race-y (i.e., when we make the second call, the block height could just have increased so we don't get the tip, but tip-1).

Generally I think EsploraClient should strive to implement all of Esplora's API methods comprehensively, allowing a user to pick-and-choose what's required. What of these methods then should be used by/exposed through BDK is a different discussion.