Skip to content

Commit a1ffddb

Browse files
committed
Merge #12298: Refactor HaveKeys to early return on false result
5bdbbdc Refactor HaveKeys to early return on false result (João Barbosa) Pull request description: This consists in a trivial change where the return type of `HaveKeys()` is now `bool` meaning that it returns whether all keys are in the keystore, and early returns when one isn't. Tree-SHA512: 03e35ea8486404b84884b49f6905c9f4fc161a3eeef080b06482d77985d5242a2bdd57a34b8d16abe19ee8c6cfa3e6fbcb935c73197d53f4cd468a2c7c0b889b
2 parents c9ca4f6 + 5bdbbdc commit a1ffddb

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)