diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index dec40e1e..5157dbb5 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -353,18 +353,19 @@ Block.prototype.__defineGetter__('commitmentHash', function() { if (!coinbase) return; - for (i = 0; i < coinbase.outputs.length; i++) { + for (i = coinbase.outputs.length - 1; i >= 0; i--) { commitment = coinbase.outputs[i].script; if (commitment.isCommitment()) { commitmentHash = commitment.getCommitmentHash(); commitmentHash = commitmentHash.toString('hex'); + + if (!this.mutable) + this._commitmentHash = commitmentHash; + break; } } - if (!this.mutable) - this._commitmentHash = commitmentHash; - return commitmentHash; });