PPCoin: Qt: display coinstake as single 'mint by stake' transaction
[novacoin.git] / src / qt / walletmodel.cpp
index 8206394..e3e68b3 100644 (file)
@@ -4,8 +4,9 @@
 #include "addresstablemodel.h"
 #include "transactiontablemodel.h"
 
+#include "ui_interface.h"
 #include "wallet.h"
-#include "db.h" // for BackupWallet
+#include "walletdb.h" // for BackupWallet
 
 #include <QSet>
 
@@ -24,6 +25,11 @@ qint64 WalletModel::getBalance() const
     return wallet->GetBalance();
 }
 
+qint64 WalletModel::getStake() const
+{
+    return wallet->GetStake();
+}
+
 qint64 WalletModel::getUnconfirmedBalance() const
 {
     return wallet->GetUnconfirmedBalance();
@@ -47,7 +53,7 @@ void WalletModel::update()
     EncryptionStatus newEncryptionStatus = getEncryptionStatus();
 
     if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance)
-        emit balanceChanged(newBalance, newUnconfirmedBalance);
+        emit balanceChanged(newBalance, getStake(), newUnconfirmedBalance);
 
     if(cachedNumTransactions != newNumTransactions)
         emit numTransactionsChanged(newNumTransactions);
@@ -58,8 +64,6 @@ void WalletModel::update()
     cachedBalance = newBalance;
     cachedUnconfirmedBalance = newUnconfirmedBalance;
     cachedNumTransactions = newNumTransactions;
-
-    addressTableModel->update();
 }
 
 void WalletModel::updateAddressList()
@@ -151,14 +155,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);
+            }
         }
     }