diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-06-11 11:39:25 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2022-06-21 10:23:20 -0300 |
commit | 83e42c4b94e376a19d3eb0a2379769b8b8ac5fc8 (patch) | |
tree | 2afdfb4ae3ff600a1051aa93dfcea54491cd5460 /src/wallet/rpc/addresses.cpp | |
parent | 2b48642499016cb357e4bcec32481cd50361194e (diff) | |
download | bitcoin-83e42c4b94e376a19d3eb0a2379769b8b8ac5fc8.tar.xz |
refactor: use 'ForEachAddrBookEntry' in RPC 'getaddressesbylabel'
Diffstat (limited to 'src/wallet/rpc/addresses.cpp')
-rw-r--r-- | src/wallet/rpc/addresses.cpp | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index f25ad59528..55dd2f935c 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -637,17 +637,6 @@ RPCHelpMan getaddressinfo() }; } -/** Convert CAddressBookData to JSON record. */ -static UniValue AddressBookDataToJSON(const CAddressBookData& data, const bool verbose) -{ - UniValue ret(UniValue::VOBJ); - if (verbose) { - ret.pushKV("name", data.GetLabel()); - } - ret.pushKV("purpose", data.purpose); - return ret; -} - RPCHelpMan getaddressesbylabel() { return RPCHelpMan{"getaddressesbylabel", @@ -680,10 +669,10 @@ RPCHelpMan getaddressesbylabel() // Find all addresses that have the given label UniValue ret(UniValue::VOBJ); std::set<std::string> addresses; - for (const std::pair<const CTxDestination, CAddressBookData>& item : pwallet->m_address_book) { - if (item.second.IsChange()) continue; - if (item.second.GetLabel() == label) { - std::string address = EncodeDestination(item.first); + pwallet->ForEachAddrBookEntry([&](const CTxDestination& _dest, const std::string& _label, const std::string& _purpose, bool _is_change) { + if (_is_change) return; + if (_label == label) { + std::string address = EncodeDestination(_dest); // CWallet::m_address_book is not expected to contain duplicate // address strings, but build a separate set as a precaution just in // case it does. @@ -693,9 +682,11 @@ RPCHelpMan getaddressesbylabel() // 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)); + UniValue value(UniValue::VOBJ); + value.pushKV("purpose", _purpose); + ret.__pushKV(address, value); } - } + }); if (ret.empty()) { throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, std::string("No addresses with label " + label)); |