Browse Source

TransactionBuilder: rename index to vout internally

hk-custom-address
Daniel Cousens 8 years ago
parent
commit
d3ccbb6277
  1. 16
      src/transaction_builder.js

16
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 // 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 // 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 // no signature
if (input.hashType === undefined) return true 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_NONE) return true
if (hashTypeMod === Transaction.SIGHASH_SINGLE) { if (hashTypeMod === Transaction.SIGHASH_SINGLE) {
// account for SIGHASH_SINGLE signing of a non-existing output, aka the "SIGHASH_SINGLE" bug // account for SIGHASH_SINGLE signing of a non-existing output, aka the "SIGHASH_SINGLE" bug
return index < nOutputs return i < nOutputs
} }
return false return false
@ -357,7 +357,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
var tx = this.tx.clone() var tx = this.tx.clone()
// Create script signatures from inputs // Create script signatures from inputs
this.inputs.forEach(function (input, index) { this.inputs.forEach(function (input, i) {
var scriptType = input.redeemScriptType || input.prevOutType var scriptType = input.redeemScriptType || input.prevOutType
if (!allowIncomplete) { if (!allowIncomplete) {
@ -374,18 +374,18 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
// build a scriptSig // build a scriptSig
var scriptSig = buildFromInputData(input, scriptType, allowIncomplete) var scriptSig = buildFromInputData(input, scriptType, allowIncomplete)
tx.setInputScript(index, scriptSig) tx.setInputScript(i, scriptSig)
}) })
return tx 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 (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 hashType = hashType || Transaction.SIGHASH_ALL
var input = this.inputs[index] var input = this.inputs[vin]
var canSign = input.hashType !== undefined && var canSign = input.hashType !== undefined &&
input.prevOutScript !== undefined && input.prevOutScript !== undefined &&
input.pubKeys !== undefined && input.pubKeys !== undefined &&
@ -453,7 +453,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
// ready to sign? // ready to sign?
var hashScript = input.redeemScript || input.prevOutScript 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 // enforce in order signing of public keys
var valid = input.pubKeys.some(function (pubKey, i) { var valid = input.pubKeys.some(function (pubKey, i) {

Loading…
Cancel
Save