Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
GetWalletAddressesForKey(const Config &config, LegacyScriptPubKeyMan *spk_man, | GetWalletAddressesForKey(const Config &config, LegacyScriptPubKeyMan *spk_man, | ||||
CWallet *const pwallet, const CKeyID &keyid, | CWallet *const pwallet, const CKeyID &keyid, | ||||
std::string &strAddr, std::string &strLabel) | std::string &strAddr, std::string &strLabel) | ||||
EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { | EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { | ||||
bool fLabelFound = false; | bool fLabelFound = false; | ||||
CKey key; | CKey key; | ||||
spk_man->GetKey(keyid, key); | spk_man->GetKey(keyid, key); | ||||
for (const auto &dest : GetAllDestinationsForKey(key.GetPubKey())) { | for (const auto &dest : GetAllDestinationsForKey(key.GetPubKey())) { | ||||
if (pwallet->mapAddressBook.count(dest)) { | const auto *address_book_entry = pwallet->FindAddressBookEntry(dest); | ||||
if (address_book_entry) { | |||||
if (!strAddr.empty()) { | if (!strAddr.empty()) { | ||||
strAddr += ","; | strAddr += ","; | ||||
} | } | ||||
strAddr += EncodeDestination(dest, config); | strAddr += EncodeDestination(dest, config); | ||||
strLabel = EncodeDumpString(pwallet->mapAddressBook[dest].name); | strLabel = EncodeDumpString(address_book_entry->name); | ||||
fLabelFound = true; | fLabelFound = true; | ||||
} | } | ||||
} | } | ||||
if (!fLabelFound) { | if (!fLabelFound) { | ||||
strAddr = EncodeDestination( | strAddr = EncodeDestination( | ||||
GetDestinationForKey(key.GetPubKey(), | GetDestinationForKey(key.GetPubKey(), | ||||
pwallet->m_default_address_type), | pwallet->m_default_address_type), | ||||
config); | config); | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | bool fRescan = true; | ||||
{ | { | ||||
pwallet->MarkDirty(); | pwallet->MarkDirty(); | ||||
// We don't know which corresponding address will be used; | // We don't know which corresponding address will be used; | ||||
// label all new addresses, and label existing addresses if a | // label all new addresses, and label existing addresses if a | ||||
// label was passed. | // label was passed. | ||||
for (const auto &dest : GetAllDestinationsForKey(pubkey)) { | for (const auto &dest : GetAllDestinationsForKey(pubkey)) { | ||||
if (!request.params[1].isNull() || | if (!request.params[1].isNull() || | ||||
pwallet->mapAddressBook.count(dest) == 0) { | !pwallet->FindAddressBookEntry(dest)) { | ||||
pwallet->SetAddressBook(dest, strLabel, "receive"); | pwallet->SetAddressBook(dest, strLabel, "receive"); | ||||
} | } | ||||
} | } | ||||
// Use timestamp of 1 to scan the whole chain | // Use timestamp of 1 to scan the whole chain | ||||
if (!pwallet->ImportPrivKeys({{vchAddress, key}}, 1)) { | if (!pwallet->ImportPrivKeys({{vchAddress, key}}, 1)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Error adding key to wallet"); | "Error adding key to wallet"); | ||||
▲ Show 20 Lines • Show All 1,636 Lines • Show Last 20 Lines |