From f7b2fdfe60b8710ec378e06db820925347b9f51a Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 6 Oct 2016 20:31:44 +1100 Subject: [PATCH] TransactionBuilder: avoid input mutation until after exception possibility --- src/transaction_builder.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index a600c5c..add817e 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -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