diff options
78 files changed, 288 insertions, 229 deletions
diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index 260c8991ce..269ac847a5 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -9,6 +9,7 @@ #include <common/args.h> #include <consensus/validation.h> #include <streams.h> +#include <util/chaintype.h> #include <validation.h> // These are the two major time-sinks which happen after we have fully received @@ -36,7 +37,7 @@ static void DeserializeAndCheckBlockTest(benchmark::Bench& bench) stream.write({&a, 1}); // Prevent compaction ArgsManager bench_args; - const auto chainParams = CreateChainParams(bench_args, CBaseChainParams::MAIN); + const auto chainParams = CreateChainParams(bench_args, ChainType::MAIN); bench.unit("block").run([&] { CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here diff --git a/src/bench/load_external.cpp b/src/bench/load_external.cpp index 0fd842c7c3..2ff72a3012 100644 --- a/src/bench/load_external.cpp +++ b/src/bench/load_external.cpp @@ -6,6 +6,7 @@ #include <bench/data.h> #include <chainparams.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #include <validation.h> /** @@ -22,7 +23,7 @@ */ static void LoadExternalBlockFile(benchmark::Bench& bench) { - const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN)}; + const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)}; // Create a single block as in the blocks files (magic bytes, block size, // block data) as a stream object. diff --git a/src/bench/logging.cpp b/src/bench/logging.cpp index 9aedb26236..c97c4e151b 100644 --- a/src/bench/logging.cpp +++ b/src/bench/logging.cpp @@ -5,6 +5,7 @@ #include <bench/bench.h> #include <logging.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> // All but 2 of the benchmarks should have roughly similar performance: // @@ -18,7 +19,7 @@ static void Logging(benchmark::Bench& bench, const std::vector<const char*>& ext LogInstance().DisableCategory(BCLog::LogFlags::ALL); TestingSetup test_setup{ - CBaseChainParams::REGTEST, + ChainType::REGTEST, extra_args, }; diff --git a/src/bench/mempool_stress.cpp b/src/bench/mempool_stress.cpp index 80c959cdfb..826da73800 100644 --- a/src/bench/mempool_stress.cpp +++ b/src/bench/mempool_stress.cpp @@ -7,6 +7,7 @@ #include <policy/policy.h> #include <test/util/setup_common.h> #include <txmempool.h> +#include <util/chaintype.h> #include <validation.h> #include <vector> @@ -88,7 +89,7 @@ static void ComplexMemPool(benchmark::Bench& bench) childTxs = static_cast<int>(bench.complexityN()); } std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /*min_ancestors=*/1); - const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN); + const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN); CTxMemPool& pool = *testing_setup.get()->m_node.mempool; LOCK2(cs_main, pool.cs); bench.run([&]() NO_THREAD_SAFETY_ANALYSIS { @@ -103,7 +104,7 @@ static void ComplexMemPool(benchmark::Bench& bench) static void MempoolCheck(benchmark::Bench& bench) { FastRandomContext det_rand{true}; - auto testing_setup = MakeNoLogFileContext<TestChain100Setup>(CBaseChainParams::REGTEST, {"-checkmempool=1"}); + auto testing_setup = MakeNoLogFileContext<TestChain100Setup>(ChainType::REGTEST, {"-checkmempool=1"}); CTxMemPool& pool = *testing_setup.get()->m_node.mempool; LOCK2(cs_main, pool.cs); testing_setup->PopulateMempool(det_rand, 400, true); diff --git a/src/bench/rpc_blockchain.cpp b/src/bench/rpc_blockchain.cpp index f68b6acb5b..a9b197b190 100644 --- a/src/bench/rpc_blockchain.cpp +++ b/src/bench/rpc_blockchain.cpp @@ -8,6 +8,7 @@ #include <rpc/blockchain.h> #include <streams.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #include <validation.h> #include <univalue.h> @@ -15,7 +16,7 @@ namespace { struct TestBlockAndIndex { - const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN)}; + const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)}; CBlock block{}; uint256 blockHash{}; CBlockIndex blockindex{}; diff --git a/src/bench/rpc_mempool.cpp b/src/bench/rpc_mempool.cpp index e3e1a07c83..af1fa7c572 100644 --- a/src/bench/rpc_mempool.cpp +++ b/src/bench/rpc_mempool.cpp @@ -9,6 +9,7 @@ #include <rpc/mempool.h> #include <test/util/setup_common.h> #include <txmempool.h> +#include <util/chaintype.h> #include <univalue.h> @@ -21,7 +22,7 @@ static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& poo static void RpcMempool(benchmark::Bench& bench) { - const auto testing_setup = MakeNoLogFileContext<const ChainTestingSetup>(CBaseChainParams::MAIN); + const auto testing_setup = MakeNoLogFileContext<const ChainTestingSetup>(ChainType::MAIN); CTxMemPool& pool = *Assert(testing_setup->m_node.mempool); LOCK2(cs_main, pool.cs); diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp index 2b139cf908..52e697a78d 100644 --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -25,6 +25,7 @@ #include <node/chainstate.h> #include <scheduler.h> #include <script/sigcache.h> +#include <util/chaintype.h> #include <util/thread.h> #include <validation.h> #include <validationinterface.h> @@ -52,7 +53,7 @@ int main(int argc, char* argv[]) // SETUP: Misc Globals - SelectParams(CBaseChainParams::MAIN); + SelectParams(ChainType::MAIN); auto chainparams = CChainParams::Main(); kernel::Context kernel_context{}; diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 63ba6a935d..a66134128d 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -20,6 +20,7 @@ #include <rpc/request.h> #include <tinyformat.h> #include <univalue.h> +#include <util/chaintype.h> #include <util/exception.h> #include <util/strencodings.h> #include <util/system.h> @@ -73,10 +74,10 @@ static void SetupCliArgs(ArgsManager& argsman) { SetupHelpOptions(argsman); - const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); - const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET); - const auto signetBaseParams = CreateBaseChainParams(CBaseChainParams::SIGNET); - const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST); + const auto defaultBaseParams = CreateBaseChainParams(ChainType::MAIN); + const auto testnetBaseParams = CreateBaseChainParams(ChainType::TESTNET); + const auto signetBaseParams = CreateBaseChainParams(ChainType::SIGNET); + const auto regtestBaseParams = CreateBaseChainParams(ChainType::REGTEST); argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); @@ -174,7 +175,7 @@ static int AppInitRPC(int argc, char* argv[]) } // Check for chain settings (BaseParams() calls are only valid after this clause) try { - SelectBaseParams(gArgs.GetChainName()); + SelectBaseParams(gArgs.GetChainType()); } catch (const std::exception& e) { tfm::format(std::cerr, "Error: %s\n", e.what()); return EXIT_FAILURE; @@ -426,10 +427,16 @@ private: std::vector<Peer> m_peers; std::string ChainToString() const { - if (gArgs.GetChainName() == CBaseChainParams::TESTNET) return " testnet"; - if (gArgs.GetChainName() == CBaseChainParams::SIGNET) return " signet"; - if (gArgs.GetChainName() == CBaseChainParams::REGTEST) return " regtest"; - return ""; + switch (gArgs.GetChainType()) { + case ChainType::TESTNET: + return " testnet"; + case ChainType::SIGNET: + return " signet"; + case ChainType::REGTEST: + return " regtest"; + default: + return ""; + } } std::string PingTimeToString(double seconds) const { diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index c35a111313..b82ee2aa59 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -91,7 +91,7 @@ static int AppInitRawTx(int argc, char* argv[]) // Check for chain settings (Params() calls are only valid after this clause) try { - SelectParams(gArgs.GetChainName()); + SelectParams(gArgs.GetChainType()); } catch (const std::exception& e) { tfm::format(std::cerr, "Error: %s\n", e.what()); return EXIT_FAILURE; diff --git a/src/bitcoin-util.cpp b/src/bitcoin-util.cpp index e3f70e1b76..f62a9f7bbf 100644 --- a/src/bitcoin-util.cpp +++ b/src/bitcoin-util.cpp @@ -75,7 +75,7 @@ static int AppInitUtil(ArgsManager& args, int argc, char* argv[]) // Check for chain settings (Params() calls are only valid after this clause) try { - SelectParams(args.GetChainName()); + SelectParams(args.GetChainType()); } catch (const std::exception& e) { tfm::format(std::cerr, "Error: %s\n", e.what()); return EXIT_FAILURE; diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index 5dbf8a8616..1863173aa8 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -91,7 +91,7 @@ static std::optional<int> WalletAppInit(ArgsManager& args, int argc, char* argv[ return EXIT_FAILURE; } // Check for chain settings (Params() calls are only valid after this clause) - SelectParams(args.GetChainName()); + SelectParams(args.GetChainType()); return std::nullopt; } diff --git a/src/chainparams.cpp b/src/chainparams.cpp index d3d358a3f0..cc0e6e17d5 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -12,6 +12,7 @@ #include <hash.h> // for signet block challenge hash #include <logging.h> #include <script/interpreter.h> +#include <util/chaintype.h> #include <util/string.h> #include <assert.h> @@ -97,26 +98,29 @@ const CChainParams &Params() { return *globalChainParams; } -std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain) +std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainType chain) { - if (chain == CBaseChainParams::MAIN) { + switch (chain) { + case ChainType::MAIN: return CChainParams::Main(); - } else if (chain == CBaseChainParams::TESTNET) { + case ChainType::TESTNET: return CChainParams::TestNet(); - } else if (chain == CBaseChainParams::SIGNET) { + case ChainType::SIGNET: { auto opts = CChainParams::SigNetOptions{}; ReadSigNetArgs(args, opts); return CChainParams::SigNet(opts); - } else if (chain == CBaseChainParams::REGTEST) { + } + case ChainType::REGTEST: { auto opts = CChainParams::RegTestOptions{}; ReadRegTestArgs(args, opts); return CChainParams::RegTest(opts); } - throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain)); + } + throw std::invalid_argument(strprintf("%s: Invalid ChainType value", __func__)); } -void SelectParams(const std::string& network) +void SelectParams(const ChainType chain) { - SelectBaseParams(network); - globalChainParams = CreateChainParams(gArgs, network); + SelectBaseParams(chain); + globalChainParams = CreateChainParams(gArgs, chain); } diff --git a/src/chainparams.h b/src/chainparams.h index cb34d068e1..52f001c096 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -13,6 +13,7 @@ #include <netaddress.h> #include <primitives/block.h> #include <protocol.h> +#include <util/chaintype.h> #include <util/hash_type.h> #include <cstdint> @@ -26,7 +27,7 @@ * @returns a CChainParams* of the chosen chain. * @throws a std::runtime_error if the chain is not supported. */ -std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain); +std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainType chain); /** * Return the currently selected parameters. This won't change after app @@ -38,6 +39,6 @@ const CChainParams &Params(); * Sets the params returned by Params() to those for the given chain name. * @throws std::runtime_error when the chain is not supported. */ -void SelectParams(const std::string& chain); +void SelectParams(const ChainType chain); #endif // BITCOIN_CHAINPARAMS_H diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index eb7b31923d..4ebfeae1a7 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -7,14 +7,10 @@ #include <common/args.h> #include <tinyformat.h> +#include <util/chaintype.h> #include <assert.h> -const std::string CBaseChainParams::MAIN = "main"; -const std::string CBaseChainParams::TESTNET = "test"; -const std::string CBaseChainParams::SIGNET = "signet"; -const std::string CBaseChainParams::REGTEST = "regtest"; - void SetupChainParamsBaseOptions(ArgsManager& argsman) { argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, signet, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); @@ -40,22 +36,23 @@ const CBaseChainParams& BaseParams() * Port numbers for incoming Tor connections (8334, 18334, 38334, 18445) have * been chosen arbitrarily to keep ranges of used ports tight. */ -std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain) +std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainType chain) { - if (chain == CBaseChainParams::MAIN) { + switch (chain) { + case ChainType::MAIN: return std::make_unique<CBaseChainParams>("", 8332, 8334); - } else if (chain == CBaseChainParams::TESTNET) { + case ChainType::TESTNET: return std::make_unique<CBaseChainParams>("testnet3", 18332, 18334); - } else if (chain == CBaseChainParams::SIGNET) { + case ChainType::SIGNET: return std::make_unique<CBaseChainParams>("signet", 38332, 38334); - } else if (chain == CBaseChainParams::REGTEST) { + case ChainType::REGTEST: return std::make_unique<CBaseChainParams>("regtest", 18443, 18445); } - throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain)); + throw std::invalid_argument(strprintf("%s: Invalid ChainType value", __func__)); } -void SelectBaseParams(const std::string& chain) +void SelectBaseParams(const ChainType chain) { globalChainBaseParams = CreateBaseChainParams(chain); - gArgs.SelectConfigNetwork(chain); + gArgs.SelectConfigNetwork(ChainTypeToString(chain)); } diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h index d593cff722..73e449d11b 100644 --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_CHAINPARAMSBASE_H #define BITCOIN_CHAINPARAMSBASE_H +#include <util/chaintype.h> + #include <memory> #include <string> @@ -17,14 +19,6 @@ class ArgsManager; class CBaseChainParams { public: - ///@{ - /** Chain name strings */ - static const std::string MAIN; - static const std::string TESTNET; - static const std::string SIGNET; - static const std::string REGTEST; - ///@} - const std::string& DataDir() const { return strDataDir; } uint16_t RPCPort() const { return m_rpc_port; } uint16_t OnionServiceTargetPort() const { return m_onion_service_target_port; } @@ -44,7 +38,7 @@ private: * @returns a CBaseChainParams* of the chosen chain. * @throws a std::runtime_error if the chain is not supported. */ -std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain); +std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainType chain); /** *Set the arguments for chainparams @@ -57,7 +51,7 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman); */ const CBaseChainParams& BaseParams(); -/** Sets the params returned by Params() to those for the given network. */ -void SelectBaseParams(const std::string& chain); +/** Sets the params returned by Params() to those for the given chain. */ +void SelectBaseParams(const ChainType chain); #endif // BITCOIN_CHAINPARAMSBASE_H diff --git a/src/common/args.cpp b/src/common/args.cpp index 266ec5943e..93f2005931 100644 --- a/src/common/args.cpp +++ b/src/common/args.cpp @@ -143,7 +143,7 @@ std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const if (m_network.empty()) return std::set<std::string> {}; // if it's okay to use the default section for this network, don't worry - if (m_network == CBaseChainParams::MAIN) return std::set<std::string> {}; + if (m_network == ChainTypeToString(ChainType::MAIN)) return std::set<std::string> {}; for (const auto& arg : m_network_only_args) { if (OnlyHasDefaultSectionSetting(m_settings, m_network, SettingName(arg))) { @@ -157,10 +157,10 @@ std::list<SectionInfo> ArgsManager::GetUnrecognizedSections() const { // Section names to be recognized in the config file. static const std::set<std::string> available_sections{ - CBaseChainParams::REGTEST, - CBaseChainParams::SIGNET, - CBaseChainParams::TESTNET, - CBaseChainParams::MAIN + ChainTypeToString(ChainType::REGTEST), + ChainTypeToString(ChainType::SIGNET), + ChainTypeToString(ChainType::TESTNET), + ChainTypeToString(ChainType::MAIN), }; LOCK(cs_args); @@ -445,7 +445,7 @@ util::SettingsValue ArgsManager::GetPersistentSetting(const std::string& name) c { LOCK(cs_args); return util::GetSetting(m_settings, m_network, name, !UseDefaultSection("-" + name), - /*ignore_nonpersistent=*/true, /*get_chain_name=*/false); + /*ignore_nonpersistent=*/true, /*get_chain_type=*/false); } bool ArgsManager::IsArgNegated(const std::string& strArg) const @@ -726,7 +726,7 @@ ChainType ArgsManager::GetChainType() const throw std::runtime_error(strprintf("Unknown chain %s.", std::get<std::string>(arg))); } -std::string ArgsManager::GetChainName() const +std::string ArgsManager::GetChainTypeString() const { auto arg = GetChainArg(); if (auto* parsed = std::get_if<ChainType>(&arg)) return ChainTypeToString(*parsed); @@ -740,7 +740,7 @@ std::variant<ChainType, std::string> ArgsManager::GetChainArg() const util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg), /* ignore_default_section_config= */ false, /*ignore_nonpersistent=*/false, - /* get_chain_name= */ true); + /* get_chain_type= */ true); return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str()); }; @@ -765,7 +765,7 @@ std::variant<ChainType, std::string> ArgsManager::GetChainArg() const bool ArgsManager::UseDefaultSection(const std::string& arg) const { - return m_network == CBaseChainParams::MAIN || m_network_only_args.count(arg) == 0; + return m_network == ChainTypeToString(ChainType::MAIN) || m_network_only_args.count(arg) == 0; } util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const @@ -773,7 +773,7 @@ util::SettingsValue ArgsManager::GetSetting(const std::string& arg) const LOCK(cs_args); return util::GetSetting( m_settings, m_network, SettingName(arg), !UseDefaultSection(arg), - /*ignore_nonpersistent=*/false, /*get_chain_name=*/false); + /*ignore_nonpersistent=*/false, /*get_chain_type=*/false); } std::vector<util::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const diff --git a/src/common/args.h b/src/common/args.h index 66cd83ed4e..5335633911 100644 --- a/src/common/args.h +++ b/src/common/args.h @@ -336,7 +336,7 @@ protected: * @return ChainType::MAIN string by default; raises runtime error if an * invalid combination is given. */ - std::string GetChainName() const; + std::string GetChainTypeString() const; /** * Add argument diff --git a/src/common/config.cpp b/src/common/config.cpp index 747503ad2a..5efb5efb67 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -8,6 +8,7 @@ #include <sync.h> #include <tinyformat.h> #include <univalue.h> +#include <util/chaintype.h> #include <util/fs.h> #include <util/settings.h> #include <util/string.h> @@ -152,7 +153,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) } } if (use_conf_file) { - std::string chain_id = GetChainName(); + std::string chain_id = GetChainTypeString(); std::vector<std::string> conf_file_names; auto add_includes = [&](const std::string& network, size_t skip = 0) { @@ -191,7 +192,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) conf_file_names.clear(); add_includes(chain_id, /* skip= */ chain_includes); add_includes({}, /* skip= */ default_includes); - std::string chain_id_final = GetChainName(); + std::string chain_id_final = GetChainTypeString(); if (chain_id_final != chain_id) { // Also warn about recursive includeconf for the chain that was specified in one of the includeconfs add_includes(chain_id_final); diff --git a/src/common/init.cpp b/src/common/init.cpp index 6ffa44847a..8933d59c27 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -26,7 +26,7 @@ std::optional<ConfigError> InitConfig(ArgsManager& args, SettingsAbortFn setting } // Check for chain settings (Params() calls are only valid after this clause) - SelectParams(args.GetChainName()); + SelectParams(args.GetChainType()); // Create datadir if it does not exist. const auto base_path{args.GetDataDirBase()}; diff --git a/src/init.cpp b/src/init.cpp index ddee3bddc2..ce0e1f1ad5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -69,6 +69,7 @@ #include <txdb.h> #include <txmempool.h> #include <util/asmap.h> +#include <util/chaintype.h> #include <util/check.h> #include <util/fs.h> #include <util/fs_helpers.h> @@ -408,14 +409,14 @@ void SetupServerArgs(ArgsManager& argsman) init::AddLoggingArgs(argsman); - const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); - const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET); - const auto signetBaseParams = CreateBaseChainParams(CBaseChainParams::SIGNET); - const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST); - const auto defaultChainParams = CreateChainParams(argsman, CBaseChainParams::MAIN); - const auto testnetChainParams = CreateChainParams(argsman, CBaseChainParams::TESTNET); - const auto signetChainParams = CreateChainParams(argsman, CBaseChainParams::SIGNET); - const auto regtestChainParams = CreateChainParams(argsman, CBaseChainParams::REGTEST); + const auto defaultBaseParams = CreateBaseChainParams(ChainType::MAIN); + const auto testnetBaseParams = CreateBaseChainParams(ChainType::TESTNET); + const auto signetBaseParams = CreateBaseChainParams(ChainType::SIGNET); + const auto regtestBaseParams = CreateBaseChainParams(ChainType::REGTEST); + const auto defaultChainParams = CreateChainParams(argsman, ChainType::MAIN); + const auto testnetChainParams = CreateChainParams(argsman, ChainType::TESTNET); + const auto signetChainParams = CreateChainParams(argsman, ChainType::SIGNET); + const auto regtestChainParams = CreateChainParams(argsman, ChainType::REGTEST); // Hidden Options std::vector<std::string> hidden_args = { @@ -844,14 +845,14 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb // Error if network-specific options (-addnode, -connect, etc) are // specified in default section of config file, but not overridden - // on the command line or in this network's section of the config file. - std::string network = args.GetChainName(); - if (network == CBaseChainParams::SIGNET) { + // on the command line or in this chain's section of the config file. + ChainType chain = args.GetChainType(); + if (chain == ChainType::SIGNET) { LogPrintf("Signet derived magic (message start): %s\n", HexStr(chainparams.MessageStart())); } bilingual_str errors; for (const auto& arg : args.GetUnsuitableSectionOnlyArgs()) { - errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section.") + Untranslated("\n"), arg, network, network); + errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section.") + Untranslated("\n"), arg, ChainTypeToString(chain), ChainTypeToString(chain)); } if (!errors.empty()) { diff --git a/src/kernel/chainparams.cpp b/src/kernel/chainparams.cpp index 2827737ee1..065ad17fc8 100644 --- a/src/kernel/chainparams.cpp +++ b/src/kernel/chainparams.cpp @@ -17,6 +17,7 @@ #include <script/interpreter.h> #include <script/script.h> #include <uint256.h> +#include <util/chaintype.h> #include <util/strencodings.h> #include <algorithm> @@ -70,7 +71,7 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits class CMainParams : public CChainParams { public: CMainParams() { - strNetworkID = CBaseChainParams::MAIN; + m_chain_type = ChainType::MAIN; consensus.signet_blocks = false; consensus.signet_challenge.clear(); consensus.nSubsidyHalvingInterval = 210000; @@ -192,7 +193,7 @@ public: class CTestNetParams : public CChainParams { public: CTestNetParams() { - strNetworkID = CBaseChainParams::TESTNET; + m_chain_type = ChainType::TESTNET; consensus.signet_blocks = false; consensus.signet_challenge.clear(); consensus.nSubsidyHalvingInterval = 210000; @@ -328,7 +329,7 @@ public: vSeeds = *options.seeds; } - strNetworkID = CBaseChainParams::SIGNET; + m_chain_type = ChainType::SIGNET; consensus.signet_blocks = true; consensus.signet_challenge.assign(bin.begin(), bin.end()); consensus.nSubsidyHalvingInterval = 210000; @@ -397,7 +398,7 @@ class CRegTestParams : public CChainParams public: explicit CRegTestParams(const RegTestOptions& opts) { - strNetworkID = CBaseChainParams::REGTEST; + m_chain_type = ChainType::REGTEST; consensus.signet_blocks = false; consensus.signet_challenge.clear(); consensus.nSubsidyHalvingInterval = 150; diff --git a/src/kernel/chainparams.h b/src/kernel/chainparams.h index 32fe618dbd..ad0b49a885 100644 --- a/src/kernel/chainparams.h +++ b/src/kernel/chainparams.h @@ -11,6 +11,7 @@ #include <primitives/block.h> #include <protocol.h> #include <uint256.h> +#include <util/chaintype.h> #include <util/hash_type.h> #include <cstdint> @@ -114,8 +115,10 @@ public: uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; } /** Whether it is possible to mine blocks on demand (no retargeting) */ bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; } - /** Return the network string */ - std::string NetworkIDString() const { return strNetworkID; } + /** Return the chain type string */ + std::string GetChainTypeString() const { return ChainTypeToString(m_chain_type); } + /** Return the chain type */ + ChainType GetChainType() const { return m_chain_type; } /** Return the list of hostnames to look up for DNS seeds */ const std::vector<std::string>& DNSSeeds() const { return vSeeds; } const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; } @@ -172,7 +175,7 @@ protected: std::vector<std::string> vSeeds; std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES]; std::string bech32_hrp; - std::string strNetworkID; + ChainType m_chain_type; CBlock genesis; std::vector<uint8_t> vFixedSeeds; bool fDefaultConsistencyChecks; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 5fcace833f..49b88c3596 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -239,7 +239,7 @@ public: std::vector<ExternalSigner> signers = {}; const std::string command = args().GetArg("-signer", ""); if (command == "") return {}; - ExternalSigner::Enumerate(command, signers, Params().NetworkIDString()); + ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString()); std::vector<std::unique_ptr<interfaces::ExternalSigner>> result; result.reserve(signers.size()); for (auto& signer : signers) { diff --git a/src/node/mempool_args.cpp b/src/node/mempool_args.cpp index f193469506..294111a58a 100644 --- a/src/node/mempool_args.cpp +++ b/src/node/mempool_args.cpp @@ -89,7 +89,7 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, con mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); if (!chainparams.IsTestChain() && !mempool_opts.require_standard) { - return strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString()); + return strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.GetChainTypeString()); } mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf); diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 2f00009596..d602d2c1ac 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -601,7 +601,7 @@ int GuiMain(int argc, char* argv[]) PaymentServer::ipcParseCommandLine(argc, argv); #endif - QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().NetworkIDString())); + QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().GetChainType())); assert(!networkStyle.isNull()); // Allow for separate UI settings for testnets QApplication::setApplicationName(networkStyle->getAppName()); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index dc7daed4bc..8d8328aad8 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -21,6 +21,7 @@ #include <protocol.h> #include <script/script.h> #include <script/standard.h> +#include <util/chaintype.h> #include <util/exception.h> #include <util/fs.h> #include <util/fs_helpers.h> @@ -503,12 +504,12 @@ bool LabelOutOfFocusEventFilter::eventFilter(QObject* watched, QEvent* event) #ifdef WIN32 fs::path static StartupShortcutPath() { - std::string chain = gArgs.GetChainName(); - if (chain == CBaseChainParams::MAIN) + ChainType chain = gArgs.GetChainType(); + if (chain == ChainType::MAIN) return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk"; - if (chain == CBaseChainParams::TESTNET) // Remove this special case when CBaseChainParams::TESTNET = "testnet4" + if (chain == ChainType::TESTNET) // Remove this special case when testnet CBaseChainParams::DataDir() is incremented to "testnet4" return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin (testnet).lnk"; - return GetSpecialFolderPath(CSIDL_STARTUP) / fs::u8path(strprintf("Bitcoin (%s).lnk", chain)); + return GetSpecialFolderPath(CSIDL_STARTUP) / fs::u8path(strprintf("Bitcoin (%s).lnk", ChainTypeToString(chain))); } bool GetStartOnSystemStartup() @@ -541,7 +542,7 @@ bool SetStartOnSystemStartup(bool fAutoStart) // Start client minimized QString strArgs = "-min"; // Set -testnet /-regtest options - strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName())); + strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainTypeString())); // Set the path to the shortcut target psl->SetPath(pszExePath); @@ -586,10 +587,10 @@ fs::path static GetAutostartDir() fs::path static GetAutostartFilePath() { - std::string chain = gArgs.GetChainName(); - if (chain == CBaseChainParams::MAIN) + ChainType chain = gArgs.GetChainType(); + if (chain == ChainType::MAIN) return GetAutostartDir() / "bitcoin.desktop"; - return GetAutostartDir() / fs::u8path(strprintf("bitcoin-%s.desktop", chain)); + return GetAutostartDir() / fs::u8path(strprintf("bitcoin-%s.desktop", ChainTypeToString(chain))); } bool GetStartOnSystemStartup() @@ -629,15 +630,15 @@ bool SetStartOnSystemStartup(bool fAutoStart) std::ofstream optionFile{GetAutostartFilePath(), std::ios_base::out | std::ios_base::trunc}; if (!optionFile.good()) return false; - std::string chain = gArgs.GetChainName(); + ChainType chain = gArgs.GetChainType(); // Write a bitcoin.desktop file to the autostart directory: optionFile << "[Desktop Entry]\n"; optionFile << "Type=Application\n"; - if (chain == CBaseChainParams::MAIN) + if (chain == ChainType::MAIN) optionFile << "Name=Bitcoin\n"; else - optionFile << strprintf("Name=Bitcoin (%s)\n", chain); - optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain); + optionFile << strprintf("Name=Bitcoin (%s)\n", ChainTypeToString(chain)); + optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", ChainTypeToString(chain)); optionFile << "Terminal=false\n"; optionFile << "Hidden=false\n"; optionFile.close(); diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index a54ba19354..f86b167076 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -9,6 +9,7 @@ #include <chainparams.h> #include <qt/intro.h> #include <qt/forms/ui_intro.h> +#include <util/chaintype.h> #include <util/fs.h> #include <qt/guiconstants.h> @@ -219,7 +220,7 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) { /* Use selectParams here to guarantee Params() can be used by node interface */ try { - SelectParams(gArgs.GetChainName()); + SelectParams(gArgs.GetChainType()); } catch (const std::exception&) { return false; } diff --git a/src/qt/networkstyle.cpp b/src/qt/networkstyle.cpp index b789e6a958..e9ec4349b5 100644 --- a/src/qt/networkstyle.cpp +++ b/src/qt/networkstyle.cpp @@ -8,19 +8,20 @@ #include <chainparamsbase.h> #include <tinyformat.h> +#include <util/chaintype.h> #include <QApplication> static const struct { - const char *networkId; + const ChainType networkId; const char *appName; const int iconColorHueShift; const int iconColorSaturationReduction; } network_styles[] = { - {"main", QAPP_APP_NAME_DEFAULT, 0, 0}, - {"test", QAPP_APP_NAME_TESTNET, 70, 30}, - {"signet", QAPP_APP_NAME_SIGNET, 35, 15}, - {"regtest", QAPP_APP_NAME_REGTEST, 160, 30}, + {ChainType::MAIN, QAPP_APP_NAME_DEFAULT, 0, 0}, + {ChainType::TESTNET, QAPP_APP_NAME_TESTNET, 70, 30}, + {ChainType::SIGNET, QAPP_APP_NAME_SIGNET, 35, 15}, + {ChainType::REGTEST, QAPP_APP_NAME_REGTEST, 160, 30}, }; // titleAddText needs to be const char* for tr() @@ -77,9 +78,9 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift, trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256))); } -const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId) +const NetworkStyle* NetworkStyle::instantiate(const ChainType networkId) { - std::string titleAddText = networkId == CBaseChainParams::MAIN ? "" : strprintf("[%s]", networkId); + std::string titleAddText = networkId == ChainType::MAIN ? "" : strprintf("[%s]", ChainTypeToString(networkId)); for (const auto& network_style : network_styles) { if (networkId == network_style.networkId) { return new NetworkStyle( diff --git a/src/qt/networkstyle.h b/src/qt/networkstyle.h index a73e3e2625..dd2aee3eb3 100644 --- a/src/qt/networkstyle.h +++ b/src/qt/networkstyle.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_QT_NETWORKSTYLE_H #define BITCOIN_QT_NETWORKSTYLE_H +#include <util/chaintype.h> + #include <QIcon> #include <QPixmap> #include <QString> @@ -14,7 +16,7 @@ class NetworkStyle { public: /** Get style associated with provided network id, or 0 if not known */ - static const NetworkStyle* instantiate(const std::string& networkId); + static const NetworkStyle* instantiate(const ChainType networkId); const QString &getAppName() const { return appName; } const QIcon &getAppIcon() const { return appIcon; } diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 76500a4a36..972bc36ad2 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -744,7 +744,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_ ui->dataDir->setText(model->dataDir()); ui->blocksDir->setText(model->blocksDir()); ui->startupTime->setText(model->formatClientStartupTime()); - ui->networkName->setText(QString::fromStdString(Params().NetworkIDString())); + ui->networkName->setText(QString::fromStdString(Params().GetChainTypeString())); //Setup autocomplete and attach it QStringList wordList; diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp index 000bbe65be..e918e84184 100644 --- a/src/qt/test/apptests.cpp +++ b/src/qt/test/apptests.cpp @@ -73,7 +73,7 @@ void AppTests::appTests() qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo"); m_app.parameterSetup(); QVERIFY(m_app.createOptionsModel(/*resetSettings=*/true)); - QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().NetworkIDString())); + QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().GetChainType())); m_app.setupPlatformStyle(); m_app.createWindow(style.data()); connect(&m_app, &BitcoinApplication::windowShown, this, &AppTests::guiTests); diff --git a/src/qt/test/test_main.cpp b/src/qt/test/test_main.cpp index 2d069f76a0..eaadbd7f7a 100644 --- a/src/qt/test/test_main.cpp +++ b/src/qt/test/test_main.cpp @@ -14,6 +14,7 @@ #include <qt/test/rpcnestedtests.h> #include <qt/test/uritests.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #ifdef ENABLE_WALLET #include <qt/test/addressbooktests.h> @@ -57,7 +58,7 @@ int main(int argc, char* argv[]) // // All tests must use their own testing setup (if needed). fs::create_directories([] { - BasicTestingSetup dummy{CBaseChainParams::REGTEST}; + BasicTestingSetup dummy{ChainType::REGTEST}; return gArgs.GetDataDirNet() / "blocks"; }()); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 11484a9d8d..e7a40f812c 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1256,7 +1256,7 @@ RPCHelpMan getblockchaininfo() const CBlockIndex& tip{*CHECK_NONFATAL(active_chainstate.m_chain.Tip())}; const int height{tip.nHeight}; UniValue obj(UniValue::VOBJ); - obj.pushKV("chain", chainman.GetParams().NetworkIDString()); + obj.pushKV("chain", chainman.GetParams().GetChainTypeString()); obj.pushKV("blocks", height); obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1); obj.pushKV("bestblockhash", tip.GetBlockHash().GetHex()); diff --git a/src/rpc/external_signer.cpp b/src/rpc/external_signer.cpp index 1e139c9990..b7d065ad57 100644 --- a/src/rpc/external_signer.cpp +++ b/src/rpc/external_signer.cpp @@ -43,7 +43,7 @@ static RPCHelpMan enumeratesigners() { const std::string command = gArgs.GetArg("-signer", ""); if (command == "") throw JSONRPCError(RPC_MISC_ERROR, "Error: restart bitcoind with -signer=<cmd>"); - const std::string chain = gArgs.GetChainName(); + const std::string chain = gArgs.GetChainTypeString(); UniValue signers_res = UniValue::VARR; try { std::vector<ExternalSigner> signers; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index d55e20ba5e..334bc988cc 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -435,7 +435,7 @@ static RPCHelpMan getmininginfo() obj.pushKV("difficulty", (double)GetDifficulty(active_chain.Tip())); obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request)); obj.pushKV("pooledtx", (uint64_t)mempool.size()); - obj.pushKV("chain", chainman.GetParams().NetworkIDString()); + obj.pushKV("chain", chainman.GetParams().GetChainTypeString()); obj.pushKV("warnings", GetWarnings(false).original); return obj; }, diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 7ffa777ef4..dc9ea8dece 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -21,6 +21,7 @@ #include <rpc/util.h> #include <sync.h> #include <timedata.h> +#include <util/chaintype.h> #include <util/strencodings.h> #include <util/string.h> #include <util/time.h> @@ -354,7 +355,7 @@ static RPCHelpMan addconnection() }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - if (Params().NetworkIDString() != CBaseChainParams::REGTEST) { + if (Params().GetChainType() != ChainType::REGTEST) { throw std::runtime_error("addconnection is for regression testing (-regtest mode) only."); } diff --git a/src/test/argsman_tests.cpp b/src/test/argsman_tests.cpp index 6a0925f0bb..4d6ef206c7 100644 --- a/src/test/argsman_tests.cpp +++ b/src/test/argsman_tests.cpp @@ -8,6 +8,7 @@ #include <test/util/setup_common.h> #include <test/util/str.h> #include <univalue.h> +#include <util/chaintype.h> #include <util/fs.h> #include <util/strencodings.h> @@ -580,7 +581,7 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream) test_args.SetNetworkOnlyArg("-ccc"); test_args.SetNetworkOnlyArg("-h"); - test_args.SelectConfigNetwork(CBaseChainParams::MAIN); + test_args.SelectConfigNetwork(ChainTypeToString(ChainType::MAIN)); BOOST_CHECK(test_args.GetArg("-d", "xxx") == "e"); BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2); BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0"); @@ -637,7 +638,7 @@ BOOST_AUTO_TEST_CASE(util_GetArg) BOOST_CHECK_EQUAL(testArgs.GetArg("pritest4", "default"), "b"); } -BOOST_AUTO_TEST_CASE(util_GetChainName) +BOOST_AUTO_TEST_CASE(util_GetChainTypeString) { TestArgsManager test_args; const auto testnet = std::make_pair("-testnet", ArgsManager::ALLOW_ANY); @@ -655,39 +656,39 @@ BOOST_AUTO_TEST_CASE(util_GetChainName) std::string error; BOOST_CHECK(test_args.ParseParameters(0, (char**)argv_testnet, error)); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "main"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "main"); BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_testnet, error)); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "test"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test"); BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_regtest, error)); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "regtest"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "regtest"); BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_test_no_reg, error)); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "test"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test"); BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_both, error)); - BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error); + BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); BOOST_CHECK(test_args.ParseParameters(0, (char**)argv_testnet, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "test"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test"); BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_testnet, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "test"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test"); BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_regtest, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error); + BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_test_no_reg, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "test"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test"); BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_both, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error); + BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); // check setting the network to test (and thus making // [test] regtest=1 potentially relevant) doesn't break things @@ -695,23 +696,23 @@ BOOST_AUTO_TEST_CASE(util_GetChainName) BOOST_CHECK(test_args.ParseParameters(0, (char**)argv_testnet, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "test"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test"); BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_testnet, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "test"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test"); BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_regtest, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error); + BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); BOOST_CHECK(test_args.ParseParameters(2, (char**)argv_test_no_reg, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_EQUAL(test_args.GetChainName(), "test"); + BOOST_CHECK_EQUAL(test_args.GetChainTypeString(), "test"); BOOST_CHECK(test_args.ParseParameters(3, (char**)argv_both, error)); test_args.ReadConfigString(testnetconf); - BOOST_CHECK_THROW(test_args.GetChainName(), std::runtime_error); + BOOST_CHECK_THROW(test_args.GetChainTypeString(), std::runtime_error); } // Test different ways settings can be merged, and verify results. This test can @@ -755,8 +756,8 @@ struct ArgsMergeTestingSetup : public BasicTestingSetup { ForEachNoDup(conf_actions, SET, SECTION_NEGATE, [&] { for (bool soft_set : {false, true}) { for (bool force_set : {false, true}) { - for (const std::string& section : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET}) { - for (const std::string& network : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET}) { + for (const std::string& section : {ChainTypeToString(ChainType::MAIN), ChainTypeToString(ChainType::TESTNET), ChainTypeToString(ChainType::SIGNET)}) { + for (const std::string& network : {ChainTypeToString(ChainType::MAIN), ChainTypeToString(ChainType::TESTNET), ChainTypeToString(ChainType::SIGNET)}) { for (bool net_specific : {false, true}) { fn(arg_actions, conf_actions, soft_set, force_set, section, network, net_specific); } @@ -913,7 +914,7 @@ BOOST_FIXTURE_TEST_CASE(util_ArgsMerge, ArgsMergeTestingSetup) BOOST_CHECK_EQUAL(out_sha_hex, "d1e436c1cd510d0ec44d5205d4b4e3bee6387d316e0075c58206cb16603f3d82"); } -// Similar test as above, but for ArgsManager::GetChainName function. +// Similar test as above, but for ArgsManager::GetChainTypeString function. struct ChainMergeTestingSetup : public BasicTestingSetup { static constexpr int MAX_ACTIONS = 2; @@ -982,7 +983,7 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup) desc += " || "; try { - desc += parser.GetChainName(); + desc += parser.GetChainTypeString(); } catch (const std::runtime_error& e) { desc += "error: "; desc += e.what(); diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp index 321c86ebfa..fd33a21147 100644 --- a/src/test/blockmanager_tests.cpp +++ b/src/test/blockmanager_tests.cpp @@ -5,6 +5,7 @@ #include <chainparams.h> #include <node/blockstorage.h> #include <node/context.h> +#include <util/chaintype.h> #include <validation.h> #include <boost/test/unit_test.hpp> @@ -20,7 +21,7 @@ BOOST_FIXTURE_TEST_SUITE(blockmanager_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos) { - const auto params {CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)}; + const auto params {CreateChainParams(ArgsManager{}, ChainType::MAIN)}; node::BlockManager::Options blockman_opts{ .chainparams = *params, }; diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 9011e703e8..cb3831071a 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -7,6 +7,7 @@ #include <sync.h> #include <test/util/random.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #include <util/time.h> #include <boost/test/unit_test.hpp> @@ -27,9 +28,9 @@ struct NoLockLoggingTestingSetup : public TestingSetup { NoLockLoggingTestingSetup() #ifdef DEBUG_LOCKCONTENTION - : TestingSetup{CBaseChainParams::MAIN, /*extra_args=*/{"-debugexclude=lock"}} {} + : TestingSetup{ChainType::MAIN, /*extra_args=*/{"-debugexclude=lock"}} {} #else - : TestingSetup{CBaseChainParams::MAIN} {} + : TestingSetup{ChainType::MAIN} {} #endif }; diff --git a/src/test/fuzz/addrman.cpp b/src/test/fuzz/addrman.cpp index 5ad7a25c53..7218bb82d1 100644 --- a/src/test/fuzz/addrman.cpp +++ b/src/test/fuzz/addrman.cpp @@ -16,6 +16,7 @@ #include <test/util/setup_common.h> #include <time.h> #include <util/asmap.h> +#include <util/chaintype.h> #include <cassert> #include <cstdint> @@ -34,7 +35,7 @@ int32_t GetCheckRatio() void initialize_addrman() { - static const auto testing_setup = MakeNoLogFileContext<>(CBaseChainParams::REGTEST); + static const auto testing_setup = MakeNoLogFileContext<>(ChainType::REGTEST); g_setup = testing_setup.get(); } diff --git a/src/test/fuzz/block.cpp b/src/test/fuzz/block.cpp index c3e17724eb..e90dcc189a 100644 --- a/src/test/fuzz/block.cpp +++ b/src/test/fuzz/block.cpp @@ -11,6 +11,7 @@ #include <pubkey.h> #include <streams.h> #include <test/fuzz/fuzz.h> +#include <util/chaintype.h> #include <validation.h> #include <version.h> @@ -19,7 +20,7 @@ void initialize_block() { - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(block, initialize_block) diff --git a/src/test/fuzz/descriptor_parse.cpp b/src/test/fuzz/descriptor_parse.cpp index 1f5601ca9f..12c22ef2ed 100644 --- a/src/test/fuzz/descriptor_parse.cpp +++ b/src/test/fuzz/descriptor_parse.cpp @@ -6,11 +6,12 @@ #include <pubkey.h> #include <script/descriptor.h> #include <test/fuzz/fuzz.h> +#include <util/chaintype.h> void initialize_descriptor_parse() { ECC_Start(); - SelectParams(CBaseChainParams::MAIN); + SelectParams(ChainType::MAIN); } FUZZ_TARGET_INIT(descriptor_parse, initialize_descriptor_parse) diff --git a/src/test/fuzz/headerssync.cpp b/src/test/fuzz/headerssync.cpp index 521afadb51..c1a187038b 100644 --- a/src/test/fuzz/headerssync.cpp +++ b/src/test/fuzz/headerssync.cpp @@ -6,6 +6,7 @@ #include <test/fuzz/util.h> #include <test/util/setup_common.h> #include <uint256.h> +#include <util/chaintype.h> #include <util/time.h> #include <validation.h> @@ -15,7 +16,7 @@ static void initialize_headers_sync_state_fuzz() { static const auto testing_setup = MakeNoLogFileContext<>( - /*chain_name=*/CBaseChainParams::MAIN); + /*chain_type=*/ChainType::MAIN); } void MakeHeadersContinuous( diff --git a/src/test/fuzz/integer.cpp b/src/test/fuzz/integer.cpp index ead877fe05..392f3591f1 100644 --- a/src/test/fuzz/integer.cpp +++ b/src/test/fuzz/integer.cpp @@ -26,6 +26,7 @@ #include <test/fuzz/util.h> #include <uint256.h> #include <univalue.h> +#include <util/chaintype.h> #include <util/check.h> #include <util/moneystr.h> #include <util/overflow.h> @@ -42,7 +43,7 @@ void initialize_integer() { - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(integer, initialize_integer) diff --git a/src/test/fuzz/key.cpp b/src/test/fuzz/key.cpp index ea6883c08d..e22321c71e 100644 --- a/src/test/fuzz/key.cpp +++ b/src/test/fuzz/key.cpp @@ -17,6 +17,7 @@ #include <script/standard.h> #include <streams.h> #include <test/fuzz/fuzz.h> +#include <util/chaintype.h> #include <util/strencodings.h> #include <cassert> @@ -28,7 +29,7 @@ void initialize_key() { ECC_Start(); - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(key, initialize_key) diff --git a/src/test/fuzz/key_io.cpp b/src/test/fuzz/key_io.cpp index 29c6996365..a1c587a75b 100644 --- a/src/test/fuzz/key_io.cpp +++ b/src/test/fuzz/key_io.cpp @@ -5,6 +5,7 @@ #include <chainparams.h> #include <key_io.h> #include <test/fuzz/fuzz.h> +#include <util/chaintype.h> #include <cassert> #include <cstdint> @@ -14,7 +15,7 @@ void initialize_key_io() { ECC_Start(); - SelectParams(CBaseChainParams::MAIN); + SelectParams(ChainType::MAIN); } FUZZ_TARGET_INIT(key_io, initialize_key_io) diff --git a/src/test/fuzz/message.cpp b/src/test/fuzz/message.cpp index 63e24aacdd..8b7e3f11cc 100644 --- a/src/test/fuzz/message.cpp +++ b/src/test/fuzz/message.cpp @@ -7,6 +7,7 @@ #include <test/fuzz/FuzzedDataProvider.h> #include <test/fuzz/fuzz.h> #include <test/fuzz/util.h> +#include <util/chaintype.h> #include <util/message.h> #include <util/strencodings.h> @@ -19,7 +20,7 @@ void initialize_message() { ECC_Start(); - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(message, initialize_message) diff --git a/src/test/fuzz/net.cpp b/src/test/fuzz/net.cpp index 13b4638688..ca10381e4a 100644 --- a/src/test/fuzz/net.cpp +++ b/src/test/fuzz/net.cpp @@ -16,6 +16,7 @@ #include <test/util/net.h> #include <test/util/setup_common.h> #include <util/asmap.h> +#include <util/chaintype.h> #include <cstdint> #include <optional> @@ -24,7 +25,7 @@ void initialize_net() { - static const auto testing_setup = MakeNoLogFileContext<>(CBaseChainParams::MAIN); + static const auto testing_setup = MakeNoLogFileContext<>(ChainType::MAIN); } FUZZ_TARGET_INIT(net, initialize_net) diff --git a/src/test/fuzz/p2p_transport_serialization.cpp b/src/test/fuzz/p2p_transport_serialization.cpp index 96254aa222..ec3cdbff5a 100644 --- a/src/test/fuzz/p2p_transport_serialization.cpp +++ b/src/test/fuzz/p2p_transport_serialization.cpp @@ -9,6 +9,7 @@ #include <protocol.h> #include <test/fuzz/FuzzedDataProvider.h> #include <test/fuzz/fuzz.h> +#include <util/chaintype.h> #include <cassert> #include <cstdint> @@ -18,7 +19,7 @@ void initialize_p2p_transport_serialization() { - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(p2p_transport_serialization, initialize_p2p_transport_serialization) diff --git a/src/test/fuzz/parse_univalue.cpp b/src/test/fuzz/parse_univalue.cpp index 16486f6b96..be15a38e92 100644 --- a/src/test/fuzz/parse_univalue.cpp +++ b/src/test/fuzz/parse_univalue.cpp @@ -7,13 +7,14 @@ #include <rpc/client.h> #include <rpc/util.h> #include <test/fuzz/fuzz.h> +#include <util/chaintype.h> #include <limits> #include <string> void initialize_parse_univalue() { - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(parse_univalue, initialize_parse_univalue) diff --git a/src/test/fuzz/pow.cpp b/src/test/fuzz/pow.cpp index e5a3a6e68a..6d584c9f10 100644 --- a/src/test/fuzz/pow.cpp +++ b/src/test/fuzz/pow.cpp @@ -9,6 +9,7 @@ #include <test/fuzz/FuzzedDataProvider.h> #include <test/fuzz/fuzz.h> #include <test/fuzz/util.h> +#include <util/chaintype.h> #include <util/check.h> #include <util/overflow.h> @@ -19,7 +20,7 @@ void initialize_pow() { - SelectParams(CBaseChainParams::MAIN); + SelectParams(ChainType::MAIN); } FUZZ_TARGET_INIT(pow, initialize_pow) diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp index 0a7924f226..70dd1e17c5 100644 --- a/src/test/fuzz/process_message.cpp +++ b/src/test/fuzz/process_message.cpp @@ -19,6 +19,7 @@ #include <test/util/net.h> #include <test/util/setup_common.h> #include <test/util/validation.h> +#include <util/chaintype.h> #include <validationinterface.h> #include <version.h> @@ -57,7 +58,7 @@ void initialize_process_message() Assert(GetNumMsgTypes() == getAllNetMessageTypes().size()); // If this fails, add or remove the message type below static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>( - /*chain_name=*/CBaseChainParams::REGTEST, + /*chain_type=*/ChainType::REGTEST, /*extra_args=*/{"-txreconciliation"}); g_setup = testing_setup.get(); for (int i = 0; i < 2 * COINBASE_MATURITY; i++) { diff --git a/src/test/fuzz/process_messages.cpp b/src/test/fuzz/process_messages.cpp index 96339743ba..68d4e02a26 100644 --- a/src/test/fuzz/process_messages.cpp +++ b/src/test/fuzz/process_messages.cpp @@ -24,7 +24,7 @@ const TestingSetup* g_setup; void initialize_process_messages() { static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>( - /*chain_name=*/CBaseChainParams::REGTEST, + /*chain_type=*/ChainType::REGTEST, /*extra_args=*/{"-txreconciliation"}); g_setup = testing_setup.get(); for (int i = 0; i < 2 * COINBASE_MATURITY; i++) { diff --git a/src/test/fuzz/rpc.cpp b/src/test/fuzz/rpc.cpp index 1c6140c66a..e1f378ceff 100644 --- a/src/test/fuzz/rpc.cpp +++ b/src/test/fuzz/rpc.cpp @@ -23,6 +23,7 @@ #include <test/util/setup_common.h> #include <tinyformat.h> #include <univalue.h> +#include <util/chaintype.h> #include <util/strencodings.h> #include <util/string.h> #include <util/time.h> @@ -37,7 +38,7 @@ namespace { struct RPCFuzzTestingSetup : public TestingSetup { - RPCFuzzTestingSetup(const std::string& chain_name, const std::vector<const char*>& extra_args) : TestingSetup{chain_name, extra_args} + RPCFuzzTestingSetup(const ChainType chain_type, const std::vector<const char*>& extra_args) : TestingSetup{chain_type, extra_args} { } diff --git a/src/test/fuzz/script.cpp b/src/test/fuzz/script.cpp index 1037dd934a..8a88c1107a 100644 --- a/src/test/fuzz/script.cpp +++ b/src/test/fuzz/script.cpp @@ -22,6 +22,7 @@ #include <test/fuzz/fuzz.h> #include <test/fuzz/util.h> #include <univalue.h> +#include <util/chaintype.h> #include <algorithm> #include <cassert> @@ -32,7 +33,7 @@ void initialize_script() { - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(script, initialize_script) diff --git a/src/test/fuzz/script_format.cpp b/src/test/fuzz/script_format.cpp index 9186746bcf..5aa0ea58ff 100644 --- a/src/test/fuzz/script_format.cpp +++ b/src/test/fuzz/script_format.cpp @@ -11,10 +11,11 @@ #include <test/fuzz/fuzz.h> #include <test/fuzz/util.h> #include <univalue.h> +#include <util/chaintype.h> void initialize_script_format() { - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(script_format, initialize_script_format) diff --git a/src/test/fuzz/script_sign.cpp b/src/test/fuzz/script_sign.cpp index c78c22e6cc..84930d42ef 100644 --- a/src/test/fuzz/script_sign.cpp +++ b/src/test/fuzz/script_sign.cpp @@ -14,6 +14,7 @@ #include <test/fuzz/FuzzedDataProvider.h> #include <test/fuzz/fuzz.h> #include <test/fuzz/util.h> +#include <util/chaintype.h> #include <util/translation.h> #include <cassert> @@ -27,7 +28,7 @@ void initialize_script_sign() { ECC_Start(); - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(script_sign, initialize_script_sign) diff --git a/src/test/fuzz/signet.cpp b/src/test/fuzz/signet.cpp index 303dcf13e3..e9af93c639 100644 --- a/src/test/fuzz/signet.cpp +++ b/src/test/fuzz/signet.cpp @@ -11,6 +11,7 @@ #include <test/fuzz/fuzz.h> #include <test/fuzz/util.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #include <cstdint> #include <optional> @@ -18,7 +19,7 @@ void initialize_signet() { - static const auto testing_setup = MakeNoLogFileContext<>(CBaseChainParams::SIGNET); + static const auto testing_setup = MakeNoLogFileContext<>(ChainType::SIGNET); } FUZZ_TARGET_INIT(signet, initialize_signet) diff --git a/src/test/fuzz/system.cpp b/src/test/fuzz/system.cpp index 935f0c21e1..04cbbe52cb 100644 --- a/src/test/fuzz/system.cpp +++ b/src/test/fuzz/system.cpp @@ -108,7 +108,7 @@ FUZZ_TARGET_INIT(system, initialize_system) (void)args_manager.GetArgs(s1); (void)args_manager.GetBoolArg(s1, b); try { - (void)args_manager.GetChainName(); + (void)args_manager.GetChainTypeString(); } catch (const std::runtime_error&) { } (void)args_manager.GetHelpMessage(); diff --git a/src/test/fuzz/transaction.cpp b/src/test/fuzz/transaction.cpp index bacb178b44..7035c53d13 100644 --- a/src/test/fuzz/transaction.cpp +++ b/src/test/fuzz/transaction.cpp @@ -15,6 +15,7 @@ #include <streams.h> #include <test/fuzz/fuzz.h> #include <univalue.h> +#include <util/chaintype.h> #include <util/rbf.h> #include <validation.h> #include <version.h> @@ -23,7 +24,7 @@ void initialize_transaction() { - SelectParams(CBaseChainParams::REGTEST); + SelectParams(ChainType::REGTEST); } FUZZ_TARGET_INIT(transaction, initialize_transaction) diff --git a/src/test/fuzz/utxo_snapshot.cpp b/src/test/fuzz/utxo_snapshot.cpp index be34906025..b4ef0c7a3e 100644 --- a/src/test/fuzz/utxo_snapshot.cpp +++ b/src/test/fuzz/utxo_snapshot.cpp @@ -10,6 +10,7 @@ #include <test/fuzz/util.h> #include <test/util/mining.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #include <util/fs.h> #include <validation.h> #include <validationinterface.h> @@ -22,7 +23,7 @@ const std::vector<std::shared_ptr<CBlock>>* g_chain; void initialize_chain() { - const auto params{CreateChainParams(ArgsManager{}, CBaseChainParams::REGTEST)}; + const auto params{CreateChainParams(ArgsManager{}, ChainType::REGTEST)}; static const auto chain{CreateBlockChain(2 * COINBASE_MATURITY, *params)}; g_chain = &chain; } diff --git a/src/test/fuzz/utxo_total_supply.cpp b/src/test/fuzz/utxo_total_supply.cpp index 7813b7854b..19f41880f4 100644 --- a/src/test/fuzz/utxo_total_supply.cpp +++ b/src/test/fuzz/utxo_total_supply.cpp @@ -14,6 +14,7 @@ #include <test/fuzz/util.h> #include <test/util/mining.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #include <validation.h> #include <version.h> @@ -21,7 +22,7 @@ FUZZ_TARGET(utxo_total_supply) { /** The testing setup that creates a chainman only (no chainstate) */ ChainTestingSetup test_setup{ - CBaseChainParams::REGTEST, + ChainType::REGTEST, { "-testactivationheight=bip34@2", }, diff --git a/src/test/fuzz/versionbits.cpp b/src/test/fuzz/versionbits.cpp index e6a19d6e91..b3df4dadd2 100644 --- a/src/test/fuzz/versionbits.cpp +++ b/src/test/fuzz/versionbits.cpp @@ -7,6 +7,7 @@ #include <common/args.h> #include <consensus/params.h> #include <primitives/block.h> +#include <util/chaintype.h> #include <versionbits.h> #include <test/fuzz/FuzzedDataProvider.h> @@ -104,7 +105,7 @@ std::unique_ptr<const CChainParams> g_params; void initialize() { // this is actually comparatively slow, so only do it once - g_params = CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN); + g_params = CreateChainParams(ArgsManager{}, ChainType::MAIN); assert(g_params != nullptr); } diff --git a/src/test/key_io_tests.cpp b/src/test/key_io_tests.cpp index a400afee71..fa3430fc89 100644 --- a/src/test/key_io_tests.cpp +++ b/src/test/key_io_tests.cpp @@ -10,6 +10,7 @@ #include <script/script.h> #include <test/util/json.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #include <util/strencodings.h> #include <boost/test/unit_test.hpp> @@ -24,7 +25,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_parse) UniValue tests = read_json(std::string(json_tests::key_io_valid, json_tests::key_io_valid + sizeof(json_tests::key_io_valid))); CKey privkey; CTxDestination destination; - SelectParams(CBaseChainParams::MAIN); + SelectParams(ChainType::MAIN); for (unsigned int idx = 0; idx < tests.size(); idx++) { const UniValue& test = tests[idx]; @@ -37,7 +38,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_parse) const std::vector<std::byte> exp_payload{ParseHex<std::byte>(test[1].get_str())}; const UniValue &metadata = test[2].get_obj(); bool isPrivkey = find_value(metadata, "isPrivkey").get_bool(); - SelectParams(find_value(metadata, "chain").get_str()); + SelectParams(ChainTypeFromString(find_value(metadata, "chain").get_str()).value()); bool try_case_flip = find_value(metadata, "tryCaseFlip").isNull() ? false : find_value(metadata, "tryCaseFlip").get_bool(); if (isPrivkey) { bool isCompressed = find_value(metadata, "isCompressed").get_bool(); @@ -96,7 +97,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_gen) std::vector<unsigned char> exp_payload = ParseHex(test[1].get_str()); const UniValue &metadata = test[2].get_obj(); bool isPrivkey = find_value(metadata, "isPrivkey").get_bool(); - SelectParams(find_value(metadata, "chain").get_str()); + SelectParams(ChainTypeFromString(find_value(metadata, "chain").get_str()).value()); if (isPrivkey) { bool isCompressed = find_value(metadata, "isCompressed").get_bool(); CKey key; @@ -113,7 +114,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_gen) } } - SelectParams(CBaseChainParams::MAIN); + SelectParams(ChainType::MAIN); } @@ -135,7 +136,7 @@ BOOST_AUTO_TEST_CASE(key_io_invalid) std::string exp_base58string = test[0].get_str(); // must be invalid as public and as private key - for (const auto& chain : { CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET, CBaseChainParams::REGTEST }) { + for (const auto& chain : {ChainType::MAIN, ChainType::TESTNET, ChainType::SIGNET, ChainType::REGTEST}) { SelectParams(chain); destination = DecodeDestination(exp_base58string); BOOST_CHECK_MESSAGE(!IsValidDestination(destination), "IsValid pubkey in mainnet:" + strTest); diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp index addc925bab..5bd14f22c6 100644 --- a/src/test/pow_tests.cpp +++ b/src/test/pow_tests.cpp @@ -7,6 +7,7 @@ #include <pow.h> #include <test/util/random.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #include <boost/test/unit_test.hpp> @@ -15,7 +16,7 @@ BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup) /* Test calculation of next difficulty target with no constraints applying */ BOOST_AUTO_TEST_CASE(get_next_work) { - const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN); int64_t nLastRetargetTime = 1261130161; // Block #30240 CBlockIndex pindexLast; pindexLast.nHeight = 32255; @@ -34,7 +35,7 @@ BOOST_AUTO_TEST_CASE(get_next_work) /* Test the constraint on the upper bound for next work */ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit) { - const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN); int64_t nLastRetargetTime = 1231006505; // Block #0 CBlockIndex pindexLast; pindexLast.nHeight = 2015; @@ -48,7 +49,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit) /* Test the constraint on the lower bound for actual time taken */ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual) { - const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN); int64_t nLastRetargetTime = 1279008237; // Block #66528 CBlockIndex pindexLast; pindexLast.nHeight = 68543; @@ -65,7 +66,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual) /* Test the constraint on the upper bound for actual time taken */ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual) { - const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN); int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time CBlockIndex pindexLast; pindexLast.nHeight = 46367; @@ -81,7 +82,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual) BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target) { - const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus(); + const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus(); uint256 hash; unsigned int nBits; nBits = UintToArith256(consensus.powLimit).GetCompact(true); @@ -91,7 +92,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target) BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_overflow_target) { - const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus(); + const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus(); uint256 hash; unsigned int nBits{~0x00800000U}; hash.SetHex("0x1"); @@ -100,7 +101,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_overflow_target) BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_too_easy_target) { - const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus(); + const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus(); uint256 hash; unsigned int nBits; arith_uint256 nBits_arith = UintToArith256(consensus.powLimit); @@ -112,7 +113,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_too_easy_target) BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_biger_hash_than_target) { - const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus(); + const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus(); uint256 hash; unsigned int nBits; arith_uint256 hash_arith = UintToArith256(consensus.powLimit); @@ -124,7 +125,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_biger_hash_than_target) BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target) { - const auto consensus = CreateChainParams(*m_node.args, CBaseChainParams::MAIN)->GetConsensus(); + const auto consensus = CreateChainParams(*m_node.args, ChainType::MAIN)->GetConsensus(); uint256 hash; unsigned int nBits; arith_uint256 hash_arith{0}; @@ -135,7 +136,7 @@ BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target) BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test) { - const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN); std::vector<CBlockIndex> blocks(10000); for (int i = 0; i < 10000; i++) { blocks[i].pprev = i ? &blocks[i - 1] : nullptr; @@ -155,9 +156,9 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test) } } -void sanity_check_chainparams(const ArgsManager& args, std::string chainName) +void sanity_check_chainparams(const ArgsManager& args, ChainType chain_type) { - const auto chainParams = CreateChainParams(args, chainName); + const auto chainParams = CreateChainParams(args, chain_type); const auto consensus = chainParams->GetConsensus(); // hash genesis is correct @@ -184,22 +185,22 @@ void sanity_check_chainparams(const ArgsManager& args, std::string chainName) BOOST_AUTO_TEST_CASE(ChainParams_MAIN_sanity) { - sanity_check_chainparams(*m_node.args, CBaseChainParams::MAIN); + sanity_check_chainparams(*m_node.args, ChainType::MAIN); } BOOST_AUTO_TEST_CASE(ChainParams_REGTEST_sanity) { - sanity_check_chainparams(*m_node.args, CBaseChainParams::REGTEST); + sanity_check_chainparams(*m_node.args, ChainType::REGTEST); } BOOST_AUTO_TEST_CASE(ChainParams_TESTNET_sanity) { - sanity_check_chainparams(*m_node.args, CBaseChainParams::TESTNET); + sanity_check_chainparams(*m_node.args, ChainType::TESTNET); } BOOST_AUTO_TEST_CASE(ChainParams_SIGNET_sanity) { - sanity_check_chainparams(*m_node.args, CBaseChainParams::SIGNET); + sanity_check_chainparams(*m_node.args, ChainType::SIGNET); } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/settings_tests.cpp b/src/test/settings_tests.cpp index 604eb48df6..fff84d24f0 100644 --- a/src/test/settings_tests.cpp +++ b/src/test/settings_tests.cpp @@ -6,12 +6,12 @@ #include <test/util/setup_common.h> #include <test/util/str.h> -#include <util/fs.h> - #include <boost/test/unit_test.hpp> #include <common/args.h> #include <univalue.h> +#include <util/chaintype.h> +#include <util/fs.h> #include <util/strencodings.h> #include <util/string.h> @@ -190,7 +190,7 @@ BOOST_FIXTURE_TEST_CASE(Merge, MergeTestingSetup) if (!out_file) throw std::system_error(errno, std::generic_category(), "fopen failed"); } - const std::string& network = CBaseChainParams::MAIN; + const std::string& network = ChainTypeToString(ChainType::MAIN); ForEachMergeSetup([&](const ActionList& arg_actions, const ActionList& conf_actions, bool force_set, bool ignore_default_section_config) { std::string desc; @@ -225,7 +225,7 @@ BOOST_FIXTURE_TEST_CASE(Merge, MergeTestingSetup) } desc += " || "; - desc += GetSetting(settings, network, name, ignore_default_section_config, /*ignore_nonpersistent=*/false, /*get_chain_name=*/false).write(); + desc += GetSetting(settings, network, name, ignore_default_section_config, /*ignore_nonpersistent=*/false, /*get_chain_type=*/false).write(); desc += " |"; for (const auto& s : GetSettingsList(settings, network, name, ignore_default_section_config)) { desc += " "; diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp index 8cdea3890e..8f8628169f 100644 --- a/src/test/txvalidationcache_tests.cpp +++ b/src/test/txvalidationcache_tests.cpp @@ -9,13 +9,14 @@ #include <script/standard.h> #include <test/util/setup_common.h> #include <txmempool.h> +#include <util/chaintype.h> #include <validation.h> #include <boost/test/unit_test.hpp> struct Dersig100Setup : public TestChain100Setup { Dersig100Setup() - : TestChain100Setup{CBaseChainParams::REGTEST, {"-testactivationheight=dersig@102"}} {} + : TestChain100Setup{ChainType::REGTEST, {"-testactivationheight=dersig@102"}} {} }; bool CheckInputScripts(const CTransaction& tx, TxValidationState& state, diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index b3072a8295..642350b033 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -42,6 +42,7 @@ #include <timedata.h> #include <txdb.h> #include <txmempool.h> +#include <util/chaintype.h> #include <util/strencodings.h> #include <util/string.h> #include <util/system.h> @@ -98,7 +99,7 @@ std::ostream& operator<<(std::ostream& os, const uint256& num) return os; } -BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args) +BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vector<const char*>& extra_args) : m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()}, m_args{} { @@ -132,7 +133,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve throw std::runtime_error{error}; } } - SelectParams(chainName); + SelectParams(chainType); SeedInsecureRand(); if (G_TEST_LOG_FUN) LogInstance().PushBackCallback(G_TEST_LOG_FUN); InitLogging(*m_node.args); @@ -163,8 +164,8 @@ BasicTestingSetup::~BasicTestingSetup() gArgs.ClearArgs(); } -ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::vector<const char*>& extra_args) - : BasicTestingSetup(chainName, extra_args) +ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vector<const char*>& extra_args) + : BasicTestingSetup(chainType, extra_args) { const CChainParams& chainparams = Params(); @@ -240,11 +241,11 @@ void ChainTestingSetup::LoadVerifyActivateChainstate() } TestingSetup::TestingSetup( - const std::string& chainName, + const ChainType chainType, const std::vector<const char*>& extra_args, const bool coins_db_in_memory, const bool block_tree_db_in_memory) - : ChainTestingSetup(chainName, extra_args) + : ChainTestingSetup(chainType, extra_args) { m_coins_db_in_memory = coins_db_in_memory; m_block_tree_db_in_memory = block_tree_db_in_memory; @@ -271,11 +272,11 @@ TestingSetup::TestingSetup( } TestChain100Setup::TestChain100Setup( - const std::string& chain_name, + const ChainType chain_type, const std::vector<const char*>& extra_args, const bool coins_db_in_memory, const bool block_tree_db_in_memory) - : TestingSetup{CBaseChainParams::REGTEST, extra_args, coins_db_in_memory, block_tree_db_in_memory} + : TestingSetup{ChainType::REGTEST, extra_args, coins_db_in_memory, block_tree_db_in_memory} { SetMockTime(1598887952); constexpr std::array<unsigned char, 32> vchKey = { diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 62e025e819..a93e1559dd 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -14,6 +14,7 @@ #include <pubkey.h> #include <random.h> #include <stdexcept> +#include <util/chaintype.h> #include <util/check.h> #include <util/fs.h> #include <util/string.h> @@ -80,7 +81,7 @@ static constexpr CAmount CENT{1000000}; struct BasicTestingSetup { node::NodeContext m_node; // keep as first member to be destructed last - explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {}); + explicit BasicTestingSetup(const ChainType chainType = ChainType::MAIN, const std::vector<const char*>& extra_args = {}); ~BasicTestingSetup(); const fs::path m_path_root; @@ -96,7 +97,7 @@ struct ChainTestingSetup : public BasicTestingSetup { bool m_coins_db_in_memory{true}; bool m_block_tree_db_in_memory{true}; - explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {}); + explicit ChainTestingSetup(const ChainType chainType = ChainType::MAIN, const std::vector<const char*>& extra_args = {}); ~ChainTestingSetup(); // Supplies a chainstate, if one is needed @@ -107,7 +108,7 @@ struct ChainTestingSetup : public BasicTestingSetup { */ struct TestingSetup : public ChainTestingSetup { explicit TestingSetup( - const std::string& chainName = CBaseChainParams::MAIN, + const ChainType chainType = ChainType::MAIN, const std::vector<const char*>& extra_args = {}, const bool coins_db_in_memory = true, const bool block_tree_db_in_memory = true); @@ -116,7 +117,7 @@ struct TestingSetup : public ChainTestingSetup { /** Identical to TestingSetup, but chain set to regtest */ struct RegTestingSetup : public TestingSetup { RegTestingSetup() - : TestingSetup{CBaseChainParams::REGTEST} {} + : TestingSetup{ChainType::REGTEST} {} }; class CBlock; @@ -128,7 +129,7 @@ class CScript; */ struct TestChain100Setup : public TestingSetup { TestChain100Setup( - const std::string& chain_name = CBaseChainParams::REGTEST, + const ChainType chain_type = ChainType::REGTEST, const std::vector<const char*>& extra_args = {}, const bool coins_db_in_memory = true, const bool block_tree_db_in_memory = true); @@ -206,7 +207,7 @@ struct TestChain100Setup : public TestingSetup { * be used in "hot loops", for example fuzzing or benchmarking. */ template <class T = const BasicTestingSetup> -std::unique_ptr<T> MakeNoLogFileContext(const std::string& chain_name = CBaseChainParams::REGTEST, const std::vector<const char*>& extra_args = {}) +std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::REGTEST, const std::vector<const char*>& extra_args = {}) { const std::vector<const char*> arguments = Cat( { @@ -215,7 +216,7 @@ std::unique_ptr<T> MakeNoLogFileContext(const std::string& chain_name = CBaseCha }, extra_args); - return std::make_unique<T>(chain_name, arguments); + return std::make_unique<T>(chain_type, arguments); } CBlock getBlock13b8a(); diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp index 0b4c491615..d00f2ff4d1 100644 --- a/src/test/validation_tests.cpp +++ b/src/test/validation_tests.cpp @@ -7,6 +7,7 @@ #include <net.h> #include <signet.h> #include <uint256.h> +#include <util/chaintype.h> #include <validation.h> #include <test/util/setup_common.h> @@ -41,7 +42,7 @@ static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval) BOOST_AUTO_TEST_CASE(block_subsidy_test) { - const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN); TestBlockSubsidyHalvings(chainParams->GetConsensus()); // As in main TestBlockSubsidyHalvings(150); // As in regtest TestBlockSubsidyHalvings(1000); // Just another interval @@ -49,7 +50,7 @@ BOOST_AUTO_TEST_CASE(block_subsidy_test) BOOST_AUTO_TEST_CASE(subsidy_limit_test) { - const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto chainParams = CreateChainParams(*m_node.args, ChainType::MAIN); CAmount nSum = 0; for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) { CAmount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus()); @@ -64,7 +65,7 @@ BOOST_AUTO_TEST_CASE(signet_parse_tests) { ArgsManager signet_argsman; signet_argsman.ForceSetArg("-signetchallenge", "51"); // set challenge to OP_TRUE - const auto signet_params = CreateChainParams(signet_argsman, CBaseChainParams::SIGNET); + const auto signet_params = CreateChainParams(signet_argsman, ChainType::SIGNET); CBlock block; BOOST_CHECK(signet_params->GetConsensus().signet_challenge == std::vector<uint8_t>{OP_TRUE}); CScript challenge{OP_TRUE}; @@ -124,7 +125,7 @@ BOOST_AUTO_TEST_CASE(signet_parse_tests) //! Test retrieval of valid assumeutxo values. BOOST_AUTO_TEST_CASE(test_assumeutxo) { - const auto params = CreateChainParams(*m_node.args, CBaseChainParams::REGTEST); + const auto params = CreateChainParams(*m_node.args, ChainType::REGTEST); // These heights don't have assumeutxo configurations associated, per the contents // of kernel/chainparams.cpp. diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp index 80c00036e7..9e69992752 100644 --- a/src/test/versionbits_tests.cpp +++ b/src/test/versionbits_tests.cpp @@ -7,6 +7,7 @@ #include <consensus/params.h> #include <test/util/random.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> #include <versionbits.h> #include <boost/test/unit_test.hpp> @@ -418,8 +419,8 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion) // check that any deployment on any chain can conceivably reach both // ACTIVE and FAILED states in roughly the way we expect - for (const auto& chain_name : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET, CBaseChainParams::REGTEST}) { - const auto chainParams = CreateChainParams(*m_node.args, chain_name); + for (const auto& chain_type: {ChainType::MAIN, ChainType::TESTNET, ChainType::SIGNET, ChainType::REGTEST}) { + const auto chainParams = CreateChainParams(*m_node.args, chain_type); uint32_t chain_all_vbits{0}; for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i) { const auto dep = static_cast<Consensus::DeploymentPos>(i); @@ -440,7 +441,7 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion) // deployment that's not always/never active ArgsManager args; args.ForceSetArg("-vbparams", "testdummy:1199145601:1230767999"); // January 1, 2008 - December 31, 2008 - const auto chainParams = CreateChainParams(args, CBaseChainParams::REGTEST); + const auto chainParams = CreateChainParams(args, ChainType::REGTEST); check_computeblockversion(vbcache, chainParams->GetConsensus(), Consensus::DEPLOYMENT_TESTDUMMY); } @@ -450,7 +451,7 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion) // live deployment ArgsManager args; args.ForceSetArg("-vbparams", "testdummy:1199145601:1230767999:403200"); // January 1, 2008 - December 31, 2008, min act height 403200 - const auto chainParams = CreateChainParams(args, CBaseChainParams::REGTEST); + const auto chainParams = CreateChainParams(args, ChainType::REGTEST); check_computeblockversion(vbcache, chainParams->GetConsensus(), Consensus::DEPLOYMENT_TESTDUMMY); } } diff --git a/src/util/settings.cpp b/src/util/settings.cpp index bb257c0584..db3d60046e 100644 --- a/src/util/settings.cpp +++ b/src/util/settings.cpp @@ -130,7 +130,7 @@ SettingsValue GetSetting(const Settings& settings, const std::string& name, bool ignore_default_section_config, bool ignore_nonpersistent, - bool get_chain_name) + bool get_chain_type) { SettingsValue result; bool done = false; // Done merging any more settings sources. @@ -145,17 +145,17 @@ SettingsValue GetSetting(const Settings& settings, // assigned value instead of last. In general, later settings take // precedence over early settings, but for backwards compatibility in // the config file the precedence is reversed for all settings except - // chain name settings. + // chain type settings. const bool reverse_precedence = (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) && - !get_chain_name; + !get_chain_type; // Weird behavior preserved for backwards compatibility: Negated // -regtest and -testnet arguments which you would expect to override // values set in the configuration file are currently accepted but // silently ignored. It would be better to apply these just like other // negated values, or at least warn they are ignored. - const bool skip_negated_command_line = get_chain_name; + const bool skip_negated_command_line = get_chain_type; if (done) return; diff --git a/src/util/settings.h b/src/util/settings.h index 27e87a4751..bb1fe585e1 100644 --- a/src/util/settings.h +++ b/src/util/settings.h @@ -60,14 +60,14 @@ bool WriteSettings(const fs::path& path, //! command line). Only return settings in the //! read-only config and read-write settings //! files. -//! @param get_chain_name - enable special backwards compatible behavior -//! for GetChainName +//! @param get_chain_type - enable special backwards compatible behavior +//! for GetChainType SettingsValue GetSetting(const Settings& settings, const std::string& section, const std::string& name, bool ignore_default_section_config, bool ignore_nonpersistent, - bool get_chain_name); + bool get_chain_type); //! Get combined setting value similar to GetSetting(), except if setting was //! specified multiple times, return a list of all the values specified. diff --git a/src/wallet/external_signer_scriptpubkeyman.cpp b/src/wallet/external_signer_scriptpubkeyman.cpp index 079e3baa4e..e2852c5d52 100644 --- a/src/wallet/external_signer_scriptpubkeyman.cpp +++ b/src/wallet/external_signer_scriptpubkeyman.cpp @@ -45,7 +45,7 @@ ExternalSigner ExternalSignerScriptPubKeyMan::GetExternalSigner() { const std::string command = gArgs.GetArg("-signer", ""); if (command == "") throw std::runtime_error(std::string(__func__) + ": restart bitcoind with -signer=<cmd>"); std::vector<ExternalSigner> signers; - ExternalSigner::Enumerate(command, signers, Params().NetworkIDString()); + ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString()); if (signers.empty()) throw std::runtime_error(std::string(__func__) + ": No external signers found"); // TODO: add fingerprint argument instead of failing in case of multiple signers. if (signers.size() > 1) throw std::runtime_error(std::string(__func__) + ": More than one external signer found. Please connect only one at a time."); diff --git a/src/wallet/test/init_test_fixture.cpp b/src/wallet/test/init_test_fixture.cpp index 0adc63876c..5bdf36ec19 100644 --- a/src/wallet/test/init_test_fixture.cpp +++ b/src/wallet/test/init_test_fixture.cpp @@ -4,6 +4,7 @@ #include <common/args.h> #include <univalue.h> +#include <util/chaintype.h> #include <util/check.h> #include <util/fs.h> @@ -13,7 +14,7 @@ #include <wallet/test/init_test_fixture.h> namespace wallet { -InitWalletDirTestingSetup::InitWalletDirTestingSetup(const std::string& chainName) : BasicTestingSetup(chainName) +InitWalletDirTestingSetup::InitWalletDirTestingSetup(const ChainType chainType) : BasicTestingSetup(chainType) { m_wallet_loader = MakeWalletLoader(*m_node.chain, m_args); diff --git a/src/wallet/test/init_test_fixture.h b/src/wallet/test/init_test_fixture.h index df5819fd1d..ac7bb8997c 100644 --- a/src/wallet/test/init_test_fixture.h +++ b/src/wallet/test/init_test_fixture.h @@ -9,11 +9,12 @@ #include <interfaces/wallet.h> #include <node/context.h> #include <test/util/setup_common.h> +#include <util/chaintype.h> namespace wallet { struct InitWalletDirTestingSetup: public BasicTestingSetup { - explicit InitWalletDirTestingSetup(const std::string& chainName = CBaseChainParams::MAIN); + explicit InitWalletDirTestingSetup(const ChainType chain_type = ChainType::MAIN); ~InitWalletDirTestingSetup(); void SetWalletDir(const fs::path& walletdir_path); diff --git a/src/wallet/test/wallet_test_fixture.cpp b/src/wallet/test/wallet_test_fixture.cpp index 2dd8f9ad33..369526d17f 100644 --- a/src/wallet/test/wallet_test_fixture.cpp +++ b/src/wallet/test/wallet_test_fixture.cpp @@ -5,10 +5,11 @@ #include <wallet/test/wallet_test_fixture.h> #include <scheduler.h> +#include <util/chaintype.h> namespace wallet { -WalletTestingSetup::WalletTestingSetup(const std::string& chainName) - : TestingSetup(chainName), +WalletTestingSetup::WalletTestingSetup(const ChainType chainType) + : TestingSetup(chainType), m_wallet_loader{interfaces::MakeWalletLoader(*m_node.chain, *Assert(m_node.args))}, m_wallet(m_node.chain.get(), "", CreateMockWalletDatabase()) { diff --git a/src/wallet/test/wallet_test_fixture.h b/src/wallet/test/wallet_test_fixture.h index f1ef15a282..4aae02e075 100644 --- a/src/wallet/test/wallet_test_fixture.h +++ b/src/wallet/test/wallet_test_fixture.h @@ -10,6 +10,7 @@ #include <interfaces/chain.h> #include <interfaces/wallet.h> #include <node/context.h> +#include <util/chaintype.h> #include <util/check.h> #include <wallet/wallet.h> @@ -19,7 +20,7 @@ namespace wallet { /** Testing setup and teardown for wallet. */ struct WalletTestingSetup : public TestingSetup { - explicit WalletTestingSetup(const std::string& chainName = CBaseChainParams::MAIN); + explicit WalletTestingSetup(const ChainType chainType = ChainType::MAIN); ~WalletTestingSetup(); std::unique_ptr<interfaces::WalletLoader> m_wallet_loader; |