diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -706,7 +706,8 @@ // type we use subject to privacy issues, but not restricted by what // other software supports. const OutputType change_type = - walletModel->wallet().getDefaultChangeType() != OutputType::NONE + walletModel->wallet().getDefaultChangeType() != + OutputType::CHANGE_AUTO ? walletModel->wallet().getDefaultChangeType() : walletModel->wallet().getDefaultAddressType(); walletModel->wallet().learnRelatedScripts(newKey, change_type); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -190,9 +190,7 @@ OutputType output_type = pwallet->m_default_address_type; if (!request.params[1].isNull()) { - output_type = ParseOutputType(request.params[1].get_str(), - pwallet->m_default_address_type); - if (output_type == OutputType::NONE) { + if (!ParseOutputType(request.params[1].get_str(), output_type)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[1].get_str())); @@ -335,12 +333,12 @@ pwallet->TopUpKeyPool(); } - OutputType output_type = pwallet->m_default_change_type != OutputType::NONE - ? pwallet->m_default_change_type - : pwallet->m_default_address_type; + OutputType output_type = + pwallet->m_default_change_type != OutputType::CHANGE_AUTO + ? pwallet->m_default_change_type + : pwallet->m_default_address_type; if (!request.params[0].isNull()) { - output_type = ParseOutputType(request.params[0].get_str(), output_type); - if (output_type == OutputType::NONE) { + if (!ParseOutputType(request.params[0].get_str(), output_type)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str())); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -92,13 +92,23 @@ }; enum class OutputType { - NONE, LEGACY, + + /** + * Special output type for change outputs only. Automatically choose type + * based on address type setting and the types other of non-change outputs + * (see -changetype option documentation and implementation in + * CWallet::TransactionChangeType for details). + */ + CHANGE_AUTO, }; //! Default for -addresstype constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::LEGACY}; +//! Default for -changetype +constexpr OutputType DEFAULT_CHANGE_TYPE{OutputType::CHANGE_AUTO}; + /** A key pool entry */ class CKeyPool { public: @@ -1112,8 +1122,7 @@ */ CFeeRate m_fallback_fee{DEFAULT_FALLBACK_FEE}; OutputType m_default_address_type{DEFAULT_ADDRESS_TYPE}; - // Default to OutputType::NONE if not set by -changetype - OutputType m_default_change_type{OutputType::NONE}; + OutputType m_default_change_type{DEFAULT_CHANGE_TYPE}; bool NewKeyPool(); size_t KeypoolCountExternalKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); @@ -1391,7 +1400,7 @@ } }; -OutputType ParseOutputType(const std::string &str, OutputType default_type); +bool ParseOutputType(const std::string &str, OutputType &output_type); const std::string &FormatOutputType(OutputType type); /** diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2888,7 +2888,7 @@ CWallet::TransactionChangeType(OutputType change_type, const std::vector &vecSend) { // If -changetype is specified, always use that change type. - if (change_type != OutputType::NONE) { + if (change_type != OutputType::CHANGE_AUTO) { return change_type; } @@ -4581,7 +4581,7 @@ gArgs.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE); walletInstance->m_default_address_type = DEFAULT_ADDRESS_TYPE; - walletInstance->m_default_change_type = OutputType::NONE; + walletInstance->m_default_change_type = DEFAULT_CHANGE_TYPE; LogPrintf(" wallet %15dms\n", GetTimeMillis() - nStart); @@ -4780,14 +4780,12 @@ static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy"; -OutputType ParseOutputType(const std::string &type, OutputType default_type) { - if (type.empty()) { - return default_type; - } else if (type == OUTPUT_TYPE_STRING_LEGACY) { - return OutputType::LEGACY; - } else { - return OutputType::NONE; +bool ParseOutputType(const std::string &type, OutputType &output_type) { + if (type == OUTPUT_TYPE_STRING_LEGACY) { + output_type = OutputType::LEGACY; + return true; } + return false; } const std::string &FormatOutputType(OutputType type) {