make ParseOutputType return a std::optional<OutputType>

This commit is contained in:
fanquake
2021-08-04 13:38:36 +08:00
parent 3308c61091
commit 32fa49a184
7 changed files with 40 additions and 36 deletions

View File

@@ -24,6 +24,7 @@
#include <util/strencodings.h>
#include <util/system.h>
#include <optional>
#include <stdint.h>
#include <tuple>
#ifdef HAVE_MALLOC_INFO
@@ -128,12 +129,13 @@ static RPCHelpMan createmultisig()
// Get the output type
OutputType output_type = OutputType::LEGACY;
if (!request.params[2].isNull()) {
if (!ParseOutputType(request.params[2].get_str(), output_type)) {
std::optional<OutputType> parsed = ParseOutputType(request.params[2].get_str());
if (!parsed) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[2].get_str()));
}
if (output_type == OutputType::BECH32M) {
} else if (parsed.value() == OutputType::BECH32M) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "createmultisig cannot create bech32m multisig addresses");
}
output_type = parsed.value();
}
// Construct using pay-to-script-hash: