Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | static UniValue getlabeladdress(const Config &config, | ||||
// Parse the label first so we don't generate a key if there's an error | // Parse the label first so we don't generate a key if there's an error | ||||
std::string label = LabelFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
bool force = request.strMethod == "getaccountaddress"; | bool force = request.strMethod == "getaccountaddress"; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
force = request.params[1].get_bool(); | force = request.params[1].get_bool(); | ||||
} | } | ||||
bool label_found = false; | bool label_found = false; | ||||
for (const std::pair<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) { | ||||
label_found = true; | label_found = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (!force && !label_found) { | if (!force && !label_found) { | ||||
throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, | throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, | ||||
▲ Show 20 Lines • Show All 4,589 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) | ||||
HelpExampleRpc("getaddressesbylabel", "\"tabby\"")); | HelpExampleRpc("getaddressesbylabel", "\"tabby\"")); | ||||
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); | ||||
for (const std::pair<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), | ret.pushKV(EncodeDestination(item.first, config), | ||||
AddressBookDataToJSON(item.second, false)); | AddressBookDataToJSON(item.second, false)); | ||||
} | } | ||||
} | } | ||||
if (ret.empty()) { | if (ret.empty()) { | ||||
Show All 38 Lines | UniValue listlabels(const Config &config, const JSONRPCRequest &request) { | ||||
std::string purpose; | std::string purpose; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
purpose = request.params[0].get_str(); | purpose = request.params[0].get_str(); | ||||
} | } | ||||
// Add to a set to sort by label name, then insert into Univalue array | // Add to a set to sort by label name, then insert into Univalue array | ||||
std::set<std::string> label_set; | std::set<std::string> label_set; | ||||
for (const std::pair<CTxDestination, CAddressBookData> &entry : | for (const std::pair<const CTxDestination, CAddressBookData> &entry : | ||||
pwallet->mapAddressBook) { | pwallet->mapAddressBook) { | ||||
if (purpose.empty() || entry.second.purpose == purpose) { | if (purpose.empty() || entry.second.purpose == purpose) { | ||||
label_set.insert(entry.second.name); | label_set.insert(entry.second.name); | ||||
} | } | ||||
} | } | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
for (const std::string &name : label_set) { | for (const std::string &name : label_set) { | ||||
▲ Show 20 Lines • Show All 556 Lines • Show Last 20 Lines |