aboutsummaryrefslogtreecommitdiff
path: root/src/chainparamsbase.cpp
diff options
context:
space:
mode:
authorJorge Timón <jtimon@jtimon.cc>2015-06-30 21:39:49 +0200
committerJorge Timón <jtimon@jtimon.cc>2015-10-20 14:22:44 +0200
commitf3525e24e3a156eaa004ca28a59fe2d449dc1f9e (patch)
tree6fceee33ff5c9efff9e97ea0045f4726239714b0 /src/chainparamsbase.cpp
parent49793fbb097e9f00149a054adeddad07f0444c12 (diff)
Chainparams: Replace CBaseChainParams::Network enum with string constants (suggested by Wladimir)
Diffstat (limited to 'src/chainparamsbase.cpp')
-rw-r--r--src/chainparamsbase.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp
index 9c87bf2154..e46212279f 100644
--- a/src/chainparamsbase.cpp
+++ b/src/chainparamsbase.cpp
@@ -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 = &regTestParams;
- 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;