diff --git a/blockfiles.c b/blockfiles.c index aa73a72..0383107 100644 --- a/blockfiles.c +++ b/blockfiles.c @@ -21,8 +21,7 @@ static void add_name(char ***names_p, unsigned int num, char *name) (*names_p)[num] = name; } -char **block_filenames(tal_t *ctx, const char *path, bool testnet3) -{ +char **block_filenames(tal_t *ctx, const char *path, enum networks network){ char **names = tal_arr(ctx, char *, 0); char *tmp_ctx = tal_arr(ctx, char, 0); DIR *dir; @@ -38,8 +37,10 @@ char **block_filenames(tal_t *ctx, const char *path, bool testnet3) } base = path_join(tmp_ctx, base, ".bitcoin"); - if (testnet3) + if (network == TESTNET3) base = path_join(tmp_ctx, base, "testnet3"); + if (network == REGTEST) + base = path_join(tmp_ctx, base, "regtest"); /* First try new-style: $HOME/.bitcoin/blocks/blk[0-9]*.dat. */ path = path_join(tmp_ctx, base, "blocks"); diff --git a/blockfiles.h b/blockfiles.h index 5b5aff5..febc8c1 100644 --- a/blockfiles.h +++ b/blockfiles.h @@ -1,4 +1,10 @@ #include +enum networks { + MAIN, + TESTNET3, + REGTEST +}; + /* Return a tal_array of filenames. */ -char **block_filenames(tal_t *ctx, const char *base, bool testnet3); +char **block_filenames(tal_t *ctx, const char *base, enum networks network); \ No newline at end of file diff --git a/iterate.c b/iterate.c index f96417f..16d05a9 100644 --- a/iterate.c +++ b/iterate.c @@ -835,10 +835,12 @@ int main(int argc, char *argv[]) struct space space; size_t num_misses = 0; bool use_testnet = false; + bool use_regtest = false; u32 netmarker; u8 tip[SHA256_DIGEST_LENGTH] = { 0 }, start_hash[SHA256_DIGEST_LENGTH] = { 0 }; unsigned int utxo_period = 144; + enum networks network = MAIN; err_set_progname(argv[0]); opt_register_noarg("-h|--help", opt_usage_and_exit, @@ -920,6 +922,8 @@ int main(int argc, char *argv[]) "Don't output progress information"); opt_register_noarg("--testnet|-t", opt_set_bool, &use_testnet, "Look for testnet3 blocks"); + opt_register_noarg("--regtest|-r", opt_set_bool, &use_regtest, + "Look for regtest blocks"); opt_register_arg("--blockdir", opt_set_charp, NULL, &blockdir, "Block directory instead of ~/.bitcoin/[testnet3/]blocks"); opt_register_arg("--end-hash", opt_set_hash, NULL, tip, @@ -939,11 +943,17 @@ int main(int argc, char *argv[]) if (use_testnet) { netmarker = 0x0709110B; + network = TESTNET3; + + } else if (use_regtest) { + netmarker = 0xDAB5BFFA; + network = REGTEST; } else { netmarker = 0xD9B4BEF9; + network = MAIN; } - block_fnames = block_filenames(tal_ctx, blockdir, use_testnet); + block_fnames = block_filenames(tal_ctx, blockdir, network); if (cachedir && tal_count(block_fnames)) { size_t last = tal_count(block_fnames) - 1;