Skip to content

Commit 55295fb

Browse files
committed
wallet: Lock address type in ReserveDestination
1 parent bbc9e41 commit 55295fb

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,8 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
24902490
int& nChangePosInOut, std::string& strFailReason, const CCoinControl& coin_control, bool sign)
24912491
{
24922492
CAmount nValue = 0;
2493-
ReserveDestination reservedest(this);
2493+
const OutputType change_type = TransactionChangeType(coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend);
2494+
ReserveDestination reservedest(this, change_type);
24942495
int nChangePosRequest = nChangePosInOut;
24952496
unsigned int nSubtractFeeFromAmount = 0;
24962497
for (const auto& recipient : vecSend)
@@ -2549,8 +2550,7 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
25492550
return false;
25502551
}
25512552
CTxDestination dest;
2552-
const OutputType change_type = TransactionChangeType(coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend);
2553-
bool ret = reservedest.GetReservedDestination(change_type, dest, true);
2553+
bool ret = reservedest.GetReservedDestination(dest, true);
25542554
if (!ret)
25552555
{
25562556
strFailReason = "Keypool ran out, please call keypoolrefill first";
@@ -3069,8 +3069,8 @@ bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& des
30693069

30703070
m_spk_man->TopUp();
30713071

3072-
ReserveDestination reservedest(this);
3073-
if (!reservedest.GetReservedDestination(type, dest, true)) {
3072+
ReserveDestination reservedest(this, type);
3073+
if (!reservedest.GetReservedDestination(dest, true)) {
30743074
error = "Error: Keypool ran out, please call keypoolrefill first";
30753075
return false;
30763076
}
@@ -3235,7 +3235,7 @@ std::set<CTxDestination> CWallet::GetLabelAddresses(const std::string& label) co
32353235
return result;
32363236
}
32373237

3238-
bool ReserveDestination::GetReservedDestination(const OutputType type, CTxDestination& dest, bool internal)
3238+
bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool internal)
32393239
{
32403240
m_spk_man = pwallet->GetLegacyScriptPubKeyMan();
32413241
if (!m_spk_man) {

src/wallet/wallet.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ class ReserveDestination
140140
{
141141
protected:
142142
//! The wallet to reserve from
143-
CWallet* pwallet;
143+
CWallet* const pwallet;
144144
LegacyScriptPubKeyMan* m_spk_man{nullptr};
145+
OutputType const type;
145146
//! The index of the address's key in the keypool
146147
int64_t nIndex{-1};
147148
//! The public key for the address
@@ -153,10 +154,9 @@ class ReserveDestination
153154

154155
public:
155156
//! Construct a ReserveDestination object. This does NOT reserve an address yet
156-
explicit ReserveDestination(CWallet* pwalletIn)
157-
{
158-
pwallet = pwalletIn;
159-
}
157+
explicit ReserveDestination(CWallet* pwallet, OutputType type)
158+
: pwallet(pwallet)
159+
, type(type) { }
160160

161161
ReserveDestination(const ReserveDestination&) = delete;
162162
ReserveDestination& operator=(const ReserveDestination&) = delete;
@@ -168,7 +168,7 @@ class ReserveDestination
168168
}
169169

170170
//! Reserve an address
171-
bool GetReservedDestination(const OutputType type, CTxDestination& pubkey, bool internal);
171+
bool GetReservedDestination(CTxDestination& pubkey, bool internal);
172172
//! Return reserved address
173173
void ReturnDestination();
174174
//! Keep the address. Do not return it's key to the keypool when this object goes out of scope

0 commit comments

Comments
 (0)