Should be able to deal with incomplete P2SH/P2WSH inputs when allowIncomplete is set

This commit is contained in:
Thomas Kerin 2017-08-01 22:12:34 +02:00 committed by Daniel Cousens
parent bc3aef5a92
commit 0b1c3bfbd9
2 changed files with 37 additions and 9 deletions

View file

@ -406,7 +406,7 @@ function buildInput (input, allowIncomplete) {
if (scriptType === bscript.types.P2SH) {
// We can remove this error later when we have a guarantee prepareInput
// rejects unsignable scripts - it MUST be signable at this point.
if (P2SH.indexOf(input.redeemScriptType) === -1) {
if (P2SH.indexOf(input.redeemScriptType) === -1 && !allowIncomplete) {
throw new Error('Impossible to sign this type')
}
p2sh = true
@ -422,16 +422,13 @@ function buildInput (input, allowIncomplete) {
witness = buildStack(bscript.types.P2PKH, input.signatures, input.pubKeys, allowIncomplete)
} else if (scriptType === bscript.types.P2WSH) {
// We can remove this check later
if (SIGNABLE.indexOf(input.witnessScriptType) !== -1) {
if (SIGNABLE.indexOf(input.witnessScriptType) === -1 && !allowIncomplete) {
throw new Error('Impossible to sign this type')
} else if (SIGNABLE.indexOf(input.witnessScriptType) !== -1) {
witness = buildStack(input.witnessScriptType, input.signatures, input.pubKeys, allowIncomplete)
witness.push(input.witnessScript)
} else {
// We can remove this error later when we have a guarantee prepareInput
// rejects unsignble scripts - it MUST be signable at this point.
throw new Error()
scriptType = input.witnessScriptType
}
scriptType = input.witnessScriptType
}
// append redeemScript if necessary
@ -578,7 +575,6 @@ TransactionBuilder.prototype.__addInputUnsafe = function (txHash, vout, options)
var vin = this.tx.addInput(txHash, vout, options.sequence, options.scriptSig)
this.inputs[vin] = input
this.prevTxMap[prevTxOut] = vin
return vin
}