| 248 | } |
| 249 | |
| 250 | static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch, |
| 251 | const std::string& index_name, |
| 252 | int start_height, int stop_height) |
| 253 | { |
| 254 | DBHeightKey key{start_height}; |
| 255 | db_it.Seek(key); |
| 256 | |
| 257 | for (int height = start_height; height <= stop_height; ++height) { |
| 258 | if (!db_it.GetKey(key) || key.height != height) { |
| 259 | return error("%s: unexpected key in %s: expected (%c, %d)", |
| 260 | __func__, index_name, DB_BLOCK_HEIGHT, height); |
| 261 | } |
| 262 | |
| 263 | std::pair<uint256, DBVal> value; |
| 264 | if (!db_it.GetValue(value)) { |
| 265 | return error("%s: unable to read value in %s at key (%c, %d)", |
| 266 | __func__, index_name, DB_BLOCK_HEIGHT, height); |
| 267 | } |
| 268 | |
| 269 | batch.Write(DBHashKey(value.first), std::move(value.second)); |
| 270 | |
| 271 | db_it.Next(); |
| 272 | } |
| 273 | return true; |
| 274 | } |
| 275 | |
| 276 | bool CoinStatsIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip) |
| 277 | { |