mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-17 18:40:09 +00:00
Refactor: CAddressBookData for mapAddressBook
Straight refactor, so mapAddressBook stores a CAddressBookData (which just contains a std::string) instead of a std::string. Preparation for payment protocol work, which will add the notion of refund addresses to the address book.
This commit is contained in:
parent
b94595bb7f
commit
618855133d
@ -59,10 +59,10 @@ public:
|
||||
cachedAddressTable.clear();
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, std::string)& item, wallet->mapAddressBook)
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& item, wallet->mapAddressBook)
|
||||
{
|
||||
const CBitcoinAddress& address = item.first;
|
||||
const std::string& strName = item.second;
|
||||
const std::string& strName = item.second.name;
|
||||
bool fMine = IsMine(*wallet, address.Get());
|
||||
cachedAddressTable.append(AddressTableEntry(fMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending,
|
||||
QString::fromStdString(strName),
|
||||
@ -397,10 +397,10 @@ QString AddressTableModel::labelForAddress(const QString &address) const
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
CBitcoinAddress address_parsed(address.toStdString());
|
||||
std::map<CTxDestination, std::string>::iterator mi = wallet->mapAddressBook.find(address_parsed.Get());
|
||||
std::map<CTxDestination, CAddressBookData>::iterator mi = wallet->mapAddressBook.find(address_parsed.Get());
|
||||
if (mi != wallet->mapAddressBook.end())
|
||||
{
|
||||
return QString::fromStdString(mi->second);
|
||||
return QString::fromStdString(mi->second.name);
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
|
@ -88,8 +88,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
|
||||
strHTML += "<b>" + tr("From") + ":</b> " + tr("unknown") + "<br>";
|
||||
strHTML += "<b>" + tr("To") + ":</b> ";
|
||||
strHTML += GUIUtil::HtmlEscape(CBitcoinAddress(address).ToString());
|
||||
if (!wallet->mapAddressBook[address].empty())
|
||||
strHTML += " (" + tr("own address") + ", " + tr("label") + ": " + GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + ")";
|
||||
if (!wallet->mapAddressBook[address].name.empty())
|
||||
strHTML += " (" + tr("own address") + ", " + tr("label") + ": " + GUIUtil::HtmlEscape(wallet->mapAddressBook[address].name) + ")";
|
||||
else
|
||||
strHTML += " (" + tr("own address") + ")";
|
||||
strHTML += "<br>";
|
||||
@ -110,8 +110,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
|
||||
std::string strAddress = wtx.mapValue["to"];
|
||||
strHTML += "<b>" + tr("To") + ":</b> ";
|
||||
CTxDestination dest = CBitcoinAddress(strAddress).Get();
|
||||
if (wallet->mapAddressBook.count(dest) && !wallet->mapAddressBook[dest].empty())
|
||||
strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[dest]) + " ";
|
||||
if (wallet->mapAddressBook.count(dest) && !wallet->mapAddressBook[dest].name.empty())
|
||||
strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[dest].name) + " ";
|
||||
strHTML += GUIUtil::HtmlEscape(strAddress) + "<br>";
|
||||
}
|
||||
|
||||
@ -167,8 +167,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
|
||||
if (ExtractDestination(txout.scriptPubKey, address))
|
||||
{
|
||||
strHTML += "<b>" + tr("To") + ":</b> ";
|
||||
if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty())
|
||||
strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + " ";
|
||||
if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].name.empty())
|
||||
strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address].name) + " ";
|
||||
strHTML += GUIUtil::HtmlEscape(CBitcoinAddress(address).ToString());
|
||||
strHTML += "<br>";
|
||||
}
|
||||
@ -254,8 +254,8 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
|
||||
CTxDestination address;
|
||||
if (ExtractDestination(vout.scriptPubKey, address))
|
||||
{
|
||||
if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty())
|
||||
strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + " ";
|
||||
if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].name.empty())
|
||||
strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address].name) + " ";
|
||||
strHTML += QString::fromStdString(CBitcoinAddress(address).ToString());
|
||||
}
|
||||
strHTML = strHTML + " " + tr("Amount") + "=" + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, vout.nValue);
|
||||
|
@ -214,10 +214,10 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
|
||||
std::map<CTxDestination, std::string>::iterator mi = wallet->mapAddressBook.find(dest);
|
||||
std::map<CTxDestination, CAddressBookData>::iterator mi = wallet->mapAddressBook.find(dest);
|
||||
|
||||
// Check if we have a new address or an updated label
|
||||
if (mi == wallet->mapAddressBook.end() || mi->second != strLabel)
|
||||
if (mi == wallet->mapAddressBook.end() || mi->second.name != strLabel)
|
||||
{
|
||||
wallet->SetAddressBookName(dest, strLabel);
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ Value dumpwallet(const Array& params, bool fHelp)
|
||||
CKey key;
|
||||
if (pwalletMain->GetKey(keyid, key)) {
|
||||
if (pwalletMain->mapAddressBook.count(keyid)) {
|
||||
file << strprintf("%s %s label=%s # addr=%s\n", CBitcoinSecret(key).ToString().c_str(), strTime.c_str(), EncodeDumpString(pwalletMain->mapAddressBook[keyid]).c_str(), strAddr.c_str());
|
||||
file << strprintf("%s %s label=%s # addr=%s\n", CBitcoinSecret(key).ToString().c_str(), strTime.c_str(), EncodeDumpString(pwalletMain->mapAddressBook[keyid].name).c_str(), strAddr.c_str());
|
||||
} else if (setKeyPool.count(keyid)) {
|
||||
file << strprintf("%s %s reserve=1 # addr=%s\n", CBitcoinSecret(key).ToString().c_str(), strTime.c_str(), strAddr.c_str());
|
||||
} else {
|
||||
|
@ -229,7 +229,7 @@ Value listunspent(const Array& params, bool fHelp)
|
||||
{
|
||||
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
|
||||
if (pwalletMain->mapAddressBook.count(address))
|
||||
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address]));
|
||||
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
|
||||
}
|
||||
entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end())));
|
||||
if (pk.IsPayToScriptHash())
|
||||
|
@ -196,7 +196,7 @@ Value setaccount(const Array& params, bool fHelp)
|
||||
// Detect when changing the account of an address that is the 'unused current key' of another account:
|
||||
if (pwalletMain->mapAddressBook.count(address.Get()))
|
||||
{
|
||||
string strOldAccount = pwalletMain->mapAddressBook[address.Get()];
|
||||
string strOldAccount = pwalletMain->mapAddressBook[address.Get()].name;
|
||||
if (address == GetAccountAddress(strOldAccount))
|
||||
GetAccountAddress(strOldAccount, true);
|
||||
}
|
||||
@ -219,9 +219,9 @@ Value getaccount(const Array& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
||||
|
||||
string strAccount;
|
||||
map<CTxDestination, string>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
|
||||
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.empty())
|
||||
strAccount = (*mi).second;
|
||||
map<CTxDestination, CAddressBookData>::iterator mi = pwalletMain->mapAddressBook.find(address.Get());
|
||||
if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.name.empty())
|
||||
strAccount = (*mi).second.name;
|
||||
return strAccount;
|
||||
}
|
||||
|
||||
@ -237,10 +237,10 @@ Value getaddressesbyaccount(const Array& params, bool fHelp)
|
||||
|
||||
// Find all addresses that have the given account
|
||||
Array ret;
|
||||
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook)
|
||||
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
|
||||
{
|
||||
const CBitcoinAddress& address = item.first;
|
||||
const string& strName = item.second;
|
||||
const string& strName = item.second.name;
|
||||
if (strName == strAccount)
|
||||
ret.push_back(address.ToString());
|
||||
}
|
||||
@ -301,7 +301,7 @@ Value listaddressgroupings(const Array& params, bool fHelp)
|
||||
{
|
||||
LOCK(pwalletMain->cs_wallet);
|
||||
if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end())
|
||||
addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second);
|
||||
addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second.name);
|
||||
}
|
||||
jsonGrouping.push_back(addressInfo);
|
||||
}
|
||||
@ -423,10 +423,10 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
|
||||
|
||||
void GetAccountAddresses(string strAccount, set<CTxDestination>& setAddress)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, string)& item, pwalletMain->mapAddressBook)
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& item, pwalletMain->mapAddressBook)
|
||||
{
|
||||
const CTxDestination& address = item.first;
|
||||
const string& strName = item.second;
|
||||
const string& strName = item.second.name;
|
||||
if (strName == strAccount)
|
||||
setAddress.insert(address);
|
||||
}
|
||||
@ -862,10 +862,10 @@ Value ListReceived(const Array& params, bool fByAccounts)
|
||||
// Reply
|
||||
Array ret;
|
||||
map<string, tallyitem> mapAccountTally;
|
||||
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook)
|
||||
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, CAddressBookData)& item, pwalletMain->mapAddressBook)
|
||||
{
|
||||
const CBitcoinAddress& address = item.first;
|
||||
const string& strAccount = item.second;
|
||||
const string& strAccount = item.second.name;
|
||||
map<CBitcoinAddress, tallyitem>::iterator it = mapTally.find(address);
|
||||
if (it == mapTally.end() && !fIncludeEmpty)
|
||||
continue;
|
||||
@ -988,7 +988,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
|
||||
{
|
||||
string account;
|
||||
if (pwalletMain->mapAddressBook.count(r.first))
|
||||
account = pwalletMain->mapAddressBook[r.first];
|
||||
account = pwalletMain->mapAddressBook[r.first].name;
|
||||
if (fAllAccounts || (account == strAccount))
|
||||
{
|
||||
Object entry;
|
||||
@ -1101,9 +1101,9 @@ Value listaccounts(const Array& params, bool fHelp)
|
||||
nMinDepth = params[0].get_int();
|
||||
|
||||
map<string, int64> mapAccountBalances;
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, string)& entry, pwalletMain->mapAddressBook) {
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
|
||||
if (IsMine(*pwalletMain, entry.first)) // This address belongs to me
|
||||
mapAccountBalances[entry.second] = 0;
|
||||
mapAccountBalances[entry.second.name] = 0;
|
||||
}
|
||||
|
||||
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||||
@ -1121,7 +1121,7 @@ Value listaccounts(const Array& params, bool fHelp)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived)
|
||||
if (pwalletMain->mapAddressBook.count(r.first))
|
||||
mapAccountBalances[pwalletMain->mapAddressBook[r.first]] += r.second;
|
||||
mapAccountBalances[pwalletMain->mapAddressBook[r.first].name] += r.second;
|
||||
else
|
||||
mapAccountBalances[""] += r.second;
|
||||
}
|
||||
@ -1470,7 +1470,7 @@ Value validateaddress(const Array& params, bool fHelp)
|
||||
ret.insert(ret.end(), detail.begin(), detail.end());
|
||||
}
|
||||
if (pwalletMain->mapAddressBook.count(dest))
|
||||
ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest]));
|
||||
ret.push_back(Pair("account", pwalletMain->mapAddressBook[dest].name));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -717,8 +717,8 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nReceived,
|
||||
{
|
||||
if (pwallet->mapAddressBook.count(r.first))
|
||||
{
|
||||
map<CTxDestination, string>::const_iterator mi = pwallet->mapAddressBook.find(r.first);
|
||||
if (mi != pwallet->mapAddressBook.end() && (*mi).second == strAccount)
|
||||
map<CTxDestination, CAddressBookData>::const_iterator mi = pwallet->mapAddressBook.find(r.first);
|
||||
if (mi != pwallet->mapAddressBook.end() && (*mi).second.name == strAccount)
|
||||
nReceived += r.second;
|
||||
}
|
||||
else if (strAccount.empty())
|
||||
@ -1459,8 +1459,8 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
||||
|
||||
bool CWallet::SetAddressBookName(const CTxDestination& address, const string& strName)
|
||||
{
|
||||
std::map<CTxDestination, std::string>::iterator mi = mapAddressBook.find(address);
|
||||
mapAddressBook[address] = strName;
|
||||
std::map<CTxDestination, CAddressBookData>::iterator mi = mapAddressBook.find(address);
|
||||
mapAddressBook[address].name = strName;
|
||||
NotifyAddressBookChanged(this, address, strName, ::IsMine(*this, address), (mi == mapAddressBook.end()) ? CT_NEW : CT_UPDATED);
|
||||
if (!fFileBacked)
|
||||
return false;
|
||||
|
18
src/wallet.h
18
src/wallet.h
@ -64,6 +64,22 @@ public:
|
||||
)
|
||||
};
|
||||
|
||||
/** Address book data */
|
||||
class CAddressBookData
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
|
||||
CAddressBookData()
|
||||
{
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
(
|
||||
READWRITE(name);
|
||||
)
|
||||
};
|
||||
|
||||
/** A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
|
||||
* and provides the ability to create new transactions.
|
||||
*/
|
||||
@ -124,7 +140,7 @@ public:
|
||||
int64 nOrderPosNext;
|
||||
std::map<uint256, int> mapRequestCount;
|
||||
|
||||
std::map<CTxDestination, std::string> mapAddressBook;
|
||||
std::map<CTxDestination, CAddressBookData> mapAddressBook;
|
||||
|
||||
CPubKey vchDefaultKey;
|
||||
|
||||
|
@ -212,7 +212,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
|
||||
{
|
||||
string strAddress;
|
||||
ssKey >> strAddress;
|
||||
ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()];
|
||||
ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()].name;
|
||||
}
|
||||
else if (strType == "tx")
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user