diff options
author | fanquake <fanquake@gmail.com> | 2023-05-29 10:35:14 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-05-29 10:48:53 +0100 |
commit | a2e111b8a3d17e328eba6111f6c9138543255f3d (patch) | |
tree | 3c600b7b4863b731d36acd1b8efa14fb45e11bdd /src | |
parent | b5ed656c3ba5198f58e771cc5f7147e02247a789 (diff) | |
parent | fa6b11a55663e70369bfbbba5fccc55b33f2b310 (diff) |
Merge bitcoin/bitcoin#27765: test: Throw error when -signetchallenge is non-hex
fa6b11a55663e70369bfbbba5fccc55b33f2b310 test: Throw error when -signetchallenge is non-hex (MarcoFalke)
Pull request description:
Instead of silently parsing non-hex to an empty challenge, throw an error.
Also, add missing includes while touching the file.
ACKs for top commit:
kevkevinpal:
ACK [fa6b11a](https://github.com/bitcoin/bitcoin/pull/27765/commits/fa6b11a55663e70369bfbbba5fccc55b33f2b310)
kallewoof:
ACK fa6b11a
TheCharlatan:
Nice, ACK fa6b11a55663e70369bfbbba5fccc55b33f2b310
Tree-SHA512: 018ebbbf819ba7cdf0c6dd294fdfaa5ddb81b87058a8b9c57b96066d5b07e1656fd78f18e3cef375aebefa191fa515c2c70bc764880fa05f98f526334431a616
Diffstat (limited to 'src')
-rw-r--r-- | src/chainparams.cpp | 21 | ||||
-rw-r--r-- | src/chainparams.h | 13 | ||||
-rw-r--r-- | src/util/strencodings.h | 4 | ||||
-rw-r--r-- | src/util/string.h | 4 |
4 files changed, 19 insertions, 23 deletions
diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 6f4453d1fe..539578085b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -6,17 +6,20 @@ #include <chainparams.h> #include <chainparamsbase.h> -#include <chainparamsseeds.h> #include <common/args.h> -#include <consensus/merkle.h> +#include <consensus/params.h> #include <deploymentinfo.h> -#include <hash.h> // for signet block challenge hash #include <logging.h> -#include <script/interpreter.h> +#include <tinyformat.h> #include <util/chaintype.h> +#include <util/strencodings.h> #include <util/string.h> -#include <assert.h> +#include <cassert> +#include <cstdint> +#include <limits> +#include <stdexcept> +#include <vector> void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options) { @@ -26,9 +29,13 @@ void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& option if (args.IsArgSet("-signetchallenge")) { const auto signet_challenge = args.GetArgs("-signetchallenge"); if (signet_challenge.size() != 1) { - throw std::runtime_error(strprintf("%s: -signetchallenge cannot be multiple values.", __func__)); + throw std::runtime_error("-signetchallenge cannot be multiple values."); } - options.challenge.emplace(ParseHex(signet_challenge[0])); + const auto val{TryParseHex<uint8_t>(signet_challenge[0])}; + if (!val) { + throw std::runtime_error(strprintf("-signetchallenge must be hex, not '%s'.", signet_challenge[0])); + } + options.challenge.emplace(*val); } } diff --git a/src/chainparams.h b/src/chainparams.h index 1e8366dcf5..4743e022db 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -6,20 +6,9 @@ #ifndef BITCOIN_CHAINPARAMS_H #define BITCOIN_CHAINPARAMS_H -#include <kernel/chainparams.h> +#include <kernel/chainparams.h> // IWYU pragma: export -#include <consensus/params.h> -#include <netaddress.h> -#include <primitives/block.h> -#include <protocol.h> -#include <util/chaintype.h> -#include <util/hash_type.h> - -#include <cstdint> #include <memory> -#include <string> -#include <unordered_map> -#include <vector> class ArgsManager; diff --git a/src/util/strencodings.h b/src/util/strencodings.h index 05e7b957c4..d792562735 100644 --- a/src/util/strencodings.h +++ b/src/util/strencodings.h @@ -17,8 +17,8 @@ #include <cstdint> #include <limits> #include <optional> -#include <string> -#include <string_view> +#include <string> // IWYU pragma: export +#include <string_view> // IWYU pragma: export #include <system_error> #include <type_traits> #include <vector> diff --git a/src/util/string.h b/src/util/string.h index fb93d2a80e..8b69d6ccae 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -12,8 +12,8 @@ #include <cstring> #include <locale> #include <sstream> -#include <string> -#include <string_view> +#include <string> // IWYU pragma: export +#include <string_view> // IWYU pragma: export #include <vector> void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute); |