Add GetNewChangeDestination for getting new change Destinations

Adds a GetNewChangeDestination that has the same objective as GetNewDestination
This commit is contained in:
Andrew Chow 2019-06-18 15:49:02 -04:00
parent 33d13edd2b
commit 8e7f930828
3 changed files with 22 additions and 9 deletions

View file

@ -226,10 +226,6 @@ static UniValue getrawchangeaddress(const JSONRPCRequest& request)
throw JSONRPCError(RPC_WALLET_ERROR, "Error: This wallet has no available keys"); throw JSONRPCError(RPC_WALLET_ERROR, "Error: This wallet has no available keys");
} }
if (!pwallet->IsLocked()) {
pwallet->TopUpKeyPool();
}
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 != OutputType::CHANGE_AUTO ? pwallet->m_default_change_type : pwallet->m_default_address_type;
if (!request.params[0].isNull()) { if (!request.params[0].isNull()) {
if (!ParseOutputType(request.params[0].get_str(), output_type)) { if (!ParseOutputType(request.params[0].get_str(), output_type)) {
@ -237,12 +233,11 @@ static UniValue getrawchangeaddress(const JSONRPCRequest& request)
} }
} }
ReserveDestination reservedest(pwallet);
CTxDestination dest; CTxDestination dest;
if (!reservedest.GetReservedDestination(output_type, dest, true)) std::string error;
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); if (!pwallet->GetNewChangeDestination(output_type, dest, error)) {
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error);
reservedest.KeepDestination(); }
return EncodeDestination(dest); return EncodeDestination(dest);
} }

View file

@ -3531,6 +3531,23 @@ bool CWallet::GetNewDestination(const OutputType type, const std::string label,
return true; return true;
} }
bool CWallet::GetNewChangeDestination(const OutputType type, CTxDestination& dest, std::string& error)
{
error.clear();
if (!IsLocked()) {
TopUpKeyPool();
}
ReserveDestination reservedest(this);
if (!reservedest.GetReservedDestination(type, dest, true)) {
error = "Error: Keypool ran out, please call keypoolrefill first";
return false;
}
reservedest.KeepDestination();
return true;
}
static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, WalletBatch& batch) { static int64_t GetOldestKeyTimeInPool(const std::set<int64_t>& setKeyPool, WalletBatch& batch) {
if (setKeyPool.empty()) { if (setKeyPool.empty()) {
return GetTime(); return GetTime();

View file

@ -1128,6 +1128,7 @@ public:
std::set<CTxDestination> GetLabelAddresses(const std::string& label) const; std::set<CTxDestination> GetLabelAddresses(const std::string& label) const;
bool GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, std::string& error); bool GetNewDestination(const OutputType type, const std::string label, CTxDestination& dest, std::string& error);
bool GetNewChangeDestination(const OutputType type, CTxDestination& dest, std::string& error);
isminetype IsMine(const CTxIn& txin) const; isminetype IsMine(const CTxIn& txin) const;
/** /**