| 312 | } |
| 313 | |
| 314 | static bool LookUpOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVal& result) |
| 315 | { |
| 316 | // First check if the result is stored under the height index and the value |
| 317 | // there matches the block hash. This should be the case if the block is on |
| 318 | // the active chain. |
| 319 | std::pair<uint256, DBVal> read_out; |
| 320 | if (!db.Read(DBHeightKey(block_index->nHeight), read_out)) { |
| 321 | return false; |
| 322 | } |
| 323 | if (read_out.first == block_index->GetBlockHash()) { |
| 324 | result = std::move(read_out.second); |
| 325 | return true; |
| 326 | } |
| 327 | |
| 328 | // If value at the height index corresponds to an different block, the |
| 329 | // result will be stored in the hash index. |
| 330 | return db.Read(DBHashKey(block_index->GetBlockHash()), result); |
| 331 | } |
| 332 | |
| 333 | bool CoinStatsIndex::LookUpStats(const CBlockIndex* block_index, CCoinsStats& coins_stats) const |
| 334 | { |
no test coverage detected