Chainparams: Translations: DRY: options and error strings

Also remove SelectBaseParamsFromCommandLine and SelectParamsFromCommandLine
This commit is contained in:
Jorge Timón 2015-05-25 09:00:17 +02:00 committed by Jack Grigg
parent af9b9652fa
commit bd87de60ed
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
8 changed files with 33 additions and 49 deletions

View File

@ -29,9 +29,7 @@ std::string HelpMessageCli()
strUsage += HelpMessageOpt("-?", _("This help message"));
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "zcash.conf"));
strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory"));
strUsage += HelpMessageOpt("-testnet", _("Use the test network"));
strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be "
"solved instantly. This is intended for regression testing tools and app development."));
AppendParamsHelpMessages(strUsage);
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), "127.0.0.1"));
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), 8232, 18232));
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
@ -107,8 +105,10 @@ static int AppInitRPC(int argc, char* argv[])
return EXIT_FAILURE;
}
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
if (!SelectBaseParamsFromCommandLine()) {
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
try {
SelectBaseParams(ChainNameFromCommandLine());
} catch(std::exception &e) {
fprintf(stderr, "Error: %s\n", e.what());
return EXIT_FAILURE;
}
if (GetBoolArg("-rpcssl", false))

View File

@ -38,8 +38,10 @@ static int AppInitRawTx(int argc, char* argv[])
ParseParameters(argc, argv);
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) {
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
try {
SelectParams(ChainNameFromCommandLine());
} catch(std::exception &e) {
fprintf(stderr, "Error: %s\n", e.what());
return false;
}
@ -61,8 +63,7 @@ static int AppInitRawTx(int argc, char* argv[])
strUsage += HelpMessageOpt("-create", _("Create new, empty TX."));
strUsage += HelpMessageOpt("-json", _("Select JSON output"));
strUsage += HelpMessageOpt("-txid", _("Output only the hex-encoded transaction id of the resultant transaction."));
strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly."));
strUsage += HelpMessageOpt("-testnet", _("Use the test network"));
AppendParamsHelpMessages(strUsage);
fprintf(stdout, "%s", strUsage.c_str());

View File

@ -123,8 +123,10 @@ bool AppInit(int argc, char* argv[])
return false;
}
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) {
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
try {
SelectParams(ChainNameFromCommandLine());
} catch(std::exception &e) {
fprintf(stderr, "Error: %s\n", e.what());
return false;
}

View File

@ -563,16 +563,6 @@ void SelectParams(const std::string& network)
}
}
bool SelectParamsFromCommandLine()
{
std::string network = ChainNameFromCommandLine();
if (network == CBaseChainParams::MAX_NETWORK_TYPES)
return false;
SelectParams(network);
return true;
}
// Block height must be >0 and <=last founders reward block height
// Index variable i ranges from 0 - (vFoundersRewardAddress.size()-1)

View File

@ -150,12 +150,6 @@ CChainParams& Params(const std::string& chain);
*/
void SelectParams(const std::string& chain);
/**
* Looks for -regtest or -testnet and then calls SelectParams as appropriate.
* Returns false if an invalid combination is given.
*/
bool SelectParamsFromCommandLine();
/**
* Allows modifying the network upgrade regtest parameters.
*/

View File

@ -13,7 +13,16 @@
const std::string CBaseChainParams::MAIN = "main";
const std::string CBaseChainParams::TESTNET = "test";
const std::string CBaseChainParams::REGTEST = "regtest";
const std::string CBaseChainParams::MAX_NETWORK_TYPES = "unknown_chain";
void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
{
strUsage += HelpMessageGroup(_("Chain selection options:"));
strUsage += HelpMessageOpt("-testnet", _("Use the test chain"));
if (debugHelp) {
strUsage += HelpMessageOpt("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
"This is intended for regression testing tools and app development.");
}
}
/**
* Main network
@ -95,7 +104,7 @@ std::string ChainNameFromCommandLine()
bool fTestNet = GetBoolArg("-testnet", false);
if (fTestNet && fRegTest)
return CBaseChainParams::MAX_NETWORK_TYPES;
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
if (fRegTest)
return CBaseChainParams::REGTEST;
if (fTestNet)
@ -103,16 +112,6 @@ std::string ChainNameFromCommandLine()
return CBaseChainParams::MAIN;
}
bool SelectBaseParamsFromCommandLine()
{
std::string network = ChainNameFromCommandLine();
if (network == CBaseChainParams::MAX_NETWORK_TYPES)
return false;
SelectBaseParams(network);
return true;
}
bool AreBaseParamsConfigured()
{
return pCurrentBaseParams != NULL;

View File

@ -19,7 +19,6 @@ public:
static const std::string MAIN;
static const std::string TESTNET;
static const std::string REGTEST;
static const std::string MAX_NETWORK_TYPES;
const std::string& DataDir() const { return strDataDir; }
int RPCPort() const { return nRPCPort; }
@ -31,6 +30,12 @@ protected:
std::string strDataDir;
};
/**
* Append the help messages for the chainparams options to the
* parameter string.
*/
void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp=true);
/**
* Return the currently selected parameters. This won't change after app
* startup, except for unit tests.
@ -46,12 +51,6 @@ void SelectBaseParams(const std::string& chain);
*/
std::string ChainNameFromCommandLine();
/**
* Calls NetworkIdFromCommandLine() and then calls SelectParams as appropriate.
* Returns false if an invalid combination is given.
*/
bool SelectBaseParamsFromCommandLine();
/**
* Return true if SelectBaseParamsFromCommandLine() has been called to select
* a network.

View File

@ -481,11 +481,10 @@ std::string HelpMessage(HelpMessageMode mode)
{
strUsage += HelpMessageOpt("-printpriority", strprintf("Log transaction priority and fee per kB when mining blocks (default: %u)", 0));
strUsage += HelpMessageOpt("-privdb", strprintf("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)", 1));
strUsage += HelpMessageOpt("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
"This is intended for regression testing tools and app development.");
}
// strUsage += HelpMessageOpt("-shrinkdebugfile", _("Shrink debug.log file on client startup (default: 1 when no -debug)"));
strUsage += HelpMessageOpt("-testnet", _("Use the test network"));
AppendParamsHelpMessages(strUsage, showDebug);
strUsage += HelpMessageGroup(_("Node relay options:"));
strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), 1));