Skip to content

Commit

Permalink
TransactionBuilder: avoid input mutation until after exception possib…
Browse files Browse the repository at this point in the history
…ility
  • Loading branch information
dcousens committed Oct 6, 2016
1 parent 8e72b05 commit 8a96c7c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,17 @@ function prepareInput (input, kpPubKey, redeemScript, hashType) {

var prevOutScriptScriptHash = bscript.decompile(input.prevOutScript)[1]
if (!bufferEquals(prevOutScriptScriptHash, 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
Expand Down

0 comments on commit 8a96c7c

Please sign in to comment.