diff options
author | fanquake <fanquake@gmail.com> | 2023-05-10 11:57:45 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-05-10 12:27:18 +0100 |
commit | 104eed116614996d9724f82d47e373ef420cd372 (patch) | |
tree | 0d99e6641d9bf059fde2fd863bbcbf5192b980c4 /src | |
parent | 883766fa4517d310839c8968994d1fb4effdc7c2 (diff) | |
parent | e23088707be2c3bf247f4b777290c8e401db48cb (diff) |
Merge bitcoin/bitcoin#27611: refactor: Use ChainType enum exhaustively
e23088707be2c3bf247f4b777290c8e401db48cb refactor: Use ChainType enum exhaustively (TheCharlatan)
Pull request description:
This is a follow up of https://github.com/bitcoin/bitcoin/pull/27491, more concretely https://github.com/bitcoin/bitcoin/pull/27491#discussion_r1188847896, for not using default cases (as per the style guide), and https://github.com/bitcoin/bitcoin/pull/27491#discussion_r1188852707 and https://github.com/bitcoin/bitcoin/pull/27491#discussion_r1188851857 for avoiding dead code.
ACKs for top commit:
fanquake:
ACK e23088707be2c3bf247f4b777290c8e401db48cb - deals with almost all follow up comments out of #27491.
Tree-SHA512: 1794190b03b91d3ca349a4da08e9610dbb3432983eee7cb21ecc758d1d7d710560c97661de14cdf493c28c00ebe8977511b4696055c0940e7f815b622dbacd16
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoin-cli.cpp | 3 | ||||
-rw-r--r-- | src/chainparams.cpp | 2 | ||||
-rw-r--r-- | src/chainparams.h | 5 | ||||
-rw-r--r-- | src/chainparamsbase.cpp | 2 | ||||
-rw-r--r-- | src/chainparamsbase.h | 2 | ||||
-rw-r--r-- | src/common/args.h | 6 | ||||
-rw-r--r-- | src/test/argsman_tests.cpp | 2 |
7 files changed, 9 insertions, 13 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index a66134128d..3657fde140 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -434,9 +434,10 @@ private: return " signet"; case ChainType::REGTEST: return " regtest"; - default: + case ChainType::MAIN: return ""; } + assert(false); } std::string PingTimeToString(double seconds) const { diff --git a/src/chainparams.cpp b/src/chainparams.cpp index f61bf01745..6f4453d1fe 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -117,7 +117,7 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c return CChainParams::RegTest(opts); } } - throw std::invalid_argument(strprintf("%s: Invalid ChainType value", __func__)); + assert(false); } void SelectParams(const ChainType chain) diff --git a/src/chainparams.h b/src/chainparams.h index 6a65f40f80..1e8366dcf5 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -25,8 +25,6 @@ class ArgsManager; /** * Creates and returns a std::unique_ptr<CChainParams> of the chosen chain. - * @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 ChainType chain); @@ -37,8 +35,7 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c 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. + * Sets the params returned by Params() to those for the given chain type. */ void SelectParams(const ChainType chain); diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 4ebfeae1a7..8cbf9e85e0 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -48,7 +48,7 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainType chain) case ChainType::REGTEST: return std::make_unique<CBaseChainParams>("regtest", 18443, 18445); } - throw std::invalid_argument(strprintf("%s: Invalid ChainType value", __func__)); + assert(false); } void SelectBaseParams(const ChainType chain) diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h index 73e449d11b..ea933d1ca8 100644 --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -35,8 +35,6 @@ private: /** * Creates and returns a std::unique_ptr<CBaseChainParams> of the chosen chain. - * @returns a CBaseChainParams* of the chosen chain. - * @throws a std::runtime_error if the chain is not supported. */ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ChainType chain); diff --git a/src/common/args.h b/src/common/args.h index 5335633911..537a64fcfd 100644 --- a/src/common/args.h +++ b/src/common/args.h @@ -325,14 +325,14 @@ protected: void ForceSetArg(const std::string& strArg, const std::string& strValue); /** - * Returns the appropriate chain name from the program arguments. + * Returns the appropriate chain type from the program arguments. * @return ChainType::MAIN by default; raises runtime error if an invalid * combination, or unknown chain is given. */ ChainType GetChainType() const; /** - * Returns the appropriate chain name string from the program arguments. + * Returns the appropriate chain type string from the program arguments. * @return ChainType::MAIN string by default; raises runtime error if an * invalid combination is given. */ @@ -423,7 +423,7 @@ private: /** * Return -regtest/-signet/-testnet/-chain= setting as a ChainType enum if a - * recognized chain name was set, or as a string if an unrecognized chain + * recognized chain type was set, or as a string if an unrecognized chain * name was set. Raise an exception if an invalid combination of flags was * provided. */ diff --git a/src/test/argsman_tests.cpp b/src/test/argsman_tests.cpp index 4d6ef206c7..48bffc4ac9 100644 --- a/src/test/argsman_tests.cpp +++ b/src/test/argsman_tests.cpp @@ -255,7 +255,7 @@ BOOST_AUTO_TEST_CASE(util_ParseInvalidParameters) BOOST_CHECK(!test.ParseParameters(2, (char**)argv, error)); BOOST_CHECK_EQUAL(error, "Invalid parameter -unregistered"); - // Make sure registered parameters prefixed with a chain name trigger errors. + // Make sure registered parameters prefixed with a chain type trigger errors. // (Previously, they were accepted and ignored.) argv[1] = "-test.registered"; BOOST_CHECK(!test.ParseParameters(2, (char**)argv, error)); |