wallet: improve ownInput and ownOutput.

This commit is contained in:
Christopher Jeffrey 2014-06-12 02:55:53 -05:00
parent dbd3b5025a
commit 9442920e73
2 changed files with 22 additions and 0 deletions

View File

@ -236,6 +236,20 @@ script.isPubkeyhash = function isPubkeyhash(s, hash) {
return s[2];
};
script.isSimplePubkeyhash = function isSimplePubkeyhash(s, hash) {
if (s.length !== 2)
return false;
var match = Array.isArray(s[0]) && s[1] === 'checksig';
if (!match)
return false;
if (hash)
return utils.isEqual(s[0], hash);
else
return s[0];
};
script.isMultisig = function isMultisig(s, key) {
if (s.length < 4)
return false;

View File

@ -170,6 +170,9 @@ Wallet.prototype.ownOutput = function ownOutput(tx, index) {
if (bcoin.script.isPubkeyhash(s, hash))
return true;
if (bcoin.script.isSimplePubkeyhash(s, hash))
return true;
if (bcoin.script.isMultisig(s, key))
return true;
@ -189,6 +192,11 @@ Wallet.prototype.ownInput = function ownInput(tx, index) {
if (index !== undefined && index !== i)
return false;
if (bcoin.script.isPubkeyhashInput(input.script)
&& utils.isEqual(input.script[1], key)) {
return true;
}
if (!input.out.tx)
return false;