| 302 | } |
| 303 | |
| 304 | static bool LookupOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVal& result) |
| 305 | { |
| 306 | // First check if the result is stored under the height index and the value there matches the |
| 307 | // block hash. This should be the case if the block is on the active chain. |
| 308 | std::pair<uint256, DBVal> read_out; |
| 309 | if (!db.Read(DBHeightKey(block_index->nHeight), read_out)) { |
| 310 | return false; |
| 311 | } |
| 312 | if (read_out.first == block_index->GetBlockHash()) { |
| 313 | result = std::move(read_out.second); |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | // If value at the height index corresponds to an different block, the result will be stored in |
| 318 | // the hash index. |
| 319 | return db.Read(DBHashKey(block_index->GetBlockHash()), result); |
| 320 | } |
| 321 | |
| 322 | static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start_height, |
| 323 | const CBlockIndex* stop_index, std::vector<DBVal>& results) |
no test coverage detected