@ -5,6 +5,7 @@
# include "txdb.h"
# include "txdb.h"
# include "main.h"
# include "main.h"
# include "hash.h"
using namespace std ;
using namespace std ;
@ -114,6 +115,10 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
leveldb : : Iterator * pcursor = db . NewIterator ( ) ;
leveldb : : Iterator * pcursor = db . NewIterator ( ) ;
pcursor - > SeekToFirst ( ) ;
pcursor - > SeekToFirst ( ) ;
CHashWriter ss ( SER_GETHASH , PROTOCOL_VERSION ) ;
stats . hashBlock = GetBestBlock ( ) - > GetBlockHash ( ) ;
ss < < stats . hashBlock ;
int64 nTotalAmount = 0 ;
while ( pcursor - > Valid ( ) ) {
while ( pcursor - > Valid ( ) ) {
boost : : this_thread : : interruption_point ( ) ;
boost : : this_thread : : interruption_point ( ) ;
try {
try {
@ -128,13 +133,22 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
ssValue > > coins ;
ssValue > > coins ;
uint256 txhash ;
uint256 txhash ;
ssKey > > txhash ;
ssKey > > txhash ;
ss < < txhash ;
ss < < VARINT ( coins . nVersion ) ;
ss < < ( coins . fCoinBase ? ' c ' : ' n ' ) ;
ss < < VARINT ( coins . nHeight ) ;
stats . nTransactions + + ;
stats . nTransactions + + ;
BOOST_FOREACH ( const CTxOut & out , coins . vout ) {
for ( unsigned int i = 0 ; i < coins . vout . size ( ) ; i + + ) {
if ( ! out . IsNull ( ) )
const CTxOut & out = coins . vout [ i ] ;
if ( ! out . IsNull ( ) ) {
stats . nTransactionOutputs + + ;
stats . nTransactionOutputs + + ;
ss < < VARINT ( i + 1 ) ;
ss < < out ;
nTotalAmount + = out . nValue ;
}
}
}
stats . nSerializedSize + = 32 + slValue . size ( ) ;
stats . nSerializedSize + = 32 + slValue . size ( ) ;
ss < < VARINT ( 0 ) ;
}
}
pcursor - > Next ( ) ;
pcursor - > Next ( ) ;
} catch ( std : : exception & e ) {
} catch ( std : : exception & e ) {
@ -143,6 +157,8 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) {
}
}
delete pcursor ;
delete pcursor ;
stats . nHeight = GetBestBlock ( ) - > nHeight ;
stats . nHeight = GetBestBlock ( ) - > nHeight ;
stats . hashSerialized = ss . GetHash ( ) ;
stats . nTotalAmount = nTotalAmount ;
return true ;
return true ;
}
}