Adding 'confirmations' property to TX getJSON

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
This commit is contained in:
Daniel McNally 2017-09-28 22:47:50 -04:00
parent 17e473fda5
commit 0f68427778
2 changed files with 6 additions and 4 deletions

View File

@ -210,7 +210,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
const view = await this.node.getMetaView(meta);
res.send(200, meta.getJSON(this.network, view));
res.send(200, meta.getJSON(this.network, view, this.chain.height));
});
// TX by address
@ -226,7 +226,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
for (const meta of metas) {
const view = await this.node.getMetaView(meta);
result.push(meta.getJSON(this.network, view));
result.push(meta.getJSON(this.network, view, this.chain.height));
}
res.send(200, result);
@ -245,7 +245,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
for (const meta of metas) {
const view = await this.node.getMetaView(meta);
result.push(meta.getJSON(this.network, view));
result.push(meta.getJSON(this.network, view, this.chain.height));
}
res.send(200, result);

View File

@ -151,12 +151,14 @@ TXMeta.prototype.toJSON = function toJSON() {
* @returns {Object}
*/
TXMeta.prototype.getJSON = function getJSON(network, view) {
TXMeta.prototype.getJSON = function getJSON(network, view, chainheight) {
const json = this.tx.getJSON(network, view, null, this.index);
json.mtime = this.mtime;
json.height = this.height;
json.block = this.block ? util.revHex(this.block) : null;
json.time = this.time;
if (chainheight)
json.confirmations = chainheight - this.height;
return json;
};