From 727dc6625217eaa59ea81fc2f2885ece5a77133f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 2 Jul 2016 00:18:52 -0700 Subject: [PATCH] more tx method refactoring. --- lib/bcoin/mempool.js | 6 +++--- lib/bcoin/tx.js | 33 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/bcoin/mempool.js b/lib/bcoin/mempool.js index 48b38471..bb6cd278 100644 --- a/lib/bcoin/mempool.js +++ b/lib/bcoin/mempool.js @@ -691,11 +691,11 @@ Mempool.prototype.addTX = function addTX(tx, callback, force) { } if (this.requireStandard) { - if (!tx.isStandard(flags, ret)) { + if (!tx.isStandard(ret)) { return callback(new VerifyError(tx, 'nonstandard', ret.reason, - 0)); + ret.score)); } if (!this.chain.csvActive && tx.version >= 2) { @@ -981,7 +981,7 @@ Mempool.prototype.verify = function verify(entry, callback) { 0)); } - if (self.requireStandard && !tx.hasStandardInputs(flags)) { + if (self.requireStandard && !tx.hasStandardInputs()) { return callback(new VerifyError(tx, 'nonstandard', 'bad-txns-nonstandard-inputs', diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index b3dffe57..be681f32 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -1300,23 +1300,22 @@ TX.prototype.isSane = function isSane(ret) { * @returns {Boolean} */ -TX.prototype.isStandard = function isStandard(flags, ret) { +TX.prototype.isStandard = function isStandard(ret) { var i, input, output; var nulldata = 0; if (!ret) ret = {}; - if (flags == null) - flags = constants.flags.STANDARD_VERIFY_FLAGS; - if (this.version < 1 || this.version > constants.tx.MAX_VERSION) { ret.reason = 'version'; + ret.score = 0; return false; } - if (this.getCost() > constants.tx.MAX_COST) { + if (this.getCost() >= constants.tx.MAX_COST) { ret.reason = 'tx-size'; + ret.score = 0; return false; } @@ -1325,14 +1324,14 @@ TX.prototype.isStandard = function isStandard(flags, ret) { if (input.script.getSize() > 1650) { ret.reason = 'scriptsig-size'; + ret.score = 0; return false; } - if (flags & constants.flags.VERIFY_SIGPUSHONLY) { - if (!input.script.isPushOnly()) { - ret.reason = 'scriptsig-not-pushonly'; - return false; - } + if (!input.script.isPushOnly()) { + ret.reason = 'scriptsig-not-pushonly'; + ret.score = 0; + return false; } } @@ -1341,6 +1340,7 @@ TX.prototype.isStandard = function isStandard(flags, ret) { if (!output.script.isStandard()) { ret.reason = 'scriptpubkey'; + ret.score = 0; return false; } @@ -1351,17 +1351,20 @@ TX.prototype.isStandard = function isStandard(flags, ret) { if (output.script.isMultisig() && !constants.tx.BARE_MULTISIG) { ret.reason = 'bare-multisig'; + ret.score = 0; return false; } if (output.isDust(constants.tx.MIN_RELAY)) { ret.reason = 'dust'; + ret.score = 0; return false; } } if (nulldata > 1) { ret.reason = 'multi-op-return'; + ret.score = 0; return false; } @@ -1372,18 +1375,15 @@ TX.prototype.isStandard = function isStandard(flags, ret) { * Perform contextual checks to verify coin and input * script standardness (including the redeem script). * @see AreInputsStandard() - * @param {VerifyFlags?} + * @param {VerifyFlags?} flags * @returns {Boolean} */ -TX.prototype.hasStandardInputs = function hasStandardInputs(flags) { +TX.prototype.hasStandardInputs = function hasStandardInputs() { var maxSigops = constants.script.MAX_SCRIPTHASH_SIGOPS; var VERIFY_NONE = constants.flags.VERIFY_NONE; var i, input, stack, redeem; - if (flags == null) - flags = constants.flags.STANDARD_VERIFY_FLAGS; - if (this.isCoinbase()) return true; @@ -1396,8 +1396,7 @@ TX.prototype.hasStandardInputs = function hasStandardInputs(flags) { if (input.coin.script.isUnknown()) return false; - if ((flags & constants.flags.VERIFY_P2SH) - && input.coin.script.isScripthash()) { + if (input.coin.script.isScripthash()) { stack = new Stack(); try {