@@ -266,12 +266,13 @@ static RPCHelpMan getnewaddress()
266266
267267 OutputType output_type = pwallet->m_default_address_type ;
268268 if (!request.params [1 ].isNull ()) {
269- if (!ParseOutputType (request.params [1 ].get_str (), output_type)) {
269+ std::optional<OutputType> parsed = ParseOutputType (request.params [1 ].get_str ());
270+ if (!parsed) {
270271 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, strprintf (" Unknown address type '%s'" , request.params [1 ].get_str ()));
271- }
272- if (output_type == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan ()) {
272+ } else if (parsed.value () == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan ()) {
273273 throw JSONRPCError (RPC_INVALID_PARAMETER, " Legacy wallets cannot provide bech32m addresses" );
274274 }
275+ output_type = parsed.value ();
275276 }
276277
277278 CTxDestination dest;
@@ -313,12 +314,13 @@ static RPCHelpMan getrawchangeaddress()
313314
314315 OutputType output_type = pwallet->m_default_change_type .value_or (pwallet->m_default_address_type );
315316 if (!request.params [0 ].isNull ()) {
316- if (!ParseOutputType (request.params [0 ].get_str (), output_type)) {
317+ std::optional<OutputType> parsed = ParseOutputType (request.params [0 ].get_str ());
318+ if (!parsed) {
317319 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, strprintf (" Unknown address type '%s'" , request.params [0 ].get_str ()));
318- }
319- if (output_type == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan ()) {
320+ } else if (parsed.value () == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan ()) {
320321 throw JSONRPCError (RPC_INVALID_PARAMETER, " Legacy wallets cannot provide bech32m addresses" );
321322 }
323+ output_type = parsed.value ();
322324 }
323325
324326 CTxDestination dest;
@@ -1007,12 +1009,13 @@ static RPCHelpMan addmultisigaddress()
10071009
10081010 OutputType output_type = pwallet->m_default_address_type ;
10091011 if (!request.params [3 ].isNull ()) {
1010- if (!ParseOutputType (request.params [3 ].get_str (), output_type)) {
1012+ std::optional<OutputType> parsed = ParseOutputType (request.params [3 ].get_str ());
1013+ if (!parsed) {
10111014 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, strprintf (" Unknown address type '%s'" , request.params [3 ].get_str ()));
1012- }
1013- if (output_type == OutputType::BECH32M) {
1015+ } else if (parsed.value () == OutputType::BECH32M) {
10141016 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Bech32m multisig addresses cannot be created with legacy wallets" );
10151017 }
1018+ output_type = parsed.value ();
10161019 }
10171020
10181021 // Construct using pay-to-script-hash:
@@ -3133,11 +3136,11 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
31333136 if (options.exists (" changeAddress" ) || options.exists (" change_address" )) {
31343137 throw JSONRPCError (RPC_INVALID_PARAMETER, " Cannot specify both change address and address type options" );
31353138 }
3136- OutputType out_type;
3137- if (!ParseOutputType (options[" change_type" ].get_str (), out_type)) {
3139+ if (std::optional<OutputType> parsed = ParseOutputType (options[" change_type" ].get_str ())) {
3140+ coinControl.m_change_type .emplace (parsed.value ());
3141+ } else {
31383142 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, strprintf (" Unknown change type '%s'" , options[" change_type" ].get_str ()));
31393143 }
3140- coinControl.m_change_type .emplace (out_type);
31413144 }
31423145
31433146 const UniValue include_watching_option = options.exists (" include_watching" ) ? options[" include_watching" ] : options[" includeWatching" ];
0 commit comments