Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove spent transactions from minting table #468

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/kernelrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ bool KernelRecord::showTransaction(const CWalletTx &wtx)
}
}

if(!wtx.IsConfirmed())
{
return false;
}

return true;
}

Expand Down Expand Up @@ -56,7 +51,7 @@ vector<KernelRecord> KernelRecord::decomposeOutput(const CWallet *wallet, const
addrStr = mapValue["to"];
}

parts.push_back(KernelRecord(hash, nTime, addrStr, txOut.nValue, wtx.IsSpent(nOut), coinAge));
parts.push_back(KernelRecord(hash, nTime, addrStr, txOut.nValue, nOut, wtx.IsSpent(nOut), coinAge));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/kernelrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class KernelRecord

KernelRecord(uint256 hash, int64 nTime,
const std::string &address,
int64 nValue, bool spent, int64 coinAge):
int64 nValue, int idx, bool spent, int64 coinAge):
hash(hash), nTime(nTime), address(address), nValue(nValue),
idx(0), spent(spent), coinAge(coinAge), prevMinutes(0), prevDifficulty(0), prevProbability(0)
idx(idx), spent(spent), coinAge(coinAge), prevMinutes(0), prevDifficulty(0), prevProbability(0)
{
}

Expand Down
37 changes: 33 additions & 4 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 @@ -132,16 +133,16 @@ class MintingTablePriv
KernelRecord::decomposeOutput(wallet, mi->second);
if(!toInsert.empty()) /* only if something to insert */
{
parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
int insert_idx = lowerIndex;
BOOST_FOREACH(const KernelRecord &rec, toInsert)
{
if(!rec.spent) {
parent->beginInsertRows(QModelIndex(), insert_idx, insert_idx);
cachedWallet.insert(insert_idx, rec);
insert_idx += 1;
parent->endInsertRows();
}
}
parent->endInsertRows();
}
}
else if(!inWallet && inModel)
Expand All @@ -153,7 +154,30 @@ 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);
if(!toCheck.empty())
{
BOOST_FOREACH(const KernelRecord &rec, toCheck)
{
if(rec.spent)
{
for(int i = lowerIndex; i < upperIndex; i++)
{
KernelRecord cachedRec = cachedWallet.at(i);
if((rec.address == cachedRec.address)
&& (rec.nValue == cachedRec.nValue)
&& (rec.idx == cachedRec.idx))
{
parent->beginRemoveRows(QModelIndex(), i, i);
cachedWallet.removeAt(i);
parent->endRemoveRows();
break;
}
}
}
}
}
}
}
}
Expand Down Expand Up @@ -233,9 +257,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 +475,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