Skip to content

Commit 0ab3e99

Browse files
ajtownsrandom-zebra
authored andcommitted
Move ChainNameFromCommandLine into ArgsManager, rename to GetChainName
1 parent 1ea7ce6 commit 0ab3e99

File tree

9 files changed

+32
-25
lines changed

9 files changed

+32
-25
lines changed

src/chainparamsbase.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,3 @@ void SelectBaseParams(const std::string& chain)
8787
{
8888
globalChainBaseParams = CreateBaseChainParams(chain);
8989
}
90-
91-
std::string ChainNameFromCommandLine()
92-
{
93-
bool fRegTest = gArgs.GetBoolArg("-regtest", false);
94-
bool fTestNet = gArgs.GetBoolArg("-testnet", false);
95-
96-
if (fTestNet && fRegTest)
97-
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
98-
if (fRegTest)
99-
return CBaseChainParams::REGTEST;
100-
if (fTestNet)
101-
return CBaseChainParams::TESTNET;
102-
return CBaseChainParams::MAIN;
103-
}

src/chainparamsbase.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright (c) 2014 The Bitcoin developers
2-
// Copyright (c) 2017-2020 The PIVX developers
1+
// Copyright (c) 2014-2021 The Bitcoin developers
2+
// Copyright (c) 2017-2021 The PIVX developers
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6-
#ifndef BITCOIN_CHAINPARAMSBASE_H
7-
#define BITCOIN_CHAINPARAMSBASE_H
6+
#ifndef PIVX_CHAINPARAMSBASE_H
7+
#define PIVX_CHAINPARAMSBASE_H
88

99
#include <memory>
1010
#include <string>
@@ -62,4 +62,4 @@ void SelectBaseParams(const std::string& chain);
6262
*/
6363
std::string ChainNameFromCommandLine();
6464

65-
#endif // BITCOIN_CHAINPARAMSBASE_H
65+
#endif // PIVX_CHAINPARAMSBASE_H

src/pivx-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static bool AppInitRPC(int argc, char* argv[])
9494
}
9595
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
9696
try {
97-
SelectBaseParams(ChainNameFromCommandLine());
97+
SelectBaseParams(gArgs.GetChainName());
9898
} catch(const std::exception& e) {
9999
fprintf(stderr, "Error: %s\n", e.what());
100100
return false;

src/pivx-tx.cpp

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

3535
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
3636
try {
37-
SelectParams(ChainNameFromCommandLine());
37+
SelectParams(gArgs.GetChainName());
3838
} catch(const std::exception& e) {
3939
fprintf(stderr, "Error: %s\n", e.what());
4040
return false;

src/pivxd.cpp

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

src/qt/guiutil.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,10 @@ bool DHMSTableWidgetItem::operator<(QTableWidgetItem const& item) const
630630
#ifdef WIN32
631631
fs::path static StartupShortcutPath()
632632
{
633-
if (gArgs.GetBoolArg("-testnet", false))
633+
std::string chain = gArgs.GetChainName();
634+
if (chain == CBaseChainParams::TESTNET)
634635
return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX (testnet).lnk";
635-
else if (gArgs.GetBoolArg("-regtest", false))
636+
else if (chain == CBaseChainParams::REGTEST)
636637
return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX (regtest).lnk";
637638

638639
return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX.lnk";

src/qt/pivx.cpp

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

624624
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
625625
try {
626-
SelectParams(ChainNameFromCommandLine());
626+
SelectParams(gArgs.GetChainName());
627627
} catch(const std::exception& e) {
628628
QMessageBox::critical(0, QObject::tr("PIVX Core"), QObject::tr("Error: %1").arg(e.what()));
629629
return 1;

src/util.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,20 @@ fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
538538
return fs::absolute(path, GetDataDir(net_specific));
539539
}
540540

541+
std::string ArgsManager::GetChainName() const
542+
{
543+
bool fRegTest = GetBoolArg("-regtest", false);
544+
bool fTestNet = GetBoolArg("-testnet", false);
545+
546+
if (fTestNet && fRegTest)
547+
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
548+
if (fRegTest)
549+
return CBaseChainParams::REGTEST;
550+
if (fTestNet)
551+
return CBaseChainParams::TESTNET;
552+
return CBaseChainParams::MAIN;
553+
}
554+
541555
#ifndef WIN32
542556
fs::path GetPidFile()
543557
{

src/util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ class ArgsManager
202202
// Forces a arg setting, used only in testing
203203
void ForceSetArg(const std::string& strArg, const std::string& strValue);
204204

205+
/**
206+
* Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
207+
* @return CBaseChainParams::MAIN by default; raises runtime error if an invalid combination is given.
208+
*/
209+
std::string GetChainName() const;
210+
205211
private:
206212

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

0 commit comments

Comments
 (0)