From 58d2f66a700c20f11f7b48e58a5c023e7166ce7a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 28 Feb 2016 23:11:18 -0800 Subject: [PATCH] fix checkinputs. --- lib/bcoin/chain.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index b5d737aa..f2012766 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -668,6 +668,23 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac tx = block.txs[i]; hash = tx.hash('hex'); + // Check for block sigops limits + // Start counting P2SH sigops once block + // timestamps reach March 31st, 2012. + if (block.ts >= constants.block.bip16time) + sigops += tx.getSigops(true); + else + sigops += tx.getSigops(); + + if (sigops > constants.script.maxBlockSigops) { + utils.debug('Block has too many sigops: %s', block.rhash); + return callback(null, false); + } + + // Coinbases do not have prevouts + if (tx.isCoinbase()) + continue; + if (tx.getOutputValue().cmp(tx.getInputValue()) > 0) { utils.debug('TX is spending funds it does not have: %s', tx.rhash); return false; @@ -676,10 +693,6 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac for (j = 0; j < tx.inputs.length; j++) { input = tx.inputs[j]; - // Coinbases do not have prevouts - if (tx.isCoinbase()) - continue; - // Ensure tx is not double spending an output if (!input.output) { utils.debug('Block is using spent inputs: %s (tx: %s, output: %s)', @@ -711,22 +724,6 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac return callback(null, false); } } - - if (!scriptCheck) - continue; - - // Check for block sigops limits - // Start counting P2SH sigops once block - // timestamps reach March 31st, 2012. - if (block.ts >= constants.block.bip16time) - sigops += tx.getSigops(true); - else - sigops += tx.getSigops(); - - if (sigops > constants.script.maxBlockSigops) { - utils.debug('Block has too many sigops: %s', block.rhash); - return callback(null, false); - } } return callback(null, true);