|
|
@ -98,8 +98,8 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const { |
|
|
|
/* It seems that there are no "const iterators" for LevelDB. Since we
|
|
|
|
/* It seems that there are no "const iterators" for LevelDB. Since we
|
|
|
|
only need read operations on it, use a const-cast to get around |
|
|
|
only need read operations on it, use a const-cast to get around |
|
|
|
that restriction. */ |
|
|
|
that restriction. */ |
|
|
|
boost::scoped_ptr<leveldb::Iterator> pcursor(const_cast<CLevelDBWrapper*>(&db)->NewIterator()); |
|
|
|
boost::scoped_ptr<CLevelDBWrapper> pcursor(const_cast<CLevelDBWrapper*>(&db)->NewIterator()); |
|
|
|
pcursor->SeekToFirst(); |
|
|
|
pcursor->Seek('c'); |
|
|
|
|
|
|
|
|
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); |
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); |
|
|
|
stats.hashBlock = GetBestBlock(); |
|
|
|
stats.hashBlock = GetBestBlock(); |
|
|
@ -107,22 +107,10 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const { |
|
|
|
CAmount nTotalAmount = 0; |
|
|
|
CAmount nTotalAmount = 0; |
|
|
|
while (pcursor->Valid()) { |
|
|
|
while (pcursor->Valid()) { |
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
try { |
|
|
|
std::pair<char, uint256> key; |
|
|
|
leveldb::Slice slKey = pcursor->key(); |
|
|
|
|
|
|
|
CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); |
|
|
|
|
|
|
|
char chType; |
|
|
|
|
|
|
|
ssKey >> chType; |
|
|
|
|
|
|
|
if (chType == DB_COINS) { |
|
|
|
|
|
|
|
leveldb::Slice slValue = pcursor->value(); |
|
|
|
|
|
|
|
CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); |
|
|
|
|
|
|
|
CCoins coins; |
|
|
|
CCoins coins; |
|
|
|
ssValue >> coins; |
|
|
|
if (pcursor->GetKey(key) && key.first == 'c') { |
|
|
|
uint256 txhash; |
|
|
|
if (pcursor->GetValue(coins)) { |
|
|
|
ssKey >> txhash; |
|
|
|
|
|
|
|
ss << txhash; |
|
|
|
|
|
|
|
ss << VARINT(coins.nVersion); |
|
|
|
|
|
|
|
ss << (coins.fCoinBase ? 'c' : 'n'); |
|
|
|
|
|
|
|
ss << VARINT(coins.nHeight); |
|
|
|
|
|
|
|
stats.nTransactions++; |
|
|
|
stats.nTransactions++; |
|
|
|
for (unsigned int i=0; i<coins.vout.size(); i++) { |
|
|
|
for (unsigned int i=0; i<coins.vout.size(); i++) { |
|
|
|
const CTxOut &out = coins.vout[i]; |
|
|
|
const CTxOut &out = coins.vout[i]; |
|
|
@ -133,13 +121,15 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const { |
|
|
|
nTotalAmount += out.nValue; |
|
|
|
nTotalAmount += out.nValue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
stats.nSerializedSize += 32 + slValue.size(); |
|
|
|
stats.nSerializedSize += 32 + pcursor->GetKeySize(); |
|
|
|
ss << VARINT(0); |
|
|
|
ss << VARINT(0); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return error("CCoinsViewDB::GetStats() : unable to read value"); |
|
|
|
} |
|
|
|
} |
|
|
|
pcursor->Next(); |
|
|
|
} else { |
|
|
|
} catch (const std::exception& e) { |
|
|
|
break; |
|
|
|
return error("%s: Deserialize or I/O error - %s", __func__, e.what()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
pcursor->Next(); |
|
|
|
} |
|
|
|
} |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_main); |
|
|
|
LOCK(cs_main); |
|
|
@ -189,24 +179,15 @@ bool CBlockTreeDB::LoadBlockIndexGuts() |
|
|
|
{ |
|
|
|
{ |
|
|
|
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator()); |
|
|
|
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator()); |
|
|
|
|
|
|
|
|
|
|
|
CDataStream ssKeySet(SER_DISK, CLIENT_VERSION); |
|
|
|
pcursor->Seek(make_pair('b', uint256(0))); |
|
|
|
ssKeySet << make_pair(DB_BLOCK_INDEX, uint256()); |
|
|
|
|
|
|
|
pcursor->Seek(ssKeySet.str()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load mapBlockIndex
|
|
|
|
// Load mapBlockIndex
|
|
|
|
while (pcursor->Valid()) { |
|
|
|
while (pcursor->Valid()) { |
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
try { |
|
|
|
std::pair<char, uint256> key; |
|
|
|
leveldb::Slice slKey = pcursor->key(); |
|
|
|
if (pcursor->GetKey(key) && key.first == 'b') { |
|
|
|
CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); |
|
|
|
|
|
|
|
char chType; |
|
|
|
|
|
|
|
ssKey >> chType; |
|
|
|
|
|
|
|
if (chType == DB_BLOCK_INDEX) { |
|
|
|
|
|
|
|
leveldb::Slice slValue = pcursor->value(); |
|
|
|
|
|
|
|
CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); |
|
|
|
|
|
|
|
CDiskBlockIndex diskindex; |
|
|
|
CDiskBlockIndex diskindex; |
|
|
|
ssValue >> diskindex; |
|
|
|
if (pcursor->GetValue(diskindex)) { |
|
|
|
|
|
|
|
|
|
|
|
// Construct block index object
|
|
|
|
// Construct block index object
|
|
|
|
CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash()); |
|
|
|
CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash()); |
|
|
|
pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev); |
|
|
|
pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev); |
|
|
@ -227,10 +208,10 @@ bool CBlockTreeDB::LoadBlockIndexGuts() |
|
|
|
|
|
|
|
|
|
|
|
pcursor->Next(); |
|
|
|
pcursor->Next(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
break; // if shutdown requested or finished loading block index
|
|
|
|
return error("LoadBlockIndex() : failed to read value"); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (const std::exception& e) { |
|
|
|
} else { |
|
|
|
return error("%s: Deserialize or I/O error - %s", __func__, e.what()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|