@@ -637,17 +637,6 @@ RPCHelpMan getaddressinfo()
637
637
};
638
638
}
639
639
640
- /* * Convert CAddressBookData to JSON record. */
641
- static UniValue AddressBookDataToJSON (const CAddressBookData& data, const bool verbose)
642
- {
643
- UniValue ret (UniValue::VOBJ);
644
- if (verbose) {
645
- ret.pushKV (" name" , data.GetLabel ());
646
- }
647
- ret.pushKV (" purpose" , data.purpose );
648
- return ret;
649
- }
650
-
651
640
RPCHelpMan getaddressesbylabel ()
652
641
{
653
642
return RPCHelpMan{" getaddressesbylabel" ,
@@ -680,10 +669,10 @@ RPCHelpMan getaddressesbylabel()
680
669
// Find all addresses that have the given label
681
670
UniValue ret (UniValue::VOBJ);
682
671
std::set<std::string> addresses;
683
- for ( const std::pair< const CTxDestination, CAddressBookData>& item : pwallet-> m_address_book ) {
684
- if (item. second . IsChange ()) continue ;
685
- if (item. second . GetLabel () == label) {
686
- std::string address = EncodeDestination (item. first );
672
+ pwallet-> ForEachAddrBookEntry ([&]( const CTxDestination& _dest, const std::string& _label, const std::string& _purpose, bool _is_change ) {
673
+ if (_is_change) return ;
674
+ if (_label == label) {
675
+ std::string address = EncodeDestination (_dest );
687
676
// CWallet::m_address_book is not expected to contain duplicate
688
677
// address strings, but build a separate set as a precaution just in
689
678
// case it does.
@@ -693,9 +682,11 @@ RPCHelpMan getaddressesbylabel()
693
682
// and since duplicate addresses are unexpected (checked with
694
683
// std::set in O(log(N))), UniValue::__pushKV is used instead,
695
684
// which currently is O(1).
696
- ret.__pushKV (address, AddressBookDataToJSON (item.second , false ));
685
+ UniValue value (UniValue::VOBJ);
686
+ value.pushKV (" purpose" , _purpose);
687
+ ret.__pushKV (address, value);
697
688
}
698
- }
689
+ });
699
690
700
691
if (ret.empty ()) {
701
692
throw JSONRPCError (RPC_WALLET_INVALID_LABEL_NAME, std::string (" No addresses with label " + label));
0 commit comments