Skip to content

Commit 3431977

Browse files
jtimonfurszy
authored andcommitted
Chainparams: Translations: DRY: options and error strings Also remove SelectBaseParamsFromCommandLine and SelectParamsFromCommandLin
1 parent ce7a792 commit 3431977

File tree

10 files changed

+36
-53
lines changed

10 files changed

+36
-53
lines changed

src/chainparams.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -525,16 +525,6 @@ void SelectParams(const std::string& network)
525525
pCurrentParams = &Params(network);
526526
}
527527

528-
bool SelectParamsFromCommandLine()
529-
{
530-
std::string network = ChainNameFromCommandLine();
531-
if (network == CBaseChainParams::MAX_NETWORK_TYPES)
532-
return false;
533-
534-
SelectParams(network);
535-
return true;
536-
}
537-
538528
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight)
539529
{
540530
regTestParams.UpdateNetworkUpgradeParameters(idx, nActivationHeight);

src/chainparams.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ CChainParams& Params(const std::string& chain);
116116
*/
117117
void SelectParams(const std::string& chain);
118118

119-
120-
/**
121-
* Looks for -regtest or -testnet and then calls SelectParams as appropriate.
122-
* Returns false if an invalid combination is given.
123-
*/
124-
bool SelectParamsFromCommandLine();
125-
126119
/**
127120
* Allows modifying the network upgrade regtest parameters.
128121
*/

src/chainparamsbase.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414
const std::string CBaseChainParams::MAIN = "main";
1515
const std::string CBaseChainParams::TESTNET = "test";
1616
const std::string CBaseChainParams::REGTEST = "regtest";
17-
const std::string CBaseChainParams::MAX_NETWORK_TYPES = "unknown_chain";
17+
18+
void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
19+
{
20+
strUsage += HelpMessageGroup(_("Chain selection options:"));
21+
strUsage += HelpMessageOpt("-testnet", _("Use the test chain"));
22+
if (debugHelp) {
23+
strUsage += HelpMessageOpt("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
24+
"This is intended for regression testing tools and app development.");
25+
}
26+
}
1827

1928
/**
2029
* Main network
@@ -95,14 +104,3 @@ std::string ChainNameFromCommandLine()
95104
return CBaseChainParams::TESTNET;
96105
return CBaseChainParams::MAIN;
97106
}
98-
99-
bool SelectBaseParamsFromCommandLine()
100-
{
101-
std::string network = ChainNameFromCommandLine();
102-
if (network == CBaseChainParams::MAX_NETWORK_TYPES)
103-
return false;
104-
105-
SelectBaseParams(network);
106-
return true;
107-
}
108-

src/chainparamsbase.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class CBaseChainParams
2020
static const std::string MAIN;
2121
static const std::string TESTNET;
2222
static const std::string REGTEST;
23-
static const std::string MAX_NETWORK_TYPES;
2423

2524
const std::string& DataDir() const { return strDataDir; }
2625
int RPCPort() const { return nRPCPort; }
@@ -32,6 +31,12 @@ class CBaseChainParams
3231
std::string strDataDir;
3332
};
3433

34+
/**
35+
* Append the help messages for the chainparams options to the
36+
* parameter string.
37+
*/
38+
void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp=true);
39+
3540
/**
3641
* Return the currently selected parameters. This won't change after app startup
3742
* startup, except for unit tests.
@@ -49,10 +54,4 @@ void SelectBaseParams(const std::string& chain);
4954
*/
5055
std::string ChainNameFromCommandLine();
5156

52-
/**
53-
* Calls NetworkIdFromCommandLine() and then calls SelectParams as appropriate.
54-
* Returns false if an invalid combination is given.
55-
*/
56-
bool SelectBaseParamsFromCommandLine();
57-
5857
#endif // BITCOIN_CHAINPARAMSBASE_H

src/dbwrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class CDBIterator
145145
try {
146146
CDataStream ssKey(slKey.data(), slKey.data() + slKey.size(), SER_DISK, CLIENT_VERSION);
147147
ssKey >> key;
148-
} catch(std::exception &e) {
148+
} catch(const std::exception& e) {
149149
return false;
150150
}
151151
return true;
@@ -160,7 +160,7 @@ class CDBIterator
160160
try {
161161
CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION);
162162
ssValue >> value;
163-
} catch(std::exception &e) {
163+
} catch(const std::exception& e) {
164164
return false;
165165
}
166166
return true;

