Line data Source code
1 : // Copyright (c) 2010 Satoshi Nakamoto 2 : // Copyright (c) 2009-2021 The Bitcoin Core developers 3 : // Distributed under the MIT software license, see the accompanying 4 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 : 6 : #include <chainparamsbase.h> 7 : 8 : #include <tinyformat.h> 9 : #include <util/system.h> 10 : 11 : #include <assert.h> 12 : 13 : const std::string CBaseChainParams::MAIN = "main"; 14 : const std::string CBaseChainParams::TESTNET = "test"; 15 : const std::string CBaseChainParams::DEVNET = "devnet"; 16 : const std::string CBaseChainParams::REGTEST = "regtest"; 17 : 18 5195 : void SetupChainParamsBaseOptions(ArgsManager& argsman) 19 : { 20 5195 : argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, devnet, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); 21 5195 : argsman.AddArg("-devnet=<name>", "Use devnet chain with provided name", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); 22 5195 : argsman.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. " 23 5195 : "This is intended for regression testing tools and app development. Equivalent to -chain=regtest", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); 24 5195 : argsman.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); 25 5195 : } 26 : 27 : static std::unique_ptr<CBaseChainParams> globalChainBaseParams; 28 : 29 20413 : const CBaseChainParams& BaseParams() 30 : { 31 20413 : assert(globalChainBaseParams); 32 20413 : return *globalChainBaseParams; 33 : } 34 : 35 : /** 36 : * Port numbers for incoming Tor connections (9996, 19996, 19796, 19896) have 37 : * been chosen arbitrarily to keep ranges of used ports tight. 38 : */ 39 25334 : std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain) 40 : { 41 25334 : if (chain == CBaseChainParams::MAIN) 42 5681 : return std::make_unique<CBaseChainParams>("", 9998, 9996); 43 19653 : else if (chain == CBaseChainParams::TESTNET) 44 5079 : return std::make_unique<CBaseChainParams>("testnet3", 19998, 19996); 45 14574 : else if (chain == CBaseChainParams::DEVNET) 46 4986 : return std::make_unique<CBaseChainParams>(gArgs.GetDevNetName(), 19798, 19796); 47 9588 : else if (chain == CBaseChainParams::REGTEST) 48 9588 : return std::make_unique<CBaseChainParams>("regtest", 19898, 19896); 49 : else 50 0 : throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain)); 51 25334 : } 52 : 53 5406 : void SelectBaseParams(const std::string& chain) 54 : { 55 5406 : globalChainBaseParams = CreateBaseChainParams(chain); 56 5406 : gArgs.SelectConfigNetwork(chain); 57 5406 : }