From 36ac1307520055f48b856385a3868d32be1913c8 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Tue, 28 Jan 2020 15:36:35 +0000 Subject: [PATCH] Add DEFAULT chain and set to liquidv1 This fixes f.e. that when arguments are set in CLI or the config file without a network attached (`port` instead of `liquidv1.port`), they will now be assigned to the liquidv1 instead of Bitcoin mainnet. --- src/chainparamsbase.cpp | 2 ++ src/chainparamsbase.h | 2 ++ src/init.cpp | 6 ++++-- src/test/util_tests.cpp | 2 +- src/util/system.cpp | 4 ++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index fe8b73861e7..c846e947372 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -16,6 +16,8 @@ const std::string CBaseChainParams::TESTNET = "test"; const std::string CBaseChainParams::REGTEST = "regtest"; const std::string CBaseChainParams::LIQUID1 = "liquidv1"; +const std::string CBaseChainParams::DEFAULT = CBaseChainParams::LIQUID1; + void SetupChainParamsBaseOptions() { gArgs.AddArg("-chain=", "Use the chain (default: main). Reserved values: main, test, regtest", false, OptionsCategory::CHAINPARAMS); diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h index 273128178f8..35defd28d9e 100644 --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -22,6 +22,8 @@ class CBaseChainParams static const std::string REGTEST; static const std::string LIQUID1; + static const std::string DEFAULT; + const std::string& DataDir() const { return strDataDir; } int RPCPort() const { return nRPCPort; } int MainchainRPCPort() const { return nMainchainRPCPort; } diff --git a/src/init.cpp b/src/init.cpp index 2980679a47a..4c02c8f7470 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -363,10 +363,12 @@ void SetupServerArgs() SetupHelpOptions(gArgs); gArgs.AddArg("-help-debug", "Print help message with debugging options and exit", false, OptionsCategory::DEBUG_TEST); // server-only for now - const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); + const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::DEFAULT); + const auto mainnetBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET); const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST); - const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN); + const auto defaultChainParams = CreateChainParams(CBaseChainParams::DEFAULT); + const auto mainnetChainParams = CreateChainParams(CBaseChainParams::MAIN); const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET); const auto regtestChainParams = CreateChainParams(CBaseChainParams::REGTEST); diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index c56402b5ba8..6402d294099 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -480,7 +480,7 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream) test_args.SetNetworkOnlyArg("-ccc"); test_args.SetNetworkOnlyArg("-h"); - test_args.SelectConfigNetwork(CBaseChainParams::MAIN); + test_args.SelectConfigNetwork(CBaseChainParams::DEFAULT); BOOST_CHECK(test_args.GetArg("-d", "xxx") == "e"); BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2); BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0"); diff --git a/src/util/system.cpp b/src/util/system.cpp index e31764eebc2..487efa27517 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -174,7 +174,7 @@ class ArgsManagerHelper { * See also comments around ArgsManager::ArgsManager() below. */ static inline bool UseDefaultSection(const ArgsManager& am, const std::string& arg) EXCLUSIVE_LOCKS_REQUIRED(am.cs_args) { - return (am.m_network == CBaseChainParams::MAIN || am.m_network_only_args.count(arg) == 0); + return (am.m_network == CBaseChainParams::DEFAULT || am.m_network_only_args.count(arg) == 0); } /** Convert regular argument into the network-specific setting */ @@ -336,7 +336,7 @@ const std::set ArgsManager::GetUnsuitableSectionOnlyArgs() const if (m_network.empty()) return std::set {}; // if it's okay to use the default section for this network, don't worry - if (m_network == CBaseChainParams::MAIN) return std::set {}; + if (m_network == CBaseChainParams::DEFAULT) return std::set {}; for (const auto& arg : m_network_only_args) { std::pair found_result;