Fixes to TX & Block confirmations property

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).
This commit is contained in:
Daniel McNally 2017-10-02 00:58:48 -07:00
parent c2cef86296
commit 4f317992f5
2 changed files with 5 additions and 4 deletions

View File

@ -279,8 +279,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
}
const height = await this.chain.getHeight(hash);
const confirmations = this.chain.height - height;
res.send(200, block.getJSON(this.network, view, height, confirmations));
});

View File

@ -157,8 +157,10 @@ TXMeta.prototype.getJSON = function getJSON(network, view, chainheight) {
json.height = this.height;
json.block = this.block ? util.revHex(this.block) : null;
json.time = this.time;
if (chainheight)
json.confirmations = chainheight - this.height;
if (this.block === null)
json.confirmations = 0;
else
json.confirmations = chainheight - this.height + 1;
return json;
};