From a7882149213a4d4903ddb5a45292ab9b479d695a Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 5 Feb 2015 14:33:31 +1100 Subject: [PATCH] TxBuilder: fix undefined scriptSig Fixed and typeForce used to enforce this wont happen again in future. --- src/transaction.js | 3 +++ src/transaction_builder.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index a952dbb..31c8657 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -308,6 +308,9 @@ Transaction.prototype.toHex = function() { } Transaction.prototype.setInputScript = function(index, script) { + typeForce('Number', index) + typeForce('Script', script) + this.ins[index].script = script } diff --git a/src/transaction_builder.js b/src/transaction_builder.js index fb394ee..14c3451 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -249,12 +249,15 @@ TransactionBuilder.prototype.__build = function(allowIncomplete) { } } - // if we built a scriptSig, wrap as scriptHash if necessary - if (scriptSig && input.prevOutType === 'scripthash') { - scriptSig = scripts.scriptHashInput(scriptSig, input.redeemScript) - } + // did we build a scriptSig? + if (scriptSig) { + // wrap as scriptHash if necessary + if (input.prevOutType === 'scripthash') { + scriptSig = scripts.scriptHashInput(scriptSig, input.redeemScript) + } - tx.setInputScript(index, scriptSig) + tx.setInputScript(index, scriptSig) + } }) return tx