Skip to content

Commit

Permalink
Merge pull request ElementsProject#65 from jtimon/alpha-fix-55
Browse files Browse the repository at this point in the history
Chainparams: fix the factory the #6907 way
  • Loading branch information
apoelstra committed Nov 26, 2015
2 parents 2f7f3bf + 62f96fb commit 7180042
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
#include <assert.h>

#include <boost/assign/list_of.hpp>
#include <boost/scoped_ptr.hpp>

using namespace std;
using namespace boost::assign;
@@ -310,14 +311,14 @@ class CUnitTestParams : public CMainParams, public CModifiableParams {
virtual void setSkipProofOfWorkCheck(bool afSkipProofOfWorkCheck) { fSkipProofOfWorkCheck = afSkipProofOfWorkCheck; }
};

static CChainParams *pCurrentParams;
static boost::scoped_ptr<CChainParams> globalChainParams;
static boost::scoped_ptr<CChainParams> globalSwitchingChainParams;

const CChainParams &Params() {
assert(pCurrentParams);
return *pCurrentParams;
assert(globalChainParams.get());
return *globalChainParams;
}


CChainParams* CChainParams::Factory(CBaseChainParams::Network network, CScript scriptDestination) {
switch (network) {
case CBaseChainParams::MAIN:
@@ -334,9 +335,15 @@ CChainParams* CChainParams::Factory(CBaseChainParams::Network network, CScript s
}
}

const CChainParams& Params(CBaseChainParams::Network network)
{
globalSwitchingChainParams.reset(CChainParams::Factory(network, CScript()));
return *globalSwitchingChainParams;
}

void SelectParams(CBaseChainParams::Network network, CScript scriptDestination) {
SelectBaseParams(network);
pCurrentParams = CChainParams::Factory(network, scriptDestination);
globalChainParams.reset(CChainParams::Factory(network, scriptDestination));
}

void SelectParams(CBaseChainParams::Network network) {
6 changes: 4 additions & 2 deletions src/chainparams.h
Original file line number Diff line number Diff line change
@@ -142,8 +142,10 @@ class CModifiableParams {
*/
const CChainParams &Params();

/** Return parameters for the given network. */
CChainParams &Params(CBaseChainParams::Network network);
/**
* @deprecated Use CChainParams::Factory() instead.
*/
const CChainParams& Params(CBaseChainParams::Network network);

/** Sets the params returned by Params() to those for the given network. */
void SelectParams(CBaseChainParams::Network network);

0 comments on commit 7180042

Please sign in to comment.