bdk-ffi icon indicating copy to clipboard operation
bdk-ffi copied to clipboard

Bring back getHeight()

Open geigerzaehler242 opened this issue 1 year ago • 7 comments

please bring back the getHeight() method which returns block height. it was there in 0.31.1

geigerzaehler242 avatar May 30 '24 18:05 geigerzaehler242

Are you looking for this in one of the 1.0 alphas?

reez avatar May 30 '24 18:05 reez

yes. can't seem to find it there

geigerzaehler242 avatar May 30 '24 19:05 geigerzaehler242

Yeah, it’s there but just in a different place/way because 1.0 is structured a bit differently, so I can totally understand it being hard to find at the moment.

We do have it though, here is one spot I’m using it in BDKSwiftExampleWallet as of recently when I updated main to 1.0 alpha 11: https://github.com/bitcoindevkit/BDKSwiftExampleWallet/commit/d275596fb4dfa139626ee0271928976866e1815c#diff-846bbaac2100f437c6f4c82df4cfcb50de5aba72dd8d0252731e44f0112db272R48-R55

That’s essentially my Transaction Detail View where I’m showing a transaction and what block height it was confirmed (or if it’s unconfirmed), etc.

Let me know if that’s the sort of thing you’re looking for or not, or any other thoughts/questions around it, since I definitely know things are structured differently in 1.0 and it might take a bit to get the hang of things (its really nice though!).

reez avatar May 30 '24 22:05 reez

@geigerzaehler242 does that resolve your issue/question or any other thoughts or follow up?

reez avatar Jun 11 '24 17:06 reez

the method previously returned the current block height of the time chain. i guess it was just doing an api call to mempoolspace?

geigerzaehler242 avatar Jun 14 '24 15:06 geigerzaehler242

https://docs.rs/bdk/0.29.0/bdk/blockchain/trait.GetHeight.html#tymethod.get_height

Adding a link to pre-1.0 docs method

reez avatar Jun 17 '24 15:06 reez

The current 1.0 beta doesnt have get_height anywhere. Can this please be included again?

andreasgriffin avatar Aug 03 '24 21:08 andreasgriffin

This is the method to expose I think:

    /// Get the height of the current blockchain tip.
    pub fn get_height(&self) -> Result<u32, Error> {
        self.get_response_str("/blocks/tip/height")
            .map(|s| u32::from_str(s.as_str()).map_err(Error::Parsing))?
    }

reez avatar Nov 05 '24 17:11 reez

@reez : Thanks. @thunderbiscuit, @reez : Can this also be added for electrum client?

andreasgriffin avatar Nov 08 '24 16:11 andreasgriffin

@reez : Thanks. @thunderbiscuit, @reez : Can this also be added for electrum client?

@andreasgriffin

Would be happy to! Do you know exactly what method you'd want for it because when I was looking thru the available methods I wasn't seeing something close enough to the get_height that is found on Esplora? Sorry if I'm missing it and its obvious, maybe I'm not quite as familiar w Electrum as I am with Esplora-

reez avatar Nov 08 '24 16:11 reez

@reez : The get_height was (before 1.0) in the electrum client: https://github.com/bitcoindevkit/bdk/blob/213c270ab475e2afbf6863271550a537cd203c15/src/blockchain/electrum.rs#L94

Is it possible to bring it back?

andreasgriffin avatar Nov 08 '24 17:11 andreasgriffin

@reez : The get_height was (before 1.0) in the electrum client: https://github.com/bitcoindevkit/bdk/blob/213c270ab475e2afbf6863271550a537cd203c15/src/blockchain/electrum.rs#L94

Is it possible to bring it back?

Let me ask in our Discord channel right now to try to fill in some of the details for myself-

reez avatar Nov 08 '24 17:11 reez

Per Evan:

You can subscribe to block header notifications.

I think it's the only way unfortunately

https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html#blockchain-headers-subscribe

The subscribe request returns height + blockhash directly

reez avatar Nov 12 '24 19:11 reez

@reez : Ok. I hoped there would be a bdk-native way. But thanks.

andreasgriffin avatar Nov 12 '24 19:11 andreasgriffin