Skip to content

Commit 11b6b5b

Browse files
committed
Move ChainNameFromCommandLine into ArgsManager and rename to GetChainName
1 parent 5f0c6a7 commit 11b6b5b

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int AppInitRPC(int argc, char* argv[])
114114
}
115115
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
116116
try {
117-
SelectBaseParams(ChainNameFromCommandLine());
117+
SelectBaseParams(gArgs.GetChainName());
118118
} catch (const std::exception& e) {
119119
fprintf(stderr, "Error: %s\n", e.what());
120120
return EXIT_FAILURE;

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int AppInitRawTx(int argc, char* argv[])
4444

4545
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
4646
try {
47-
SelectParams(ChainNameFromCommandLine());
47+
SelectParams(gArgs.GetChainName());
4848
} catch (const std::exception& e) {
4949
fprintf(stderr, "Error: %s\n", e.what());
5050
return EXIT_FAILURE;

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ bool AppInit(int argc, char* argv[])
111111
}
112112
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
113113
try {
114-
SelectParams(ChainNameFromCommandLine());
114+
SelectParams(gArgs.GetChainName());
115115
} catch (const std::exception& e) {
116116
fprintf(stderr, "Error: %s\n", e.what());
117117
return false;

src/chainparamsbase.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,3 @@ void SelectBaseParams(const std::string& chain)
4949
{
5050
globalChainBaseParams = CreateBaseChainParams(chain);
5151
}
52-
53-
std::string ChainNameFromCommandLine()
54-
{
55-
bool fRegTest = gArgs.GetBoolArg("-regtest", false);
56-
bool fTestNet = gArgs.GetBoolArg("-testnet", false);
57-
58-
if (fTestNet && fRegTest)
59-
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
60-
if (fRegTest)
61-
return CBaseChainParams::REGTEST;
62-
if (fTestNet)
63-
return CBaseChainParams::TESTNET;
64-
return CBaseChainParams::MAIN;
65-
}

src/chainparamsbase.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,4 @@ const CBaseChainParams& BaseParams();
5454
/** Sets the params returned by Params() to those for the given network. */
5555
void SelectBaseParams(const std::string& chain);
5656

57-
/**
58-
* Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
59-
* @return CBaseChainParams::MAX_NETWORK_TYPES if an invalid combination is given. CBaseChainParams::MAIN by default.
60-
*/
61-
std::string ChainNameFromCommandLine();
62-
6357
#endif // BITCOIN_CHAINPARAMSBASE_H

src/qt/bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ int main(int argc, char *argv[])
630630

631631
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
632632
try {
633-
node->selectParams(ChainNameFromCommandLine());
633+
node->selectParams(gArgs.GetChainName());
634634
} catch(std::exception &e) {
635635
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what()));
636636
return EXIT_FAILURE;

src/qt/guiutil.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer(QTableView* t
599599
#ifdef WIN32
600600
fs::path static StartupShortcutPath()
601601
{
602-
std::string chain = ChainNameFromCommandLine();
602+
std::string chain = gArgs.GetChainName();
603603
if (chain == CBaseChainParams::MAIN)
604604
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk";
605605
if (chain == CBaseChainParams::TESTNET) // Remove this special case when CBaseChainParams::TESTNET = "testnet4"
@@ -697,7 +697,7 @@ fs::path static GetAutostartDir()
697697

698698
fs::path static GetAutostartFilePath()
699699
{
700-
std::string chain = ChainNameFromCommandLine();
700+
std::string chain = gArgs.GetChainName();
701701
if (chain == CBaseChainParams::MAIN)
702702
return GetAutostartDir() / "bitcoin.desktop";
703703
return GetAutostartDir() / strprintf("bitcoin-%s.lnk", chain);
@@ -739,7 +739,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
739739
fs::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out|std::ios_base::trunc);
740740
if (!optionFile.good())
741741
return false;
742-
std::string chain = ChainNameFromCommandLine();
742+
std::string chain = gArgs.GetChainName();
743743
// Write a bitcoin.desktop file to the autostart directory:
744744
optionFile << "[Desktop Entry]\n";
745745
optionFile << "Type=Application\n";

src/util.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,20 @@ void ArgsManager::ReadConfigFile(const std::string& confPath)
764764
}
765765
}
766766

767+
std::string ArgsManager::GetChainName() const
768+
{
769+
bool fRegTest = GetBoolArg("-regtest", false);
770+
bool fTestNet = GetBoolArg("-testnet", false);
771+
772+
if (fTestNet && fRegTest)
773+
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
774+
if (fRegTest)
775+
return CBaseChainParams::REGTEST;
776+
if (fTestNet)
777+
return CBaseChainParams::TESTNET;
778+
return CBaseChainParams::MAIN;
779+
}
780+
767781
#ifndef WIN32
768782
fs::path GetPidFile()
769783
{

src/util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ class ArgsManager
306306
// been set. Also called directly in testing.
307307
void ForceSetArg(const std::string& strArg, const std::string& strValue);
308308

309+
/**
310+
* Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
311+
* @return CBaseChainParams::MAIN by default; raises runtime error if an invalid combination is given.
312+
*/
313+
std::string GetChainName() const;
314+
309315
private:
310316

311317
// Munge -nofoo into -foo=0 and track the value as negated.

0 commit comments

Comments
 (0)