Merge pull request from bitcoinjs/op0fix

TransactionBuilder multisig OP_0 fix
This commit is contained in:
Daniel Cousens 2015-03-05 18:46:16 +11:00
commit 7a469f6620
5 changed files with 40 additions and 28 deletions

View file

@ -250,13 +250,8 @@ function multisigInput (signatures, scriptPubKey) {
var m = mOp - (ops.OP_1 - 1)
var n = nOp - (ops.OP_1 - 1)
var count = 0
signatures.forEach(function (signature) {
count += (signature !== ops.OP_0)
})
assert(count >= m, 'Not enough signatures provided')
assert(count <= n, 'Too many signatures provided')
assert(signatures.length >= m, 'Not enough signatures provided')
assert(signatures.length <= n, 'Too many signatures provided')
}
return Script.fromChunks([].concat(ops.OP_0, signatures))

View file

@ -242,10 +242,15 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
})
// fill in blanks with OP_0
for (var i = 0; i < msSignatures.length; ++i) {
if (msSignatures[i]) continue
if (allowIncomplete) {
for (var i = 0; i < msSignatures.length; ++i) {
if (msSignatures[i]) continue
msSignatures[i] = ops.OP_0
msSignatures[i] = ops.OP_0
}
} else {
// Array.prototype.filter returns non-sparse array
msSignatures = msSignatures.filter(function (x) { return x })
}
var redeemScript = allowIncomplete ? undefined : input.redeemScript