@@ -406,7 +406,7 @@ function buildInput (input, allowIncomplete) {
406406 if ( scriptType === bscript . types . P2SH ) {
407407 // We can remove this error later when we have a guarantee prepareInput
408408 // rejects unsignable scripts - it MUST be signable at this point.
409- if ( P2SH . indexOf ( input . redeemScriptType ) === - 1 ) {
409+ if ( P2SH . indexOf ( input . redeemScriptType ) === - 1 && ! allowIncomplete ) {
410410 throw new Error ( 'Impossible to sign this type' )
411411 }
412412 p2sh = true
@@ -422,16 +422,13 @@ function buildInput (input, allowIncomplete) {
422422 witness = buildStack ( bscript . types . P2PKH , input . signatures , input . pubKeys , allowIncomplete )
423423 } else if ( scriptType === bscript . types . P2WSH ) {
424424 // We can remove this check later
425- if ( SIGNABLE . indexOf ( input . witnessScriptType ) !== - 1 ) {
425+ if ( SIGNABLE . indexOf ( input . witnessScriptType ) === - 1 && ! allowIncomplete ) {
426+ throw new Error ( 'Impossible to sign this type' )
427+ } else if ( SIGNABLE . indexOf ( input . witnessScriptType ) !== - 1 ) {
426428 witness = buildStack ( input . witnessScriptType , input . signatures , input . pubKeys , allowIncomplete )
427429 witness . push ( input . witnessScript )
428- } else {
429- // We can remove this error later when we have a guarantee prepareInput
430- // rejects unsignble scripts - it MUST be signable at this point.
431- throw new Error ( )
430+ scriptType = input . witnessScriptType
432431 }
433-
434- scriptType = input . witnessScriptType
435432 }
436433
437434 // append redeemScript if necessary
@@ -578,7 +575,6 @@ TransactionBuilder.prototype.__addInputUnsafe = function (txHash, vout, options)
578575 var vin = this . tx . addInput ( txHash , vout , options . sequence , options . scriptSig )
579576 this . inputs [ vin ] = input
580577 this . prevTxMap [ prevTxOut ] = vin
581-
582578 return vin
583579}
584580
0 commit comments