mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +02:00
refactor: RPC 'listlabels', encapsulate 'CWallet::ListAddrBookLabels' functionality
Mainly to not access 'm_address_book' externally.
This commit is contained in:
parent
83e42c4b94
commit
fa9f2ab8fd
@ -733,13 +733,7 @@ RPCHelpMan listlabels()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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 = pwallet->ListAddrBookLabels(purpose);
|
||||||
for (const std::pair<const CTxDestination, CAddressBookData>& entry : pwallet->m_address_book) {
|
|
||||||
if (entry.second.IsChange()) continue;
|
|
||||||
if (purpose.empty() || entry.second.purpose == purpose) {
|
|
||||||
label_set.insert(entry.second.GetLabel());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UniValue ret(UniValue::VARR);
|
UniValue ret(UniValue::VARR);
|
||||||
for (const std::string& name : label_set) {
|
for (const std::string& name : label_set) {
|
||||||
|
@ -2373,6 +2373,20 @@ std::vector<CTxDestination> CWallet::ListAddrBookAddresses(const std::optional<A
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<std::string> CWallet::ListAddrBookLabels(const std::string& purpose) const
|
||||||
|
{
|
||||||
|
AssertLockHeld(cs_wallet);
|
||||||
|
std::set<std::string> label_set;
|
||||||
|
ForEachAddrBookEntry([&](const CTxDestination& _dest, const std::string& _label,
|
||||||
|
const std::string& _purpose, bool _is_change) {
|
||||||
|
if (_is_change) return;
|
||||||
|
if (purpose.empty() || _purpose == purpose) {
|
||||||
|
label_set.insert(_label);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return label_set;
|
||||||
|
}
|
||||||
|
|
||||||
bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool internal, bilingual_str& error)
|
bool ReserveDestination::GetReservedDestination(CTxDestination& dest, bool internal, bilingual_str& error)
|
||||||
{
|
{
|
||||||
m_spk_man = pwallet->GetScriptPubKeyMan(type, internal);
|
m_spk_man = pwallet->GetScriptPubKeyMan(type, internal);
|
||||||
|
@ -648,6 +648,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
std::vector<CTxDestination> ListAddrBookAddresses(const std::optional<AddrBookFilter>& filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
std::vector<CTxDestination> ListAddrBookAddresses(const std::optional<AddrBookFilter>& filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all the known labels in the address book
|
||||||
|
*/
|
||||||
|
std::set<std::string> ListAddrBookLabels(const std::string& purpose) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Walk-through the address book entries.
|
* Walk-through the address book entries.
|
||||||
* Stops when the provided 'ListAddrBookFunc' returns false.
|
* Stops when the provided 'ListAddrBookFunc' returns false.
|
||||||
|
Loading…
Reference in New Issue
Block a user