diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -13,7 +13,11 @@ /** Coin Control Features. */ class CCoinControl { public: + //! Custom change destination, if not set an address is generated CTxDestination destChange; + //! Custom change type, ignored if destChange is set, defaults to + //! g_change_type + OutputType change_type; //! If false, allows unselected inputs, but requires all selected inputs be //! used bool fAllowOtherInputs; diff --git a/src/wallet/coincontrol.cpp b/src/wallet/coincontrol.cpp --- a/src/wallet/coincontrol.cpp +++ b/src/wallet/coincontrol.cpp @@ -8,6 +8,7 @@ void CCoinControl::SetNull() { destChange = CNoDestination(); + change_type = g_change_type; fAllowOtherInputs = false; fAllowWatchOnly = false; m_avoid_partial_spends = diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1010,7 +1010,8 @@ const std::string *account) const; Amount GetAvailableBalance(const CCoinControl *coinControl = nullptr) const; - OutputType TransactionChangeType(const std::vector &vecSend); + OutputType TransactionChangeType(OutputType change_type, + const std::vector &vecSend); /** * Insert additional inputs into the transaction by calling diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2890,10 +2890,11 @@ } OutputType -CWallet::TransactionChangeType(const std::vector &vecSend) { +CWallet::TransactionChangeType(OutputType change_type, + const std::vector &vecSend) { // If -changetype is specified, always use that change type. - if (g_change_type != OutputType::NONE) { - return g_change_type; + if (change_type != OutputType::NONE) { + return change_type; } // if g_address_type is legacy, use legacy address as change. @@ -3005,7 +3006,8 @@ return false; } - const OutputType change_type = TransactionChangeType(vecSend); + const OutputType change_type = + TransactionChangeType(coinControl.change_type, vecSend); LearnRelatedScripts(vchPubKey, change_type); scriptChange = GetScriptForDestination(