diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -137,8 +137,9 @@ class ReserveDestination { protected: //! The wallet to reserve from - CWallet *pwallet; + CWallet *const pwallet; LegacyScriptPubKeyMan *m_spk_man{nullptr}; + OutputType const type; //! The index of the address's key in the keypool int64_t nIndex{-1}; //! The public key for the address @@ -151,7 +152,8 @@ public: //! Construct a ReserveDestination object. This does NOT reserve an address //! yet - explicit ReserveDestination(CWallet *pwalletIn) { pwallet = pwalletIn; } + explicit ReserveDestination(CWallet *_pwallet, OutputType _type) + : pwallet(_pwallet), type(_type) {} ReserveDestination(const ReserveDestination &) = delete; ReserveDestination &operator=(const ReserveDestination &) = delete; @@ -161,8 +163,7 @@ ~ReserveDestination() { ReturnDestination(); } //! Reserve an address - bool GetReservedDestination(const OutputType type, CTxDestination &pubkey, - bool internal); + bool GetReservedDestination(CTxDestination &pubkey, bool internal); //! Return reserved address void ReturnDestination(); //! Keep the address. Do not return it's key to the keypool when this object diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2845,7 +2845,11 @@ std::string &strFailReason, const CCoinControl &coinControl, bool sign) { Amount nValue = Amount::zero(); - ReserveDestination reservedest(this); + const OutputType change_type = TransactionChangeType( + coinControl.m_change_type ? *coinControl.m_change_type + : m_default_change_type, + vecSend); + ReserveDestination reservedest(this, change_type); int nChangePosRequest = nChangePosInOut; unsigned int nSubtractFeeFromAmount = 0; for (const auto &recipient : vecSend) { @@ -2911,12 +2915,7 @@ return false; } CTxDestination dest; - const OutputType change_type = TransactionChangeType( - coinControl.m_change_type ? *coinControl.m_change_type - : m_default_change_type, - vecSend); - bool ret = - reservedest.GetReservedDestination(change_type, dest, true); + bool ret = reservedest.GetReservedDestination(dest, true); if (!ret) { strFailReason = _("Keypool ran out, please call keypoolrefill first") @@ -3467,8 +3466,8 @@ m_spk_man->TopUp(); - ReserveDestination reservedest(this); - if (!reservedest.GetReservedDestination(type, dest, true)) { + ReserveDestination reservedest(this, type); + if (!reservedest.GetReservedDestination(dest, true)) { error = "Error: Keypool ran out, please call keypoolrefill first"; return false; } @@ -3650,8 +3649,7 @@ return result; } -bool ReserveDestination::GetReservedDestination(const OutputType type, - CTxDestination &dest, +bool ReserveDestination::GetReservedDestination(CTxDestination &dest, bool internal) { m_spk_man = pwallet->GetLegacyScriptPubKeyMan(); if (!m_spk_man) {