Skip to content

Commit bfceb4c

Browse files
committed
Add regtest support to bitcoin-chainstate tool
Adds -regtest flag to enable testing with regtest chain parameters.
1 parent d5c8199 commit bfceb4c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/bitcoin-chainstate.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,18 @@ class TestKernelNotifications : public KernelNotifications
131131
int main(int argc, char* argv[])
132132
{
133133
// SETUP: Argument parsing and handling
134-
if (argc != 2) {
134+
const bool has_regtest_flag{argc == 3 && std::string(argv[1]) == "-regtest"};
135+
if (argc < 2 || argc > 3 || (argc == 3 && !has_regtest_flag)) {
135136
std::cerr
136-
<< "Usage: " << argv[0] << " DATADIR" << std::endl
137+
<< "Usage: " << argv[0] << " [-regtest] DATADIR" << std::endl
137138
<< "Display DATADIR information, and process hex-encoded blocks on standard input." << std::endl
139+
<< "Uses mainnet parameters by default, regtest with -regtest flag" << std::endl
138140
<< std::endl
139141
<< "IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING ONLY, AND EXPECTED TO" << std::endl
140142
<< " BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR ACTUAL DATADIR." << std::endl;
141143
return 1;
142144
}
143-
std::filesystem::path abs_datadir{std::filesystem::absolute(argv[1])};
145+
std::filesystem::path abs_datadir{std::filesystem::absolute(argv[argc-1])};
144146
std::filesystem::create_directories(abs_datadir);
145147

146148
btck_LoggingOptions logging_options = {
@@ -156,7 +158,7 @@ int main(int argc, char* argv[])
156158
Logger logger{std::make_unique<KernelLog>()};
157159

158160
ContextOptions options{};
159-
ChainParams params{ChainType::MAINNET};
161+
ChainParams params{has_regtest_flag ? ChainType::REGTEST : ChainType::MAINNET};
160162
options.SetChainParams(params);
161163

162164
options.SetNotifications(std::make_shared<TestKernelNotifications>());

0 commit comments

Comments
 (0)