Remove spent transactions from minting table. 79/head
authorfsb4000 <fsb4000@yandex.ru>
Fri, 12 Dec 2014 06:21:44 +0000 (12:21 +0600)
committerfsb4000 <fsb4000@yandex.ru>
Fri, 12 Dec 2014 06:21:44 +0000 (12:21 +0600)
Спасибо разработчикам PeerUnity

https://github.com/Peerunity/Peerunity/commit/df9b6c25942e94aee61326aa028e9eb3b3ca7bc4

src/qt/mintingtablemodel.cpp
src/qt/mintingtablemodel.h
src/qt/mintingview.cpp

index 1007c95..7eece74 100644 (file)
@@ -1,4 +1,5 @@
 #include "mintingtablemodel.h"
+#include "mintingfilterproxy.h"
 #include "transactiontablemodel.h"
 #include "guiutil.h"
 #include "kernelrecord.h"
@@ -157,7 +158,27 @@ public:
                 }
                 else if(inWallet && inModel)
                 {               
-                    // Updated -- nothing to do, status update will take care of this
+                    // Updated -- remove spent coins from table
+                    std::vector<KernelRecord> toCheck = KernelRecord::decomposeOutput(wallet, mi->second);
+                    BOOST_FOREACH(const KernelRecord &rec, toCheck)
+                    {
+                        if(rec.spent)
+                        {
+                            for(int i = 0; i < cachedWallet.size(); i++)
+                            {
+                                KernelRecord cachedRec = cachedWallet.at(i);
+                                if((rec.hash == cachedRec.hash)
+                                    && (rec.nTime == cachedRec.nTime)
+                                    && (rec.nValue == cachedRec.nValue))
+                                {
+                                    parent->beginRemoveRows(QModelIndex(), i, i);
+                                    cachedWallet.removeAt(i);
+                                    parent->endRemoveRows();
+                                    break;
+                                }
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -229,6 +250,16 @@ void MintingTableModel::update()
             BOOST_FOREACH(uint256 hash, wallet->vMintingWalletUpdated)
             {
                 updated.append(hash);
+
+                // Also check the inputs to remove spent outputs from the table if necessary
+                CWalletTx wtx;
+                if(wallet->GetTransaction(hash, wtx))
+                {
+                    BOOST_FOREACH(const CTxIn& txin, wtx.vin)
+                    {
+                        updated.append(txin.prevout.hash);
+                    }
+                }
             }
             wallet->vMintingWalletUpdated.clear();
         }
@@ -237,9 +268,15 @@ void MintingTableModel::update()
     if(!updated.empty())
     {
         priv->updateWallet(updated);
+        mintingProxyModel->invalidate(); // Force deletion of empty rows
     }
 }
 
+void MintingTableModel::setMintingProxyModel(MintingFilterProxy *mintingProxy)
+{
+    mintingProxyModel = mintingProxy;
+}
+
 int MintingTableModel::rowCount(const QModelIndex &parent) const
 {
     Q_UNUSED(parent);
index 47c5120..86b6465 100644 (file)
@@ -7,6 +7,7 @@
 
 class CWallet;
 class MintingTablePriv;
+class MintingFilterProxy;
 class KernelRecord;
 class WalletModel;
 
@@ -27,7 +28,7 @@ public:
         MintReward = 6
     };
 
-
+    void setMintingProxyModel(MintingFilterProxy *mintingProxy);
     int rowCount(const QModelIndex &parent) const;
     int columnCount(const QModelIndex &parent) const;
     QVariant data(const QModelIndex &index, int role) const;
@@ -42,6 +43,7 @@ private:
     QStringList columns;
     int mintingInterval;
     MintingTablePriv *priv;
+    MintingFilterProxy *mintingProxyModel;
 
     QString lookupAddress(const std::string &address, bool tooltip) const;
 
index 9a227e8..1fdef92 100644 (file)
@@ -129,6 +129,7 @@ void MintingView::setModel(WalletModel *model)
         mintingProxyModel->setSourceModel(model->getMintingTableModel());
         mintingProxyModel->setDynamicSortFilter(true);
         mintingProxyModel->setSortRole(Qt::EditRole);
+        model->getMintingTableModel()->setMintingProxyModel(mintingProxyModel);
 
         mintingView->setModel(mintingProxyModel);
         mintingView->setAlternatingRowColors(true);