From c2cef86296d2f7e36ff120d5345680651fe6ddad Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Thu, 28 Sep 2017 23:41:13 -0400 Subject: [PATCH] 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 --- lib/http/server.js | 3 ++- lib/primitives/block.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/http/server.js b/lib/http/server.js index f2ff9332..23fb3d97 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -279,8 +279,9 @@ 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)); + res.send(200, block.getJSON(this.network, view, height, confirmations)); }); // Mempool snapshot diff --git a/lib/primitives/block.js b/lib/primitives/block.js index ae9c8918..9be79213 100644 --- a/lib/primitives/block.js +++ b/lib/primitives/block.js @@ -575,11 +575,12 @@ Block.prototype.toJSON = function toJSON() { * @returns {Object} */ -Block.prototype.getJSON = function getJSON(network, view, height) { +Block.prototype.getJSON = function getJSON(network, view, height, confirmations) { network = Network.get(network); return { hash: this.rhash(), height: height, + confirmations: confirmations, version: this.version, prevBlock: util.revHex(this.prevBlock), merkleRoot: util.revHex(this.merkleRoot),