From 32fa49a18497a9b8c72e36a72ae96e7b23930223 Mon Sep 17 00:00:00 2001 From: fanquake Date: Wed, 4 Aug 2021 13:38:36 +0800 Subject: make ParseOutputType return a std::optional --- src/outputtype.cpp | 17 +++++++---------- src/outputtype.h | 3 ++- src/rpc/misc.cpp | 8 +++++--- src/test/fuzz/kitchen_sink.cpp | 8 ++++---- src/test/fuzz/string.cpp | 3 +-- src/wallet/rpcwallet.cpp | 27 +++++++++++++++------------ src/wallet/wallet.cpp | 10 ++++++---- 7 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/outputtype.cpp b/src/outputtype.cpp index 8ede7b9974..b5f1df9792 100644 --- a/src/outputtype.cpp +++ b/src/outputtype.cpp @@ -13,6 +13,7 @@ #include #include +#include #include static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy"; @@ -20,22 +21,18 @@ static const std::string OUTPUT_TYPE_STRING_P2SH_SEGWIT = "p2sh-segwit"; static const std::string OUTPUT_TYPE_STRING_BECH32 = "bech32"; static const std::string OUTPUT_TYPE_STRING_BECH32M = "bech32m"; -bool ParseOutputType(const std::string& type, OutputType& output_type) +std::optional ParseOutputType(const std::string& type) { if (type == OUTPUT_TYPE_STRING_LEGACY) { - output_type = OutputType::LEGACY; - return true; + return OutputType::LEGACY; } else if (type == OUTPUT_TYPE_STRING_P2SH_SEGWIT) { - output_type = OutputType::P2SH_SEGWIT; - return true; + return OutputType::P2SH_SEGWIT; } else if (type == OUTPUT_TYPE_STRING_BECH32) { - output_type = OutputType::BECH32; - return true; + return OutputType::BECH32; } else if (type == OUTPUT_TYPE_STRING_BECH32M) { - output_type = OutputType::BECH32M; - return true; + return OutputType::BECH32M; } - return false; + return std::nullopt; } const std::string& FormatOutputType(OutputType type) diff --git a/src/outputtype.h b/src/outputtype.h index 2b83235cd0..0de7689125 100644 --- a/src/outputtype.h +++ b/src/outputtype.h @@ -11,6 +11,7 @@ #include