This commit is contained in:
jl777
2018-06-12 00:41:46 -11:00
parent 50b11c4a55
commit 67d2e41b3f
3 changed files with 13 additions and 11 deletions

View File

@@ -585,12 +585,12 @@ CBlockTreeDB *pblocktree = NULL;
#define KOMODO_ZCASH #define KOMODO_ZCASH
#include "komodo.h" #include "komodo.h"
int32_t komodo_snapshot() int64_t komodo_snapshot()
{ {
int32_t num = -1; int64_t total = -1;
if ( pblocktree != 0 ) if ( pblocktree != 0 )
num = pblocktree->Snapshot(); total = pblocktree->Snapshot();
return(num); return(total);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@@ -997,15 +997,15 @@ int32_t komodo_snapshot();
UniValue getsnapshot(const UniValue& params, bool fHelp) UniValue getsnapshot(const UniValue& params, bool fHelp)
{ {
UniValue result(UniValue::VOBJ); int32_t num; UniValue result(UniValue::VOBJ); int64_t total;
if ( fHelp || params.size() > 0 ) if ( fHelp || params.size() > 0 )
{ {
throw runtime_error( throw runtime_error(
"getsnapshot\n" "getsnapshot\n"
); );
} }
if ( (num= komodo_snapshot()) >= 0 ) if ( (total= komodo_snapshot()) >= 0 )
result.push_back(Pair("numaddresses", num)); result.push_back(Pair("total", (double)total/COIN));
else result.push_back(Pair("error", "no addressindex")); else result.push_back(Pair("error", "no addressindex"));
return(result); return(result);
} }

View File

@@ -398,9 +398,9 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type,
bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address); bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address);
int32_t CBlockTreeDB::Snapshot() int64_t CBlockTreeDB::Snapshot()
{ {
char chType; int32_t num = 0; std::string address; char chType; int64_t total = -1; std::string address;
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator()); boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());
while (pcursor->Valid()) while (pcursor->Valid())
{ {
@@ -421,7 +421,9 @@ int32_t CBlockTreeDB::Snapshot()
ssValue >> nValue; ssValue >> nValue;
getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); getAddressFromIndex(indexKey.type, indexKey.hashBytes, address);
fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN);
num++; if ( total < 0 )
total = (int64_t)nValue;
else total += (int64_t)nValue;
//addressIndex.push_back(make_pair(indexKey, nValue)); //addressIndex.push_back(make_pair(indexKey, nValue));
pcursor->Next(); pcursor->Next();
} catch (const std::exception& e) { } catch (const std::exception& e) {
@@ -432,7 +434,7 @@ int32_t CBlockTreeDB::Snapshot()
break; break;
} }
} }
return(num); return(total);
} }
bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey &timestampIndex) { bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey &timestampIndex) {