From 20ba439d0541ed7b74ff4c647a08286f1c4b30ac Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 19 Jul 2018 05:37:27 +0000 Subject: [PATCH] Add number of utxos to metadata in json response --- src/txdb.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index af6cd0fbf..8ae2caa7b 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,6 +402,7 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr extern UniValue CBlockTreeDB::Snapshot() { char chType; int64_t total = 0; int64_t totalAddresses = 0; std::string address; + int64_t utxos = 0; boost::scoped_ptr iter(NewIterator()); std::map addressAmounts; UniValue result(UniValue::VOBJ); @@ -445,7 +446,7 @@ extern UniValue CBlockTreeDB::Snapshot() } //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; @@ -458,7 +459,7 @@ extern UniValue CBlockTreeDB::Snapshot() } UniValue addresses(UniValue::VARR); - fprintf(stderr, "total=%f, totalAddresses=%li\n", (double) total / COIN, totalAddresses); + fprintf(stderr, "total=%f, totalAddresses=%li, utxos=%li\n", (double) total / COIN, totalAddresses, utxos); typedef std::function, std::pair)> Comparator; Comparator compFunctor = [](std::pair elem1 ,std::pair elem2) { @@ -467,6 +468,8 @@ extern UniValue CBlockTreeDB::Snapshot() // This is our intermediate data structure that allows us to calculate addressSorted std::set, Comparator> sortedSnapshot(addressAmounts.begin(), addressAmounts.end(), compFunctor); + //fprintf(stderr, "sortedSnapshot.size=%li\n", sortedSnapshot.size() ); + UniValue obj(UniValue::VOBJ); UniValue addressesSorted(UniValue::VARR); for (std::pair element : sortedSnapshot) { @@ -480,9 +483,11 @@ extern UniValue CBlockTreeDB::Snapshot() if (totalAddresses > 0) { result.push_back(make_pair("addresses", addressesSorted)); - result.push_back(make_pair("total", total / COIN )); + result.push_back(make_pair("total", (double) total / COIN )); result.push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); } + // Total number of utxos in this snaphot + result.push_back(make_pair("utxos", utxos)); // Total number of addresses in this snaphot result.push_back(make_pair("total_addresses", totalAddresses)); // The snapshot began at this block height