aboutsummaryrefslogtreecommitdiff
path: root/src/txdb.cpp
diff options
context:
space:
mode:
authorPieter Wuille <sipa@ulyssis.org>2013-05-01 16:23:27 +0200
committerPieter Wuille <sipa@ulyssis.org>2013-05-01 17:21:43 +0200
commite31aa7c9d7dd204b5658f20c19565eee308e35c1 (patch)
tree74ce2ecac7281c3b42a35ef0e3c9207a01b25797 /src/txdb.cpp
parenteef2091fe9ee39ecd8e874c91d3ab0ff023c5356 (diff)
downloadbitcoin-e31aa7c9d7dd204b5658f20c19565eee308e35c1.tar.xz
Improve gettxoutsetinfo command
* Bugfix: output the correct best block hash (during IBD, it can differ from the actual current best block) * Add height to output * Add hash_serialized, which is a hash of the entire UTXO state. Can be useful to compare two nodes. * Add total_amount, the sum of all UTXOs' values.
Diffstat (limited to 'src/txdb.cpp')
-rw-r--r--src/txdb.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 5b0527c76c..3d34710d22 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -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) {
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) {
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) {
}
delete pcursor;
stats.nHeight = GetBestBlock()->nHeight;
+ stats.hashSerialized = ss.GetHash();
+ stats.nTotalAmount = nTotalAmount;
return true;
}