-
Notifications
You must be signed in to change notification settings - Fork 809
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
Adding confirmations property to block and tx getJSON #325
Conversation
Adds a 'confirmations' property to the JSON returned by cli tx [hash] as well as the REST '/tx/:hash' call by subtracting TX height from chain height
Adds a 'confirmations' property to the JSON returned by `cli tx [hash]` as well as the Rest `/tx/:hash` call by subtracting block height from chain height
Why would confirmations be added to the block endpoint? |
@Sexual, I had that thought too, but it appears to be consistent with bitcoind's
I figure it's a quick an easy way to verify a block is part of the main chain and to see how deeply embedded it is. Rereading the bold part above does make me think that maybe I should add in logic to return -1 for |
The |
Looks like it would make sense to try and implement the same logic for unconfirmed/conflicted (which I assume means it's a doublespend attempt) transactions as described here as well https://bitcoin.org/en/developer-reference#gettransaction:
|
TX `confirmations` property set to 0 for unconfirmed transactions. Block `confirmations` property set to -1 for orphaned blocks. Fixing to add +1 to `confirmations` to match bitcoind behavior and corresponding bcoin rpc methods - block or tx at tip of main chain starts with 1 confirmation (not zero).
I refined this a bit. I previously was failing to add 1 to Unconfirmed transactions will have 0 for One last consideration is that this change would put the client out of sync with the examples at http://bcoin.io/api-docs/. It looks like that isn't part of this repository though. |
Thanks for adding this support @sangaman and keeping on top of the PR. For the docs, all of that info is managed in the bcoin.io github pages repo. That is also all open though as well, so feel free to submit an issue with the changes to the API that would be necessary once this gets approved. |
Thanks for linking me to that repo, I tried looking for it earlier but must have missed it. I created a pull request there to sync with the changes here. |
Looks good, but just a warning that we're running dangerously close to 4 parameters for that function. I think it's a good rule to keep it at 3 or under, and never over 4. Could be that the chain height is the last thing we can justify adding. :) |
Adds a
confirmations
property to the JSON returned bycli tx [hash]
andcli block [hash/height]
aswell as the REST
/tx/:hash
and/block/:block
calls by subtracting TX/block height from chain height.I'm new to this codebase but I tried to implement this as cleanly and sensibly as I could. It passed all mocha tests as well as some manual testing with regtest.
This addresses issue #320.