Skip to content

Commit

Permalink
Merge pull request zcash#4804 from jtimon/chainparams3
Browse files Browse the repository at this point in the history
Remove CBaseChainParams::NetworkID()
  • Loading branch information
laanwj committed Oct 17, 2014
2 parents c2fc972 + ca3ce0f commit 494ff05
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
9 changes: 6 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,13 @@ void SelectParams(CBaseChainParams::Network network) {
pCurrentParams = &Params(network);
}

bool SelectParamsFromCommandLine() {
if (!SelectBaseParamsFromCommandLine())
bool SelectParamsFromCommandLine()
{
CBaseChainParams::Network network = NetworkIdFromCommandLine();
if (network == CBaseChainParams::MAX_NETWORK_TYPES)
return false;

SelectParams(BaseParams().NetworkID());
SelectBaseParams(network);
SelectParams(network);
return true;
}
25 changes: 15 additions & 10 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,27 @@ void SelectBaseParams(CBaseChainParams::Network network)
}
}

bool SelectBaseParamsFromCommandLine()
CBaseChainParams::Network NetworkIdFromCommandLine()
{
bool fRegTest = GetBoolArg("-regtest", false);
bool fTestNet = GetBoolArg("-testnet", false);

if (fTestNet && fRegTest) {
if (fTestNet && fRegTest)
return CBaseChainParams::MAX_NETWORK_TYPES;
if (fRegTest)
return CBaseChainParams::REGTEST;
if (fTestNet)
return CBaseChainParams::TESTNET;
return CBaseChainParams::MAIN;
}

bool SelectBaseParamsFromCommandLine()
{
CBaseChainParams::Network network = NetworkIdFromCommandLine();
if (network == CBaseChainParams::MAX_NETWORK_TYPES)
return false;
}

if (fRegTest) {
SelectBaseParams(CBaseChainParams::REGTEST);
} else if (fTestNet) {
SelectBaseParams(CBaseChainParams::TESTNET);
} else {
SelectBaseParams(CBaseChainParams::MAIN);
}
SelectBaseParams(network);
return true;
}

Expand Down
9 changes: 7 additions & 2 deletions src/chainparamsbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class CBaseChainParams

const std::string& DataDir() const { return strDataDir; }
int RPCPort() const { return nRPCPort; }
Network NetworkID() const { return networkID; }

protected:
CBaseChainParams() {}
Expand All @@ -46,7 +45,13 @@ const CBaseChainParams& BaseParams();
void SelectBaseParams(CBaseChainParams::Network network);

/**
* Looks for -regtest or -testnet and then calls SelectParams as appropriate.
* Looks for -regtest or -testnet and returns the appropriate Network ID.
* Returns MAX_NETWORK_TYPES if an invalid combination is given.
*/
CBaseChainParams::Network NetworkIdFromCommandLine();

/**
* Calls NetworkIdFromCommandLine() and then calls SelectParams as appropriate.
* Returns false if an invalid combination is given.
*/
bool SelectBaseParamsFromCommandLine();
Expand Down
12 changes: 5 additions & 7 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ boost::filesystem::path GetDefaultDataDir()
#endif
}

static boost::filesystem::path pathCached[CBaseChainParams::MAX_NETWORK_TYPES+1];
static boost::filesystem::path pathCached;
static boost::filesystem::path pathCachedNetSpecific;
static CCriticalSection csPathCached;

const boost::filesystem::path &GetDataDir(bool fNetSpecific)
Expand All @@ -404,10 +405,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)

LOCK(csPathCached);

int nNet = CBaseChainParams::MAX_NETWORK_TYPES;
if (fNetSpecific) nNet = BaseParams().NetworkID();

fs::path &path = pathCached[nNet];
fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;

// This can be called during exceptions by LogPrintf(), so we cache the
// value so we don't have to do memory allocations after that.
Expand All @@ -433,8 +431,8 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)

void ClearDatadirCache()
{
std::fill(&pathCached[0], &pathCached[CBaseChainParams::MAX_NETWORK_TYPES+1],
boost::filesystem::path());
pathCached = boost::filesystem::path();
pathCachedNetSpecific = boost::filesystem::path();
}

boost::filesystem::path GetConfigFile()
Expand Down

0 comments on commit 494ff05

Please sign in to comment.