Skip to content

Commit

Permalink
more contains patches
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCharlatan committed Jan 8, 2024
1 parent f41eaff commit 63fcfbe
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
if (vvTried[nKBucket][nKBucketPos] != -1) {
// find an item to evict
int nIdEvict = vvTried[nKBucket][nKBucketPos];
assert(mapInfo.count(nIdEvict) == 1);
assert(mapInfo.contains(nIdEvict));
AddrInfo& infoOld = mapInfo[nIdEvict];

// Remove the to-be-evicted item from the tried set.
Expand Down Expand Up @@ -909,7 +909,7 @@ void AddrManImpl::ResolveCollisions_()
bool erase_collision = false;

// If id_new not found in mapInfo remove it from m_tried_collisions
if (mapInfo.count(id_new) != 1) {
if (!mapInfo.count(id_new)) {
erase_collision = true;
} else {
AddrInfo& info_new = mapInfo[id_new];
Expand Down Expand Up @@ -975,7 +975,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::SelectTriedCollision_()
int id_new = *it;

// If id_new not found in mapInfo remove it from m_tried_collisions
if (mapInfo.count(id_new) != 1) {
if (!mapInfo.contains(id_new)) {
m_tried_collisions.erase(it);
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)

// Signal NODE_COMPACT_FILTERS if peerblockfilters and basic filters index are both enabled.
if (args.GetBoolArg("-peerblockfilters", DEFAULT_PEERBLOCKFILTERS)) {
if (g_enabled_filter_types.count(BlockFilterType::BASIC) != 1) {
if (!g_enabled_filter_types.contains(BlockFilterType::BASIC)) {
return InitError(_("Cannot set -peerblockfilters without -blockfilterindex."));
}

Expand Down
4 changes: 2 additions & 2 deletions src/policy/packages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool IsChildWithParents(const Package& package)

// Every transaction must be a parent of the last transaction in the package.
return std::all_of(package.cbegin(), package.cend() - 1,
[&input_txids](const auto& ptx) { return input_txids.count(ptx->GetHash()) > 0; });
[&input_txids](const auto& ptx) { return input_txids.contains(ptx->GetHash()); });
}

bool IsChildWithParentsTree(const Package& package)
Expand All @@ -142,7 +142,7 @@ bool IsChildWithParentsTree(const Package& package)
// Each parent must not have an input who is one of the other parents.
return std::all_of(package.cbegin(), package.cend() - 1, [&](const auto& ptx) {
for (const auto& input : ptx->vin) {
if (parent_txids.count(input.prevout.hash) > 0) return false;
if (parent_txids.contains(input.prevout.hash)) return false;
}
return true;
});
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ static inline bool SetHasKeys(const std::set<T>& set) {return false;}
template<typename T, typename Tk, typename... Args>
static inline bool SetHasKeys(const std::set<T>& set, const Tk& key, const Args&... args)
{
return (set.count(key) != 0) || SetHasKeys(set, args...);
return (set.contains(key)) || SetHasKeys(set, args...);
}

// outpoint (needed for the utxo index) + nHeight + fCoinBase
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,12 +773,12 @@ static RPCHelpMan getblocktemplate()
const Consensus::Params& consensusParams = chainman.GetParams().GetConsensus();

// GBT must be called with 'signet' set in the rules for signet chains
if (consensusParams.signet_blocks && setClientRules.count("signet") != 1) {
if (consensusParams.signet_blocks && !setClientRules.contains("signet")) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the signet rule set (call with {\"rules\": [\"segwit\", \"signet\"]})");
}

// GBT must be called with 'segwit' set in the rules
if (setClientRules.count("segwit") != 1) {
if (!setClientRules.contains("segwit")) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the segwit rule set (call with {\"rules\": [\"segwit\"]})");
}

Expand Down
24 changes: 12 additions & 12 deletions src/test/argsman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,18 +458,18 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
BOOST_CHECK(test_args.m_settings.ro_config["sec1"].size() == 3);
BOOST_CHECK(test_args.m_settings.ro_config["sec2"].size() == 2);

BOOST_CHECK(test_args.m_settings.ro_config[""].count("a"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("b"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("ccc"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("d"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("fff"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("ggg"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("h"));
BOOST_CHECK(test_args.m_settings.ro_config[""].count("i"));
BOOST_CHECK(test_args.m_settings.ro_config["sec1"].count("ccc"));
BOOST_CHECK(test_args.m_settings.ro_config["sec1"].count("h"));
BOOST_CHECK(test_args.m_settings.ro_config["sec2"].count("ccc"));
BOOST_CHECK(test_args.m_settings.ro_config["sec2"].count("iii"));
BOOST_CHECK(test_args.m_settings.ro_config[""].contains("a"));
BOOST_CHECK(test_args.m_settings.ro_config[""].contains("b"));
BOOST_CHECK(test_args.m_settings.ro_config[""].contains("ccc"));
BOOST_CHECK(test_args.m_settings.ro_config[""].contains("d"));
BOOST_CHECK(test_args.m_settings.ro_config[""].contains("fff"));
BOOST_CHECK(test_args.m_settings.ro_config[""].contains("ggg"));
BOOST_CHECK(test_args.m_settings.ro_config[""].contains("h"));
BOOST_CHECK(test_args.m_settings.ro_config[""].contains("i"));
BOOST_CHECK(test_args.m_settings.ro_config["sec1"].contains("ccc"));
BOOST_CHECK(test_args.m_settings.ro_config["sec1"].contains("h"));
BOOST_CHECK(test_args.m_settings.ro_config["sec2"].contains("ccc"));
BOOST_CHECK(test_args.m_settings.ro_config["sec2"].contains("iii"));

BOOST_CHECK(test_args.IsArgSet("-a"));
BOOST_CHECK(test_args.IsArgSet("-b"));
Expand Down
2 changes: 1 addition & 1 deletion src/test/descriptor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
// Test whether the observed key path is present in the 'paths' variable (which contains expected, unobserved paths),
// and then remove it from that set.
for (const auto& origin : script_provider.origins) {
BOOST_CHECK_MESSAGE(paths.count(origin.second.second.path), "Unexpected key path: " + prv);
BOOST_CHECK_MESSAGE(paths.contains(origin.second.second.path), "Unexpected key path: " + prv);
left_paths.erase(origin.second.second.path);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/validation_chainstatemanager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
// chainstate, and only blocks where are ancestors of the snapshot block
// are added as candidates for the background chainstate.
BOOST_CHECK_EQUAL(cs1.setBlockIndexCandidates.size(), 2);
BOOST_CHECK_EQUAL(cs1.setBlockIndexCandidates.count(validated_tip), 1);
BOOST_CHECK_EQUAL(cs1.setBlockIndexCandidates.count(assumed_base), 1);
BOOST_CHECK(cs1.setBlockIndexCandidates.contains(validated_tip));
BOOST_CHECK(cs1.setBlockIndexCandidates.contains(assumed_base));

// The assumed-valid tolerant chain has the assumed valid base as a
// candidate, but otherwise has none of the assumed-valid (which do not
Expand All @@ -544,13 +544,13 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_loadblockindex, TestChain100Setup)
// - Blocks 111-120 are added because they have data.

// Check that block 90 is absent
BOOST_CHECK_EQUAL(cs2.setBlockIndexCandidates.count(validated_tip), 0);
BOOST_CHECK(!cs2.setBlockIndexCandidates.contains(validated_tip));
// Check that block 109 is absent
BOOST_CHECK_EQUAL(cs2.setBlockIndexCandidates.count(assumed_base->pprev), 0);
BOOST_CHECK(!cs2.setBlockIndexCandidates.contains(assumed_base->pprev));
// Check that block 110 is present
BOOST_CHECK_EQUAL(cs2.setBlockIndexCandidates.count(assumed_base), 1);
BOOST_CHECK(cs2.setBlockIndexCandidates.contains(assumed_base));
// Check that block 120 is present
BOOST_CHECK_EQUAL(cs2.setBlockIndexCandidates.count(assumed_tip), 1);
BOOST_CHECK(cs2.setBlockIndexCandidates.contains(assumed_tip));
// Check that 11 blocks total are present.
BOOST_CHECK_EQUAL(cs2.setBlockIndexCandidates.size(), num_indexes - last_assumed_valid_idx + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/spend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ util::Result<CreatedTransactionResult> FundTransaction(CWallet& wallet, const CM
const CTxOut& txOut = tx.vout[idx];
CTxDestination dest;
ExtractDestination(txOut.scriptPubKey, dest);
CRecipient recipient = {dest, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
CRecipient recipient = {dest, txOut.nValue, setSubtractFeeFromOutputs.contains(idx)};
vecSend.push_back(recipient);
}

Expand Down
18 changes: 9 additions & 9 deletions src/wallet/test/ismine_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().contains(scriptPubKey));
}

// P2PK compressed - Descriptor
Expand Down Expand Up @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().contains(scriptPubKey));
}

// P2PK uncompressed - Descriptor
Expand Down Expand Up @@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey));
}

// P2PKH compressed - Descriptor
Expand Down Expand Up @@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().contains(scriptPubKey));
}

// P2PKH uncompressed - Descriptor
Expand Down Expand Up @@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().contains(scriptPubKey));
}

// P2SH - Descriptor
Expand Down Expand Up @@ -341,7 +341,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().contains(scriptPubKey));
}

// P2WPKH compressed - Descriptor
Expand Down Expand Up @@ -453,7 +453,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript));
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().contains(scriptPubKey));
}

// P2SH multisig - Descriptor
Expand Down Expand Up @@ -496,7 +496,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey));
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().contains(scriptPubKey));
}

// P2WSH multisig with compressed keys - Descriptor
Expand Down Expand Up @@ -579,7 +579,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().count(scriptPubKey) == 1);
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->GetScriptPubKeys().contains(scriptPubKey));
}

// P2WSH multisig wrapped in P2SH - Descriptor
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/test/wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,8 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
BOOST_CHECK_EQUAL(addtx_count, 3);
{
LOCK(wallet->cs_wallet);
BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetHash()), 1U);
BOOST_CHECK_EQUAL(wallet->mapWallet.count(mempool_tx.GetHash()), 1U);
BOOST_CHECK(wallet->mapWallet.contains(block_tx.GetHash()));
BOOST_CHECK(wallet->mapWallet.contains(mempool_tx.GetHash()));
}


Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
wallet.reset();
{
WAIT_LOCK(g_wallet_release_mutex, lock);
while (g_unloading_wallet_set.count(name) == 1) {
while (g_unloading_wallet_set.contains(name)) {
g_wallet_release_cv.wait(lock);
}
}
Expand Down

0 comments on commit 63fcfbe

Please sign in to comment.