mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-11 05:03:16 +01:00
Chainparams: Replace CBaseChainParams::Network enum with string constants (suggested by Wladimir)
This commit is contained in:
@@ -5,10 +5,16 @@
|
||||
|
||||
#include "chainparamsbase.h"
|
||||
|
||||
#include "tinyformat.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
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";
|
||||
|
||||
/**
|
||||
* Main network
|
||||
*/
|
||||
@@ -71,25 +77,19 @@ const CBaseChainParams& BaseParams()
|
||||
return *pCurrentBaseParams;
|
||||
}
|
||||
|
||||
void SelectBaseParams(CBaseChainParams::Network network)
|
||||
void SelectBaseParams(const std::string& chain)
|
||||
{
|
||||
switch (network) {
|
||||
case CBaseChainParams::MAIN:
|
||||
if (chain == CBaseChainParams::MAIN)
|
||||
pCurrentBaseParams = &mainParams;
|
||||
break;
|
||||
case CBaseChainParams::TESTNET:
|
||||
else if (chain == CBaseChainParams::TESTNET)
|
||||
pCurrentBaseParams = &testNetParams;
|
||||
break;
|
||||
case CBaseChainParams::REGTEST:
|
||||
else if (chain == CBaseChainParams::REGTEST)
|
||||
pCurrentBaseParams = ®TestParams;
|
||||
break;
|
||||
default:
|
||||
assert(false && "Unimplemented network");
|
||||
return;
|
||||
}
|
||||
else
|
||||
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||
}
|
||||
|
||||
CBaseChainParams::Network NetworkIdFromCommandLine()
|
||||
std::string ChainNameFromCommandLine()
|
||||
{
|
||||
bool fRegTest = GetBoolArg("-regtest", false);
|
||||
bool fTestNet = GetBoolArg("-testnet", false);
|
||||
@@ -105,7 +105,7 @@ CBaseChainParams::Network NetworkIdFromCommandLine()
|
||||
|
||||
bool SelectBaseParamsFromCommandLine()
|
||||
{
|
||||
CBaseChainParams::Network network = NetworkIdFromCommandLine();
|
||||
std::string network = ChainNameFromCommandLine();
|
||||
if (network == CBaseChainParams::MAX_NETWORK_TYPES)
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user