diff --git a/lib/primitives/block.js b/lib/primitives/block.js index 60aea44b..663d2756 100644 --- a/lib/primitives/block.js +++ b/lib/primitives/block.js @@ -38,7 +38,6 @@ function Block(options) { this.txs = []; this._cbHeight = null; - this._commitmentHash = null; this._raw = null; this._size = -1; @@ -400,32 +399,23 @@ Block.prototype.getWitnessNonce = function getWitnessNonce() { */ Block.prototype.getCommitmentHash = function getCommitmentHash(enc) { - var hash = this._commitmentHash; - var i, coinbase, output; + var coinbase = this.txs[0]; + var i, hash, output; - if (!hash) { - coinbase = this.txs[0]; + if (!coinbase) + return null; - if (!coinbase) - return null; - - for (i = coinbase.outputs.length - 1; i >= 0; i--) { - output = coinbase.outputs[i]; - - if (output.script.isCommitment()) { - hash = output.script.getCommitmentHash(); - - if (!this.mutable) - this._commitmentHash = hash; - - break; - } + for (i = coinbase.outputs.length - 1; i >= 0; i--) { + output = coinbase.outputs[i]; + if (output.script.isCommitment()) { + hash = output.script.getCommitmentHash(); + break; } - - if (!hash) - return null; } + if (!hash) + return null; + return enc === 'hex' ? hash.toString('hex') : hash;