Merge pull request #325 from sangaman/master
Adding confirmations property to block and tx getJSON
This commit is contained in:
commit
e137288b78
@ -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);
|
||||
@ -279,8 +279,8 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
||||
}
|
||||
|
||||
const height = await this.chain.getHeight(hash);
|
||||
|
||||
res.send(200, block.getJSON(this.network, view, height));
|
||||
|
||||
res.send(200, block.getJSON(this.network, view, height, confirmations));
|
||||
});
|
||||
|
||||
// Mempool snapshot
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -151,12 +151,16 @@ 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 (this.block === null)
|
||||
json.confirmations = 0;
|
||||
else
|
||||
json.confirmations = chainheight - this.height + 1;
|
||||
return json;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user