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()) {