refactor: wallet: return util::Result from GetReservedDestination methods

This commit is contained in:
Sebastian Falbesoner
2022-07-20 19:06:57 +02:00
parent 006740b6f6
commit 76b3c37fcb
5 changed files with 26 additions and 40 deletions

View File

@@ -2351,15 +2351,11 @@ util::Result<CTxDestination> CWallet::GetNewChangeDestination(const OutputType t
{
LOCK(cs_wallet);
CTxDestination dest;
bilingual_str error;
ReserveDestination reservedest(this, type);
if (!reservedest.GetReservedDestination(dest, true, error)) {
return util::Error{error};
}
auto op_dest = reservedest.GetReservedDestination(true);
if (op_dest) reservedest.KeepDestination();
reservedest.KeepDestination();
return dest;
return op_dest;
}
std::optional<int64_t> CWallet::GetOldestKeyPoolTime() const
@@ -2429,27 +2425,24 @@ std::set<std::string> CWallet::ListAddrBookLabels(const std::string& purpose) co
return label_set;
}
bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool internal, bilingual_str& error)
util::Result<CTxDestination> ReserveDestination::GetReservedDestination(bool internal)
{
m_spk_man = pwallet->GetScriptPubKeyMan(type, internal);
if (!m_spk_man) {
error = strprintf(_("Error: No %s addresses available."), FormatOutputType(type));
return false;
return util::Error{strprintf(_("Error: No %s addresses available."), FormatOutputType(type))};
}
if (nIndex == -1)
{
m_spk_man->TopUp();
CKeyPool keypool;
if (!m_spk_man->GetReservedDestination(type, internal, address, nIndex, keypool, error)) {
return false;
}
auto op_address = m_spk_man->GetReservedDestination(type, internal, nIndex, keypool);
if (!op_address) return op_address;
address = *op_address;
fInternal = keypool.fInternal;
}
dest = address;
return true;
return address;
}
void ReserveDestination::KeepDestination()