mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
Move ChainNameFromCommandLine into ArgsManager and rename to GetChainName
This commit is contained in:
parent
5f0c6a7b0e
commit
11b6b5b86e
@ -114,7 +114,7 @@ static int 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 EXIT_FAILURE;
|
||||
|
@ -44,7 +44,7 @@ static int 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 EXIT_FAILURE;
|
||||
|
@ -111,7 +111,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;
|
||||
|
@ -49,17 +49,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;
|
||||
}
|
||||
|
@ -54,10 +54,4 @@ const CBaseChainParams& BaseParams();
|
||||
/** Sets the params returned by Params() to those for the given network. */
|
||||
void SelectBaseParams(const std::string& chain);
|
||||
|
||||
/**
|
||||
* Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
|
||||
* @return CBaseChainParams::MAX_NETWORK_TYPES if an invalid combination is given. CBaseChainParams::MAIN by default.
|
||||
*/
|
||||
std::string ChainNameFromCommandLine();
|
||||
|
||||
#endif // BITCOIN_CHAINPARAMSBASE_H
|
||||
|
@ -630,7 +630,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
|
||||
try {
|
||||
node->selectParams(ChainNameFromCommandLine());
|
||||
node->selectParams(gArgs.GetChainName());
|
||||
} catch(std::exception &e) {
|
||||
QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what()));
|
||||
return EXIT_FAILURE;
|
||||
|
@ -599,7 +599,7 @@ TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer(QTableView* t
|
||||
#ifdef WIN32
|
||||
fs::path static StartupShortcutPath()
|
||||
{
|
||||
std::string chain = ChainNameFromCommandLine();
|
||||
std::string chain = gArgs.GetChainName();
|
||||
if (chain == CBaseChainParams::MAIN)
|
||||
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk";
|
||||
if (chain == CBaseChainParams::TESTNET) // Remove this special case when CBaseChainParams::TESTNET = "testnet4"
|
||||
@ -697,7 +697,7 @@ fs::path static GetAutostartDir()
|
||||
|
||||
fs::path static GetAutostartFilePath()
|
||||
{
|
||||
std::string chain = ChainNameFromCommandLine();
|
||||
std::string chain = gArgs.GetChainName();
|
||||
if (chain == CBaseChainParams::MAIN)
|
||||
return GetAutostartDir() / "bitcoin.desktop";
|
||||
return GetAutostartDir() / strprintf("bitcoin-%s.lnk", chain);
|
||||
@ -739,7 +739,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
||||
fs::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out|std::ios_base::trunc);
|
||||
if (!optionFile.good())
|
||||
return false;
|
||||
std::string chain = ChainNameFromCommandLine();
|
||||
std::string chain = gArgs.GetChainName();
|
||||
// Write a bitcoin.desktop file to the autostart directory:
|
||||
optionFile << "[Desktop Entry]\n";
|
||||
optionFile << "Type=Application\n";
|
||||
|
14
src/util.cpp
14
src/util.cpp
@ -764,6 +764,20 @@ void ArgsManager::ReadConfigFile(const std::string& confPath)
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
@ -306,6 +306,12 @@ public:
|
||||
// been set. Also called directly 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.
|
||||
|
Loading…
Reference in New Issue
Block a user