26
src/txdb.cpp
26
src/txdb.cpp
@@ -402,8 +402,10 @@ 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<leveldb::Iterator> iter(NewIterator());
|
||||
std::map <std::string, CAmount> addressAmounts;
|
||||
std::vector <std::pair<CAmount, std::string>> vaddr;
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("start_time", time(NULL)));
|
||||
|
||||
@@ -445,7 +447,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,31 +460,31 @@ 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<bool(std::pair<std::string, CAmount>, std::pair<std::string, CAmount>)> Comparator;
|
||||
Comparator compFunctor = [](std::pair<std::string, CAmount> elem1 ,std::pair<std::string, CAmount> elem2) {
|
||||
return elem1.second > elem2.second; /* descending */
|
||||
};
|
||||
// This is our intermediate data structure that allows us to calculate addressSorted
|
||||
std::set<std::pair<std::string, CAmount>, Comparator> sortedSnapshot(addressAmounts.begin(), addressAmounts.end(), compFunctor);
|
||||
for (std::pair<std::string, CAmount> element : addressAmounts) {
|
||||
vaddr.push_back( make_pair(element.second, element.first) );
|
||||
}
|
||||
std::sort(vaddr.begin(), vaddr.end());
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
UniValue addressesSorted(UniValue::VARR);
|
||||
for (std::pair<std::string, CAmount> element : sortedSnapshot) {
|
||||
for (std::vector<std::pair<CAmount, std::string>>::iterator it = vaddr.begin(); it!=vaddr.end(); ++it) {
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back( make_pair("addr", element.first.c_str() ) );
|
||||
obj.push_back( make_pair("addr", it->second.c_str() ) );
|
||||
char amount[32];
|
||||
sprintf(amount, "%.8f", (double) element.second / COIN);
|
||||
sprintf(amount, "%.8f", (double) it->first / COIN);
|
||||
obj.push_back( make_pair("amount", amount) );
|
||||
addressesSorted.push_back(obj);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user