aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/rpcwallet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/rpcwallet.cpp')
-rw-r--r--src/wallet/rpcwallet.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index f1d5117415..43b67076cd 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -266,12 +266,13 @@ static RPCHelpMan getnewaddress()
OutputType output_type = pwallet->m_default_address_type;
if (!request.params[1].isNull()) {
- if (!ParseOutputType(request.params[1].get_str(), output_type)) {
+ std::optional<OutputType> parsed = ParseOutputType(request.params[1].get_str());
+ if (!parsed) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[1].get_str()));
- }
- if (output_type == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan()) {
+ } else if (parsed.value() == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Legacy wallets cannot provide bech32m addresses");
}
+ output_type = parsed.value();
}
CTxDestination dest;
@@ -313,12 +314,13 @@ static RPCHelpMan getrawchangeaddress()
OutputType output_type = pwallet->m_default_change_type.value_or(pwallet->m_default_address_type);
if (!request.params[0].isNull()) {
- if (!ParseOutputType(request.params[0].get_str(), output_type)) {
+ std::optional<OutputType> parsed = ParseOutputType(request.params[0].get_str());
+ if (!parsed) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str()));
- }
- if (output_type == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan()) {
+ } else if (parsed.value() == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Legacy wallets cannot provide bech32m addresses");
}
+ output_type = parsed.value();
}
CTxDestination dest;
@@ -1007,12 +1009,13 @@ static RPCHelpMan addmultisigaddress()
OutputType output_type = pwallet->m_default_address_type;
if (!request.params[3].isNull()) {
- if (!ParseOutputType(request.params[3].get_str(), output_type)) {
+ std::optional<OutputType> parsed = ParseOutputType(request.params[3].get_str());
+ if (!parsed) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[3].get_str()));
- }
- if (output_type == OutputType::BECH32M) {
+ } else if (parsed.value() == OutputType::BECH32M) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Bech32m multisig addresses cannot be created with legacy wallets");
}
+ output_type = parsed.value();
}
// Construct using pay-to-script-hash:
@@ -3133,11 +3136,11 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
if (options.exists("changeAddress") || options.exists("change_address")) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both change address and address type options");
}
- OutputType out_type;
- if (!ParseOutputType(options["change_type"].get_str(), out_type)) {
+ if (std::optional<OutputType> parsed = ParseOutputType(options["change_type"].get_str())) {
+ coinControl.m_change_type.emplace(parsed.value());
+ } else {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown change type '%s'", options["change_type"].get_str()));
}
- coinControl.m_change_type.emplace(out_type);
}
const UniValue include_watching_option = options.exists("include_watching") ? options["include_watching"] : options["includeWatching"];