scripted-diff: Wallet: Rename mapAddressBook to m_address_book

Previous versions assumed absence of an entry in mapAddressBook indicated change.
This no longer holds true (due to bugs) and will shortly be made intentional.
Renaming the field helps ensure that old code using mapAddressBook directly gets checked for necessary rebasing.

-BEGIN VERIFY SCRIPT-
sed -i -e 's/mapAddressBook/m_address_book/g' $(git grep -l 'mapAddressBook' ./src)
-END VERIFY SCRIPT-
This commit is contained in:
Luke Dashjr 2020-02-21 21:52:52 +00:00
parent 41fa2926d8
commit b86cd155f6
9 changed files with 47 additions and 47 deletions

View file

@ -151,8 +151,8 @@ public:
std::string* purpose) override std::string* purpose) override
{ {
LOCK(m_wallet->cs_wallet); LOCK(m_wallet->cs_wallet);
auto it = m_wallet->mapAddressBook.find(dest); auto it = m_wallet->m_address_book.find(dest);
if (it == m_wallet->mapAddressBook.end()) { if (it == m_wallet->m_address_book.end()) {
return false; return false;
} }
if (name) { if (name) {
@ -170,7 +170,7 @@ public:
{ {
LOCK(m_wallet->cs_wallet); LOCK(m_wallet->cs_wallet);
std::vector<WalletAddress> result; std::vector<WalletAddress> result;
for (const auto& item : m_wallet->mapAddressBook) { for (const auto& item : m_wallet->m_address_book) {
result.emplace_back(item.first, m_wallet->IsMine(item.first), item.second.name, item.second.purpose); result.emplace_back(item.first, m_wallet->IsMine(item.first), item.second.name, item.second.purpose);
} }
return result; return result;

View file

@ -55,7 +55,7 @@ struct AddressTableEntryLessThan
static AddressTableEntry::Type translateTransactionType(const QString &strPurpose, bool isMine) static AddressTableEntry::Type translateTransactionType(const QString &strPurpose, bool isMine)
{ {
AddressTableEntry::Type addressType = AddressTableEntry::Hidden; AddressTableEntry::Type addressType = AddressTableEntry::Hidden;
// "refund" addresses aren't shown, and change addresses aren't in mapAddressBook at all. // "refund" addresses aren't shown, and change addresses aren't in m_address_book at all.
if (strPurpose == "send") if (strPurpose == "send")
addressType = AddressTableEntry::Sending; addressType = AddressTableEntry::Sending;
else if (strPurpose == "receive") else if (strPurpose == "receive")

View file

@ -97,7 +97,7 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
auto check_addbook_size = [&wallet](int expected_size) { auto check_addbook_size = [&wallet](int expected_size) {
LOCK(wallet->cs_wallet); LOCK(wallet->cs_wallet);
QCOMPARE(static_cast<int>(wallet->mapAddressBook.size()), expected_size); QCOMPARE(static_cast<int>(wallet->m_address_book.size()), expected_size);
}; };
// We should start with the two addresses we added earlier and nothing else. // We should start with the two addresses we added earlier and nothing else.

View file

@ -60,12 +60,12 @@ static bool GetWalletAddressesForKey(LegacyScriptPubKeyMan* spk_man, const CWall
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)) { if (pwallet->m_address_book.count(dest)) {
if (!strAddr.empty()) { if (!strAddr.empty()) {
strAddr += ","; strAddr += ",";
} }
strAddr += EncodeDestination(dest); strAddr += EncodeDestination(dest);
strLabel = EncodeDumpString(pwallet->mapAddressBook.at(dest).name); strLabel = EncodeDumpString(pwallet->m_address_book.at(dest).name);
fLabelFound = true; fLabelFound = true;
} }
} }
@ -168,7 +168,7 @@ UniValue importprivkey(const JSONRPCRequest& request)
// 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() || pwallet->mapAddressBook.count(dest) == 0) { if (!request.params[1].isNull() || pwallet->m_address_book.count(dest) == 0) {
pwallet->SetAddressBook(dest, strLabel, "receive"); pwallet->SetAddressBook(dest, strLabel, "receive");
} }
} }

View file

@ -505,8 +505,8 @@ static UniValue listaddressgroupings(const JSONRPCRequest& request)
addressInfo.push_back(EncodeDestination(address)); addressInfo.push_back(EncodeDestination(address));
addressInfo.push_back(ValueFromAmount(balances[address])); addressInfo.push_back(ValueFromAmount(balances[address]));
{ {
if (pwallet->mapAddressBook.find(address) != pwallet->mapAddressBook.end()) { if (pwallet->m_address_book.find(address) != pwallet->m_address_book.end()) {
addressInfo.push_back(pwallet->mapAddressBook.find(address)->second.name); addressInfo.push_back(pwallet->m_address_book.find(address)->second.name);
} }
} }
jsonGrouping.push_back(addressInfo); jsonGrouping.push_back(addressInfo);
@ -1098,13 +1098,13 @@ static UniValue ListReceived(interfaces::Chain::Lock& locked_chain, const CWalle
UniValue ret(UniValue::VARR); UniValue ret(UniValue::VARR);
std::map<std::string, tallyitem> label_tally; std::map<std::string, tallyitem> label_tally;
// Create mapAddressBook iterator // Create m_address_book iterator
// If we aren't filtering, go from begin() to end() // If we aren't filtering, go from begin() to end()
auto start = pwallet->mapAddressBook.begin(); auto start = pwallet->m_address_book.begin();
auto end = pwallet->mapAddressBook.end(); auto end = pwallet->m_address_book.end();
// If we are filtering, find() the applicable entry // If we are filtering, find() the applicable entry
if (has_filtered_address) { if (has_filtered_address) {
start = pwallet->mapAddressBook.find(filtered_address); start = pwallet->m_address_book.find(filtered_address);
if (start != end) { if (start != end) {
end = std::next(start); end = std::next(start);
} }
@ -1313,8 +1313,8 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, const CWalle
MaybePushAddress(entry, s.destination); MaybePushAddress(entry, s.destination);
entry.pushKV("category", "send"); entry.pushKV("category", "send");
entry.pushKV("amount", ValueFromAmount(-s.amount)); entry.pushKV("amount", ValueFromAmount(-s.amount));
if (pwallet->mapAddressBook.count(s.destination)) { if (pwallet->m_address_book.count(s.destination)) {
entry.pushKV("label", pwallet->mapAddressBook.at(s.destination).name); entry.pushKV("label", pwallet->m_address_book.at(s.destination).name);
} }
entry.pushKV("vout", s.vout); entry.pushKV("vout", s.vout);
entry.pushKV("fee", ValueFromAmount(-nFee)); entry.pushKV("fee", ValueFromAmount(-nFee));
@ -1330,8 +1330,8 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, const CWalle
for (const COutputEntry& r : listReceived) for (const COutputEntry& r : listReceived)
{ {
std::string label; std::string label;
if (pwallet->mapAddressBook.count(r.destination)) { if (pwallet->m_address_book.count(r.destination)) {
label = pwallet->mapAddressBook.at(r.destination).name; label = pwallet->m_address_book.at(r.destination).name;
} }
if (filter_label && label != *filter_label) { if (filter_label && label != *filter_label) {
continue; continue;
@ -1355,7 +1355,7 @@ static void ListTransactions(interfaces::Chain::Lock& locked_chain, const CWalle
entry.pushKV("category", "receive"); entry.pushKV("category", "receive");
} }
entry.pushKV("amount", ValueFromAmount(r.amount)); entry.pushKV("amount", ValueFromAmount(r.amount));
if (pwallet->mapAddressBook.count(r.destination)) { if (pwallet->m_address_book.count(r.destination)) {
entry.pushKV("label", label); entry.pushKV("label", label);
} }
entry.pushKV("vout", r.vout); entry.pushKV("vout", r.vout);
@ -2955,8 +2955,8 @@ static UniValue listunspent(const JSONRPCRequest& request)
if (fValidAddress) { if (fValidAddress) {
entry.pushKV("address", EncodeDestination(address)); entry.pushKV("address", EncodeDestination(address));
auto i = pwallet->mapAddressBook.find(address); auto i = pwallet->m_address_book.find(address);
if (i != pwallet->mapAddressBook.end()) { if (i != pwallet->m_address_book.end()) {
entry.pushKV("label", i->second.name); entry.pushKV("label", i->second.name);
} }
@ -3814,8 +3814,8 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
// DEPRECATED: Return label field if existing. Currently only one label can // DEPRECATED: Return label field if existing. Currently only one label can
// be associated with an address, so the label should be equivalent to the // be associated with an address, so the label should be equivalent to the
// value of the name key/value pair in the labels array below. // value of the name key/value pair in the labels array below.
if ((pwallet->chain().rpcEnableDeprecated("label")) && (pwallet->mapAddressBook.count(dest))) { if ((pwallet->chain().rpcEnableDeprecated("label")) && (pwallet->m_address_book.count(dest))) {
ret.pushKV("label", pwallet->mapAddressBook.at(dest).name); ret.pushKV("label", pwallet->m_address_book.at(dest).name);
} }
ret.pushKV("ischange", pwallet->IsChange(scriptPubKey)); ret.pushKV("ischange", pwallet->IsChange(scriptPubKey));
@ -3838,8 +3838,8 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
// stable if we allow multiple labels to be associated with an address in // stable if we allow multiple labels to be associated with an address in
// the future. // the future.
UniValue labels(UniValue::VARR); UniValue labels(UniValue::VARR);
std::map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(dest); std::map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->m_address_book.find(dest);
if (mi != pwallet->mapAddressBook.end()) { if (mi != pwallet->m_address_book.end()) {
// DEPRECATED: The previous behavior of returning an array containing a // DEPRECATED: The previous behavior of returning an array containing a
// JSON object of `name` and `purpose` key/value pairs is deprecated. // JSON object of `name` and `purpose` key/value pairs is deprecated.
if (pwallet->chain().rpcEnableDeprecated("labelspurpose")) { if (pwallet->chain().rpcEnableDeprecated("labelspurpose")) {
@ -3889,10 +3889,10 @@ static UniValue getaddressesbylabel(const JSONRPCRequest& request)
// Find all addresses that have the given label // Find all addresses that have the given label
UniValue ret(UniValue::VOBJ); UniValue ret(UniValue::VOBJ);
std::set<std::string> addresses; std::set<std::string> addresses;
for (const std::pair<const CTxDestination, CAddressBookData>& item : pwallet->mapAddressBook) { for (const std::pair<const CTxDestination, CAddressBookData>& item : pwallet->m_address_book) {
if (item.second.name == label) { if (item.second.name == label) {
std::string address = EncodeDestination(item.first); std::string address = EncodeDestination(item.first);
// CWallet::mapAddressBook is not expected to contain duplicate // CWallet::m_address_book is not expected to contain duplicate
// address strings, but build a separate set as a precaution just in // address strings, but build a separate set as a precaution just in
// case it does. // case it does.
bool unique = addresses.emplace(address).second; bool unique = addresses.emplace(address).second;
@ -3953,7 +3953,7 @@ static UniValue listlabels(const JSONRPCRequest& request)
// 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;
for (const std::pair<const CTxDestination, CAddressBookData>& entry : pwallet->mapAddressBook) { for (const std::pair<const CTxDestination, CAddressBookData>& entry : pwallet->m_address_book) {
if (purpose.empty() || entry.second.purpose == purpose) { if (purpose.empty() || entry.second.purpose == purpose) {
label_set.insert(entry.second.name); label_set.insert(entry.second.name);
} }

View file

@ -1237,7 +1237,7 @@ bool CWallet::IsChange(const CScript& script) const
return true; return true;
LOCK(cs_wallet); LOCK(cs_wallet);
if (!mapAddressBook.count(address)) if (!m_address_book.count(address))
return true; return true;
} }
return false; return false;
@ -3191,11 +3191,11 @@ bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& add
bool fUpdated = false; bool fUpdated = false;
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
std::map<CTxDestination, CAddressBookData>::iterator mi = mapAddressBook.find(address); std::map<CTxDestination, CAddressBookData>::iterator mi = m_address_book.find(address);
fUpdated = mi != mapAddressBook.end(); fUpdated = mi != m_address_book.end();
mapAddressBook[address].name = strName; m_address_book[address].name = strName;
if (!strPurpose.empty()) /* update purpose only if requested */ if (!strPurpose.empty()) /* update purpose only if requested */
mapAddressBook[address].purpose = strPurpose; m_address_book[address].purpose = strPurpose;
} }
NotifyAddressBookChanged(this, address, strName, IsMine(address) != ISMINE_NO, NotifyAddressBookChanged(this, address, strName, IsMine(address) != ISMINE_NO,
strPurpose, (fUpdated ? CT_UPDATED : CT_NEW) ); strPurpose, (fUpdated ? CT_UPDATED : CT_NEW) );
@ -3217,11 +3217,11 @@ bool CWallet::DelAddressBook(const CTxDestination& address)
// Delete destdata tuples associated with address // Delete destdata tuples associated with address
std::string strAddress = EncodeDestination(address); std::string strAddress = EncodeDestination(address);
for (const std::pair<const std::string, std::string> &item : mapAddressBook[address].destdata) for (const std::pair<const std::string, std::string> &item : m_address_book[address].destdata)
{ {
WalletBatch(*database).EraseDestData(strAddress, item.first); WalletBatch(*database).EraseDestData(strAddress, item.first);
} }
mapAddressBook.erase(address); m_address_book.erase(address);
} }
NotifyAddressBookChanged(this, address, "", IsMine(address) != ISMINE_NO, "", CT_DELETED); NotifyAddressBookChanged(this, address, "", IsMine(address) != ISMINE_NO, "", CT_DELETED);
@ -3457,7 +3457,7 @@ std::set<CTxDestination> CWallet::GetLabelAddresses(const std::string& label) co
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
std::set<CTxDestination> result; std::set<CTxDestination> result;
for (const std::pair<const CTxDestination, CAddressBookData>& item : mapAddressBook) for (const std::pair<const CTxDestination, CAddressBookData>& item : m_address_book)
{ {
const CTxDestination& address = item.first; const CTxDestination& address = item.first;
const std::string& strName = item.second.name; const std::string& strName = item.second.name;
@ -3661,26 +3661,26 @@ bool CWallet::AddDestData(WalletBatch& batch, const CTxDestination &dest, const
if (boost::get<CNoDestination>(&dest)) if (boost::get<CNoDestination>(&dest))
return false; return false;
mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); m_address_book[dest].destdata.insert(std::make_pair(key, value));
return batch.WriteDestData(EncodeDestination(dest), key, value); return batch.WriteDestData(EncodeDestination(dest), key, value);
} }
bool CWallet::EraseDestData(WalletBatch& batch, const CTxDestination &dest, const std::string &key) bool CWallet::EraseDestData(WalletBatch& batch, const CTxDestination &dest, const std::string &key)
{ {
if (!mapAddressBook[dest].destdata.erase(key)) if (!m_address_book[dest].destdata.erase(key))
return false; return false;
return batch.EraseDestData(EncodeDestination(dest), key); return batch.EraseDestData(EncodeDestination(dest), key);
} }
void CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value) void CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
{ {
mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); m_address_book[dest].destdata.insert(std::make_pair(key, value));
} }
bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const
{ {
std::map<CTxDestination, CAddressBookData>::const_iterator i = mapAddressBook.find(dest); std::map<CTxDestination, CAddressBookData>::const_iterator i = m_address_book.find(dest);
if(i != mapAddressBook.end()) if(i != m_address_book.end())
{ {
CAddressBookData::StringMap::const_iterator j = i->second.destdata.find(key); CAddressBookData::StringMap::const_iterator j = i->second.destdata.find(key);
if(j != i->second.destdata.end()) if(j != i->second.destdata.end())
@ -3696,7 +3696,7 @@ bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, st
std::vector<std::string> CWallet::GetDestValues(const std::string& prefix) const std::vector<std::string> CWallet::GetDestValues(const std::string& prefix) const
{ {
std::vector<std::string> values; std::vector<std::string> values;
for (const auto& address : mapAddressBook) { for (const auto& address : m_address_book) {
for (const auto& data : address.second.destdata) { for (const auto& data : address.second.destdata) {
if (!data.first.compare(0, prefix.size(), prefix)) { if (!data.first.compare(0, prefix.size(), prefix)) {
values.emplace_back(data.second); values.emplace_back(data.second);
@ -4098,7 +4098,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
{ {
walletInstance->WalletLogPrintf("setKeyPool.size() = %u\n", walletInstance->GetKeyPoolSize()); walletInstance->WalletLogPrintf("setKeyPool.size() = %u\n", walletInstance->GetKeyPoolSize());
walletInstance->WalletLogPrintf("mapWallet.size() = %u\n", walletInstance->mapWallet.size()); walletInstance->WalletLogPrintf("mapWallet.size() = %u\n", walletInstance->mapWallet.size());
walletInstance->WalletLogPrintf("mapAddressBook.size() = %u\n", walletInstance->mapAddressBook.size()); walletInstance->WalletLogPrintf("m_address_book.size() = %u\n", walletInstance->m_address_book.size());
} }
return walletInstance; return walletInstance;

View file

@ -775,7 +775,7 @@ public:
int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0; int64_t nOrderPosNext GUARDED_BY(cs_wallet) = 0;
uint64_t nAccountingEntryNumber = 0; uint64_t nAccountingEntryNumber = 0;
std::map<CTxDestination, CAddressBookData> mapAddressBook GUARDED_BY(cs_wallet); std::map<CTxDestination, CAddressBookData> m_address_book GUARDED_BY(cs_wallet);
std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet); std::set<COutPoint> setLockedCoins GUARDED_BY(cs_wallet);

View file

@ -206,11 +206,11 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
if (strType == DBKeys::NAME) { if (strType == DBKeys::NAME) {
std::string strAddress; std::string strAddress;
ssKey >> strAddress; ssKey >> strAddress;
ssValue >> pwallet->mapAddressBook[DecodeDestination(strAddress)].name; ssValue >> pwallet->m_address_book[DecodeDestination(strAddress)].name;
} else if (strType == DBKeys::PURPOSE) { } else if (strType == DBKeys::PURPOSE) {
std::string strAddress; std::string strAddress;
ssKey >> strAddress; ssKey >> strAddress;
ssValue >> pwallet->mapAddressBook[DecodeDestination(strAddress)].purpose; ssValue >> pwallet->m_address_book[DecodeDestination(strAddress)].purpose;
} else if (strType == DBKeys::TX) { } else if (strType == DBKeys::TX) {
uint256 hash; uint256 hash;
ssKey >> hash; ssKey >> hash;

View file

@ -99,7 +99,7 @@ static void WalletShowInfo(CWallet* wallet_instance)
tfm::format(std::cout, "HD (hd seed available): %s\n", wallet_instance->IsHDEnabled() ? "yes" : "no"); tfm::format(std::cout, "HD (hd seed available): %s\n", wallet_instance->IsHDEnabled() ? "yes" : "no");
tfm::format(std::cout, "Keypool Size: %u\n", wallet_instance->GetKeyPoolSize()); tfm::format(std::cout, "Keypool Size: %u\n", wallet_instance->GetKeyPoolSize());
tfm::format(std::cout, "Transactions: %zu\n", wallet_instance->mapWallet.size()); tfm::format(std::cout, "Transactions: %zu\n", wallet_instance->mapWallet.size());
tfm::format(std::cout, "Address Book: %zu\n", wallet_instance->mapAddressBook.size()); tfm::format(std::cout, "Address Book: %zu\n", wallet_instance->m_address_book.size());
} }
bool ExecuteWalletToolFunc(const std::string& command, const std::string& name) bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)