TransactionBuilder: avoid input mutation until after exception possibility

This commit is contained in:
Daniel Cousens 2016-10-06 20:31:44 +11:00 committed by Daniel Cousens
parent 17377381c4
commit f7b2fdfe60

View file

@ -191,16 +191,17 @@ function prepareInput (input, kpPubKey, redeemScript, hashType) {
var prevOutScriptScriptHash = bscript.decompile(input.prevOutScript)[1]
if (!prevOutScriptScriptHash.equals(redeemScriptHash)) throw new Error('Inconsistent hash160(RedeemScript)')
// or, we don't have a prevOutScript, so generate a P2SH script
} else {
input.prevOutScript = bscript.scriptHashOutput(redeemScriptHash)
input.prevOutType = 'scripthash'
}
var expanded = expandOutput(redeemScript, undefined, kpPubKey)
if (!expanded.pubKeys) throw new Error('RedeemScript not supported "' + bscript.toASM(redeemScript) + '"')
// if we don't have a prevOutScript, generate a P2SH script
if (!input.prevOutType) {
input.prevOutScript = bscript.scriptHashOutput(redeemScriptHash)
input.prevOutType = 'scripthash'
}
input.pubKeys = expanded.pubKeys
input.redeemScript = redeemScript
input.redeemScriptType = expanded.scriptType