Skip to content

Commit 8e7f930

Browse files
committed
Add GetNewChangeDestination for getting new change Destinations
Adds a GetNewChangeDestination that has the same objective as GetNewDestination
1 parent 33d13ed commit 8e7f930

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,18 @@ static UniValue getrawchangeaddress(const JSONRPCRequest& request)
226226
throw JSONRPCError(RPC_WALLET_ERROR, "Error: This wallet has no available keys");
227227
}
228228

229-
if (!pwallet->IsLocked()) {
230-
pwallet->TopUpKeyPool();
231-
}
232-
233229
OutputType output_type = pwallet->m_default_change_type != OutputType::CHANGE_AUTO ? pwallet->m_default_change_type : pwallet->m_default_address_type;
234230
if (!request.params[0].isNull()) {
235231
if (!ParseOutputType(request.params[0].get_str(), output_type)) {
236232
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str()));
237233
}
238234
}
239235

240-
ReserveDestination reservedest(pwallet);
241236
CTxDestination dest;
242-
if (!reservedest.GetReservedDestination(output_type, dest, true))
243-
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
244-
245-
reservedest.KeepDestination();
237+
std::string error;
238+
if (!pwallet->GetNewChangeDestination(output_type, dest, error)) {
239+
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error);
240+
}
246241
return EncodeDestination(dest);
247242
}
248243

src/wallet/wallet.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,6 +3531,23 @@ bool CWallet::GetNewDestination(const OutputType type, const std::string label,
35313531
return true;
35323532
}
35333533

3534+
bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& dest, std::string& error)
3535+
{
3536+
error.clear();
3537+
if (!IsLocked()) {
3538+
TopUpKeyPool();
3539+
}
3540+
3541+
ReserveDestination reservedest(this);
3542+
if (!reservedest.GetReservedDestination(type, dest, true)) {
3543+
error = "Error: Keypool ran out, please call keypoolrefill first";
3544+
return false;
3545+
}
3546+
3547+
reservedest.KeepDestination();
3548+
return true;
3549+
}
3550+
35343551
static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, WalletBatch& batch) {
35353552
if (setKeyPool.empty()) {
35363553
return GetTime();

src/wallet/wallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,7 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
11281128
std::set<CTxDestination> GetLabelAddresses(const std::string& label) const;
11291129

11301130
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, std::string& error);
1131+
bool GetNewChangeDestination(const OutputType type, CTxDestination& dest, std::string& error);
11311132

11321133
isminetype IsMine(const CTxIn& txin) const;
11331134
/**

0 commit comments

Comments
 (0)