fix #952 by checking if we have a new address or an updated label
authorPhilip Kaufmann <phil.kaufmann@t-online.de>
Thu, 3 May 2012 12:52:15 +0000 (14:52 +0200)
committerLuke Dashjr <luke-jr+git@utopios.org>
Sun, 6 May 2012 22:52:12 +0000 (22:52 +0000)
src/qt/walletmodel.cpp

index a915274..b9ccb06 100644 (file)
@@ -150,14 +150,21 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie
         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();
         {
             LOCK(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);
+            }
         }
     }