refactor: unify container presence checks - trivial counts
What changed, and why it matters
This commit is a pure code cleanup: it replaces older-style container lookups like `m.count(k)` with the newer, clearer `m.contains(k)` across many files. The behavior is identical, so there is no security impact.
No action required. This is a non-functional refactor with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit performs a mechanical refactor from count()-based presence checks to contains() for associative containers. For all containers involved (e.g., std::map, std::set, std::unordered_map, std::unordered_set), contains(k) is semantically equivalent to count(k) != 0 for presence and count(k) == 0 for absence. No logic, control flow, or data structures change. The diff is +163/-163 in 56 files, all one-to-one substitutions.
Changed components
src/addrman.cppsrc/bitcoin-tx.cppsrc/common/args.cppsrc/httprpc.cppsrc/merkleblock.cppsrc/net.cppsrc/net_processing.cppsrc/netbase.hsrc/node/mini_miner.cppsrc/policy/fees/block_policy_estimator.cppsrc/policy/packages.cppsrc/policy/rbf.cppsrc/policy/truc_policy.cppsrc/psbt.cppsrc/psbt.hsrc/rpc/blockchain.cppsrc/rpc/mining.cppsrc/rpc/rawtransaction.cppsrc/rpc/txoutproof.cppsrc/rpc/util.cppsrc/script/sign.cppsrc/script/signingprovider.cppsrc/sync.cppsrc/test/argsman_tests.cppsrc/test/coins_tests.cppsrc/test/descriptor_tests.cppsrc/test/fuzz/coinscache_sim.cppsrc/test/fuzz/miniscript.cppsrc/test/fuzz/partially_downloaded_block.cppsrc/test/fuzz/txorphan.cppsrc/test/miniminer_tests.cppsrc/test/miniscript_tests.cppsrc/test/net_peer_eviction_tests.cppsrc/test/script_tests.cppsrc/test/util/txmempool.cppsrc/torcontrol.cppsrc/txgraph.cppsrc/txmempool.hsrc/util/fs_helpers.cppsrc/validation.cppsrc/versionbits.cppsrc/wallet/coincontrol.cppsrc/wallet/feebumper.cppsrc/wallet/migrate.cppsrc/wallet/receive.cppsrc/wallet/rpc/backup.cppsrc/wallet/rpc/coins.cppsrc/wallet/rpc/spend.cppsrc/wallet/rpc/transactions.cppsrc/wallet/rpc/wallet.cppsrc/wallet/scriptpubkeyman.cppsrc/wallet/spend.cppsrc/wallet/test/util.cppsrc/wallet/test/wallet_tests.cppsrc/wallet/wallet.cppsrc/wallet/walletdb.cppInspect captured patch +163 / −163
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 5cd1d41f..f1529375 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -457,7 +457,7 @@ void AddrManImpl::Delete(nid_type nId)
{
AssertLockHeld(cs);
- assert(mapInfo.count(nId) != 0);
+ assert(mapInfo.contains(nId));
AddrInfo& info = mapInfo[nId];
assert(!info.fInTried);
assert(info.nRefCount == 0);
@@ -1115,7 +1115,7 @@ int AddrManImpl::CheckAddrman() const
for (int n = 0; n < ADDRMAN_TRIED_BUCKET_COUNT; n++) {
for (int i = 0; i < ADDRMAN_BUCKET_SIZE; i++) {
if (vvTried[n][i] != -1) {
- if (!setTried.count(vvTried[n][i]))
+ if (!setTried.contains(vvTried[n][i]))
return -11;
const auto it{mapInfo.find(vvTried[n][i])};
if (it == mapInfo.end() || it->second.GetTriedBucket(nKey, m_netgroupman) != n) {
@@ -1132,7 +1132,7 @@ int AddrManImpl::CheckAddrman() const
for (int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) {
for (int i = 0; i < ADDRMAN_BUCKET_SIZE; i++) {
if (vvNew[n][i] != -1) {
- if (!mapNew.count(vvNew[n][i]))
+ if (!mapNew.contains(vvNew[n][i]))
return -12;
const auto it{mapInfo.find(vvNew[n][i])};
if (it == mapInfo.end() || it->second.GetBucketPosition(nKey, true, n) != i) {
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
index 937db68e..f26da247 100644
--- a/src/bitcoin-tx.cpp
+++ b/src/bitcoin-tx.cpp
@@ -588,7 +588,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
CCoinsView viewDummy;
CCoinsViewCache view(&viewDummy);
- if (!registers.count("privatekeys"))
+ if (!registers.contains("privatekeys"))
throw std::runtime_error("privatekeys register variable must be set.");
FillableSigningProvider tempKeystore;
UniValue keysObj = registers["privatekeys"];
@@ -604,7 +604,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
}
// Add previous txouts given in the RPC call:
- if (!registers.count("prevtxs"))
+ if (!registers.contains("prevtxs"))
throw std::runtime_error("prevtxs register variable must be set.");
UniValue prevtxsObj = registers["prevtxs"];
{
diff --git a/src/common/args.cpp b/src/common/args.cpp
index f7d4652a..16ef7657 100644
--- a/src/common/args.cpp
+++ b/src/common/args.cpp
@@ -832,7 +832,7 @@ std::variant<ChainType, std::string> ArgsManager::GetChainArg() const
bool ArgsManager::UseDefaultSection(const std::string& arg) const
{
- return m_network == ChainTypeToString(ChainType::MAIN) || m_network_only_args.count(arg) == 0;
+ return m_network == ChainTypeToString(ChainType::MAIN) || !m_network_only_args.contains(arg);
}
common::SettingsValue ArgsManager::GetSetting(const std::string& arg) const
diff --git a/src/httprpc.cpp b/src/httprpc.cpp
index 1766d1a1..639b437d 100644
--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -142,7 +142,7 @@ static bool HTTPReq_JSONRPC(const std::any& context, HTTPRequest* req)
jreq.URI = req->GetURI();
UniValue reply;
- bool user_has_whitelist = g_rpc_whitelist.count(jreq.authUser);
+ bool user_has_whitelist = g_rpc_whitelist.contains(jreq.authUser);
if (!user_has_whitelist && g_rpc_whitelist_default) {
LogWarning("RPC User %s not allowed to call any methods", jreq.authUser);
req->WriteReply(HTTP_FORBIDDEN);
@@ -151,7 +151,7 @@ static bool HTTPReq_JSONRPC(const std::any& context, HTTPRequest* req)
// singleton request
} else if (valRequest.isObject()) {
jreq.parse(valRequest);
- if (user_has_whitelist && !g_rpc_whitelist[jreq.authUser].count(jreq.strMethod)) {
+ if (user_has_whitelist && !g_rpc_whitelist[jreq.authUser].contains(jreq.strMethod)) {
LogWarning("RPC User %s not allowed to call method %s", jreq.authUser, jreq.strMethod);
req->WriteReply(HTTP_FORBIDDEN);
return false;
@@ -181,7 +181,7 @@ static bool HTTPReq_JSONRPC(const std::any& context, HTTPRequest* req)
const UniValue& request = valRequest[reqIdx].get_obj();
// Parse method
std::string strMethod = request.find_value("method").get_str();
- if (!g_rpc_whitelist[jreq.authUser].count(strMethod)) {
+ if (!g_rpc_whitelist[jreq.authUser].contains(strMethod)) {
LogWarning("RPC User %s not allowed to call method %s", jreq.authUser, strMethod);
req->WriteReply(HTTP_FORBIDDEN);
return false;
@@ -307,7 +307,7 @@ static bool InitRPCAuthentication()
for (const std::string& strRPCWhitelist : gArgs.GetArgs("-rpcwhitelist")) {
auto pos = strRPCWhitelist.find(':');
std::string strUser = strRPCWhitelist.substr(0, pos);
- bool intersect = g_rpc_whitelist.count(strUser);
+ bool intersect = g_rpc_whitelist.contains(strUser);
std::set<std::string>& whitelist = g_rpc_whitelist[strUser];
if (pos != std::string::npos) {
std::string strWhitelist = strRPCWhitelist.substr(pos + 1);
diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp
index 34ff06e5..927629a5 100644
--- a/src/merkleblock.cpp
+++ b/src/merkleblock.cpp
@@ -40,7 +40,7 @@ CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std:
for (unsigned int i = 0; i < block.vtx.size(); i++)
{
const Txid& hash{block.vtx[i]->GetHash()};
- if (txids && txids->count(hash)) {
+ if (txids && txids->contains(hash)) {
vMatch.push_back(true);
} else if (filter && filter->IsRelevantAndUpdate(*block.vtx[i])) {
vMatch.push_back(true);
diff --git a/src/net.cpp b/src/net.cpp
index d335f2dc..ece6810f 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -329,7 +329,7 @@ bool SeenLocal(const CService& addr)
bool IsLocal(const CService& addr)
{
LOCK(g_maplocalhost_mutex);
- return mapLocalHost.count(addr) > 0;
+ return mapLocalHost.contains(addr);
}
bool CConnman::AlreadyConnectedToHost(std::string_view host) const
@@ -2628,7 +2628,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
// (e.g. in case of -onlynet changes by the user), fixed seeds will
// be loaded only for networks for which we have no addresses.
seed_addrs.erase(std::remove_if(seed_addrs.begin(), seed_addrs.end(),
- [&fixed_seed_networks](const CAddress& addr) { return fixed_seed_networks.count(addr.GetNetwork()) == 0; }),
+ [&fixed_seed_networks](const CAddress& addr) { return !fixed_seed_networks.contains(addr.GetNetwork()); }),
seed_addrs.end());
CNetAddr local;
local.SetInternal("fixedseeds");
@@ -2775,7 +2775,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
m_anchors.pop_back();
if (!addr.IsValid() || IsLocal(addr) || !g_reachable_nets.Contains(addr) ||
!m_msgproc->HasAllDesirableServiceFlags(addr.nServices) ||
- outbound_ipv46_peer_netgroups.count(m_netgroupman.GetGroup(addr))) continue;
+ outbound_ipv46_peer_netgroups.contains(m_netgroupman.GetGroup(addr))) continue;
addrConnect = addr;
LogDebug(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToStringAddrPort());
break;
@@ -2821,7 +2821,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
}
// Require outbound IPv4/IPv6 connections, other than feelers, to be to distinct network groups
- if (!fFeeler && outbound_ipv46_peer_netgroups.count(m_netgroupman.GetGroup(addr))) {
+ if (!fFeeler && outbound_ipv46_peer_netgroups.contains(m_netgroupman.GetGroup(addr))) {
continue;
}
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 9cab2461..119b17c8 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1158,7 +1158,7 @@ std::chrono::microseconds PeerManagerImpl::NextInvToInbounds(std::chrono::micros
bool PeerManagerImpl::IsBlockRequested(const uint256& hash)
{
- return mapBlocksInFlight.count(hash);
+ return mapBlocksInFlight.contains(hash);
}
bool PeerManagerImpl::IsBlockRequestedFromOutbound(const uint256& hash)
diff --git a/src/netbase.h b/src/netbase.h
index 41b3ca8f..d3c263f9 100644
--- a/src/netbase.h
+++ b/src/netbase.h
@@ -132,7 +132,7 @@ public:
{
AssertLockNotHeld(m_mutex);
LOCK(m_mutex);
- return m_reachable.count(net) > 0;
+ return m_reachable.contains(net);
}
[[nodiscard]] bool Contains(const CNetAddr& addr) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
diff --git a/src/node/mini_miner.cpp b/src/node/mini_miner.cpp
index a2503c58..7a25f9f4 100644
--- a/src/node/mini_miner.cpp
+++ b/src/node/mini_miner.cpp
@@ -73,7 +73,7 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou
// Add every entry to m_entries_by_txid and m_entries, except the ones that will be replaced.
for (const auto& txiter : cluster) {
- if (!m_to_be_replaced.count(txiter->GetTx().GetHash())) {
+ if (!m_to_be_replaced.contains(txiter->GetTx().GetHash())) {
auto [ancestor_count, ancestor_size, ancestor_fee] = mempool.CalculateAncestorData(*txiter);
auto [mapiter, success] = m_entries_by_txid.emplace(txiter->GetTx().GetHash(),
MiniMinerMempoolEntry{/*tx_in=*/txiter->GetSharedTx(),
@@ -101,13 +101,13 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou
// Cache descendants for future use. Unlike the real mempool, a descendant MiniMinerMempoolEntry
// will not exist without its ancestor MiniMinerMempoolEntry, so these sets won't be invalidated.
std::vector<MockEntryMap::iterator> cached_descendants;
- const bool remove{m_to_be_replaced.count(txid) > 0};
+ const bool remove{m_to_be_replaced.contains(txid)};
CTxMemPool::setEntries descendants;
mempool.CalculateDescendants(txiter, descendants);
- Assume(descendants.count(txiter) > 0);
+ Assume(descendants.contains(txiter));
for (const auto& desc_txiter : descendants) {
const auto txid_desc = desc_txiter->GetTx().GetHash();
- const bool remove_desc{m_to_be_replaced.count(txid_desc) > 0};
+ const bool remove_desc{m_to_be_replaced.contains(txid_desc)};
auto desc_it{m_entries_by_txid.find(txid_desc)};
Assume((desc_it == m_entries_by_txid.end()) == remove_desc);
if (remove) Assume(remove_desc);
@@ -136,7 +136,7 @@ MiniMiner::MiniMiner(const std::vector<MiniMinerMempoolEntry>& manual_entries,
for (const auto& entry : manual_entries) {
const auto& txid = entry.GetTx().GetHash();
// We need to know the descendant set of every transaction.
- if (!Assume(descendant_caches.count(txid) > 0)) {
+ if (!Assume(descendant_caches.contains(txid))) {
m_ready_to_calculate = false;
return;
}
@@ -201,7 +201,7 @@ void MiniMiner::DeleteAncestorPackage(const std::set<MockEntryMap::iterator, Ite
Assume(ancestors.size() >= 1);
// "Mine" all transactions in this ancestor set.
for (auto& anc : ancestors) {
- Assume(m_in_block.count(anc->first) == 0);
+ Assume(!m_in_block.contains(anc->first));
m_in_block.insert(anc->first);
m_total_fees += anc->second.GetModifiedFee();
m_total_vsize += anc->second.GetTxSize();
@@ -274,7 +274,7 @@ void MiniMiner::BuildMockTemplate(std::optional<CFeeRate> target_feerate)
ancestors.insert(*iter);
for (const auto& input : (*iter)->second.GetTx().vin) {
if (auto parent_it{m_entries_by_txid.find(input.prevout.hash)}; parent_it != m_entries_by_txid.end()) {
- if (ancestors.count(parent_it) == 0) {
+ if (!ancestors.contains(parent_it)) {
to_process.insert(parent_it);
}
}
@@ -400,7 +400,7 @@ std::optional<CAmount> MiniMiner::CalculateTotalBumpFees(const CFeeRate& target_
for (const auto& [txid, outpoints] : m_requested_outpoints_by_txid) {
// Skip any ancestors that already have a miner score higher than the target feerate
// (already "made it" into the block)
- if (m_in_block.count(txid)) continue;
+ if (m_in_block.contains(txid)) continue;
auto iter = m_entries_by_txid.find(txid);
if (iter == m_entries_by_txid.end()) continue;
to_process.insert(iter);
@@ -413,7 +413,7 @@ std::optional<CAmount> MiniMiner::CalculateTotalBumpFees(const CFeeRate& target_
const CTransaction& tx = (*iter)->second.GetTx();
for (const auto& input : tx.vin) {
if (auto parent_it{m_entries_by_txid.find(input.prevout.hash)}; parent_it != m_entries_by_txid.end()) {
- if (!has_been_processed.count(input.prevout.hash)) {
+ if (!has_been_processed.contains(input.prevout.hash)) {
to_process.insert(parent_it);
}
ancestors.insert(parent_it);
diff --git a/src/policy/fees/block_policy_estimator.cpp b/src/policy/fees/block_policy_estimator.cpp
index 723cb88f..80b4f641 100644
--- a/src/policy/fees/block_policy_estimator.cpp
+++ b/src/policy/fees/block_policy_estimator.cpp
@@ -598,7 +598,7 @@ void CBlockPolicyEstimator::processTransaction(const NewMempoolTransactionInfo&
LOCK(m_cs_fee_estimator);
const unsigned int txHeight = tx.info.txHeight;
const auto& hash = tx.info.m_tx->GetHash();
- if (mapMemPoolTxs.count(hash)) {
+ if (mapMemPoolTxs.contains(hash)) {
LogDebug(BCLog::ESTIMATEFEE, "Blockpolicy error mempool tx %s already being tracked\n",
hash.ToString());
return;
diff --git a/src/policy/packages.cpp b/src/policy/packages.cpp
index 0f04b4cf..b031ba3f 100644
--- a/src/policy/packages.cpp
+++ b/src/policy/packages.cpp
@@ -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)
@@ -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;
});
diff --git a/src/policy/rbf.cpp b/src/policy/rbf.cpp
index c78fed8e..265b06b9 100644
--- a/src/policy/rbf.cpp
+++ b/src/policy/rbf.cpp
@@ -88,7 +88,7 @@ std::optional<std::string> EntriesAndTxidsDisjoint(const CTxMemPool::setEntries&
{
for (CTxMemPool::txiter ancestorIt : ancestors) {
const Txid& hashAncestor = ancestorIt->GetTx().GetHash();
- if (direct_conflicts.count(hashAncestor)) {
+ if (direct_conflicts.contains(hashAncestor)) {
return strprintf("%s spends conflicting transaction %s",
txid.ToString(),
hashAncestor.ToString());
diff --git a/src/policy/truc_policy.cpp b/src/policy/truc_policy.cpp
index bc5142c7..aed24038 100644
--- a/src/policy/truc_policy.cpp
+++ b/src/policy/truc_policy.cpp
@@ -30,7 +30,7 @@ std::vector<size_t> FindInPackageParents(const Package& package, const CTransact
// We assume the package is sorted, so that we don't need to continue
// looking past the transaction itself.
if (&(*tx) == &(*ptx)) break;
- if (possible_parents.count(tx->GetHash())) {
+ if (possible_parents.contains(tx->GetHash())) {
in_package_parents.push_back(i);
}
}
@@ -240,7 +240,7 @@ std::optional<std::pair<std::string, CTransactionRef>> SingleTRUCChecks(const CT
// TRUC transaction can only have 1 descendant.
const bool child_will_be_replaced = !descendants.empty() &&
std::any_of(descendants.cbegin(), descendants.cend(),
- [&direct_conflicts](const CTxMemPool::txiter& child){return direct_conflicts.count(child->GetTx().GetHash()) > 0;});
+ [&direct_conflicts](const CTxMemPool::txiter& child){return direct_conflicts.contains(child->GetTx().GetHash());});
if (pool.GetDescendantCount(parent_entry) + 1 > TRUC_DESCENDANT_LIMIT && !child_will_be_replaced) {
// Allow sibling eviction for TRUC transaction: if another child already exists, even if
// we don't conflict inputs with it, consider evicting it under RBF rules. We rely on TRUC rules
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 92ddcba6..9e99ca5e 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -38,7 +38,7 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
outputs[i].Merge(psbt.outputs[i]);
}
for (auto& xpub_pair : psbt.m_xpubs) {
- if (m_xpubs.count(xpub_pair.first) == 0) {
+ if (!m_xpubs.contains(xpub_pair.first)) {
m_xpubs[xpub_pair.first] = xpub_pair.second;
} else {
m_xpubs[xpub_pair.first].insert(xpub_pair.second.begin(), xpub_pair.second.end());
diff --git a/src/psbt.h b/src/psbt.h
index 2e7fe964..d8a4a52d 100644
--- a/src/psbt.h
+++ b/src/psbt.h
@@ -158,7 +158,7 @@ void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std
if (!pubkey.IsFullyValid()) {
throw std::ios_base::failure("Invalid pubkey");
}
- if (hd_keypaths.count(pubkey) > 0) {
+ if (hd_keypaths.contains(pubkey)) {
throw std::ios_base::failure("Duplicate Key, pubkey derivation path already provided");
}
@@ -518,7 +518,7 @@ struct PSBTInput
if (!pubkey.IsFullyValid()) {
throw std::ios_base::failure("Invalid pubkey");
}
- if (partial_sigs.count(pubkey.GetID()) > 0) {
+ if (partial_sigs.contains(pubkey.GetID())) {
throw std::ios_base::failure("Duplicate Key, input partial signature for pubkey already provided");
}
@@ -599,7 +599,7 @@ struct PSBTInput
// Read in the hash from key
std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
uint160 hash(hash_vec);
- if (ripemd160_preimages.count(hash) > 0) {
+ if (ripemd160_preimages.contains(hash)) {
throw std::ios_base::failure("Duplicate Key, input ripemd160 preimage already provided");
}
@@ -620,7 +620,7 @@ struct PSBTInput
// Read in the hash from key
std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
uint256 hash(hash_vec);
- if (sha256_preimages.count(hash) > 0) {
+ if (sha256_preimages.contains(hash)) {
throw std::ios_base::failure("Duplicate Key, input sha256 preimage already provided");
}
@@ -641,7 +641,7 @@ struct PSBTInput
// Read in the hash from key
std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
uint160 hash(hash_vec);
- if (hash160_preimages.count(hash) > 0) {
+ if (hash160_preimages.contains(hash)) {
throw std::ios_base::failure("Duplicate Key, input hash160 preimage already provided");
}
@@ -662,7 +662,7 @@ struct PSBTInput
// Read in the hash from key
std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
uint256 hash(hash_vec);
- if (hash256_preimages.count(hash) > 0) {
+ if (hash256_preimages.contains(hash)) {
throw std::ios_base::failure("Duplicate Key, input hash256 preimage already provided");
}
@@ -828,7 +828,7 @@ struct PSBTInput
this_prop.subtype = ReadCompactSize(skey);
this_prop.key = key;
- if (m_proprietary.count(this_prop) > 0) {
+ if (m_proprietary.contains(this_prop)) {
throw std::ios_base::failure("Duplicate Key, proprietary key already found");
}
s >> this_prop.value;
@@ -837,7 +837,7 @@ struct PSBTInput
}
// Unknown stuff
default:
- if (unknown.count(key) > 0) {
+ if (unknown.contains(key)) {
throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
}
// Read in the value
@@ -1088,7 +1088,7 @@ struct PSBTOutput
this_prop.subtype = ReadCompactSize(skey);
this_prop.key = key;
- if (m_proprietary.count(this_prop) > 0) {
+ if (m_proprietary.contains(this_prop)) {
throw std::ios_base::failure("Duplicate Key, proprietary key already found");
}
s >> this_prop.value;
@@ -1097,7 +1097,7 @@ struct PSBTOutput
}
// Unknown stuff
default: {
- if (unknown.count(key) > 0) {
+ if (unknown.contains(key)) {
throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
}
// Read in the value
@@ -1276,7 +1276,7 @@ struct PartiallySignedTransaction
if (!xpub.pubkey.IsFullyValid()) {
throw std::ios_base::failure("Invalid pubkey");
}
- if (global_xpubs.count(xpub) > 0) {
+ if (global_xpubs.contains(xpub)) {
throw std::ios_base::failure("Duplicate key, global xpub already provided");
}
global_xpubs.insert(xpub);
@@ -1286,7 +1286,7 @@ struct PartiallySignedTransaction
// Note that we store these swapped to make searches faster.
// Serialization uses xpub -> keypath to enqure key uniqueness
- if (m_xpubs.count(keypath) == 0) {
+ if (!m_xpubs.contains(keypath)) {
// Make a new set to put the xpub in
m_xpubs[keypath] = {xpub};
} else {
@@ -1317,7 +1317,7 @@ struct PartiallySignedTransaction
this_prop.subtype = ReadCompactSize(skey);
this_prop.key = key;
- if (m_proprietary.count(this_prop) > 0) {
+ if (m_proprietary.contains(this_prop)) {
throw std::ios_base::failure("Duplicate Key, proprietary key already found");
}
s >> this_prop.value;
@@ -1326,7 +1326,7 @@ struct PartiallySignedTransaction
}
// Unknown stuff
default: {
- if (unknown.count(key) > 0) {
+ if (unknown.contains(key)) {
throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
}
// Read in the value
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index ff8cb119..072eab76 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -1900,7 +1900,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
@@ -1991,12 +1991,12 @@ static RPCHelpMan getblockstats()
const CBlockUndo& blockUndo = GetUndoChecked(chainman.m_blockman, pindex);
const bool do_all = stats.size() == 0; // Calculate everything if nothing selected (default)
- const bool do_mediantxsize = do_all || stats.count("mediantxsize") != 0;
- const bool do_medianfee = do_all || stats.count("medianfee") != 0;
- const bool do_feerate_percentiles = do_all || stats.count("feerate_percentiles") != 0;
+ const bool do_mediantxsize = do_all || stats.contains("mediantxsize");
+ const bool do_medianfee = do_all || stats.contains("medianfee");
+ const bool do_feerate_percentiles = do_all || stats.contains("feerate_percentiles");
const bool loop_inputs = do_all || do_medianfee || do_feerate_percentiles ||
SetHasKeys(stats, "utxo_increase", "utxo_increase_actual", "utxo_size_inc", "utxo_size_inc_actual", "totalfee", "avgfee", "avgfeerate", "minfee", "maxfee", "minfeerate", "maxfeerate");
- const bool loop_outputs = do_all || loop_inputs || stats.count("total_out");
+ const bool loop_outputs = do_all || loop_inputs || stats.contains("total_out");
const bool do_calculate_size = do_mediantxsize ||
SetHasKeys(stats, "total_size", "avgtxsize", "mintxsize", "maxtxsize", "swtotal_size");
const bool do_calculate_weight = do_all || SetHasKeys(stats, "total_weight", "avgfeerate", "swtotal_weight", "avgfeerate", "feerate_percentiles", "minfeerate", "maxfeerate");
@@ -2189,7 +2189,7 @@ bool FindScriptPubKey(std::atomic<int>& scan_progress, const std::atomic<bool>&
uint32_t high = 0x100 * *UCharCast(key.hash.begin()) + *(UCharCast(key.hash.begin()) + 1);
scan_progress = (int)(high * 100.0 / 65536.0 + 0.5);
}
- if (needles.count(coin.out.scriptPubKey)) {
+ if (needles.contains(coin.out.scriptPubKey)) {
out_results.emplace(key, coin);
}
cursor->Next();
@@ -2464,7 +2464,7 @@ static bool CheckBlockFilterMatches(BlockManager& blockman, const CBlockIndex& b
// Check if any of the outputs match the scriptPubKey
for (const auto& tx : block.vtx) {
if (std::any_of(tx->vout.cbegin(), tx->vout.cend(), [&](const auto& txout) {
- return needles.count(std::vector<unsigned char>(txout.scriptPubKey.begin(), txout.scriptPubKey.end())) != 0;
+ return needles.contains(std::vector<unsigned char>(txout.scriptPubKey.begin(), txout.scriptPubKey.end()));
})) {
return true;
}
@@ -2472,7 +2472,7 @@ static bool CheckBlockFilterMatches(BlockManager& blockman, const CBlockIndex& b
// Check if any of the inputs match the scriptPubKey
for (const auto& txundo : block_undo.vtxundo) {
if (std::any_of(txundo.vprevout.cbegin(), txundo.vprevout.cend(), [&](const auto& coin) {
- return needles.count(std::vector<unsigned char>(coin.out.scriptPubKey.begin(), coin.out.scriptPubKey.end())) != 0;
+ return needles.contains(std::vector<unsigned char>(coin.out.scriptPubKey.begin(), coin.out.scriptPubKey.end()));
})) {
return true;
}
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index 2639b916..e710f590 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -913,7 +913,7 @@ static RPCHelpMan getblocktemplate()
UniValue deps(UniValue::VARR);
for (const CTxIn &in : tx.vin)
{
- if (setTxIndex.count(in.prevout.hash))
+ if (setTxIndex.contains(in.prevout.hash))
deps.push_back(setTxIndex[in.prevout.hash]);
}
entry.pushKV("depends", std::move(deps));
@@ -957,7 +957,7 @@ static RPCHelpMan getblocktemplate()
for (const auto& [name, info] : gbtstatus.signalling) {
vbavailable.pushKV(gbt_rule_value(name, info.gbt_optional_rule), info.bit);
- if (!info.gbt_optional_rule && !setClientRules.count(name)) {
+ if (!info.gbt_optional_rule && !setClientRules.contains(name)) {
// If the client doesn't support this, don't indicate it in the [default] version
block.nVersion &= ~info.mask;
}
@@ -966,7 +966,7 @@ static RPCHelpMan getblocktemplate()
for (const auto& [name, info] : gbtstatus.locked_in) {
block.nVersion |= info.mask;
vbavailable.pushKV(gbt_rule_value(name, info.gbt_optional_rule), info.bit);
- if (!info.gbt_optional_rule && !setClientRules.count(name)) {
+ if (!info.gbt_optional_rule && !setClientRules.contains(name)) {
// If the client doesn't support this, don't indicate it in the [default] version
block.nVersion &= ~info.mask;
}
@@ -974,7 +974,7 @@ static RPCHelpMan getblocktemplate()
for (const auto& [name, info] : gbtstatus.active) {
aRules.push_back(gbt_rule_value(name, info.gbt_optional_rule));
- if (!info.gbt_optional_rule && !setClientRules.count(name)) {
+ if (!info.gbt_optional_rule && !setClientRules.contains(name)) {
// Not supported by the client; make sure it's safe to proceed
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Support for '%s' rule requires explicit client support", name));
}
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 2baeb679..a01782e0 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -1841,7 +1841,7 @@ static RPCHelpMan joinpsbts()
merged_psbt.AddOutput(psbt.tx->vout[i], psbt.outputs[i]);
}
for (auto& xpub_pair : psbt.m_xpubs) {
- if (merged_psbt.m_xpubs.count(xpub_pair.first) == 0) {
+ if (!merged_psbt.m_xpubs.contains(xpub_pair.first)) {
merged_psbt.m_xpubs[xpub_pair.first] = xpub_pair.second;
} else {
merged_psbt.m_xpubs[xpub_pair.first].insert(xpub_pair.second.begin(), xpub_pair.second.end());
diff --git a/src/rpc/txoutproof.cpp b/src/rpc/txoutproof.cpp
index 24cb8599..4749be1a 100644
--- a/src/rpc/txoutproof.cpp
+++ b/src/rpc/txoutproof.cpp
@@ -109,7 +109,7 @@ static RPCHelpMan gettxoutproof()
unsigned int ntxFound = 0;
for (const auto& tx : block.vtx) {
- if (setTxids.count(tx->GetHash())) {
+ if (setTxids.contains(tx->GetHash())) {
ntxFound++;
}
}
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index e9c97ba0..49569c7b 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -71,7 +71,7 @@ void RPCTypeCheckObj(const UniValue& o,
{
for (const std::string& k : o.getKeys())
{
- if (typesExpected.count(k) == 0)
+ if (!typesExpected.contains(k))
{
std::string err = strprintf("Unexpected key %s", k);
throw JSONRPCError(RPC_TYPE_ERROR, err);
diff --git a/src/script/sign.cpp b/src/script/sign.cpp
index 8103e318..17e60f48 100644
--- a/src/script/sign.cpp
+++ b/src/script/sign.cpp
@@ -890,7 +890,7 @@ SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nI
for (unsigned int i = last_success_key; i < num_pubkeys; ++i) {
const valtype& pubkey = solutions[i+1];
// We either have a signature for this pubkey, or we have found a signature and it is valid
- if (data.signatures.count(CPubKey(pubkey).GetID()) || extractor_checker.CheckECDSASignature(sig, pubkey, next_script, sigversion)) {
+ if (data.signatures.contains(CPubKey(pubkey).GetID()) || extractor_checker.CheckECDSASignature(sig, pubkey, next_script, sigversion)) {
last_success_key = i + 1;
break;
}
diff --git a/src/script/signingprovider.cpp b/src/script/signingprovider.cpp
index 8557eb77..9717076f 100644
--- a/src/script/signingprovider.cpp
+++ b/src/script/signingprovider.cpp
@@ -196,7 +196,7 @@ bool FillableSigningProvider::AddKeyPubKey(const CKey& key, const CPubKey &pubke
bool FillableSigningProvider::HaveKey(const CKeyID &address) const
{
LOCK(cs_KeyStore);
- return mapKeys.count(address) > 0;
+ return mapKeys.contains(address);
}
std::set<CKeyID> FillableSigningProvider::GetKeys() const
@@ -235,7 +235,7 @@ bool FillableSigningProvider::AddCScript(const CScript& redeemScript)
bool FillableSigningProvider::HaveCScript(const CScriptID& hash) const
{
LOCK(cs_KeyStore);
- return mapScripts.count(hash) > 0;
+ return mapScripts.contains(hash);
}
std::set<CScriptID> FillableSigningProvider::GetCScripts() const
diff --git a/src/sync.cpp b/src/sync.cpp
index d33a01dc..2542cab1 100644
--- a/src/sync.cpp
+++ b/src/sync.cpp
@@ -173,11 +173,11 @@ static void push_lock(MutexType* c, const CLockLocation& locklocation)
}
const LockPair p1 = std::make_pair(i.first, c);
- if (lockdata.lockorders.count(p1))
+ if (lockdata.lockorders.contains(p1))
continue;
const LockPair p2 = std::make_pair(c, i.first);
- if (lockdata.lockorders.count(p2)) {
+ if (lockdata.lockorders.contains(p2)) {
auto lock_stack_copy = lock_stack;
lock_stack.pop_back();
potential_deadlock_detected(p1, lockdata.lockorders[p2], lock_stack_copy);
diff --git a/src/test/argsman_tests.cpp b/src/test/argsman_tests.cpp
index e5953cd5..8d6b1d11 100644
--- a/src/test/argsman_tests.cpp
+++ b/src/test/argsman_tests.cpp
@@ -232,8 +232,8 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
BOOST_CHECK(testArgs.m_settings.command_line_options.size() == 3 && testArgs.m_settings.ro_config.empty());
BOOST_CHECK(testArgs.IsArgSet("-a") && testArgs.IsArgSet("-b") && testArgs.IsArgSet("-ccc")
&& !testArgs.IsArgSet("f") && !testArgs.IsArgSet("-d"));
- BOOST_CHECK(testArgs.m_settings.command_line_options.count("a") && testArgs.m_settings.command_line_options.count("b") && testArgs.m_settings.command_line_options.count("ccc")
- && !testArgs.m_settings.command_line_options.count("f") && !testArgs.m_settings.command_line_options.count("d"));
+ BOOST_CHECK(testArgs.m_settings.command_line_options.contains("a") && testArgs.m_settings.command_line_options.contains("b") && testArgs.m_settings.command_line_options.contains("ccc")
+ && !testArgs.m_settings.command_line_options.contains("f") && !testArgs.m_settings.command_line_options.contains("d"));
BOOST_CHECK(testArgs.m_settings.command_line_options["a"].size() == 1);
BOOST_CHECK(testArgs.m_settings.command_line_options["a"].front().get_str() == "");
@@ -460,18 +460,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"));
diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp
index a1152d24..4513ab8b 100644
--- a/src/test/coins_tests.cpp
+++ b/src/test/coins_tests.cpp
@@ -386,15 +386,15 @@ BOOST_FIXTURE_TEST_CASE(updatecoins_simulation_test, UpdateTest)
auto utxod = FindRandomFrom(disconnected_coins);
tx = CMutableTransaction{std::get<0>(utxod->second)};
prevout = tx.vin[0].prevout;
- if (!CTransaction(tx).IsCoinBase() && !utxoset.count(prevout)) {
+ if (!CTransaction(tx).IsCoinBase() && !utxoset.contains(prevout)) {
disconnected_coins.erase(utxod->first);
continue;
}
// If this tx is already IN the UTXO, then it must be a coinbase, and it must be a duplicate
- if (utxoset.count(utxod->first)) {
+ if (utxoset.contains(utxod->first)) {
assert(CTransaction(tx).IsCoinBase());
- assert(duplicate_coins.count(utxod->first));
+ assert(duplicate_coins.contains(utxod->first));
}
disconnected_coins.erase(utxod->first);
}
@@ -417,7 +417,7 @@ BOOST_FIXTURE_TEST_CASE(updatecoins_simulation_test, UpdateTest)
// The test is designed to ensure spending a duplicate coinbase will work properly
// if that ever happens and not resurrect the previously overwritten coinbase
- if (duplicate_coins.count(prevout)) {
+ if (duplicate_coins.contains(prevout)) {
spent_a_duplicate_coinbase = true;
}
diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp
index 97f416dd..82e010bf 100644
--- a/src/test/descriptor_tests.cpp
+++ b/src/test/descriptor_tests.cpp
@@ -456,7 +456,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);
}
}
diff --git a/src/test/fuzz/coinscache_sim.cpp b/src/test/fuzz/coinscache_sim.cpp
index 30845c2e..01ec150d 100644
--- a/src/test/fuzz/coinscache_sim.cpp
+++ b/src/test/fuzz/coinscache_sim.cpp
@@ -155,7 +155,7 @@ public:
bool HaveCoin(const COutPoint& outpoint) const final
{
- return m_data.count(outpoint);
+ return m_data.contains(outpoint);
}
uint256 GetBestBlock() const final { return {}; }
diff --git a/src/test/fuzz/miniscript.cpp b/src/test/fuzz/miniscript.cpp
index 42195313..5d9a39bb 100644
--- a/src/test/fuzz/miniscript.cpp
+++ b/src/test/fuzz/miniscript.cpp
@@ -687,7 +687,7 @@ struct SmartInfo
while (true) {
size_t set_size = useful_types.size();
for (const auto& [type, recipes] : table) {
- if (useful_types.count(type) != 0) {
+ if (useful_types.contains(type)) {
for (const auto& [_, subtypes] : recipes) {
for (auto subtype : subtypes) useful_types.insert(subtype);
}
@@ -697,7 +697,7 @@ struct SmartInfo
}
// Remove all rules that construct uninteresting types.
for (auto type_it = table.begin(); type_it != table.end();) {
- if (useful_types.count(type_it->first) == 0) {
+ if (!useful_types.contains(type_it->first)) {
type_it = table.erase(type_it);
} else {
++type_it;
@@ -710,7 +710,7 @@ struct SmartInfo
* because they can only be constructed using recipes that involve otherwise
* non-constructible types, or because they require infinite recursion. */
std::set<Type> constructible_types{};
- auto known_constructible = [&](Type type) { return constructible_types.count(type) != 0; };
+ auto known_constructible = [&](Type type) { return constructible_types.contains(type); };
// Find the transitive closure by adding types until the set of types does not change.
while (true) {
size_t set_size = constructible_types.size();
@@ -1177,13 +1177,13 @@ void TestNode(const MsCtx script_ctx, const NodeRef& node, FuzzedDataProvider& p
case Fragment::AFTER:
return node.k & 1;
case Fragment::SHA256:
- return TEST_DATA.sha256_preimages.count(node.data);
+ return TEST_DATA.sha256_preimages.contains(node.data);
case Fragment::HASH256:
- return TEST_DATA.hash256_preimages.count(node.data);
+ return TEST_DATA.hash256_preimages.contains(node.data);
case Fragment::RIPEMD160:
- return TEST_DATA.ripemd160_preimages.count(node.data);
+ return TEST_DATA.ripemd160_preimages.contains(node.data);
case Fragment::HASH160:
- return TEST_DATA.hash160_preimages.count(node.data);
+ return TEST_DATA.hash160_preimages.contains(node.data);
default:
assert(false);
}
diff --git a/src/test/fuzz/partially_downloaded_block.cpp b/src/test/fuzz/partially_downloaded_block.cpp
index 41e7c906..0bbe9991 100644
--- a/src/test/fuzz/partially_downloaded_block.cpp
+++ b/src/test/fuzz/partially_downloaded_block.cpp
@@ -95,12 +95,12 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb)
for (size_t i = 0; i < cmpctblock.BlockTxCount(); i++) {
// If init_status == READ_STATUS_OK then a available transaction in the
// compact block (i.e. IsTxAvailable(i) == true) implies that we marked
- // that transaction as available above (i.e. available.count(i) > 0).
+ // that transaction as available above (i.e. available.contains(i)).
// The reverse is not true, due to possible compact block short id
- // collisions (i.e. available.count(i) > 0 does not imply
+ // collisions (i.e. available.contains(i) does not imply
// IsTxAvailable(i) == true).
if (init_status == READ_STATUS_OK) {
- assert(!pdb.IsTxAvailable(i) || available.count(i) > 0);
+ assert(!pdb.IsTxAvailable(i) || available.contains(i));
}
bool skip{fuzzed_data_provider.ConsumeBool()};
diff --git a/src/test/fuzz/txorphan.cpp b/src/test/fuzz/txorphan.cpp
index b6a6d855..f6720ffb 100644
--- a/src/test/fuzz/txorphan.cpp
+++ b/src/test/fuzz/txorphan.cpp
@@ -339,7 +339,7 @@ FUZZ_TARGET(txorphan_protected, .init = initialize_orphanage)
}
},
[&] { // EraseTx
- if (protected_wtxids.count(tx->GetWitnessHash())) {
+ if (protected_wtxids.contains(tx->GetWitnessHash())) {
protected_wtxids.erase(wtxid);
}
orphanage->EraseTx(wtxid);
@@ -616,7 +616,7 @@ FUZZ_TARGET(txorphanage_sim)
real->EraseForBlock(block);
std::erase_if(sim_announcements, [&](auto& ann) {
for (auto& txin : txn[ann.tx]->vin) {
- if (spent.count(txin.prevout)) return true;
+ if (spent.contains(txin.prevout)) return true;
}
return false;
});
diff --git a/src/test/miniminer_tests.cpp b/src/test/miniminer_tests.cpp
index 95b83dfa..f019ec3b 100644
--- a/src/test/miniminer_tests.cpp
+++ b/src/test/miniminer_tests.cpp
@@ -103,7 +103,7 @@ BOOST_FIXTURE_TEST_CASE(miniminer_negative, TestChain100Setup)
mini_miner_no_target.BuildMockTemplate(std::nullopt);
const auto template_txids{mini_miner_no_target.GetMockTemplateTxids()};
BOOST_CHECK_EQUAL(template_txids.size(), 1);
- BOOST_CHECK(template_txids.count(tx_mod_negative->GetHash()) > 0);
+ BOOST_CHECK(template_txids.contains(tx_mod_negative->GetHash()));
}
BOOST_FIXTURE_TEST_CASE(miniminer_1p1c, TestChain100Setup)
diff --git a/src/test/miniscript_tests.cpp b/src/test/miniscript_tests.cpp
index 4d31968c..70563d51 100644
--- a/src/test/miniscript_tests.cpp
+++ b/src/test/miniscript_tests.cpp
@@ -207,17 +207,17 @@ struct Satisfier : public KeyConverter {
//! Implement simplified CLTV logic: stack value must exactly match an entry in `supported`.
bool CheckAfter(uint32_t value) const {
- return supported.count(Challenge(ChallengeType::AFTER, value));
+ return supported.contains(Challenge(ChallengeType::AFTER, value));
}
//! Implement simplified CSV logic: stack value must exactly match an entry in `supported`.
bool CheckOlder(uint32_t value) const {
- return supported.count(Challenge(ChallengeType::OLDER, value));
+ return supported.contains(Challenge(ChallengeType::OLDER, value));
}
//! Produce a signature for the given key.
miniscript::Availability Sign(const CPubKey& key, std::vector<unsigned char>& sig) const {
- if (supported.count(Challenge(ChallengeType::PK, ChallengeNumber(key)))) {
+ if (supported.contains(Challenge(ChallengeType::PK, ChallengeNumber(key)))) {
if (!miniscript::IsTapscript(m_script_ctx)) {
auto it = g_testdata->signatures.find(key);
if (it == g_testdata->signatures.end()) return miniscript::Availability::NO;
@@ -234,7 +234,7 @@ struct Satisfier : public KeyConverter {
//! Helper function for the various hash based satisfactions.
miniscript::Availability SatHash(const std::vector<unsigned char>& hash, std::vector<unsigned char>& preimage, ChallengeType chtype) const {
- if (!supported.count(Challenge(chtype, ChallengeNumber(hash)))) return miniscript::Availability::NO;
+ if (!supported.contains(Challenge(chtype, ChallengeNumber(hash)))) return miniscript::Availability::NO;
const auto& m =
chtype == ChallengeType::SHA256 ? g_testdata->sha256_preimages :
chtype == ChallengeType::HASH256 ? g_testdata->hash256_preimages :
diff --git a/src/test/net_peer_eviction_tests.cpp b/src/test/net_peer_eviction_tests.cpp
index d9e1c233..d36958a4 100644
--- a/src/test/net_peer_eviction_tests.cpp
+++ b/src/test/net_peer_eviction_tests.cpp
@@ -40,12 +40,12 @@ bool IsProtected(int num_peers,
size_t unprotected_count{0};
for (const NodeEvictionCandidate& candidate : candidates) {
- if (protected_peer_ids.count(candidate.id)) {
+ if (protected_peer_ids.contains(candidate.id)) {
// this peer should have been removed from the eviction candidates
BOOST_TEST_MESSAGE(strprintf("expected candidate to be protected: %d", candidate.id));
return false;
}
- if (unprotected_peer_ids.count(candidate.id)) {
+ if (unprotected_peer_ids.contains(candidate.id)) {
// this peer remains in the eviction candidates, as expected
++unprotected_count;
}
@@ -577,7 +577,7 @@ bool IsEvicted(std::vector<NodeEvictionCandidate> candidates, const std::unorder
if (!evicted_node_id) {
return false;
}
- return node_ids.count(*evicted_node_id);
+ return node_ids.contains(*evicted_node_id);
}
// Create number_of_nodes random nodes, apply setup function candidate_setup_fn,
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index fc4550bb..8d6d5209 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -891,7 +891,7 @@ BOOST_AUTO_TEST_CASE(script_build)
#ifdef UPDATE_JSON_TESTS
strGen += str + ",\n";
#else
- if (tests_set.count(str) == 0) {
+ if (!tests_set.contains(str)) {
BOOST_CHECK_MESSAGE(false, "Missing auto script_valid test: " + test.GetComment());
}
#endif
diff --git a/src/test/util/txmempool.cpp b/src/test/util/txmempool.cpp
index b158713d..f73e3915 100644
--- a/src/test/util/txmempool.cpp
+++ b/src/test/util/txmempool.cpp
@@ -60,7 +60,7 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,
}
for (const auto& tx : txns) {
const auto& wtxid = tx->GetWitnessHash();
- if (result.m_tx_results.count(wtxid) == 0) {
+ if (!result.m_tx_results.contains(wtxid)) {
return strprintf("result not found for tx %s", wtxid.ToString());
}
diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp
index a95ccf7a..2b2de374 100644
--- a/src/torcontrol.cpp
+++ b/src/torcontrol.cpp
@@ -586,17 +586,17 @@ void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorContro
*/
std::string torpassword = gArgs.GetArg("-torpassword", "");
if (!torpassword.empty()) {
- if (methods.count("HASHEDPASSWORD")) {
+ if (methods.contains("HASHEDPASSWORD")) {
LogDebug(BCLog::TOR, "Using HASHEDPASSWORD authentication\n");
ReplaceAll(torpassword, "\"", "\\\"");
_conn.Command("AUTHENTICATE \"" + torpassword + "\"", std::bind(&TorController::auth_cb, this, std::placeholders::_1, std::placeholders::_2));
} else {
LogWarning("tor: Password provided with -torpassword, but HASHEDPASSWORD authentication is not available");
}
- } else if (methods.count("NULL")) {
+ } else if (methods.contains("NULL")) {
LogDebug(BCLog::TOR, "Using NULL authentication\n");
_conn.Command("AUTHENTICATE", std::bind(&TorController::auth_cb, this, std::placeholders::_1, std::placeholders::_2));
- } else if (methods.count("SAFECOOKIE")) {
+ } else if (methods.contains("SAFECOOKIE")) {
// Cookie: hexdump -e '32/1 "%02x""\n"' ~/.tor/control_auth_cookie
LogDebug(BCLog::TOR, "Using SAFECOOKIE authentication, reading cookie authentication from %s\n", cookiefile);
std::pair<bool,std::string> status_cookie = ReadBinaryFile(fs::PathFromString(cookiefile), TOR_COOKIE_SIZE);
@@ -613,7 +613,7 @@ void TorController::protocolinfo_cb(TorControlConnection& _conn, const TorContro
LogWarning("tor: Authentication cookie %s could not be opened (check permissions)", cookiefile);
}
}
- } else if (methods.count("HASHEDPASSWORD")) {
+ } else if (methods.contains("HASHEDPASSWORD")) {
LogWarning("tor: The only supported authentication mechanism left is password, but no password provided with -torpassword");
} else {
LogWarning("tor: No supported authentication method");
diff --git a/src/txgraph.cpp b/src/txgraph.cpp
index 23094bd8..d623d2ad 100644
--- a/src/txgraph.cpp
+++ b/src/txgraph.cpp
@@ -2917,7 +2917,7 @@ void TxGraphImpl::SanityCheck() const
// Check the sequence number.
assert(cluster.m_sequence < m_next_sequence_counter);
- assert(sequences.count(cluster.m_sequence) == 0);
+ assert(!sequences.contains(cluster.m_sequence));
sequences.insert(cluster.m_sequence);
// Remember we saw this Cluster (only if it is non-empty; empty Clusters aren't
// expected to be referenced by the Entry vector).
diff --git a/src/txmempool.h b/src/txmempool.h
index e8bead51..ea9754dd 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -566,7 +566,7 @@ public:
bool IsUnbroadcastTx(const Txid& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
{
AssertLockHeld(cs);
- return m_unbroadcast_txids.count(txid) != 0;
+ return m_unbroadcast_txids.contains(txid);
}
/** Guards this internal counter for external reporting */
diff --git a/src/util/fs_helpers.cpp b/src/util/fs_helpers.cpp
index b23b2dc2..98646c02 100644
--- a/src/util/fs_helpers.cpp
+++ b/src/util/fs_helpers.cpp
@@ -50,7 +50,7 @@ LockResult LockDirectory(const fs::path& directory, const fs::path& lockfile_nam
fs::path pathLockFile = directory / lockfile_name;
// If a lock for this directory already exists in the map, don't try to re-lock it
- if (dir_locks.count(fs::PathToString(pathLockFile))) {
+ if (dir_locks.contains(fs::PathToString(pathLockFile))) {
return LockResult::Success;
}
diff --git a/src/validation.cpp b/src/validation.cpp
index 73b3e91d..f8de823f 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1747,9 +1747,9 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
for (const auto& tx : package) {
const auto& wtxid = tx->GetWitnessHash();
- if (multi_submission_result.m_tx_results.count(wtxid) > 0) {
+ if (multi_submission_result.m_tx_results.contains(wtxid)) {
// We shouldn't have re-submitted if the tx result was already in results_final.
- Assume(results_final.count(wtxid) == 0);
+ Assume(!results_final.contains(wtxid));
// If it was submitted, check to see if the tx is still in the mempool. It could have
// been evicted due to LimitMempoolSize() above.
const auto& txresult = multi_submission_result.m_tx_results.at(wtxid);
@@ -1765,7 +1765,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
// Already-in-mempool transaction. Check to see if it's still there, as it could have
// been evicted when LimitMempoolSize() was called.
Assume(it->second.m_result_type != MempoolAcceptResult::ResultType::INVALID);
- Assume(individual_results_nonfinal.count(wtxid) == 0);
+ Assume(!individual_results_nonfinal.contains(wtxid));
// Query by txid to include the same-txid-different-witness ones.
if (!m_pool.exists(tx->GetHash())) {
package_state_final.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
@@ -4834,14 +4834,14 @@ bool Chainstate::ReplayBlocks()
const CBlockIndex* pindexNew; // New tip during the interrupted flush.
const CBlockIndex* pindexFork = nullptr; // Latest block common to both the old and the new tip.
- if (m_blockman.m_block_index.count(hashHeads[0]) == 0) {
+ if (!m_blockman.m_block_index.contains(hashHeads[0])) {
LogError("ReplayBlocks(): reorganization to unknown block requested\n");
return false;
}
pindexNew = &(m_blockman.m_block_index[hashHeads[0]]);
if (!hashHeads[1].IsNull()) { // The old tip is allowed to be 0, indicating it's the first flush.
- if (m_blockman.m_block_index.count(hashHeads[1]) == 0) {
+ if (!m_blockman.m_block_index.contains(hashHeads[1])) {
LogError("ReplayBlocks(): reorganization from unknown block requested\n");
return false;
}
@@ -4973,7 +4973,7 @@ bool Chainstate::LoadGenesisBlock()
// m_blockman.m_block_index. Note that we can't use m_chain here, since it is
// set based on the coins db, not the block index db, which is the only
// thing loaded at this point.
- if (m_blockman.m_block_index.count(params.GenesisBlock().GetHash()))
+ if (m_blockman.m_block_index.contains(params.GenesisBlock().GetHash()))
return true;
try {
diff --git a/src/versionbits.cpp b/src/versionbits.cpp
index 32edcd7d..09f6393a 100644
--- a/src/versionbits.cpp
+++ b/src/versionbits.cpp
@@ -48,7 +48,7 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
// Walk backwards in steps of nPeriod to find a pindexPrev whose information is known
std::vector<const CBlockIndex*> vToCompute;
- while (cache.count(pindexPrev) == 0) {
+ while (!cache.contains(pindexPrev)) {
if (pindexPrev == nullptr) {
// The genesis block is by definition defined.
cache[pindexPrev] = ThresholdState::DEFINED;
@@ -64,7 +64,7 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
}
// At this point, cache[pindexPrev] is known
- assert(cache.count(pindexPrev));
+ assert(cache.contains(pindexPrev));
ThresholdState state = cache[pindexPrev];
// Now walk forward and compute the state of descendants of pindexPrev
diff --git a/src/wallet/coincontrol.cpp b/src/wallet/coincontrol.cpp
index 873c5ab3..15fb6915 100644
--- a/src/wallet/coincontrol.cpp
+++ b/src/wallet/coincontrol.cpp
@@ -19,7 +19,7 @@ bool CCoinControl::HasSelected() const
bool CCoinControl::IsSelected(const COutPoint& outpoint) const
{
- return m_selected.count(outpoint) > 0;
+ return m_selected.contains(outpoint);
}
bool CCoinControl::IsExternalSelected(const COutPoint& outpoint) const
diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp
index fc0a68de..ee50a79e 100644
--- a/src/wallet/feebumper.cpp
+++ b/src/wallet/feebumper.cpp
@@ -39,7 +39,7 @@ static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWallet
return feebumper::Result::WALLET_ERROR;
}
- if (wtx.mapValue.count("replaced_by_txid")) {
+ if (wtx.mapValue.contains("replaced_by_txid")) {
errors.push_back(Untranslated(strprintf("Cannot bump transaction %s which was already bumped by transaction %s", wtx.GetHash().ToString(), wtx.mapValue.at("replaced_by_txid"))));
return feebumper::Result::WALLET_ERROR;
}
diff --git a/src/wallet/migrate.cpp b/src/wallet/migrate.cpp
index 7123cdee..f2a720f2 100644
--- a/src/wallet/migrate.cpp
+++ b/src/wallet/migrate.cpp
@@ -747,7 +747,7 @@ bool BerkeleyROBatch::ReadKey(DataStream&& key, DataStream& value)
bool BerkeleyROBatch::HasKey(DataStream&& key)
{
SerializeData key_data{key.begin(), key.end()};
- return m_database.m_records.count(key_data) > 0;
+ return m_database.m_records.contains(key_data);
}
BerkeleyROCursor::BerkeleyROCursor(const BerkeleyRODatabase& database, std::span<const std::byte> prefix)
diff --git a/src/wallet/receive.cpp b/src/wallet/receive.cpp
index 13a25b36..fd10d585 100644
--- a/src/wallet/receive.cpp
+++ b/src/wallet/receive.cpp
@@ -227,7 +227,7 @@ bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<Txi
// Check that this specific input being spent is trusted
if (!wallet.IsMine(parentOut)) return false;
// If we've already trusted this parent, continue
- if (trusted_parents.count(parent->GetHash())) continue;
+ if (trusted_parents.contains(parent->GetHash())) continue;
// Recurse to check that the parent is also trusted
if (!CachedTxIsTrusted(wallet, *parent, trusted_parents)) return false;
trusted_parents.insert(parent->GetHash());
diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp
index 5cb40304..c2df2f61 100644
--- a/src/wallet/rpc/backup.cpp
+++ b/src/wallet/rpc/backup.cpp
@@ -526,7 +526,7 @@ RPCHelpMan listdescriptors()
wallet_descriptors.push_back({
descriptor,
wallet_descriptor.creation_time,
- active_spk_mans.count(desc_spk_man) != 0,
+ active_spk_mans.contains(desc_spk_man),
wallet->IsInternalScriptPubKeyMan(desc_spk_man),
is_range ? std::optional(std::make_pair(wallet_descriptor.range_start, wallet_descriptor.range_end)) : std::nullopt,
wallet_descriptor.next_index
diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp
index 7aeb60f7..773747f9 100644
--- a/src/wallet/rpc/coins.cpp
+++ b/src/wallet/rpc/coins.cpp
@@ -67,7 +67,7 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b
}
for (const CTxOut& txout : wtx.tx->vout) {
- if (output_scripts.count(txout.scriptPubKey) > 0) {
+ if (output_scripts.contains(txout.scriptPubKey)) {
amount += txout.nValue;
}
}
@@ -612,7 +612,7 @@ RPCHelpMan listunspent()
bool fValidAddress = ExtractDestination(scriptPubKey, address);
bool reused = avoid_reuse && pwallet->IsSpentKey(scriptPubKey);
- if (destinations.size() && (!fValidAddress || !destinations.count(address)))
+ if (destinations.size() && (!fValidAddress || !destinations.contains(address)))
continue;
UniValue entry(UniValue::VOBJ);
diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp
index d765dc11..684aa4b8 100644
--- a/src/wallet/rpc/spend.cpp
+++ b/src/wallet/rpc/spend.cpp
@@ -1588,7 +1588,7 @@ RPCHelpMan sendall()
CTxDestination dest;
ExtractDestination(out.scriptPubKey, dest);
std::string addr{EncodeDestination(dest)};
- if (addresses_without_amount.count(addr) > 0) {
+ if (addresses_without_amount.contains(addr)) {
out.nValue = per_output_without_amount;
if (!gave_remaining_to_first) {
out.nValue += remainder % addresses_without_amount.size();
diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp
index 4e9bff19..82d37e3b 100644
--- a/src/wallet/rpc/transactions.cpp
+++ b/src/wallet/rpc/transactions.cpp
@@ -802,7 +802,7 @@ RPCHelpMan abandontransaction()
Txid hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
- if (!pwallet->mapWallet.count(hash)) {
+ if (!pwallet->mapWallet.contains(hash)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
}
if (!pwallet->AbandonTransaction(hash)) {
diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp
index 3d45c160..8651b98d 100644
--- a/src/wallet/rpc/wallet.cpp
+++ b/src/wallet/rpc/wallet.cpp
@@ -311,7 +311,7 @@ static RPCHelpMan setwalletflag()
std::string flag_str = request.params[0].get_str();
bool value = request.params[1].isNull() || request.params[1].get_bool();
- if (!STRING_TO_WALLET_FLAG.count(flag_str)) {
+ if (!STRING_TO_WALLET_FLAG.contains(flag_str)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Unknown wallet flag: %s", flag_str));
}
@@ -336,7 +336,7 @@ static RPCHelpMan setwalletflag()
pwallet->UnsetWalletFlag(flag);
}
- if (flag && value && WALLET_FLAG_CAVEATS.count(flag)) {
+ if (flag && value && WALLET_FLAG_CAVEATS.contains(flag)) {
res.pushKV("warnings", WALLET_FLAG_CAVEATS.at(flag));
}
@@ -548,10 +548,10 @@ RPCHelpMan simulaterawtransaction()
// broadcast, we will lose everything in these
for (const auto& txin : mtx.vin) {
const auto& outpoint = txin.prevout;
- if (spent.count(outpoint)) {
+ if (spent.contains(outpoint)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Transaction(s) are spending the same output more than once");
}
- if (new_utxos.count(outpoint)) {
+ if (new_utxos.contains(outpoint)) {
changes -= new_utxos.at(outpoint);
new_utxos.erase(outpoint);
} else {
diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp
index aca9cca8..a6c25484 100644
--- a/src/wallet/scriptpubkeyman.cpp
+++ b/src/wallet/scriptpubkeyman.cpp
@@ -339,7 +339,7 @@ bool LegacyDataSPKM::AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vec
bool LegacyDataSPKM::HaveWatchOnly(const CScript &dest) const
{
LOCK(cs_KeyStore);
- return setWatchOnly.count(dest) > 0;
+ return setWatchOnly.contains(dest);
}
bool LegacyDataSPKM::LoadWatchOnly(const CScript &dest)
@@ -385,7 +385,7 @@ bool LegacyDataSPKM::HaveKey(const CKeyID &address) const
if (!m_storage.HasEncryptionKeys()) {
return FillableSigningProvider::HaveKey(address);
}
- return mapCryptedKeys.count(address) > 0;
+ return mapCryptedKeys.contains(address);
}
bool LegacyDataSPKM::GetKey(const CKeyID &address, CKey& keyOut) const
@@ -560,7 +560,7 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
keyid_it++;
continue;
}
- if (!meta.hd_seed_id.IsNull() && (m_hd_chain.seed_id == meta.hd_seed_id || m_inactive_hd_chains.count(meta.hd_seed_id) > 0)) {
+ if (!meta.hd_seed_id.IsNull() && (m_hd_chain.seed_id == meta.hd_seed_id || m_inactive_hd_chains.contains(meta.hd_seed_id))) {
keyid_it = keyids.erase(keyid_it);
continue;
}
@@ -1039,7 +1039,7 @@ bool DescriptorScriptPubKeyMan::TopUpWithDB(WalletBatch& batch, unsigned int siz
}
for (const auto& pk_pair : out_keys.pubkeys) {
const CPubKey& pubkey = pk_pair.second;
- if (m_map_pubkeys.count(pubkey) != 0) {
+ if (m_map_pubkeys.contains(pubkey)) {
// We don't need to give an error here.
// It doesn't matter which of many valid indexes the pubkey has, we just need an index where we can derive it and its private key
continue;
@@ -1441,14 +1441,14 @@ void DescriptorScriptPubKeyMan::SetCache(const DescriptorCache& cache)
// Add all of the scriptPubKeys to the scriptPubKey set
new_spks.insert(scripts_temp.begin(), scripts_temp.end());
for (const CScript& script : scripts_temp) {
- if (m_map_script_pub_keys.count(script) != 0) {
+ if (m_map_script_pub_keys.contains(script)) {
throw std::runtime_error(strprintf("Error: Already loaded script at index %d as being at index %d", i, m_map_script_pub_keys[script]));
}
m_map_script_pub_keys[script] = i;
}
for (const auto& pk_pair : out_keys.pubkeys) {
const CPubKey& pubkey = pk_pair.second;
- if (m_map_pubkeys.count(pubkey) != 0) {
+ if (m_map_pubkeys.contains(pubkey)) {
// We don't need to give an error here.
// It doesn't matter which of many valid indexes the pubkey has, we just need an index where we can derive it and its private key
continue;
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index bd7bb01f..216fec48 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -219,7 +219,7 @@ void CoinsResult::Erase(const std::unordered_set<COutPoint, SaltedOutpointHasher
for (auto& [type, vec] : coins) {
auto remove_it = std::remove_if(vec.begin(), vec.end(), [&](const COutput& coin) {
// remove it if it's on the set
- if (coins_to_remove.count(coin.outpoint) == 0) return false;
+ if (!coins_to_remove.contains(coin.outpoint)) return false;
// update cached amounts
total_amount -= coin.txout.nValue;
@@ -382,7 +382,7 @@ CoinsResult AvailableCoins(const CWallet& wallet,
// be a 1-block reorg away from the chain where transactions A and C
// were accepted to another chain where B, B', and C were all
// accepted.
- if (nDepth == 0 && wtx.mapValue.count("replaces_txid")) {
+ if (nDepth == 0 && wtx.mapValue.contains("replaces_txid")) {
safeTx = false;
}
@@ -394,7 +394,7 @@ CoinsResult AvailableCoins(const CWallet& wallet,
// intending to replace A', but potentially resulting in a scenario
// where A, A', and D could all be accepted (instead of just B and
// D, or just A and A' like the user would want).
- if (nDepth == 0 && wtx.mapValue.count("replaced_by_txid")) {
+ if (nDepth == 0 && wtx.mapValue.contains("replaced_by_txid")) {
safeTx = false;
}
diff --git a/src/wallet/test/util.cpp b/src/wallet/test/util.cpp
index c06c6af5..1e4fd7aa 100644
--- a/src/wallet/test/util.cpp
+++ b/src/wallet/test/util.cpp
@@ -163,7 +163,7 @@ bool MockableBatch::HasKey(DataStream&& key)
return false;
}
SerializeData key_data{key.begin(), key.end()};
- return m_records.count(key_data) > 0;
+ return m_records.contains(key_data);
}
bool MockableBatch::ErasePrefix(std::span<const std::byte> prefix)
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index a4cbb1e1..85f8dfc3 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -631,8 +631,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()));
}
@@ -670,8 +670,8 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
BOOST_CHECK_EQUAL(addtx_count, 2 + 2);
{
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()));
}
@@ -710,13 +710,13 @@ BOOST_FIXTURE_TEST_CASE(RemoveTxs, TestChain100Setup)
LOCK(wallet->cs_wallet);
BOOST_CHECK(wallet->HasWalletSpend(prev_tx));
- BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_hash), 1u);
+ BOOST_CHECK(wallet->mapWallet.contains(block_hash));
std::vector<Txid> vHashIn{ block_hash };
BOOST_CHECK(wallet->RemoveTxs(vHashIn));
BOOST_CHECK(!wallet->HasWalletSpend(prev_tx));
- BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_hash), 0u);
+ BOOST_CHECK(!wallet->mapWallet.contains(block_hash));
}
TestUnloadWallet(std::move(wallet));
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 86474a45..48601a59 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -924,7 +924,7 @@ bool CWallet::MarkReplaced(const Txid& originalHash, const Txid& newHash)
CWalletTx& wtx = (*mi).second;
// Ensure for now that we're not overwriting data
- assert(wtx.mapValue.count("replaced_by_txid") == 0);
+ assert(!wtx.mapValue.contains("replaced_by_txid"));
wtx.mapValue["replaced_by_txid"] = newHash.ToString();
@@ -1160,7 +1160,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const SyncTxS
}
}
- bool fExisted = mapWallet.count(tx.GetHash()) != 0;
+ bool fExisted = mapWallet.contains(tx.GetHash());
if (fExisted && !fUpdate) return false;
if (fExisted || IsMine(tx) || IsFromMe(tx))
{
@@ -1336,7 +1336,7 @@ void CWallet::RecursiveUpdateTxState(WalletBatch* batch, const Txid& tx_hash, co
for (unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(COutPoint(now, i));
for (TxSpends::const_iterator iter = range.first; iter != range.second; ++iter) {
- if (!done.count(iter->second)) {
+ if (!done.contains(iter->second)) {
todo.insert(iter->second);
}
}
@@ -2534,7 +2534,7 @@ void CWallet::MarkDestinationsDirty(const std::set<CTxDestination>& destinations
if (wtx.m_is_cache_empty) continue;
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) {
CTxDestination dst;
- if (ExtractDestination(wtx.tx->vout[i].scriptPubKey, dst) && destinations.count(dst)) {
+ if (ExtractDestination(wtx.tx->vout[i].scriptPubKey, dst) && destinations.contains(dst)) {
wtx.MarkDirty();
break;
}
@@ -2678,7 +2678,7 @@ bool CWallet::UnlockAllCoins()
bool CWallet::IsLockedCoin(const COutPoint& output) const
{
AssertLockHeld(cs_wallet);
- return m_locked_coins.count(output) > 0;
+ return m_locked_coins.contains(output);
}
void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts) const
@@ -3397,7 +3397,7 @@ std::set<ScriptPubKeyMan*> CWallet::GetScriptPubKeyMans(const CScript& script) c
ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const uint256& id) const
{
- if (m_spk_managers.count(id) > 0) {
+ if (m_spk_managers.contains(id)) {
return m_spk_managers.at(id).get();
}
return nullptr;
@@ -3682,7 +3682,7 @@ DescriptorScriptPubKeyMan* CWallet::GetDescriptorScriptPubKeyMan(const WalletDes
std::optional<bool> CWallet::IsInternalScriptPubKeyMan(ScriptPubKeyMan* spk_man) const
{
// only active ScriptPubKeyMan can be internal
- if (!GetActiveScriptPubKeyMans().count(spk_man)) {
+ if (!GetActiveScriptPubKeyMans().contains(spk_man)) {
return std::nullopt;
}
@@ -3877,7 +3877,7 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
if (!data.solvable_descs.empty()) Assume(!data.solvable_wallet->m_cached_spks.empty());
for (auto& desc_spkm : data.desc_spkms) {
- if (m_spk_managers.count(desc_spkm->GetID()) > 0) {
+ if (m_spk_managers.contains(desc_spkm->GetID())) {
return util::Error{_("Error: Duplicate descriptors created during migration. Your wallet may be corrupted.")};
}
uint256 id = desc_spkm->GetID();
@@ -4025,7 +4025,7 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
if (require_transfer && !copied) {
// Skip invalid/non-watched scripts that will not be migrated
- if (not_migrated_dests.count(dest) > 0) {
+ if (not_migrated_dests.contains(dest)) {
dests_to_delete.push_back(dest);
continue;
}
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 9ca4d2da..115d6783 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -409,7 +409,7 @@ bool LoadEncryptionKey(CWallet* pwallet, DataStream& ssKey, DataStream& ssValue,
ssKey >> nID;
CMasterKey kMasterKey;
ssValue >> kMasterKey;
- if(pwallet->mapMasterKeys.count(nID) != 0)
+ if(pwallet->mapMasterKeys.contains(nID))
{
strErr = strprintf("Error reading wallet database: duplicate CMasterKey id %u", nID);
return false;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.