@@ -138,26 +138,12 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
138138 UniValue ret (UniValue::VARR);
139139 std::map<std::string, tallyitem> label_tally;
140140
141- // Create m_address_book iterator
142- // If we aren't filtering, go from begin() to end()
143- auto start = wallet.m_address_book .begin ();
144- auto end = wallet.m_address_book .end ();
145- // If we are filtering, find() the applicable entry
146- if (has_filtered_address) {
147- start = wallet.m_address_book .find (filtered_address);
148- if (start != end) {
149- end = std::next (start);
150- }
151- }
141+ const auto & func = [&](const CTxDestination& address, const std::string& label, const std::string& purpose, bool is_change) {
142+ if (is_change) return ; // no change addresses
152143
153- for (auto item_it = start; item_it != end; ++item_it)
154- {
155- if (item_it->second .IsChange ()) continue ;
156- const CTxDestination& address = item_it->first ;
157- const std::string& label = item_it->second .GetLabel ();
158144 auto it = mapTally.find (address);
159145 if (it == mapTally.end () && !fIncludeEmpty )
160- continue ;
146+ return ;
161147
162148 CAmount nAmount = 0 ;
163149 int nConf = std::numeric_limits<int >::max ();
@@ -196,6 +182,14 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
196182 obj.pushKV (" txids" , transactions);
197183 ret.push_back (obj);
198184 }
185+ };
186+
187+ if (has_filtered_address) {
188+ const auto & entry = wallet.FindAddressBookEntry (filtered_address, /* allow_change=*/ false );
189+ if (entry) func (filtered_address, entry->GetLabel (), entry->purpose , /* is_change=*/ false );
190+ } else {
191+ // No filtered addr, walk-through the addressbook entry
192+ wallet.ForEachAddrBookEntry (func);
199193 }
200194
201195 if (by_label)
0 commit comments