From 6398d6f0547436681e01f46e44a97c1430240a04 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 9 Mar 2019 14:52:49 -0800 Subject: [PATCH] Filter out amount=0 UTXOs from getsnapshot results --- src/txdb.cpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index f00f2adf8..0588d52de 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -491,27 +491,31 @@ UniValue CBlockTreeDB::Snapshot(int top) getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); - std::map ::iterator ignored = ignoredMap.find(address); - if (ignored != ignoredMap.end()) { - fprintf(stderr,"ignoring %s\n", address.c_str()); - ignoredAddresses++; - continue; - } + if (nValue > 0) { + std::map ::iterator ignored = ignoredMap.find(address); + if (ignored != ignoredMap.end()) { + fprintf(stderr,"ignoring %s\n", address.c_str()); + ignoredAddresses++; + continue; + } - std::map ::iterator pos = addressAmounts.find(address); - if (pos == addressAmounts.end()) { - // insert new address + utxo amount - //fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); - addressAmounts[address] = nValue; - totalAddresses++; + std::map ::iterator pos = addressAmounts.find(address); + if (pos == addressAmounts.end()) { + // insert new address + utxo amount + //fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + addressAmounts[address] = nValue; + totalAddresses++; + } else { + // update unspent tally for this address + //fprintf(stderr, "updating address %s with new utxo amount %li\n", address.c_str(), nValue); + addressAmounts[address] += nValue; + } + //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); + // total += nValue; + utxos++; } else { - // update unspent tally for this address - //fprintf(stderr, "updating address %s with new utxo amount %li\n", address.c_str(), nValue); - addressAmounts[address] += nValue; + fprintf(stderr,"ignoring amount=0 UTXO for %s\n", address.c_str()); } - //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - // total += nValue; - utxos++; } catch (const std::exception& e) { fprintf(stderr, "DONE %s: LevelDB addressindex exception! - %s\n", __func__, e.what()); break;