diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -250,9 +250,6 @@ // Get default address type. virtual OutputType getDefaultAddressType() = 0; - // Get default change type. - virtual OutputType getDefaultChangeType() = 0; - //! Get max tx fee. virtual Amount getDefaultMaxTxFee() = 0; diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -404,9 +404,6 @@ bool privateKeysDisabled() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); } - OutputType getDefaultChangeType() override { - return m_wallet->m_default_change_type; - } Amount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; } diff --git a/src/outputtype.h b/src/outputtype.h --- a/src/outputtype.h +++ b/src/outputtype.h @@ -14,15 +14,7 @@ #include #include -enum class OutputType { - LEGACY, - - /** - * Special output type for change outputs only. Automatically choose type - * based on address type setting and the types other of non-change outputs. - */ - CHANGE_AUTO, -}; +enum class OutputType { LEGACY }; extern const std::array OUTPUT_TYPES; diff --git a/src/outputtype.cpp b/src/outputtype.cpp --- a/src/outputtype.cpp +++ b/src/outputtype.cpp @@ -28,18 +28,16 @@ switch (type) { case OutputType::LEGACY: return OUTPUT_TYPE_STRING_LEGACY; - default: - assert(false); - } + } // no default case, so the compiler can warn about missing cases + assert(false); } CTxDestination GetDestinationForKey(const CPubKey &key, OutputType type) { switch (type) { case OutputType::LEGACY: return PKHash(key); - default: - assert(false); - } + } // no default case, so the compiler can warn about missing cases + assert(false); } std::vector GetAllDestinationsForKey(const CPubKey &key) { @@ -57,7 +55,6 @@ switch (type) { case OutputType::LEGACY: return ScriptHash(script); - default: - assert(false); - } + } // no default case, so the compiler can warn about missing cases + assert(false); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -290,10 +290,8 @@ "Error: This wallet has no available keys"); } - OutputType output_type = - pwallet->m_default_change_type != OutputType::CHANGE_AUTO - ? pwallet->m_default_change_type - : pwallet->m_default_address_type; + 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)) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -1978,9 +1978,8 @@ desc_prefix = "pkh(" + xpub + "/44'"; break; } - default: - assert(false); - } + } // no default case, so the compiler can warn about missing cases + assert(!desc_prefix.empty()); // Mainnet derives at 0', testnet and regtest derive at 1' if (m_storage.GetChainParams().IsTestChain()) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -122,9 +122,6 @@ //! Default for -addresstype constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::LEGACY}; -//! Default for -changetype -constexpr OutputType DEFAULT_CHANGE_TYPE{OutputType::CHANGE_AUTO}; - static constexpr uint64_t KNOWN_WALLET_FLAGS = WALLET_FLAG_AVOID_REUSE | WALLET_FLAG_BLANK_WALLET | WALLET_FLAG_KEY_ORIGIN_METADATA | WALLET_FLAG_DISABLE_PRIVATE_KEYS | @@ -1106,8 +1103,9 @@ Balance GetBalance(int min_depth = 0, bool avoid_reuse = true) const; Amount GetAvailableBalance(const CCoinControl *coinControl = nullptr) const; - OutputType TransactionChangeType(OutputType change_type, - const std::vector &vecSend); + OutputType + TransactionChangeType(const std::optional &change_type, + const std::vector &vecSend); /** * Insert additional inputs into the transaction by calling @@ -1218,7 +1216,13 @@ //! note: this is absolute fee, not fee rate Amount m_max_aps_fee{DEFAULT_MAX_AVOIDPARTIALSPEND_FEE}; OutputType m_default_address_type{DEFAULT_ADDRESS_TYPE}; - OutputType m_default_change_type{DEFAULT_CHANGE_TYPE}; + /** + * Default output type for change outputs. When unset, automatically choose + * type based on address type setting and the types other of non-change + * outputs (see implementation in CWallet::TransactionChangeType for + * details). + */ + std::optional m_default_change_type{}; /** * Absolute maximum transaction fee (in satoshis) used by default for the * wallet. diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3000,11 +3000,11 @@ } OutputType -CWallet::TransactionChangeType(OutputType change_type, +CWallet::TransactionChangeType(const std::optional &change_type, const std::vector &vecSend) { // If -changetype is specified, always use that change type. - if (change_type != OutputType::CHANGE_AUTO) { - return change_type; + if (change_type) { + return *change_type; } // if m_default_address_type is legacy, use legacy address as change. @@ -4408,7 +4408,6 @@ gArgs.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE); walletInstance->m_default_address_type = DEFAULT_ADDRESS_TYPE; - walletInstance->m_default_change_type = DEFAULT_CHANGE_TYPE; walletInstance->WalletLogPrintf("Wallet completed loading in %15dms\n", GetTimeMillis() - nStart);