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 704 : void SetupChainParamsBaseOptions(ArgsManager& argsman) 19 : { 20 704 : argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, devnet, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); 21 704 : argsman.AddArg("-devnet=<name>", "Use devnet chain with provided name", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); 22 704 : argsman.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. " 23 704 : "This is intended for regression testing tools and app development. Equivalent to -chain=regtest", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); 24 704 : argsman.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); 25 704 : } 26 : 27 : static std::unique_ptr<CBaseChainParams> globalChainBaseParams; 28 : 29 1370 : const CBaseChainParams& BaseParams() 30 : { 31 1370 : assert(globalChainBaseParams); 32 1370 : 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 3475 : std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain) 40 : { 41 3475 : if (chain == CBaseChainParams::MAIN) 42 1324 : return std::make_unique<CBaseChainParams>("", 9998, 9996); 43 2151 : else if (chain == CBaseChainParams::TESTNET) 44 714 : return std::make_unique<CBaseChainParams>("testnet3", 19998, 19996); 45 1437 : else if (chain == CBaseChainParams::DEVNET) 46 627 : return std::make_unique<CBaseChainParams>(gArgs.GetDevNetName(), 19798, 19796); 47 810 : else if (chain == CBaseChainParams::REGTEST) 48 810 : return std::make_unique<CBaseChainParams>("regtest", 19898, 19896); 49 : else 50 0 : throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain)); 51 3475 : } 52 : 53 967 : void SelectBaseParams(const std::string& chain) 54 : { 55 967 : globalChainBaseParams = CreateBaseChainParams(chain); 56 967 : gArgs.SelectConfigNetwork(chain); 57 967 : }