mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Chainparams: Use a regular factory for creating chainparams
This commit is contained in:
@@ -55,6 +55,12 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits
|
||||
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
|
||||
}
|
||||
|
||||
void CChainParams::UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
|
||||
{
|
||||
consensus.vDeployments[d].nStartTime = nStartTime;
|
||||
consensus.vDeployments[d].nTimeout = nTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main network
|
||||
*/
|
||||
@@ -165,7 +171,6 @@ public:
|
||||
};
|
||||
}
|
||||
};
|
||||
static CMainParams mainParams;
|
||||
|
||||
/**
|
||||
* Testnet (v3)
|
||||
@@ -253,7 +258,6 @@ public:
|
||||
|
||||
}
|
||||
};
|
||||
static CTestNetParams testNetParams;
|
||||
|
||||
/**
|
||||
* Regression test
|
||||
@@ -326,42 +330,41 @@ public:
|
||||
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
|
||||
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();
|
||||
}
|
||||
|
||||
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
|
||||
{
|
||||
consensus.vDeployments[d].nStartTime = nStartTime;
|
||||
consensus.vDeployments[d].nTimeout = nTimeout;
|
||||
}
|
||||
};
|
||||
static CRegTestParams regTestParams;
|
||||
|
||||
static CChainParams *pCurrentParams = 0;
|
||||
static std::unique_ptr<CChainParams> globalChainParams;
|
||||
static std::unique_ptr<CChainParams> globalSwitchingChainParams;
|
||||
|
||||
const CChainParams &Params() {
|
||||
assert(pCurrentParams);
|
||||
return *pCurrentParams;
|
||||
assert(globalChainParams);
|
||||
return *globalChainParams;
|
||||
}
|
||||
|
||||
CChainParams& Params(const std::string& chain)
|
||||
std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain)
|
||||
{
|
||||
if (chain == CBaseChainParams::MAIN)
|
||||
return mainParams;
|
||||
return std::unique_ptr<CChainParams>(new CMainParams());
|
||||
else if (chain == CBaseChainParams::TESTNET)
|
||||
return testNetParams;
|
||||
return std::unique_ptr<CChainParams>(new CTestNetParams());
|
||||
else if (chain == CBaseChainParams::REGTEST)
|
||||
return regTestParams;
|
||||
else
|
||||
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||
return std::unique_ptr<CChainParams>(new CRegTestParams());
|
||||
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
||||
}
|
||||
|
||||
const CChainParams& Params(const std::string& chain)
|
||||
{
|
||||
globalSwitchingChainParams = CreateChainParams(chain);
|
||||
return *globalSwitchingChainParams;
|
||||
}
|
||||
|
||||
void SelectParams(const std::string& network)
|
||||
{
|
||||
SelectBaseParams(network);
|
||||
pCurrentParams = &Params(network);
|
||||
globalChainParams = CreateChainParams(network);
|
||||
}
|
||||
|
||||
void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
|
||||
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
|
||||
{
|
||||
regTestParams.UpdateBIP9Parameters(d, nStartTime, nTimeout);
|
||||
globalChainParams->UpdateBIP9Parameters(d, nStartTime, nTimeout);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user