Skip to content

Commit c0c1e38

Browse files
committed
Testchains: Generic selection with -chain=<str> in addition of -testnet and -regtest
1 parent 56515c3 commit c0c1e38

File tree

7 files changed

+14
-11
lines changed

7 files changed

+14
-11
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static int AppInitRPC(int argc, char* argv[])
129129
fprintf(stderr, "Error reading configuration file: %s\n", error.c_str());
130130
return EXIT_FAILURE;
131131
}
132-
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
132+
// Check for -chain, -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
133133
try {
134134
SelectBaseParams(gArgs.GetChainName());
135135
} catch (const std::exception& e) {

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int AppInitRawTx(int argc, char* argv[])
8686
return EXIT_FAILURE;
8787
}
8888

89-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
89+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
9090
try {
9191
SelectParams(gArgs.GetChainName());
9292
} catch (const std::exception& e) {

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static bool AppInit(int argc, char* argv[])
9898
fprintf(stderr, "Error reading configuration file: %s\n", error.c_str());
9999
return false;
100100
}
101-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
101+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
102102
try {
103103
SelectParams(gArgs.GetChainName());
104104
} catch (const std::exception& e) {

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const std::string CBaseChainParams::REGTEST = "regtest";
1717

1818
void SetupChainParamsBaseOptions()
1919
{
20+
gArgs.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, testnet, regtest", false, OptionsCategory::CHAINPARAMS);
2021
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
2122
"This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS);
2223
gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS);

src/qt/bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ int main(int argc, char *argv[])
654654
// - QSettings() will use the new application name after this, resulting in network-specific settings
655655
// - Needs to be done before createOptionsModel
656656

657-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
657+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
658658
try {
659659
node->selectParams(gArgs.GetChainName());
660660
} catch(std::exception &e) {

src/qt/guiutil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
562562
// Start client minimized
563563
QString strArgs = "-min";
564564
// Set -testnet /-regtest options
565-
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));
565+
strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName()));
566566

567567
#ifdef UNICODE
568568
boost::scoped_array<TCHAR> args(new TCHAR[strArgs.length() + 1]);
@@ -672,7 +672,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
672672
optionFile << "Name=Bitcoin\n";
673673
else
674674
optionFile << strprintf("Name=Bitcoin (%s)\n", chain);
675-
optionFile << "Exec=" << pszExePath << strprintf(" -min -testnet=%d -regtest=%d\n", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false));
675+
optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain);
676676
optionFile << "Terminal=false\n";
677677
optionFile << "Hidden=false\n";
678678
optionFile.close();

src/util.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,16 +961,18 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
961961

962962
std::string ArgsManager::GetChainName() const
963963
{
964-
bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest");
965-
bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet");
964+
const bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest");
965+
const bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet");
966+
const bool is_chain_arg_set = IsArgSet("-chain");
966967

967-
if (fTestNet && fRegTest)
968-
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
968+
if ((int)is_chain_arg_set + (int)fRegTest + (int)fTestNet > 1) {
969+
throw std::runtime_error("Invalid combination of -regtest, -testnet and -chain. Can use at most one.");
970+
}
969971
if (fRegTest)
970972
return CBaseChainParams::REGTEST;
971973
if (fTestNet)
972974
return CBaseChainParams::TESTNET;
973-
return CBaseChainParams::MAIN;
975+
return GetArg("-chain", CBaseChainParams::MAIN);
974976
}
975977

976978
#ifndef WIN32

0 commit comments

Comments
 (0)