diff options
author | MacroFake <falke.marco@gmail.com> | 2022-08-10 14:19:11 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-08-10 14:19:17 +0200 |
commit | a6fc293c0a1f27ba1e573bfa16fd76d5f58988b2 (patch) | |
tree | bdf4912877caaf7e22365780180193ddd4494d99 /src/wallet/wallet.cpp | |
parent | aac200801b66f1300e618c115a6e3df9b01c9ec3 (diff) | |
parent | 76b3c37fcb93b4bcb047e0500fdaa605160e25d5 (diff) | |
download | bitcoin-a6fc293c0a1f27ba1e573bfa16fd76d5f58988b2.tar.xz |
Merge bitcoin/bitcoin#25656: refactor: wallet: return util::Result from `GetReservedDestination` methods
76b3c37fcb93b4bcb047e0500fdaa605160e25d5 refactor: wallet: return util::Result from `GetReservedDestination` methods (Sebastian Falbesoner)
Pull request description:
This PR is a follow-up to #25218, as suggested in comment https://github.com/bitcoin/bitcoin/pull/25218#discussion_r907710067. The interfaces of the methods `ReserveDestination::GetReservedDestination`, `{Legacy,Descriptor,}ScriptPubKeyMan::GetReservedDestination` are improved by returning `util::Result<CTxDestination>` instead of `bool` in order to get rid of the two `CTxDestination&` and `bilingual_str&` out-parameters.
ACKs for top commit:
furszy:
ACK 76b3c37f
Tree-SHA512: bf15560a88d645bcf8768024013d36012cd65caaa4a613e8a055dfd8f29cb4a219c19084606992bad177920cdca3a732ec168e9b9526f9295491f2cf79cc6815
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0a2997b3f1..de1078e646 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2359,15 +2359,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 @@ -2437,27 +2433,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() |