Skip to content

Commit 5bdbbdc

Browse files
committed
Refactor HaveKeys to early return on false result
1 parent 9d9c418 commit 5bdbbdc

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/script/ismine.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@
1313

1414
typedef std::vector<unsigned char> valtype;
1515

16-
unsigned int HaveKeys(const std::vector<valtype>& pubkeys, const CKeyStore& keystore)
16+
static bool HaveKeys(const std::vector<valtype>& pubkeys, const CKeyStore& keystore)
1717
{
18-
unsigned int nResult = 0;
19-
for (const valtype& pubkey : pubkeys)
20-
{
18+
for (const valtype& pubkey : pubkeys) {
2119
CKeyID keyID = CPubKey(pubkey).GetID();
22-
if (keystore.HaveKey(keyID))
23-
++nResult;
20+
if (!keystore.HaveKey(keyID)) return false;
2421
}
25-
return nResult;
22+
return true;
2623
}
2724

2825
isminetype IsMine(const CKeyStore& keystore, const CScript& scriptPubKey, SigVersion sigversion)
@@ -140,7 +137,7 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey, bool&
140137
}
141138
}
142139
}
143-
if (HaveKeys(keys, keystore) == keys.size())
140+
if (HaveKeys(keys, keystore))
144141
return ISMINE_SPENDABLE;
145142
break;
146143
}

0 commit comments

Comments
 (0)