Fix TransactionBuilder.addOutput

This commit is contained in:
Kirill Fomichev 2015-11-23 17:05:06 +03:00
parent 3d43a6f681
commit 5de6818fcb
2 changed files with 34 additions and 3 deletions

View file

@ -227,10 +227,13 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu
}
TransactionBuilder.prototype.addOutput = function (scriptPubKey, value) {
var valid = this.inputs.every(function (input) {
var tx = this.tx
var valid = this.inputs.every(function (input, index) {
if (input.hashType === undefined) return true
return (input.hashType & 0x1f) === Transaction.SIGHASH_SINGLE
var hashType = input.hashType & 0x1f
return hashType === Transaction.SIGHASH_NONE ||
(hashType === Transaction.SIGHASH_SINGLE && index < tx.outs.length)
})
if (!valid) throw new Error('No, this would invalidate signatures')
@ -240,7 +243,7 @@ TransactionBuilder.prototype.addOutput = function (scriptPubKey, value) {
scriptPubKey = baddress.toOutputScript(scriptPubKey, this.network)
}
return this.tx.addOutput(scriptPubKey, value)
return tx.addOutput(scriptPubKey, value)
}
TransactionBuilder.prototype.build = function () {