QtUI code cleanup / comment improvements
[novacoin.git] / src / qt / addresstablemodel.cpp
index 125ceeb..bd314ba 100644 (file)
@@ -39,18 +39,17 @@ struct AddressTablePriv
     {
         cachedAddressTable.clear();
 
-        CRITICAL_BLOCK(cs_mapPubKeys)
+        CRITICAL_BLOCK(wallet->cs_KeyStore)
         CRITICAL_BLOCK(wallet->cs_mapAddressBook)
         {
-            BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item, wallet->mapAddressBook)
+            BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, std::string)& item, wallet->mapAddressBook)
             {
-                std::string strAddress = item.first;
-                std::string strName = item.second;
-                uint160 hash160;
-                bool fMine = (AddressToHash160(strAddress, hash160) && mapPubKeys.count(hash160));
+                const CBitcoinAddress& address = item.first;
+                const std::string& strName = item.second;
+                bool fMine = wallet->HaveKey(address);
                 cachedAddressTable.append(AddressTableEntry(fMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending,
                                   QString::fromStdString(strName),
-                                  QString::fromStdString(strAddress)));
+                                  QString::fromStdString(address.ToString())));
             }
         }
     }
@@ -162,13 +161,13 @@ bool AddressTableModel::setData(const QModelIndex & index, const QVariant & valu
             rec->label = value.toString();
             break;
         case Address:
-            // Refuse to set invalid address
+            // Refuse to set invalid address, set error status and return false
             if(!walletModel->validateAddress(value.toString()))
             {
                 editStatus = INVALID_ADDRESS;
                 return false;
             }
-            // Double-check that we're not overwriting receiving address
+            // Double-check that we're not overwriting a receiving address
             if(rec->type == AddressTableEntry::Sending)
             {
                 CRITICAL_BLOCK(wallet->cs_mapAddressBook)
@@ -235,7 +234,7 @@ QModelIndex AddressTableModel::index(int row, int column, const QModelIndex & pa
 
 void AddressTableModel::updateList()
 {
-    // Update internal model from Bitcoin core
+    // Update address book model from Bitcoin core
     beginResetModel();
     priv->refreshAddressTable();
     endResetModel();
@@ -248,7 +247,6 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
 
     editStatus = OK;
 
-
     if(type == Send)
     {
         if(!walletModel->validateAddress(address))
@@ -256,7 +254,7 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
             editStatus = INVALID_ADDRESS;
             return QString();
         }
-        // Check for duplicate
+        // Check for duplicate addresses
         CRITICAL_BLOCK(wallet->cs_mapAddressBook)
         {
             if(wallet->mapAddressBook.count(strAddress))
@@ -268,9 +266,8 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
     }
     else if(type == Receive)
     {
-        // Generate a new address to associate with given label, optionally
-        // set as default receiving address.
-        strAddress = PubKeyToAddress(wallet->GetOrReuseKeyFromPool());
+        // Generate a new address to associate with given label
+        strAddress = CBitcoinAddress(wallet->GetOrReuseKeyFromPool()).ToString();
     }
     else
     {
@@ -312,7 +309,8 @@ QString AddressTableModel::labelForAddress(const QString &address) const
 {
     CRITICAL_BLOCK(wallet->cs_mapAddressBook)
     {
-        std::map<std::string, std::string>::iterator mi = wallet->mapAddressBook.find(address.toStdString());
+        CBitcoinAddress address_parsed(address.toStdString());
+        std::map<CBitcoinAddress, std::string>::iterator mi = wallet->mapAddressBook.find(address_parsed);
         if (mi != wallet->mapAddressBook.end())
         {
             return QString::fromStdString(mi->second);