From 4f715d86c7e9f591d0dd51298281ab84fadd52a9 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 10 Jul 2016 02:09:11 -0700 Subject: [PATCH] fix commitment hash checking. --- lib/bcoin/block.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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; });