use utils.indexOf.

This commit is contained in:
Christopher Jeffrey 2016-02-28 20:06:02 -08:00
parent 7829ff3bea
commit 15c63eb14a
2 changed files with 8 additions and 19 deletions

View File

@ -270,12 +270,7 @@ MTX.prototype.scriptInput = function scriptInput(index, addr) {
vector[1] = addr.publicKey;
} else if (bcoin.script.isMultisig(prev)) {
// Multisig
for (i = 0; i < prev.length; i++) {
if (utils.isEqual(prev[i], addr.publicKey))
break;
}
if (i === prev.length)
if (utils.indexOf(prev, addr.publicKey) === -1)
return false;
// Already has a script template (at least)
@ -294,12 +289,7 @@ MTX.prototype.scriptInput = function scriptInput(index, addr) {
for (i = 0; i < n; i++)
vector[i + 1] = dummy;
} else {
for (i = 0; i < prev.length; i++) {
if (utils.isEqual(prev[i], addr.publicKey))
break;
}
if (i === prev.length)
if (utils.indexOf(prev, addr.publicKey) === -1)
return false;
// Already has a script template (at least)
@ -499,15 +489,12 @@ MTX.prototype.signInput = function signInput(index, addr, type) {
// Find the key index so we can place
// the signature in the same index.
for (ki = 0; ki < keys.length; ki++) {
if (utils.isEqual(addr.publicKey, keys[ki]))
break;
}
ki = utils.indexOf(keys, addr.publicKey);
// Our public key is not in the prev_out
// script. We tried to sign a transaction
// that is not redeemable by us.
if (ki === keys.length)
if (ki === -1)
return false;
// Offset key index by one to turn it into

View File

@ -1671,10 +1671,12 @@ utils.checkMerkleBranch = function checkMerkleBranch(hash, branch, index) {
utils.indexOf = function indexOf(arr, buf) {
var i;
assert(Array.isArray(arr));
assert(Buffer.isBuffer(buf));
utils.assert(Array.isArray(arr));
utils.assert(Buffer.isBuffer(buf));
for (i = 0; i < arr.length; i++) {
if (!Buffer.isBuffer(arr[i]))
continue;
if (utils.isEqual(arr[i], buf))
return i;
}