@@ -510,6 +510,9 @@ namespace eosio { namespace chain {
510
510
else
511
511
head = {};
512
512
}
513
+
514
+ static std::optional<block_log_preamble> extract_block_log_preamble (const std::filesystem::path& block_dir,
515
+ const std::filesystem::path& retained_dir);
513
516
}; // block_log_impl
514
517
515
518
// / Would remove pre-existing block log and index, never write blocks into disk.
@@ -1459,8 +1462,8 @@ namespace eosio { namespace chain {
1459
1462
}
1460
1463
1461
1464
// static
1462
- std::optional<block_log::chain_context> block_log::extract_chain_context (const std::filesystem::path& block_dir,
1463
- const std::filesystem::path& retained_dir) {
1465
+ std::optional<block_log_preamble> detail::block_log_impl::extract_block_log_preamble (const std::filesystem::path& block_dir,
1466
+ const std::filesystem::path& retained_dir) {
1464
1467
std::filesystem::path first_block_file;
1465
1468
if (!retained_dir.empty () && std::filesystem::exists (retained_dir)) {
1466
1469
for_each_file_in_dir_matches (retained_dir, R"( blocks-1-\d+\.log)" ,
@@ -1474,9 +1477,9 @@ namespace eosio { namespace chain {
1474
1477
}
1475
1478
1476
1479
if (!first_block_file.empty ()) {
1477
- return block_log_data (first_block_file).get_preamble (). chain_context ;
1480
+ return block_log_data (first_block_file).get_preamble ();
1478
1481
}
1479
-
1482
+
1480
1483
if (!retained_dir.empty () && std::filesystem::exists (retained_dir)) {
1481
1484
const std::regex my_filter (R"( blocks-\d+-\d+\.log)" );
1482
1485
std::smatch what;
@@ -1489,12 +1492,22 @@ namespace eosio { namespace chain {
1489
1492
std::string file = p->path ().filename ().string ();
1490
1493
if (!std::regex_match (file, what, my_filter))
1491
1494
continue ;
1492
- return block_log_data (p->path ()).chain_id ();
1495
+ return block_log_data (p->path ()).get_preamble ();
1493
1496
}
1494
1497
}
1495
1498
return {};
1496
1499
}
1497
1500
1501
+ // static
1502
+ std::optional<block_log::chain_context> block_log::extract_chain_context (const std::filesystem::path& block_dir,
1503
+ const std::filesystem::path& retained_dir) {
1504
+ auto preamble = detail::block_log_impl::extract_block_log_preamble (block_dir, retained_dir);
1505
+ if (preamble) {
1506
+ return preamble->chain_context ;
1507
+ }
1508
+ return {};
1509
+ }
1510
+
1498
1511
// static
1499
1512
std::optional<genesis_state> block_log::extract_genesis_state (const std::filesystem::path& block_dir,
1500
1513
const std::filesystem::path& retained_dir) {
@@ -1516,6 +1529,16 @@ namespace eosio { namespace chain {
1516
1529
} , *context);
1517
1530
}
1518
1531
1532
+ // static
1533
+ uint32_t block_log::extract_first_block_num (const std::filesystem::path& block_dir,
1534
+ const std::filesystem::path& retained_dir) {
1535
+ auto preamble = detail::block_log_impl::extract_block_log_preamble (block_dir, retained_dir);
1536
+ if (preamble) {
1537
+ return preamble->first_block_num ;
1538
+ }
1539
+ return 0 ;
1540
+ }
1541
+
1519
1542
// static
1520
1543
bool block_log::contains_genesis_state (uint32_t version, uint32_t first_block_num) {
1521
1544
return version < genesis_state_or_chain_id_version || first_block_num == 1 ;
0 commit comments