@@ -505,7 +505,8 @@ static UniValue listaddressgroupings(const JSONRPCRequest& request)
505
505
addressInfo.push_back (EncodeDestination (address));
506
506
addressInfo.push_back (ValueFromAmount (balances[address]));
507
507
{
508
- if (pwallet->m_address_book .find (address) != pwallet->m_address_book .end ()) {
508
+ const auto * address_book_entry = pwallet->FindAddressBookEntry (address);
509
+ if (address_book_entry) {
509
510
addressInfo.push_back (pwallet->m_address_book .find (address)->second .name );
510
511
}
511
512
}
@@ -1112,6 +1113,7 @@ static UniValue ListReceived(interfaces::Chain::Lock& locked_chain, const CWalle
1112
1113
1113
1114
for (auto item_it = start; item_it != end; ++item_it)
1114
1115
{
1116
+ if (item_it->second .IsChange ()) continue ;
1115
1117
const CTxDestination& address = item_it->first ;
1116
1118
const std::string& label = item_it->second .name ;
1117
1119
auto it = mapTally.find (address);
@@ -1313,7 +1315,8 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, const CWalle
1313
1315
MaybePushAddress (entry, s.destination );
1314
1316
entry.pushKV (" category" , " send" );
1315
1317
entry.pushKV (" amount" , ValueFromAmount (-s.amount ));
1316
- if (pwallet->m_address_book .count (s.destination )) {
1318
+ const auto * address_book_entry = pwallet->FindAddressBookEntry (s.destination );
1319
+ if (address_book_entry) {
1317
1320
entry.pushKV (" label" , pwallet->m_address_book .at (s.destination ).name );
1318
1321
}
1319
1322
entry.pushKV (" vout" , s.vout );
@@ -1330,7 +1333,8 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, const CWalle
1330
1333
for (const COutputEntry& r : listReceived)
1331
1334
{
1332
1335
std::string label;
1333
- if (pwallet->m_address_book .count (r.destination )) {
1336
+ const auto * address_book_entry = pwallet->FindAddressBookEntry (r.destination );
1337
+ if (address_book_entry) {
1334
1338
label = pwallet->m_address_book .at (r.destination ).name ;
1335
1339
}
1336
1340
if (filter_label && label != *filter_label) {
@@ -1355,7 +1359,7 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, const CWalle
1355
1359
entry.pushKV (" category" , " receive" );
1356
1360
}
1357
1361
entry.pushKV (" amount" , ValueFromAmount (r.amount ));
1358
- if (pwallet-> m_address_book . count (r. destination ) ) {
1362
+ if (address_book_entry ) {
1359
1363
entry.pushKV (" label" , label);
1360
1364
}
1361
1365
entry.pushKV (" vout" , r.vout );
@@ -2955,9 +2959,9 @@ static UniValue listunspent(const JSONRPCRequest& request)
2955
2959
if (fValidAddress ) {
2956
2960
entry.pushKV (" address" , EncodeDestination (address));
2957
2961
2958
- auto i = pwallet->m_address_book . find (address);
2959
- if (i != pwallet-> m_address_book . end () ) {
2960
- entry.pushKV (" label" , i-> second . name );
2962
+ const auto * address_book_entry = pwallet->FindAddressBookEntry (address);
2963
+ if (address_book_entry ) {
2964
+ entry.pushKV (" label" , address_book_entry-> name );
2961
2965
}
2962
2966
2963
2967
std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider (scriptPubKey);
@@ -3814,7 +3818,8 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
3814
3818
// DEPRECATED: Return label field if existing. Currently only one label can
3815
3819
// be associated with an address, so the label should be equivalent to the
3816
3820
// value of the name key/value pair in the labels array below.
3817
- if ((pwallet->chain ().rpcEnableDeprecated (" label" )) && (pwallet->m_address_book .count (dest))) {
3821
+ const auto * address_book_entry = pwallet->FindAddressBookEntry (dest);
3822
+ if (pwallet->chain ().rpcEnableDeprecated (" label" ) && address_book_entry) {
3818
3823
ret.pushKV (" label" , pwallet->m_address_book .at (dest).name );
3819
3824
}
3820
3825
@@ -3838,14 +3843,13 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
3838
3843
// stable if we allow multiple labels to be associated with an address in
3839
3844
// the future.
3840
3845
UniValue labels (UniValue::VARR);
3841
- std::map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->m_address_book .find (dest);
3842
- if (mi != pwallet->m_address_book .end ()) {
3846
+ if (address_book_entry) {
3843
3847
// DEPRECATED: The previous behavior of returning an array containing a
3844
3848
// JSON object of `name` and `purpose` key/value pairs is deprecated.
3845
3849
if (pwallet->chain ().rpcEnableDeprecated (" labelspurpose" )) {
3846
- labels.push_back (AddressBookDataToJSON (mi-> second , true ));
3850
+ labels.push_back (AddressBookDataToJSON (*address_book_entry , true ));
3847
3851
} else {
3848
- labels.push_back (mi-> second . name );
3852
+ labels.push_back (address_book_entry-> name );
3849
3853
}
3850
3854
}
3851
3855
ret.pushKV (" labels" , std::move (labels));
@@ -3890,6 +3894,7 @@ static UniValue getaddressesbylabel(const JSONRPCRequest& request)
3890
3894
UniValue ret (UniValue::VOBJ);
3891
3895
std::set<std::string> addresses;
3892
3896
for (const std::pair<const CTxDestination, CAddressBookData>& item : pwallet->m_address_book ) {
3897
+ if (item.second .IsChange ()) continue ;
3893
3898
if (item.second .name == label) {
3894
3899
std::string address = EncodeDestination (item.first );
3895
3900
// CWallet::m_address_book is not expected to contain duplicate
@@ -3954,6 +3959,7 @@ static UniValue listlabels(const JSONRPCRequest& request)
3954
3959
// Add to a set to sort by label name, then insert into Univalue array
3955
3960
std::set<std::string> label_set;
3956
3961
for (const std::pair<const CTxDestination, CAddressBookData>& entry : pwallet->m_address_book ) {
3962
+ if (entry.second .IsChange ()) continue ;
3957
3963
if (purpose.empty () || entry.second .purpose == purpose) {
3958
3964
label_set.insert (entry.second .name );
3959
3965
}
0 commit comments