@@ -138,26 +138,12 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
138
138
UniValue ret (UniValue::VARR);
139
139
std::map<std::string, tallyitem> label_tally;
140
140
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
152
143
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 ();
158
144
auto it = mapTally.find (address);
159
145
if (it == mapTally.end () && !fIncludeEmpty )
160
- continue ;
146
+ return ;
161
147
162
148
CAmount nAmount = 0 ;
163
149
int nConf = std::numeric_limits<int >::max ();
@@ -196,6 +182,14 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
196
182
obj.pushKV (" txids" , transactions);
197
183
ret.push_back (obj);
198
184
}
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);
199
193
}
200
194
201
195
if (by_label)
0 commit comments