janoside / btc-rpc-explorer

Database-free, self-hosted Bitcoin explorer, via RPC to Bitcoin Core.
https://bitcoinexplorer.org
MIT License
1.58k stars 1.18k forks source link

API routes for ticker data use case #329

Closed pointbiz closed 3 years ago

pointbiz commented 3 years ago

I'd like to expose more data as a restful api as requested in issue https://github.com/janoside/btc-rpc-explorer/issues/55 Is this in scope? I want to check if ApiRouter.js is the appropriate place for these new routes? Is there some naming conventions or json object structures I should copy? (Maybe https://mempool.space/api)

For some basic ticker data I have used https://blockchain.info/q/getblockcount https://blockchain.info/q/unconfirmedcount https://blockchain.info/q/hashrate https://blockchain.info/q/totalbc https://mempool.space/api/v1/fees/recommended

Those would represent an MVP for my uses to be able to query my own node instead of those third parties.

As a second phase I would want to support looking up information by address (balance, received tx, sent tx) and txid as I believe this would be useful to the wider community. As a third phase I would want to support xpub/ypub/zpub because I have a project that consumes a third party paid API and I would like to migrate this to a more sovereign approach running on my own node.

pointbiz commented 3 years ago

~~The new routes so far are: /api/getblockcount Results look like this:~~

~~/api/getblockchaininfo Results look like this:~~

janoside commented 3 years ago

@pointbiz Yes, definitely in scope and yes, ApiRouter is the right place for this. I support the idea just haven't prioritized it. I'm glad that you have a concrete use in mind to drive this forward (since I don't it's hard to know where to start).

So far this looks good.

pointbiz commented 3 years ago

The latest commits now have support for the MVP release to provide common ticker data that I use (and presumably others use). These are the 5 calls I mentioned in the original post.

I added an API doc to the repo.

The coin supply is using the estimated value. I still have to update it to use the accurate coin supply from utxo set summary.

I used Mempool.space Restful API as inspiration but did not hold myself to following it exactly as some calls they didn't have. It also made sense to me that fees is part of the Mempool domain and Total BTC and Hash rate is part of the blocks domain.

pointbiz commented 3 years ago

Latest commit now shows accurate total btc supply if the utxo set summary is available.

The hashrate endpoint now returns a json with 1 day, 7 days and 30 days hash rate.

There is a new price API that returns the value of 1 Bitcoin in USD, EUR, GBP, XAU

new speed endpoint that returns the difficulty adjustment percentage. Same value as calculated on the homepage. For non-technical people this value is understood as current network speed. It will be placed under the blocks domain.

pointbiz commented 3 years ago

market cap under price domain /v1/price/usd/marketcap add MoscowTime (sats per USD) /v1/price/usd/moscowtime

pointbiz commented 3 years ago

Should there be a config variable to disable this new API functionality?

pointbiz commented 3 years ago

@janoside This completes phase 1 for me. I'm ready for your review.

I will leave phase 2 & 3 for the future in a different pull request.

janoside commented 3 years ago

@pointbiz At first glance this is all looking great! Will be reviewing/testing over the next couple of days. Thanks for all this!

janoside commented 3 years ago

@pointbiz Again, thanks for the great help on this. After some delay this is now merged! The demo site is also updated: https://bitcoinexplorer.org/api/docs

If you see what got merged, you'll see some changes. Let me know if you have any feedback about any of it. I still have some other misc things to do before an official release will be tagged.

pointbiz commented 3 years ago

I browsed all the changes. Looks good. It's more polished now. Good work! All the route name changes make sense to me.

I like how internal API is now split to it's own file.

The docs look fantastic.

Thank you for figuring out and adding the block and tx details routes. People will appreciate it.

I'm excited to consume the API myself on my own node.