From d3ccbb62776d3718f8ad83ddcb28d4b8179afb27 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 28 Sep 2016 01:12:39 +1000 Subject: [PATCH] TransactionBuilder: rename index to vout internally --- src/transaction_builder.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index e10ca64..99b261b 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -256,7 +256,7 @@ TransactionBuilder.prototype.addOutput = function (scriptPubKey, value) { // if signatures exist, adding outputs is only acceptable if SIGHASH_NONE or SIGHASH_SINGLE is used // throws if any signatures didn't use SIGHASH_NONE|SIGHASH_SINGLE - if (!this.inputs.every(function (input, index) { + if (!this.inputs.every(function (input, i) { // no signature if (input.hashType === undefined) return true @@ -264,7 +264,7 @@ TransactionBuilder.prototype.addOutput = function (scriptPubKey, value) { if (hashTypeMod === Transaction.SIGHASH_NONE) return true if (hashTypeMod === Transaction.SIGHASH_SINGLE) { // account for SIGHASH_SINGLE signing of a non-existing output, aka the "SIGHASH_SINGLE" bug - return index < nOutputs + return i < nOutputs } return false @@ -357,7 +357,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) { var tx = this.tx.clone() // Create script signatures from inputs - this.inputs.forEach(function (input, index) { + this.inputs.forEach(function (input, i) { var scriptType = input.redeemScriptType || input.prevOutType if (!allowIncomplete) { @@ -374,18 +374,18 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) { // build a scriptSig var scriptSig = buildFromInputData(input, scriptType, allowIncomplete) - tx.setInputScript(index, scriptSig) + tx.setInputScript(i, scriptSig) }) return tx } -TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hashType) { +TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashType) { if (keyPair.network !== this.network) throw new Error('Inconsistent network') - if (!this.inputs[index]) throw new Error('No input at index: ' + index) + if (!this.inputs[vin]) throw new Error('No input at index: ' + vin) hashType = hashType || Transaction.SIGHASH_ALL - var input = this.inputs[index] + var input = this.inputs[vin] var canSign = input.hashType !== undefined && input.prevOutScript !== undefined && input.pubKeys !== undefined && @@ -453,7 +453,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash // ready to sign? var hashScript = input.redeemScript || input.prevOutScript - var signatureHash = this.tx.hashForSignature(index, hashScript, hashType) + var signatureHash = this.tx.hashForSignature(vin, hashScript, hashType) // enforce in order signing of public keys var valid = input.pubKeys.some(function (pubKey, i) {