From 9442920e73d1ce135f44bddb397fd2c20352c34c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 12 Jun 2014 02:55:53 -0500 Subject: [PATCH] wallet: improve ownInput and ownOutput. --- lib/bcoin/script.js | 14 ++++++++++++++ lib/bcoin/wallet.js | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index af76103f..284cbd3c 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -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; diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 87520a37..d9b990b9 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -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;