aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2013-11-18 16:55:54 +0100
committerCozz Lovan <cozzlovan@yahoo.com>2014-01-19 18:21:54 +0100
commitb10e147096b0e27fdff8c22029bc8b7a1a14f042 (patch)
treedeb52bf797444b448e79df495d4a98906407af44 /src/wallet.cpp
parentdd7c1cf534b760e9da55c225d6bb05f2bdb8e2e7 (diff)
wallet: add interface for storing generic data on destinations
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 9065ba8483..f4c14b437c 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -1534,7 +1534,19 @@ bool CWallet::SetAddressBook(const CTxDestination& address, const string& strNam
bool CWallet::DelAddressBook(const CTxDestination& address)
{
+
AssertLockHeld(cs_wallet); // mapAddressBook
+
+ if(fFileBacked)
+ {
+ // Delete destdata tuples associated with address
+ std::string strAddress = CBitcoinAddress(address).ToString();
+ BOOST_FOREACH(const PAIRTYPE(string, string) &item, mapAddressBook[address].destdata)
+ {
+ CWalletDB(strWalletFile).EraseDestData(strAddress, item.first);
+ }
+ }
+
mapAddressBook.erase(address);
NotifyAddressBookChanged(this, address, "", ::IsMine(*this, address), "", CT_DELETED);
if (!fFileBacked)
@@ -2008,3 +2020,42 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
for (std::map<CKeyID, CBlockIndex*>::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++)
mapKeyBirth[it->first] = it->second->nTime - 7200; // block times can be 2h off
}
+
+bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
+{
+ mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
+ if (!fFileBacked)
+ return true;
+ return CWalletDB(strWalletFile).WriteDestData(CBitcoinAddress(dest).ToString(), key, value);
+}
+
+bool CWallet::EraseDestData(const CTxDestination &dest, const std::string &key)
+{
+ if (!mapAddressBook[dest].destdata.erase(key))
+ return false;
+ if (!fFileBacked)
+ return true;
+ return CWalletDB(strWalletFile).EraseDestData(CBitcoinAddress(dest).ToString(), key);
+}
+
+bool CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
+{
+ mapAddressBook[dest].destdata.insert(std::make_pair(key, value));
+ return true;
+}
+
+bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const
+{
+ std::map<CTxDestination, CAddressBookData>::const_iterator i = mapAddressBook.find(dest);
+ if(i != mapAddressBook.end())
+ {
+ CAddressBookData::StringMap::const_iterator j = i->second.destdata.find(key);
+ if(j != i->second.destdata.end())
+ {
+ if(value)
+ *value = j->second;
+ return true;
+ }
+ }
+ return false;
+}