Skip to content

Commit

Permalink
match scriptHash types 1 for 1, ignore classify order
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Sep 22, 2017
1 parent deb8b0f commit 71f8a92
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
22 changes: 18 additions & 4 deletions src/templates/scripthash/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,26 @@ function check (script, allowIncomplete) {
// is redeemScriptSig push only?
if (!bscript.isPushOnly(scriptSigChunks)) return false

var inputType = bscript.classifyInput(scriptSigChunks, allowIncomplete)
var outputType = bscript.classifyOutput(redeemScriptChunks)
// is witness?
if (chunks.length === 1) {
return outputType === bscript.types.P2WSH || outputType === bscript.types.P2WPKH
return bscript.witnessScriptHash.output.check(redeemScriptChunks) ||
bscript.witnessPubKeyHash.output.check(redeemScriptChunks)
}
return inputType === outputType

// match types
if (bscript.pubKeyHash.input.check(scriptSigChunks) &&
bscript.pubKeyHash.output.check(redeemScriptChunks)) return true

if (bscript.scriptHash.input.check(scriptSigChunks) &&
bscript.scriptHash.output.check(redeemScriptChunks)) return true

if (bscript.multisig.input.check(scriptSigChunks, allowIncomplete) &&
bscript.multisig.output.check(redeemScriptChunks)) return true

if (bscript.pubKey.input.check(scriptSigChunks) &&
bscript.pubKey.output.check(redeemScriptChunks)) return true

return false
}
check.toJSON = function () { return 'scriptHash input' }

Expand Down
13 changes: 10 additions & 3 deletions test/fixtures/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@
""
]
},
{
"type": "scripthash",
"redeemScript": "OP_2 0327e023a353d111808f61d554c2e1934721eaf87f33b7a771e807006908a49372 03251670bb6a179a0d43b75476c7e580c0ba274378a18077e8de0832c870e5381f 02cca7f9a64425a0466d26d5c7e9eb3ad6b64cd48ea89edb38bc08f58a792dde47 OP_3 OP_CHECKMULTISIG",
"redeemScriptSig": "OP_0 304502210093efc26facedc5f51e304aa270a7b4f1a911b2d912c3674e5c6e2ad4ac7a410402201cf0b62c240461902f9f16d8a0bc3a210b7bfcd2c06523dd4b4b63be22e8525201",
"input": "OP_0 304502210093efc26facedc5f51e304aa270a7b4f1a911b2d912c3674e5c6e2ad4ac7a410402201cf0b62c240461902f9f16d8a0bc3a210b7bfcd2c06523dd4b4b63be22e8525201 52210327e023a353d111808f61d554c2e1934721eaf87f33b7a771e807006908a493722103251670bb6a179a0d43b75476c7e580c0ba274378a18077e8de0832c870e5381f2102cca7f9a64425a0466d26d5c7e9eb3ad6b64cd48ea89edb38bc08f58a792dde4753ae",
"inputHex": "0048304502210093efc26facedc5f51e304aa270a7b4f1a911b2d912c3674e5c6e2ad4ac7a410402201cf0b62c240461902f9f16d8a0bc3a210b7bfcd2c06523dd4b4b63be22e85252014c6952210327e023a353d111808f61d554c2e1934721eaf87f33b7a771e807006908a493722103251670bb6a179a0d43b75476c7e580c0ba274378a18077e8de0832c870e5381f2102cca7f9a64425a0466d26d5c7e9eb3ad6b64cd48ea89edb38bc08f58a792dde4753ae",
"output": "OP_HASH160 fcc42dd4aa770d75cb6796bbd7853a325e746659 OP_EQUAL",
"outputHex": "a914fcc42dd4aa770d75cb6796bbd7853a325e746659"
},
{
"type": "nonstandard",
"typeIncomplete": "scripthash",
Expand Down Expand Up @@ -191,9 +200,7 @@
"outputHex": "00"
},
{
"type": "scripthash",
"redeemScript": "OP_0",
"redeemScriptSig": "OP_0",
"type": "nonstandard",
"input": "OP_0 00",
"inputHex": "000100",
"inputStack": [
Expand Down

0 comments on commit 71f8a92

Please sign in to comment.