Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 4,344 Lines • ▼ Show 20 Lines | UniValue getaddressesbylabel(const Config &config, | ||||
} | } | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
std::string label = LabelFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
// Find all addresses that have the given label | // Find all addresses that have the given label | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
std::set<std::string> addresses; | |||||
for (const std::pair<const CTxDestination, CAddressBookData> &item : | for (const std::pair<const CTxDestination, CAddressBookData> &item : | ||||
pwallet->mapAddressBook) { | pwallet->mapAddressBook) { | ||||
if (item.second.name == label) { | if (item.second.name == label) { | ||||
ret.pushKV(EncodeDestination(item.first, config), | std::string address = EncodeDestination(item.first, config); | ||||
AddressBookDataToJSON(item.second, false)); | // CWallet::mapAddressBook is not expected to contain duplicate | ||||
// address strings, but build a separate set as a precaution just in | |||||
// case it does. | |||||
bool unique = addresses.emplace(address).second; | |||||
assert(unique); | |||||
// UniValue::pushKV checks if the key exists in O(N) | |||||
// and since duplicate addresses are unexpected (checked with | |||||
// std::set in O(log(N))), UniValue::__pushKV is used instead, | |||||
// which currently is O(1). | |||||
ret.__pushKV(address, AddressBookDataToJSON(item.second, false)); | |||||
} | } | ||||
} | } | ||||
if (ret.empty()) { | if (ret.empty()) { | ||||
throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, | throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, | ||||
std::string("No addresses with label " + label)); | std::string("No addresses with label " + label)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 512 Lines • Show Last 20 Lines |