File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -3790,9 +3790,20 @@ static UniValue getaddressesbylabel(const JSONRPCRequest& request)
3790
3790
3791
3791
// Find all addresses that have the given label
3792
3792
UniValue ret (UniValue::VOBJ);
3793
+ std::set<std::string> addresses;
3793
3794
for (const std::pair<const CTxDestination, CAddressBookData>& item : pwallet->mapAddressBook ) {
3794
3795
if (item.second .name == label) {
3795
- ret.pushKV (EncodeDestination (item.first ), AddressBookDataToJSON (item.second , false ));
3796
+ std::string address = EncodeDestination (item.first );
3797
+ // CWallet::mapAddressBook is not expected to contain duplicate
3798
+ // address strings, but build a separate set as a precaution just in
3799
+ // case it does.
3800
+ bool unique = addresses.emplace (address).second ;
3801
+ assert (unique);
3802
+ // UniValue::pushKV checks if the key exists in O(N)
3803
+ // and since duplicate addresses are unexpected (checked with
3804
+ // std::set in O(log(N))), UniValue::__pushKV is used instead,
3805
+ // which currently is O(1).
3806
+ ret.__pushKV (address, AddressBookDataToJSON (item.second , false ));
3796
3807
}
3797
3808
}
3798
3809
You can’t perform that action at this time.
0 commit comments