Skip to content

Commit

Permalink
Remove spent transactions from minting table.
Browse files Browse the repository at this point in the history
  • Loading branch information
glv2 authored and MitchellCash committed Feb 19, 2016
1 parent 9b4fc44 commit aab3258
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/qt/mintingtablemodel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "mintingtablemodel.h"
#include "mintingfilterproxy.h"
#include "transactiontablemodel.h"
#include "guiutil.h"
#include "kernelrecord.h"
Expand Down Expand Up @@ -153,7 +154,27 @@ class MintingTablePriv
}
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;
}
}
}
}
}
}
}
Expand Down Expand Up @@ -225,6 +246,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();
}
Expand All @@ -233,9 +264,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);
Expand Down Expand Up @@ -445,4 +482,3 @@ QModelIndex MintingTableModel::index(int row, int column, const QModelIndex &par
return QModelIndex();
}
}

3 changes: 3 additions & 0 deletions src/qt/mintingtablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class CWallet;
class MintingTablePriv;
class MintingFilterProxy;
class KernelRecord;
class WalletModel;

Expand All @@ -27,6 +28,7 @@ class MintingTableModel : public QAbstractTableModel
};


void setMintingProxyModel(MintingFilterProxy *mintingProxy);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
Expand All @@ -41,6 +43,7 @@ class MintingTableModel : public QAbstractTableModel
QStringList columns;
int mintingInterval;
MintingTablePriv *priv;
MintingFilterProxy *mintingProxyModel;

QString lookupAddress(const std::string &address, bool tooltip) const;

Expand Down
1 change: 1 addition & 0 deletions src/qt/mintingview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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);
Expand Down

0 comments on commit aab3258

Please sign in to comment.