Skip to content

Commit 3a84038

Browse files
sipafjahr
authored andcommitted
Simplification
1 parent 765d0f0 commit 3a84038

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

src/rpc/blockchain.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -925,21 +925,18 @@ struct CCoinsStats
925925
CCoinsStats() : nHeight(0), nTransactions(0), nTransactionOutputs(0), nBogoSize(0), nDiskSize(0), nTotalAmount(0) {}
926926
};
927927

928-
static void ApplyStats(CCoinsStats &stats, MuHash3072& acc, const uint256& hash, const std::map<uint32_t, Coin>& outputs)
928+
static void ApplyStats(CCoinsStats &stats, MuHash3072& acc, const COutPoint outpoint, const Coin& coin)
929929
{
930-
assert(!outputs.empty());
931930
stats.nTransactions++;
932-
for (const auto output : outputs) {
933-
TruncatedSHA512Writer ss(SER_DISK, 0);
934-
ss << COutPoint(hash, output.first);
935-
ss << (uint32_t)(output.second.nHeight * 2 + output.second.fCoinBase);
936-
ss << output.second.out;
937-
acc *= MuHash3072(ss.GetHash().begin());
938-
stats.nTransactionOutputs++;
939-
stats.nTotalAmount += output.second.out.nValue;
940-
stats.nBogoSize += 32 /* txid */ + 4 /* vout index */ + 4 /* height + coinbase */ + 8 /* amount */ +
941-
2 /* scriptPubKey len */ + output.second.out.scriptPubKey.size() /* scriptPubKey */;
942-
}
931+
TruncatedSHA512Writer ss(SER_DISK, 0);
932+
ss << outpoint;
933+
ss << (uint32_t)(coin.nHeight * 2 + coin.fCoinBase);
934+
ss << coin.out;
935+
acc *= MuHash3072(ss.GetHash().begin());
936+
stats.nTransactionOutputs++;
937+
stats.nTotalAmount += coin.out.nValue;
938+
stats.nBogoSize += 32 /* txid */ + 4 /* vout index */ + 4 /* height + coinbase */ + 8 /* amount */ +
939+
2 /* scriptPubKey len */ + coin.out.scriptPubKey.size() /* scriptPubKey */;
943940
}
944941

945942
//! Calculate statistics about the unspent transaction output set
@@ -954,27 +951,17 @@ static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
954951
stats.nHeight = LookupBlockIndex(stats.hashBlock)->nHeight;
955952
}
956953
MuHash3072 acc;
957-
std::map<uint32_t, Coin> outputs;
958-
uint256 prevkey;
959954
while (pcursor->Valid()) {
960955
boost::this_thread::interruption_point();
961956
COutPoint key;
962957
Coin coin;
963958
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
964-
if (!outputs.empty() && key.hash != prevkey) {
965-
ApplyStats(stats, acc, prevkey, outputs);
966-
outputs.clear();
967-
}
968-
prevkey = key.hash;
969-
outputs[key.n] = std::move(coin);
959+
ApplyStats(stats, acc, key, coin);
970960
} else {
971961
return error("%s: unable to read value", __func__);
972962
}
973963
pcursor->Next();
974964
}
975-
if (!outputs.empty()) {
976-
ApplyStats(stats, acc, prevkey, outputs);
977-
}
978965
unsigned char data[384];
979966
acc.Finalize(data);
980967
TruncatedSHA512Writer ss(SER_DISK, 0);

0 commit comments

Comments
 (0)