Skip to content

Commit

Permalink
Add regtest support
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbondi authored and rustyrussell committed Jun 14, 2019
1 parent f6e1196 commit 5e82b67
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 4 additions & 3 deletions blockfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
8 changes: 7 additions & 1 deletion blockfiles.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <ccan/tal/tal.h>

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);
12 changes: 11 additions & 1 deletion iterate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit 5e82b67

Please sign in to comment.