changeset 2991:116bad5f9ba5 draft

fix #952 by checking if we have a new address or an updated label
author Philip Kaufmann <phil.kaufmann@t-online.de>
date Thu, 03 May 2012 14:52:15 +0200
parents 76f52a73a43c
children 11bc6bfc0983 0a7ba0bc28d0
files src/qt/walletmodel.cpp
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -152,14 +152,20 @@
         hex = QString::fromStdString(wtx.GetHash().GetHex());
     }
 
-    // Add addresses that we've sent to to the address book
+    // Add addresses / update labels that we've sent to to the address book
     foreach(const SendCoinsRecipient &rcp, recipients)
     {
         std::string strAddress = rcp.address.toStdString();
+        std::string strLabel = rcp.label.toStdString();
         CRITICAL_BLOCK(wallet->cs_wallet)
         {
-            if (!wallet->mapAddressBook.count(strAddress))
-                wallet->SetAddressBookName(strAddress, rcp.label.toStdString());
+            std::map<CBitcoinAddress, std::string>::iterator mi = wallet->mapAddressBook.find(strAddress);
+
+            // Check if we have a new address or an updated label
+            if (mi == wallet->mapAddressBook.end() || mi->second != strLabel)
+            {
+                wallet->SetAddressBookName(strAddress, strLabel);
+            }
         }
     }