Browse Source

Merge pull request #2602 from sipa/utxostate

Improve gettxoutsetinfo command
0.8
Gavin Andresen 12 years ago
parent
commit
26585c36b2
  1. 5
      src/main.h
  2. 5
      src/rpcblockchain.cpp
  3. 22
      src/txdb.cpp

5
src/main.h

@ -2096,11 +2096,14 @@ extern CTxMemPool mempool; @@ -2096,11 +2096,14 @@ extern CTxMemPool mempool;
struct CCoinsStats
{
int nHeight;
uint256 hashBlock;
uint64 nTransactions;
uint64 nTransactionOutputs;
uint64 nSerializedSize;
uint256 hashSerialized;
int64 nTotalAmount;
CCoinsStats() : nHeight(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0) {}
CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {}
};
/** Abstract view on the open txout dataset. */

5
src/rpcblockchain.cpp

@ -172,10 +172,13 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) @@ -172,10 +172,13 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
CCoinsStats stats;
if (pcoinsTip->GetStats(stats)) {
ret.push_back(Pair("bestblock", pcoinsTip->GetBestBlock()->GetBlockHash().GetHex()));
ret.push_back(Pair("height", (boost::int64_t)stats.nHeight));
ret.push_back(Pair("bestblock", stats.hashBlock.GetHex()));
ret.push_back(Pair("transactions", (boost::int64_t)stats.nTransactions));
ret.push_back(Pair("txouts", (boost::int64_t)stats.nTransactionOutputs));
ret.push_back(Pair("bytes_serialized", (boost::int64_t)stats.nSerializedSize));
ret.push_back(Pair("hash_serialized", stats.hashSerialized.GetHex()));
ret.push_back(Pair("total_amount", ValueFromAmount(stats.nTotalAmount)));
}
return ret;
}

22
src/txdb.cpp

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

Loading…
Cancel
Save