src/init.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,9 @@ std::string HelpMessage(HelpMessageMode mode)
523523
strUsage += HelpMessageOpt("-printtoconsole", strprintf(_("Send trace/debug info to console instead of debug.log file (default: %u)"), 0));
524524
if (showDebug) {
525525
strUsage += HelpMessageOpt("-printpriority", strprintf(_("Log transaction priority and fee per kB when mining blocks (default: %u)"), DEFAULT_PRINTPRIORITY));
526-
strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + " " +
527-
_("This is intended for regression testing tools and app development.") + " " +
528-
_("In this mode -genproclimit controls how many blocks are generated immediately."));
529526
}
530527
strUsage += HelpMessageOpt("-shrinkdebugfile", _("Shrink debug.log file on client startup (default: 1 when no -debug)"));
531-
strUsage += HelpMessageOpt("-testnet", _("Use the test network"));
528+
AppendParamsHelpMessages(strUsage, showDebug);
532529
strUsage += HelpMessageOpt("-litemode=<n>", strprintf(_("Disable all PIVX specific functionality (Masternodes, Budgeting) (0-1, default: %u)"), 0));
533530

534531
strUsage += HelpMessageGroup(_("Masternode options:"));

src/pivx-cli.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ std::string HelpMessageCli()
3232
strUsage += HelpMessageOpt("-?", _("This help message"));
3333
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), PIVX_CONF_FILENAME));
3434
strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory"));
35-
strUsage += HelpMessageOpt("-testnet", _("Use the test network"));
36-
strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be "
37-
"solved instantly. This is intended for regression testing tools and app development."));
35+
AppendParamsHelpMessages(strUsage);
3836
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), DEFAULT_RPCCONNECT));
3937
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), 51473, 51475));
4038
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
@@ -93,8 +91,10 @@ static bool AppInitRPC(int argc, char* argv[])
9391
return false;
9492
}
9593
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
96-
if (!SelectBaseParamsFromCommandLine()) {
97-
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
94+
try {
95+
SelectBaseParams(ChainNameFromCommandLine());
96+
} catch(const std::exception& e) {
97+
fprintf(stderr, "Error: %s\n", e.what());
9898
return false;
9999
}
100100
if (gArgs.GetBoolArg("-rpcssl", false))

src/pivx-tx.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ static bool AppInitRawTx(int argc, char* argv[])
3333
gArgs.ParseParameters(argc, argv);
3434

3535
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
36-
if (!SelectParamsFromCommandLine()) {
37-
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
36+
try {
37+
SelectParams(ChainNameFromCommandLine());
38+
} catch(const std::exception& e) {
39+
fprintf(stderr, "Error: %s\n", e.what());
3840
return false;
3941
}
4042

src/pivxd.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ bool AppInit(int argc, char* argv[])
8888
return false;
8989
}
9090
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
91-
if (!SelectParamsFromCommandLine()) {
92-
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
91+
try {
92+
SelectParams(ChainNameFromCommandLine());
93+
} catch(const std::exception& e) {
94+
fprintf(stderr, "Error: %s\n", e.what());
9395
return false;
9496
}
9597

src/qt/pivx.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,10 @@ int main(int argc, char* argv[])
619619
// - Needs to be done before createOptionsModel
620620

621621
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
622-
if (!SelectParamsFromCommandLine()) {
623-
QMessageBox::critical(0, QObject::tr("PIVX Core"), QObject::tr("Error: Invalid combination of -regtest and -testnet."));
622+
try {
623+
SelectParams(ChainNameFromCommandLine());
624+
} catch(const std::exception& e) {
625+
QMessageBox::critical(0, QObject::tr("PIVX Core"), QObject::tr("Error: %1").arg(e.what()));
624626
return 1;
625627
}
626628
#ifdef ENABLE_WALLET

0 commit comments

Comments
 (0)