Calculate statistics about the unspent transaction output set
| 925 | |
| 926 | //! Calculate statistics about the unspent transaction output set |
| 927 | static 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 | |
| 965 | static UniValue pruneblockchain(const JSONRPCRequest& request) |
| 966 | { |
no test coverage detected