From 60ff33bdb28dfa4018d850e4823a0e77952f9984 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 28 Feb 2017 10:13:48 -0800 Subject: [PATCH] block: minor. --- lib/primitives/block.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/primitives/block.js b/lib/primitives/block.js index cf64b744..e16a95e3 100644 --- a/lib/primitives/block.js +++ b/lib/primitives/block.js @@ -366,12 +366,13 @@ Block.prototype.getMerkleRoot = function getMerkleRoot(enc) { */ Block.prototype.getWitnessNonce = function getWitnessNonce() { - var coinbase = this.txs[0]; - var input; + var coinbase, input; - if (!coinbase) + if (this.txs.length === 0) return null; + coinbase = this.txs[0]; + if (coinbase.inputs.length !== 1) return null; @@ -394,12 +395,13 @@ Block.prototype.getWitnessNonce = function getWitnessNonce() { */ Block.prototype.getCommitmentHash = function getCommitmentHash(enc) { - var coinbase = this.txs[0]; - var i, hash, output; + var i, coinbase, hash, output; - if (!coinbase) + if (this.txs.length === 0) return null; + coinbase = this.txs[0]; + for (i = coinbase.outputs.length - 1; i >= 0; i--) { output = coinbase.outputs[i]; if (output.script.isCommitment()) {