From 3bfe8acfc70af3a48aad0e09b7a11227f255ce41 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Mon, 25 Nov 2024 03:39:31 +0400 Subject: [PATCH] Review comment applied --- src/txdb.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index eec85cd5e9..1c5bc6fb42 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -323,20 +323,24 @@ size_t CBlockTreeDB::findAddressNumWBalance() { if (pcursor->GetKey(key) && key.first == DB_ADDRESSINDEX && (key.second.type == AddressType::payToPubKeyHash || key.second.type == AddressType::payToExchangeAddress)) { CAmount nValue; if (pcursor->GetValue(nValue)) { - auto it = addrMap.find(key.second.hashBytes); - if (it != addrMap.end()) { - it->second += nValue; - if (it->second <= 0) - addrMap.erase(it); - } else { - if (nValue != 0) - addrMap[key.second.hashBytes] = nValue; + CAmount nValue; + // Retrieve the associated value + if (pcursor->GetValue(nValue) && nValue != 0) { // Only process non-zero values + addrMap[key.second.hashBytes] += nValue; // Accumulate balance for the address } } } pcursor->Next(); } - return addrMap.size(); + + size_t counter = 0; + for (auto& itr : addrMap) { + if (itr.second > 0) { + ++counter; + } + } + + return counter; } bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey ×tampIndex) {