Adding 'confirmations' property to block getJSON

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
This commit is contained in:
Daniel McNally 2017-09-28 23:41:13 -04:00
parent 0f68427778
commit c2cef86296
2 changed files with 4 additions and 2 deletions

View File

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

View File

@ -575,11 +575,12 @@ Block.prototype.toJSON = function toJSON() {
* @returns {Object} * @returns {Object}
*/ */
Block.prototype.getJSON = function getJSON(network, view, height) { Block.prototype.getJSON = function getJSON(network, view, height, confirmations) {
network = Network.get(network); network = Network.get(network);
return { return {
hash: this.rhash(), hash: this.rhash(),
height: height, height: height,
confirmations: confirmations,
version: this.version, version: this.version,
prevBlock: util.revHex(this.prevBlock), prevBlock: util.revHex(this.prevBlock),
merkleRoot: util.revHex(this.merkleRoot), merkleRoot: util.revHex(this.merkleRoot),