| 3227 | |
| 3228 | |
| 3229 | bool CWallet::SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& strPurpose) |
| 3230 | { |
| 3231 | bool fUpdated = false; |
| 3232 | { |
| 3233 | LOCK(cs_wallet); // mapAddressBook |
| 3234 | std::map<CTxDestination, CAddressBookData>::iterator mi = mapAddressBook.find(address); |
| 3235 | fUpdated = mi != mapAddressBook.end(); |
| 3236 | mapAddressBook[address].name = strName; |
| 3237 | if (!strPurpose.empty()) /* update purpose only if requested */ |
| 3238 | mapAddressBook[address].purpose = strPurpose; |
| 3239 | } |
| 3240 | NotifyAddressBookChanged(this, address, strName, ::IsMine(*this, address) != ISMINE_NO, |
| 3241 | strPurpose, (fUpdated ? CT_UPDATED : CT_NEW) ); |
| 3242 | if (!strPurpose.empty() && !WalletBatch(*database).WritePurpose(EncodeDestination(address), strPurpose)) |
| 3243 | return false; |
| 3244 | return WalletBatch(*database).WriteName(EncodeDestination(address), strName); |
| 3245 | } |
| 3246 | |
| 3247 | bool CWallet::DelAddressBook(const CTxDestination& address) |
| 3248 | { |