Fix bug where finding index entries of other types, such as timestampindex, stopped our iterator

This commit is contained in:
Duke Leto
2018-07-18 16:02:53 +00:00
parent 9ef7fec1ef
commit 3350160a6c

View File

@@ -411,6 +411,7 @@ extern UniValue CBlockTreeDB::Snapshot()
pcursor->SeekToLast(); pcursor->SeekToLast();
int64_t startingHeight = chainActive.Height(); int64_t startingHeight = chainActive.Height();
//fprintf(stderr, "starting_height=%li\n", startingHeight);
while (pcursor->Valid()) while (pcursor->Valid())
{ {
@@ -423,7 +424,8 @@ extern UniValue CBlockTreeDB::Snapshot()
ssKey >> chType; ssKey >> chType;
ssKey >> indexKey; ssKey >> indexKey;
if ( chType == DB_ADDRESSUNSPENTINDEX ) //fprintf(stderr, "chType=%d\n", chType);
if (chType == DB_ADDRESSUNSPENTINDEX)
{ {
try { try {
leveldb::Slice slValue = pcursor->value(); leveldb::Slice slValue = pcursor->value();
@@ -435,7 +437,7 @@ extern UniValue CBlockTreeDB::Snapshot()
std::map <std::string, CAmount>::iterator pos = addressAmounts.find(address); std::map <std::string, CAmount>::iterator pos = addressAmounts.find(address);
if (pos == addressAmounts.end()) { if (pos == addressAmounts.end()) {
// insert new address + utxo amount // insert new address + utxo amount
//fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue);
addressAmounts[address] = nValue; addressAmounts[address] = nValue;
totalAddresses++; totalAddresses++;
} else { } else {
@@ -446,9 +448,10 @@ extern UniValue CBlockTreeDB::Snapshot()
//fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN);
total += nValue; total += nValue;
} catch (const std::exception& e) { } catch (const std::exception& e) {
return error("failed to get address index value"); // this should not happen normally, but maybe if an index is corrupt
fprintf(stderr, "failed to get address index value\n");
} }
} else { break; } }
} catch (const std::exception& e) { } catch (const std::exception& e) {
fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what()); fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what());
break; break;
@@ -477,9 +480,11 @@ extern UniValue CBlockTreeDB::Snapshot()
addressesSorted.push_back(obj); addressesSorted.push_back(obj);
} }
result.push_back(make_pair("addresses", addressesSorted)); if (totalAddresses > 0) {
result.push_back(make_pair("total", total / COIN )); result.push_back(make_pair("addresses", addressesSorted));
result.push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); result.push_back(make_pair("total", total / COIN ));
result.push_back(make_pair("average",(double) (total/COIN) / totalAddresses ));
}
// Total number of addresses in this snaphot // Total number of addresses in this snaphot
result.push_back(make_pair("total_addresses", totalAddresses)); result.push_back(make_pair("total_addresses", totalAddresses));
// The snapshot began at this block height // The snapshot began at this block height