MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / GetUTXOStats

Function GetUTXOStats

src/rpc/blockchain.cpp:927–963  ·  view source on GitHub ↗

Calculate statistics about the unspent transaction output set

Source from the content-addressed store, hash-verified

925
926//! Calculate statistics about the unspent transaction output set
927static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
928{
929 std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
930 assert(pcursor);
931
932 CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
933 stats.hashBlock = pcursor->GetBestBlock();
934 {
935 LOCK(cs_main);
936 stats.nHeight = LookupBlockIndex(stats.hashBlock)->nHeight;
937 }
938 ss << stats.hashBlock;
939 uint256 prevkey;
940 std::map<uint32_t, Coin> outputs;
941 while (pcursor->Valid()) {
942 boost::this_thread::interruption_point();
943 COutPoint key;
944 Coin coin;
945 if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
946 if (!outputs.empty() && key.hash != prevkey) {
947 ApplyStats(stats, ss, prevkey, outputs);
948 outputs.clear();
949 }
950 prevkey = key.hash;
951 outputs[key.n] = std::move(coin);
952 } else {
953 return error("%s: unable to read value", __func__);
954 }
955 pcursor->Next();
956 }
957 if (!outputs.empty()) {
958 ApplyStats(stats, ss, prevkey, outputs);
959 }
960 stats.hashSerialized = ss.GetHash();
961 stats.nDiskSize = view->EstimateSize();
962 return true;
963}
964
965static UniValue pruneblockchain(const JSONRPCRequest& request)
966{

Callers 1

gettxoutsetinfoFunction · 0.85

Calls 13

LookupBlockIndexFunction · 0.85
ApplyStatsFunction · 0.85
errorFunction · 0.85
CursorMethod · 0.45
GetBestBlockMethod · 0.45
ValidMethod · 0.45
GetKeyMethod · 0.45
GetValueMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45
NextMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected