scripts: fix isScriptHashInput classification

This commit is contained in:
Daniel Cousens 2015-03-04 21:00:07 +11:00
parent ec66ca9b1a
commit d00ec9af29
3 changed files with 7 additions and 10 deletions

View file

@ -73,15 +73,12 @@ function isScriptHashInput (script, allowIncomplete) {
if (!Buffer.isBuffer(lastChunk)) return false
var scriptSig = Script.fromChunks(script.chunks.slice(0, -1))
var scriptPubKey
var redeemScript = Script.fromBuffer(lastChunk)
try {
scriptPubKey = Script.fromBuffer(lastChunk)
} catch (e) {
return false
}
// is redeemScript a valid script?
if (redeemScript.chunks.length === 0) return false
return classifyInput(scriptSig, allowIncomplete) === classifyOutput(scriptPubKey)
return classifyInput(scriptSig, allowIncomplete) === classifyOutput(redeemScript)
}
function isScriptHashOutput (script) {

View file

@ -113,7 +113,7 @@
"scriptSig": "OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501 OP_RESERVED"
},
{
"description": "signature forms invalid script",
"description": "redeemScript is a signature, therefore not a valid script",
"scriptSig": "OP_0 3045022100e12b17b3a4c80c401a1687487bd2bafee9e5f1f8f1ffc6180ce186672ad7b43a02205e316d1e5e71822f5ef301b694e578fa9c94af4f5f098c952c833f4691307f4e01"
}
],

View file

@ -86,7 +86,7 @@ describe('Scripts', function () {
fixtures.invalid[inputFnName].forEach(function (f) {
if (inputFn && f.scriptSig) {
it('returns false for ' + f.scriptSig, function () {
it('returns false for ' + f.description + ' (' + f.scriptSig + ')', function () {
var script = Script.fromASM(f.scriptSig)
assert.equal(inputFn(script), false)
@ -112,7 +112,7 @@ describe('Scripts', function () {
fixtures.invalid[outputFnName].forEach(function (f) {
if (outputFn && f.scriptPubKey) {
it('returns false for ' + f.scriptPubKey, function () {
it('returns false for ' + f.description + ' (' + f.scriptPubKey + ')', function () {
var script = Script.fromASM(f.scriptPubKey)
assert.equal(outputFn(script), false)