Refactoring to avoid duplicated code.

Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Emma Hopwood 2023-03-21 16:27:52 +00:00
parent 6bb8c60f41
commit 32e1d2eeeb
1 changed files with 15 additions and 20 deletions

View File

@ -526,19 +526,23 @@ UniValue listaddresses(const UniValue& params, bool fHelp)
std::set<CTxDestination> t_mnemonic_change_dests;
std::set<CTxDestination> t_imported_dests;
std::set<CTxDestination> t_watchonly_dests;
auto GetSourceForDestination = match {
[&](const CKeyID& addr) -> std::optional<PaymentAddressSource> {
return GetSourceForPaymentAddress(pwalletMain)(addr);
},
[&](const CScriptID& addr) -> std::optional<PaymentAddressSource> {
return GetSourceForPaymentAddress(pwalletMain)(addr);
},
[&](const CNoDestination& addr) -> std::optional<PaymentAddressSource> {
return std::nullopt;
},
};
// Get the CTxDestination values for all the entries in the transparent address book.
// This will include any address that has been generated by this wallet.
for (const std::pair<CTxDestination, CAddressBookData>& item : pwalletMain->mapAddressBook) {
std::optional<PaymentAddressSource> source;
examine(item.first, match {
[&](const CKeyID& addr) {
source = GetSourceForPaymentAddress(pwalletMain)(addr);
},
[&](const CScriptID& addr) {
source = GetSourceForPaymentAddress(pwalletMain)(addr);
},
[&](const CNoDestination& addr) {}
});
std::optional<PaymentAddressSource> source = std::visit(GetSourceForDestination, item.first);
if (source.has_value()) {
switch (source.value()) {
case PaymentAddressSource::Random:
@ -570,16 +574,7 @@ UniValue listaddresses(const UniValue& params, bool fHelp)
t_imported_dests.count(item.first) == 0 &&
t_watchonly_dests.count(item.first) == 0)
{
std::optional<PaymentAddressSource> source;
examine(item.first, match {
[&](const CKeyID& addr) {
source = GetSourceForPaymentAddress(pwalletMain)(addr);
},
[&](const CScriptID& addr) {
source = GetSourceForPaymentAddress(pwalletMain)(addr);
},
[&](const CNoDestination& addr) {}
});
std::optional<PaymentAddressSource> source = std::visit(GetSourceForDestination, item.first);
if (source.has_value()) {
switch (source.value()) {
case PaymentAddressSource::Random: