diff --git a/lib/wallet/txdb.js b/lib/wallet/txdb.js index fbe6b2e4..0a4fa213 100644 --- a/lib/wallet/txdb.js +++ b/lib/wallet/txdb.js @@ -3089,6 +3089,8 @@ function Details(txdb, tx, height) { this.wid = this.wallet.wid; this.id = this.wallet.id; + this.chainHeight = height; + this.hash = tx.hash('hex'); this.tx = tx; @@ -3096,7 +3098,6 @@ function Details(txdb, tx, height) { this.height = tx.height; this.ts = tx.ts; this.index = tx.index; - this.confirmations = tx.getConfirmations(height); this.ps = tx.ps; @@ -3167,6 +3168,20 @@ Details.prototype.setOutput = function setOutput(i, path) { } }; +/** + * Calculate confirmations. + * @returns {Number} + */ + +Details.prototype.getConfirmations = function getConfirmations() { + var depth = this.chainHeight - this.height; + + if (depth < 0) + return 0; + + return depth + 1; +}; + /** * Calculate fee. Only works if wallet * owns all inputs. Returns 0 otherwise. @@ -3205,6 +3220,7 @@ Details.prototype.toJSON = function toJSON() { return { wid: this.wid, id: this.id, + chainHeight: this.chainHeight, hash: utils.revHex(this.hash), height: this.height, block: this.block ? utils.revHex(this.block) : null, @@ -3212,7 +3228,7 @@ Details.prototype.toJSON = function toJSON() { ps: this.ps, index: this.index, fee: utils.btc(this.getFee()), - confirmations: this.confirmations, + confirmations: this.getConfirmations(), inputs: this.inputs.map(function(input) { return input.toJSON(self.network); }),