From fcf5af802e95c99996f10598d2a1fc8fea6b5753 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 20 Apr 2016 04:20:25 -0700 Subject: [PATCH] update isStandardProgram. --- lib/bcoin/script.js | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index b4407eff..0d334eeb 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -2379,34 +2379,30 @@ Script.prototype.isStandard = function isStandard() { */ Script.prototype.isStandardProgram = function isStandardProgram(witness, flags) { - var program, witnessScript, i; + var program = this.getWitnessProgram(); + var i; + assert(program); assert((flags & constants.flags.VERIFY_WITNESS) !== 0); - assert(this.isWitnessProgram()); - program = this.getWitnessProgram(); - - if (!program.type) - return false; - - if (program.version > 0) { + if (program.version === 0) { + if (program.data.length === 32) { + if (witness.items.length === 0) + return false; + } else if (program.data.length === 20) { + if (witness.items.length !== 2) + return false; + } else { + return false; + } + } else { if (flags & constants.flags.VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM) return false; return true; } - if (program.type === 'witnesspubkeyhash') { - if (witness.items.length !== 2) - return false; - } else if (program.type === 'witnessscripthash') { - if (witness.items.length === 0) - return false; - } else { - assert(false); - } - for (i = 0; i < witness.items.length; i++) { - if (witness.items[i].length > constants.script.MAX_SIZE) + if (witness.items[i].length > constants.script.MAX_PUSH) return false; }