| 355 | |
| 356 | |
| 357 | string DbCacheToString(CBlockIndexDB &cache) { |
| 358 | std::shared_ptr<leveldb::Iterator> pCursor(cache.NewIterator()); |
| 359 | const std::string &prefix = dbk::GetKeyPrefix(dbk::BLOCK_INDEX); |
| 360 | string str; |
| 361 | for (pCursor->Seek(prefix); pCursor->Valid(); pCursor->Next()) { |
| 362 | boost::this_thread::interruption_point(); |
| 363 | try { |
| 364 | leveldb::Slice slKey = pCursor->key(); |
| 365 | if (slKey.starts_with(prefix)) { |
| 366 | leveldb::Slice slValue = pCursor->value(); |
| 367 | CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION); |
| 368 | CDiskBlockIndex diskIndex; |
| 369 | ssValue >> diskIndex; |
| 370 | uint256 hash; |
| 371 | ParseDbKey(slKey, dbk::BLOCK_INDEX, hash); |
| 372 | str += strprintf("{%s}={%s},\n", hash.ToString(), diskIndex.ToString()); |
| 373 | |
| 374 | } else { |
| 375 | break; // if shutdown requested or finished loading block index |
| 376 | } |
| 377 | } catch (const std::exception &e) { |
| 378 | throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Deserialize or I/O error - %s", e.what())); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return strprintf("-->%s, data={%s}\n", prefix, str); |
| 383 | } |
| 384 | |
| 385 | template<int32_t PREFIX_TYPE, typename KeyType, typename ValueType> |
| 386 | string DbCacheToString(CCompositeKVCache<PREFIX_TYPE, KeyType, ValueType> &cache) { |
no test coverage detected