Skip to content

Commit

Permalink
Move ChainNameFromCommandLine into ArgsManager, rename to GetChainName
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtowns authored and random-zebra committed Apr 19, 2021
1 parent 1ea7ce6 commit 0ab3e99
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 25 deletions.
14 changes: 0 additions & 14 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,3 @@ void SelectBaseParams(const std::string& chain)
{
globalChainBaseParams = CreateBaseChainParams(chain);
}

std::string ChainNameFromCommandLine()
{
bool fRegTest = gArgs.GetBoolArg("-regtest", false);
bool fTestNet = gArgs.GetBoolArg("-testnet", false);

if (fTestNet && fRegTest)
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
if (fRegTest)
return CBaseChainParams::REGTEST;
if (fTestNet)
return CBaseChainParams::TESTNET;
return CBaseChainParams::MAIN;
}
10 changes: 5 additions & 5 deletions src/chainparamsbase.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) 2014 The Bitcoin developers
// Copyright (c) 2017-2020 The PIVX developers
// Copyright (c) 2014-2021 The Bitcoin developers
// Copyright (c) 2017-2021 The PIVX developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_CHAINPARAMSBASE_H
#define BITCOIN_CHAINPARAMSBASE_H
#ifndef PIVX_CHAINPARAMSBASE_H
#define PIVX_CHAINPARAMSBASE_H

#include <memory>
#include <string>
Expand Down Expand Up @@ -62,4 +62,4 @@ void SelectBaseParams(const std::string& chain);
*/
std::string ChainNameFromCommandLine();

#endif // BITCOIN_CHAINPARAMSBASE_H
#endif // PIVX_CHAINPARAMSBASE_H
2 changes: 1 addition & 1 deletion src/pivx-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static bool AppInitRPC(int argc, char* argv[])
}
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
try {
SelectBaseParams(ChainNameFromCommandLine());
SelectBaseParams(gArgs.GetChainName());
} catch(const std::exception& e) {
fprintf(stderr, "Error: %s\n", e.what());
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/pivx-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static bool AppInitRawTx(int argc, char* argv[])

// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
try {
SelectParams(ChainNameFromCommandLine());
SelectParams(gArgs.GetChainName());
} catch(const std::exception& e) {
fprintf(stderr, "Error: %s\n", e.what());
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/pivxd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool AppInit(int argc, char* argv[])
}
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
try {
SelectParams(ChainNameFromCommandLine());
SelectParams(gArgs.GetChainName());
} catch(const std::exception& e) {
fprintf(stderr, "Error: %s\n", e.what());
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,10 @@ bool DHMSTableWidgetItem::operator<(QTableWidgetItem const& item) const
#ifdef WIN32
fs::path static StartupShortcutPath()
{
if (gArgs.GetBoolArg("-testnet", false))
std::string chain = gArgs.GetChainName();
if (chain == CBaseChainParams::TESTNET)
return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX (testnet).lnk";
else if (gArgs.GetBoolArg("-regtest", false))
else if (chain == CBaseChainParams::REGTEST)
return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX (regtest).lnk";

return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX.lnk";
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ int main(int argc, char* argv[])

// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
try {
SelectParams(ChainNameFromCommandLine());
SelectParams(gArgs.GetChainName());
} catch(const std::exception& e) {
QMessageBox::critical(0, QObject::tr("PIVX Core"), QObject::tr("Error: %1").arg(e.what()));
return 1;
Expand Down
14 changes: 14 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,20 @@ fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific)
return fs::absolute(path, GetDataDir(net_specific));
}

std::string ArgsManager::GetChainName() const
{
bool fRegTest = GetBoolArg("-regtest", false);
bool fTestNet = GetBoolArg("-testnet", false);

if (fTestNet && fRegTest)
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
if (fRegTest)
return CBaseChainParams::REGTEST;
if (fTestNet)
return CBaseChainParams::TESTNET;
return CBaseChainParams::MAIN;
}

#ifndef WIN32
fs::path GetPidFile()
{
Expand Down
6 changes: 6 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ class ArgsManager
// Forces a arg setting, used only in testing
void ForceSetArg(const std::string& strArg, const std::string& strValue);

/**
* Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
* @return CBaseChainParams::MAIN by default; raises runtime error if an invalid combination is given.
*/
std::string GetChainName() const;

private:

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

0 comments on commit 0ab3e99

Please sign in to comment.