diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index aa3cc3867..30d7471f4 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -1,80 +1,50 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include const std::string CBaseChainParams::MAIN = "main"; const std::string CBaseChainParams::TESTNET = "test"; const std::string CBaseChainParams::REGTEST = "regtest"; void SetupChainParamsBaseOptions() { gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in " "which blocks can be solved instantly. This is intended for " "regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS); gArgs.AddArg("-testnet", _("Use the test chain"), false, OptionsCategory::CHAINPARAMS); } -/** - * Main network - */ -class CBaseMainParams : public CBaseChainParams { -public: - CBaseMainParams() { nRPCPort = 8332; } -}; - -/** - * Testnet (v3) - */ -class CBaseTestNetParams : public CBaseChainParams { -public: - CBaseTestNetParams() { - nRPCPort = 18332; - strDataDir = "testnet3"; - } -}; - -/* - * Regression test - */ -class CBaseRegTestParams : public CBaseChainParams { -public: - CBaseRegTestParams() { - nRPCPort = 18443; - strDataDir = "regtest"; - } -}; - static std::unique_ptr globalChainBaseParams; const CBaseChainParams &BaseParams() { assert(globalChainBaseParams); return *globalChainBaseParams; } std::unique_ptr CreateBaseChainParams(const std::string &chain) { if (chain == CBaseChainParams::MAIN) - return std::unique_ptr(new CBaseMainParams()); + return std::make_unique("", 8332); else if (chain == CBaseChainParams::TESTNET) - return std::unique_ptr(new CBaseTestNetParams()); + return std::make_unique("testnet3", 18332); else if (chain == CBaseChainParams::REGTEST) - return std::unique_ptr(new CBaseRegTestParams()); + return std::make_unique("regtest", 18443); else throw std::runtime_error( strprintf("%s: Unknown chain %s.", __func__, chain)); } void SelectBaseParams(const std::string &chain) { globalChainBaseParams = CreateBaseChainParams(chain); gArgs.SelectConfigNetwork(chain); } diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h index 44a575253..6f2f35d28 100644 --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -1,56 +1,58 @@ // Copyright (c) 2014-2015 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_CHAINPARAMSBASE_H #define BITCOIN_CHAINPARAMSBASE_H #include #include #include /** * CBaseChainParams defines the base parameters * (shared between bitcoin-cli and bitcoind) * of a given instance of the Bitcoin system. */ class CBaseChainParams { public: /** BIP70 chain name strings (main, test or regtest) */ static const std::string MAIN; static const std::string TESTNET; static const std::string REGTEST; const std::string &DataDir() const { return strDataDir; } int RPCPort() const { return nRPCPort; } -protected: - CBaseChainParams() {} + CBaseChainParams() = delete; + CBaseChainParams(const std::string &data_dir, int rpc_port) + : nRPCPort(rpc_port), strDataDir(data_dir) {} +private: int nRPCPort; std::string strDataDir; }; /** * Creates and returns a std::unique_ptr of the chosen chain. * @returns a CBaseChainParams* of the chosen chain. * @throws a std::runtime_error if the chain is not supported. */ std::unique_ptr CreateBaseChainParams(const std::string &chain); /** * Set the arguments for chainparams. */ void SetupChainParamsBaseOptions(); /** * Return the currently selected parameters. This won't change after app * startup, except for unit tests. */ const CBaseChainParams &BaseParams(); /** Sets the params returned by Params() to those for the given network. */ void SelectBaseParams(const std::string &chain); #endif // BITCOIN_CHAINPARAMSBASE_H