* Calculate statistics about the unspent transaction output set * * @param[in] index_requested Signals if the coinstatsindex should be used (when available). */
| 993 | * @param[in] index_requested Signals if the coinstatsindex should be used (when available). |
| 994 | */ |
| 995 | static std::optional<kernel::CCoinsStats> GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, |
| 996 | kernel::CoinStatsHashType hash_type, |
| 997 | const std::function<void()>& interruption_point = {}, |
| 998 | const CBlockIndex* pindex = nullptr, |
| 999 | bool index_requested = true) |
| 1000 | { |
| 1001 | // Use CoinStatsIndex if it is requested and available and a hash_type of Muhash or None was requested |
| 1002 | if ((hash_type == kernel::CoinStatsHashType::MUHASH || hash_type == kernel::CoinStatsHashType::NONE) && g_coin_stats_index && index_requested) { |
| 1003 | if (pindex) { |
| 1004 | return g_coin_stats_index->LookUpStats(*pindex); |
| 1005 | } else { |
| 1006 | CBlockIndex& block_index = *CHECK_NONFATAL(WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(view->GetBestBlock()))); |
| 1007 | return g_coin_stats_index->LookUpStats(block_index); |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | // If the coinstats index isn't requested or is otherwise not usable, the |
| 1012 | // pindex should either be null or equal to the view's best block. This is |
| 1013 | // because without the coinstats index we can only get coinstats about the |
| 1014 | // best block. |
| 1015 | CHECK_NONFATAL(!pindex || pindex->GetBlockHash() == view->GetBestBlock()); |
| 1016 | |
| 1017 | return kernel::ComputeUTXOStats(hash_type, view, blockman, interruption_point); |
| 1018 | } |
| 1019 | |
| 1020 | static RPCMethod gettxoutsetinfo() |
| 1021 | { |
no test coverage detected