mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
Merge pull request #6235
55a8975
Chainparams: Translations: DRY: options and error strings (Jorge Timón)f3525e2
Chainparams: Replace CBaseChainParams::Network enum with string constants (suggested by Wladimir) (Jorge Timón)
This commit is contained in:
commit
e26a3f6713
11 changed files with 79 additions and 90 deletions
|
@ -31,9 +31,7 @@ std::string HelpMessageCli()
|
||||||
strUsage += HelpMessageOpt("-?", _("This help message"));
|
strUsage += HelpMessageOpt("-?", _("This help message"));
|
||||||
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "bitcoin.conf"));
|
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "bitcoin.conf"));
|
||||||
strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory"));
|
strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory"));
|
||||||
strUsage += HelpMessageOpt("-testnet", _("Use the test network"));
|
AppendParamsHelpMessages(strUsage);
|
||||||
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("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), "127.0.0.1"));
|
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)"), 8332, 18332));
|
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), 8332, 18332));
|
||||||
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
|
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
|
||||||
|
@ -94,8 +92,10 @@ static bool AppInitRPC(int argc, char* argv[])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
|
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
|
||||||
if (!SelectBaseParamsFromCommandLine()) {
|
try {
|
||||||
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
|
SelectBaseParams(ChainNameFromCommandLine());
|
||||||
|
} catch(std::exception &e) {
|
||||||
|
fprintf(stderr, "Error: %s\n", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (GetBoolArg("-rpcssl", false))
|
if (GetBoolArg("-rpcssl", false))
|
||||||
|
|
|
@ -35,8 +35,10 @@ static bool AppInitRawTx(int argc, char* argv[])
|
||||||
ParseParameters(argc, argv);
|
ParseParameters(argc, argv);
|
||||||
|
|
||||||
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
|
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
|
||||||
if (!SelectParamsFromCommandLine()) {
|
try {
|
||||||
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
|
SelectParams(ChainNameFromCommandLine());
|
||||||
|
} catch(std::exception &e) {
|
||||||
|
fprintf(stderr, "Error: %s\n", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +60,7 @@ static bool AppInitRawTx(int argc, char* argv[])
|
||||||
strUsage += HelpMessageOpt("-create", _("Create new, empty TX."));
|
strUsage += HelpMessageOpt("-create", _("Create new, empty TX."));
|
||||||
strUsage += HelpMessageOpt("-json", _("Select JSON output"));
|
strUsage += HelpMessageOpt("-json", _("Select JSON output"));
|
||||||
strUsage += HelpMessageOpt("-txid", _("Output only the hex-encoded transaction id of the resultant transaction."));
|
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."));
|
AppendParamsHelpMessages(strUsage);
|
||||||
strUsage += HelpMessageOpt("-testnet", _("Use the test network"));
|
|
||||||
|
|
||||||
fprintf(stdout, "%s", strUsage.c_str());
|
fprintf(stdout, "%s", strUsage.c_str());
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,10 @@ bool AppInit(int argc, char* argv[])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
|
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
|
||||||
if (!SelectParamsFromCommandLine()) {
|
try {
|
||||||
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
|
SelectParams(ChainNameFromCommandLine());
|
||||||
|
} catch(std::exception &e) {
|
||||||
|
fprintf(stderr, "Error: %s\n", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "chainparams.h"
|
#include "chainparams.h"
|
||||||
|
|
||||||
|
#include "tinyformat.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "utilstrencodings.h"
|
#include "utilstrencodings.h"
|
||||||
|
|
||||||
|
@ -266,31 +267,20 @@ const CChainParams &Params() {
|
||||||
return *pCurrentParams;
|
return *pCurrentParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
CChainParams &Params(CBaseChainParams::Network network) {
|
CChainParams& Params(const std::string& chain)
|
||||||
switch (network) {
|
{
|
||||||
case CBaseChainParams::MAIN:
|
if (chain == CBaseChainParams::MAIN)
|
||||||
return mainParams;
|
return mainParams;
|
||||||
case CBaseChainParams::TESTNET:
|
else if (chain == CBaseChainParams::TESTNET)
|
||||||
return testNetParams;
|
return testNetParams;
|
||||||
case CBaseChainParams::REGTEST:
|
else if (chain == CBaseChainParams::REGTEST)
|
||||||
return regTestParams;
|
return regTestParams;
|
||||||
default:
|
else
|
||||||
assert(false && "Unimplemented network");
|
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||||
return mainParams;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectParams(CBaseChainParams::Network network) {
|
void SelectParams(const std::string& network)
|
||||||
|
{
|
||||||
SelectBaseParams(network);
|
SelectBaseParams(network);
|
||||||
pCurrentParams = &Params(network);
|
pCurrentParams = &Params(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SelectParamsFromCommandLine()
|
|
||||||
{
|
|
||||||
CBaseChainParams::Network network = NetworkIdFromCommandLine();
|
|
||||||
if (network == CBaseChainParams::MAX_NETWORK_TYPES)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SelectParams(network);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -105,16 +105,15 @@ protected:
|
||||||
*/
|
*/
|
||||||
const CChainParams &Params();
|
const CChainParams &Params();
|
||||||
|
|
||||||
/** Return parameters for the given network. */
|
/**
|
||||||
CChainParams &Params(CBaseChainParams::Network network);
|
* @returns CChainParams for the given BIP70 chain name.
|
||||||
|
*/
|
||||||
/** Sets the params returned by Params() to those for the given network. */
|
CChainParams& Params(const std::string& chain);
|
||||||
void SelectParams(CBaseChainParams::Network network);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks for -regtest or -testnet and then calls SelectParams as appropriate.
|
* Sets the params returned by Params() to those for the given BIP70 chain name.
|
||||||
* Returns false if an invalid combination is given.
|
* @throws std::runtime_error when the chain is not supported.
|
||||||
*/
|
*/
|
||||||
bool SelectParamsFromCommandLine();
|
void SelectParams(const std::string& chain);
|
||||||
|
|
||||||
#endif // BITCOIN_CHAINPARAMS_H
|
#endif // BITCOIN_CHAINPARAMS_H
|
||||||
|
|
|
@ -5,10 +5,25 @@
|
||||||
|
|
||||||
#include "chainparamsbase.h"
|
#include "chainparamsbase.h"
|
||||||
|
|
||||||
|
#include "tinyformat.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
const std::string CBaseChainParams::MAIN = "main";
|
||||||
|
const std::string CBaseChainParams::TESTNET = "test";
|
||||||
|
const std::string CBaseChainParams::REGTEST = "regtest";
|
||||||
|
|
||||||
|
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
|
* Main network
|
||||||
*/
|
*/
|
||||||
|
@ -71,31 +86,25 @@ const CBaseChainParams& BaseParams()
|
||||||
return *pCurrentBaseParams;
|
return *pCurrentBaseParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectBaseParams(CBaseChainParams::Network network)
|
void SelectBaseParams(const std::string& chain)
|
||||||
{
|
{
|
||||||
switch (network) {
|
if (chain == CBaseChainParams::MAIN)
|
||||||
case CBaseChainParams::MAIN:
|
|
||||||
pCurrentBaseParams = &mainParams;
|
pCurrentBaseParams = &mainParams;
|
||||||
break;
|
else if (chain == CBaseChainParams::TESTNET)
|
||||||
case CBaseChainParams::TESTNET:
|
|
||||||
pCurrentBaseParams = &testNetParams;
|
pCurrentBaseParams = &testNetParams;
|
||||||
break;
|
else if (chain == CBaseChainParams::REGTEST)
|
||||||
case CBaseChainParams::REGTEST:
|
|
||||||
pCurrentBaseParams = ®TestParams;
|
pCurrentBaseParams = ®TestParams;
|
||||||
break;
|
else
|
||||||
default:
|
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||||
assert(false && "Unimplemented network");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CBaseChainParams::Network NetworkIdFromCommandLine()
|
std::string ChainNameFromCommandLine()
|
||||||
{
|
{
|
||||||
bool fRegTest = GetBoolArg("-regtest", false);
|
bool fRegTest = GetBoolArg("-regtest", false);
|
||||||
bool fTestNet = GetBoolArg("-testnet", false);
|
bool fTestNet = GetBoolArg("-testnet", false);
|
||||||
|
|
||||||
if (fTestNet && fRegTest)
|
if (fTestNet && fRegTest)
|
||||||
return CBaseChainParams::MAX_NETWORK_TYPES;
|
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
|
||||||
if (fRegTest)
|
if (fRegTest)
|
||||||
return CBaseChainParams::REGTEST;
|
return CBaseChainParams::REGTEST;
|
||||||
if (fTestNet)
|
if (fTestNet)
|
||||||
|
@ -103,16 +112,6 @@ CBaseChainParams::Network NetworkIdFromCommandLine()
|
||||||
return CBaseChainParams::MAIN;
|
return CBaseChainParams::MAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SelectBaseParamsFromCommandLine()
|
|
||||||
{
|
|
||||||
CBaseChainParams::Network network = NetworkIdFromCommandLine();
|
|
||||||
if (network == CBaseChainParams::MAX_NETWORK_TYPES)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SelectBaseParams(network);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AreBaseParamsConfigured()
|
bool AreBaseParamsConfigured()
|
||||||
{
|
{
|
||||||
return pCurrentBaseParams != NULL;
|
return pCurrentBaseParams != NULL;
|
||||||
|
|
|
@ -15,13 +15,10 @@
|
||||||
class CBaseChainParams
|
class CBaseChainParams
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Network {
|
/** BIP70 chain name strings (main, test or regtest) */
|
||||||
MAIN,
|
static const std::string MAIN;
|
||||||
TESTNET,
|
static const std::string TESTNET;
|
||||||
REGTEST,
|
static const std::string REGTEST;
|
||||||
|
|
||||||
MAX_NETWORK_TYPES
|
|
||||||
};
|
|
||||||
|
|
||||||
const std::string& DataDir() const { return strDataDir; }
|
const std::string& DataDir() const { return strDataDir; }
|
||||||
int RPCPort() const { return nRPCPort; }
|
int RPCPort() const { return nRPCPort; }
|
||||||
|
@ -33,6 +30,12 @@ protected:
|
||||||
std::string strDataDir;
|
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
|
* Return the currently selected parameters. This won't change after app
|
||||||
* startup, except for unit tests.
|
* startup, except for unit tests.
|
||||||
|
@ -40,19 +43,13 @@ protected:
|
||||||
const CBaseChainParams& BaseParams();
|
const CBaseChainParams& BaseParams();
|
||||||
|
|
||||||
/** Sets the params returned by Params() to those for the given network. */
|
/** Sets the params returned by Params() to those for the given network. */
|
||||||
void SelectBaseParams(CBaseChainParams::Network network);
|
void SelectBaseParams(const std::string& chain);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks for -regtest or -testnet and returns the appropriate Network ID.
|
* Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
|
||||||
* Returns MAX_NETWORK_TYPES if an invalid combination is given.
|
* @return CBaseChainParams::MAX_NETWORK_TYPES if an invalid combination is given. CBaseChainParams::MAIN by default.
|
||||||
*/
|
*/
|
||||||
CBaseChainParams::Network NetworkIdFromCommandLine();
|
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
|
* Return true if SelectBaseParamsFromCommandLine() has been called to select
|
||||||
|
|
|
@ -439,11 +439,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("-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("-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("-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 += HelpMessageGroup(_("Node relay options:"));
|
||||||
if (showDebug)
|
if (showDebug)
|
||||||
|
|
|
@ -597,8 +597,10 @@ int main(int argc, char *argv[])
|
||||||
// - Needs to be done before createOptionsModel
|
// - Needs to be done before createOptionsModel
|
||||||
|
|
||||||
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
|
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
|
||||||
if (!SelectParamsFromCommandLine()) {
|
try {
|
||||||
QMessageBox::critical(0, QObject::tr("Bitcoin Core"), QObject::tr("Error: Invalid combination of -regtest and -testnet."));
|
SelectParams(ChainNameFromCommandLine());
|
||||||
|
} catch(std::exception &e) {
|
||||||
|
QMessageBox::critical(0, QObject::tr("Bitcoin Core"), QObject::tr("Error: %1").arg(e.what()));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
|
|
|
@ -32,13 +32,13 @@ CWallet* pwalletMain;
|
||||||
extern bool fPrintToConsole;
|
extern bool fPrintToConsole;
|
||||||
extern void noui_connect();
|
extern void noui_connect();
|
||||||
|
|
||||||
BasicTestingSetup::BasicTestingSetup(CBaseChainParams::Network network)
|
BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
|
||||||
{
|
{
|
||||||
ECC_Start();
|
ECC_Start();
|
||||||
SetupEnvironment();
|
SetupEnvironment();
|
||||||
fPrintToDebugLog = false; // don't want to write to debug.log file
|
fPrintToDebugLog = false; // don't want to write to debug.log file
|
||||||
fCheckBlockIndex = true;
|
fCheckBlockIndex = true;
|
||||||
SelectParams(network);
|
SelectParams(chainName);
|
||||||
noui_connect();
|
noui_connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ BasicTestingSetup::~BasicTestingSetup()
|
||||||
ECC_Stop();
|
ECC_Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
TestingSetup::TestingSetup(CBaseChainParams::Network network) : BasicTestingSetup(network)
|
TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
bitdb.MakeMock();
|
bitdb.MakeMock();
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
* This just configures logging and chain parameters.
|
* This just configures logging and chain parameters.
|
||||||
*/
|
*/
|
||||||
struct BasicTestingSetup {
|
struct BasicTestingSetup {
|
||||||
BasicTestingSetup(CBaseChainParams::Network network = CBaseChainParams::MAIN);
|
BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
|
||||||
~BasicTestingSetup();
|
~BasicTestingSetup();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ struct TestingSetup: public BasicTestingSetup {
|
||||||
boost::filesystem::path pathTemp;
|
boost::filesystem::path pathTemp;
|
||||||
boost::thread_group threadGroup;
|
boost::thread_group threadGroup;
|
||||||
|
|
||||||
TestingSetup(CBaseChainParams::Network network = CBaseChainParams::MAIN);
|
TestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
|
||||||
~TestingSetup();
|
~TestingSetup();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue