| 830 | } |
| 831 | |
| 832 | RPCHelpMan listlabels() |
| 833 | { |
| 834 | return RPCHelpMan{"listlabels", |
| 835 | "\nReturns the list of all labels, or labels that are assigned to addresses with a specific purpose.\n", |
| 836 | { |
| 837 | {"purpose", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "Address purpose to list labels for ('send','receive'). An empty string is the same as not providing this argument."}, |
| 838 | }, |
| 839 | RPCResult{ |
| 840 | RPCResult::Type::ARR, "", "", |
| 841 | { |
| 842 | {RPCResult::Type::STR, "label", "Label name"}, |
| 843 | } |
| 844 | }, |
| 845 | RPCExamples{ |
| 846 | "\nList all labels\n" |
| 847 | + HelpExampleCli("listlabels", "") + |
| 848 | "\nList labels that have receiving addresses\n" |
| 849 | + HelpExampleCli("listlabels", "receive") + |
| 850 | "\nList labels that have sending addresses\n" |
| 851 | + HelpExampleCli("listlabels", "send") + |
| 852 | "\nAs a JSON-RPC call\n" |
| 853 | + HelpExampleRpc("listlabels", "receive") |
| 854 | }, |
| 855 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 856 | { |
| 857 | const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request); |
| 858 | if (!pwallet) return NullUniValue; |
| 859 | |
| 860 | LOCK(pwallet->cs_wallet); |
| 861 | |
| 862 | std::string purpose; |
| 863 | if (!request.params[0].isNull()) { |
| 864 | purpose = request.params[0].get_str(); |
| 865 | } |
| 866 | |
| 867 | // Add to a set to sort by label name, then insert into Univalue array |
| 868 | std::set<std::string> label_set; |
| 869 | for (const std::pair<const CTxDestination, CAddressBookData>& entry : pwallet->m_address_book) { |
| 870 | if (entry.second.IsChange()) continue; |
| 871 | if (purpose.empty() || entry.second.purpose == purpose) { |
| 872 | label_set.insert(entry.second.GetLabel()); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | UniValue ret(UniValue::VARR); |
| 877 | for (const std::string& name : label_set) { |
| 878 | ret.push_back(name); |
| 879 | } |
| 880 | |
| 881 | return ret; |
| 882 | }, |
| 883 | }; |
| 884 | } |
| 885 | |
| 886 | |
| 887 | #ifdef ENABLE_EXTERNAL_SIGNER |
nothing calls this directly
no test coverage detected