diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-06-11 12:00:33 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2022-06-22 12:51:30 -0300 |
commit | b459fc122feace9e9a738c48aab21961cf15dddc (patch) | |
tree | a95c52a7a45ff769c07be3a2c2742b061fad9322 /src/wallet | |
parent | fa9f2ab8fd53075d2a3ec93ddac4908e73525c46 (diff) |
refactor: RPC 'ListReceived', encapsulate m_address_book access
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/rpc/transactions.cpp | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index fae9bf3ea5..5d9b0965bc 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -138,26 +138,12 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons UniValue ret(UniValue::VARR); std::map<std::string, tallyitem> label_tally; - // Create m_address_book iterator - // If we aren't filtering, go from begin() to end() - auto start = wallet.m_address_book.begin(); - auto end = wallet.m_address_book.end(); - // If we are filtering, find() the applicable entry - if (has_filtered_address) { - start = wallet.m_address_book.find(filtered_address); - if (start != end) { - end = std::next(start); - } - } + const auto& func = [&](const CTxDestination& address, const std::string& label, const std::string& purpose, bool is_change) { + if (is_change) return; // no change addresses - for (auto item_it = start; item_it != end; ++item_it) - { - if (item_it->second.IsChange()) continue; - const CTxDestination& address = item_it->first; - const std::string& label = item_it->second.GetLabel(); auto it = mapTally.find(address); if (it == mapTally.end() && !fIncludeEmpty) - continue; + return; CAmount nAmount = 0; int nConf = std::numeric_limits<int>::max(); @@ -196,6 +182,14 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons obj.pushKV("txids", transactions); ret.push_back(obj); } + }; + + if (has_filtered_address) { + const auto& entry = wallet.FindAddressBookEntry(filtered_address, /*allow_change=*/false); + if (entry) func(filtered_address, entry->GetLabel(), entry->purpose, /*is_change=*/false); + } else { + // No filtered addr, walk-through the addressbook entry + wallet.ForEachAddrBookEntry(func); } if (by_label) |