From aab3258788c041e5ef7b56ebdf923ed7ccce9077 Mon Sep 17 00:00:00 2001 From: Guillaume LE VAILLANT Date: Wed, 10 Dec 2014 22:06:44 +0100 Subject: [PATCH 1/2] Remove spent transactions from minting table. --- src/qt/mintingtablemodel.cpp | 40 ++++++++++++++++++++++++++++++++++-- src/qt/mintingtablemodel.h | 3 +++ src/qt/mintingview.cpp | 1 + 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/qt/mintingtablemodel.cpp b/src/qt/mintingtablemodel.cpp index 18fd6591..5da17b27 100644 --- a/src/qt/mintingtablemodel.cpp +++ b/src/qt/mintingtablemodel.cpp @@ -1,4 +1,5 @@ #include "mintingtablemodel.h" +#include "mintingfilterproxy.h" #include "transactiontablemodel.h" #include "guiutil.h" #include "kernelrecord.h" @@ -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 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; + } + } + } + } } } } @@ -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(); } @@ -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); @@ -445,4 +482,3 @@ QModelIndex MintingTableModel::index(int row, int column, const QModelIndex &par return QModelIndex(); } } - diff --git a/src/qt/mintingtablemodel.h b/src/qt/mintingtablemodel.h index c265ce52..db521635 100644 --- a/src/qt/mintingtablemodel.h +++ b/src/qt/mintingtablemodel.h @@ -7,6 +7,7 @@ class CWallet; class MintingTablePriv; +class MintingFilterProxy; class KernelRecord; class WalletModel; @@ -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; @@ -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; diff --git a/src/qt/mintingview.cpp b/src/qt/mintingview.cpp index 07505757..7b4eb922 100644 --- a/src/qt/mintingview.cpp +++ b/src/qt/mintingview.cpp @@ -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); From 172618032157fb895245d9a398e3353d8dd2b32d Mon Sep 17 00:00:00 2001 From: Guillaume LE VAILLANT Date: Tue, 17 Mar 2015 15:28:25 +0100 Subject: [PATCH 2/2] Fix minting table update. --- src/kernelrecord.cpp | 7 +------ src/kernelrecord.h | 4 ++-- src/qt/mintingtablemodel.cpp | 39 +++++++++++++++--------------------- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/kernelrecord.cpp b/src/kernelrecord.cpp index 6fbb44fe..78ce1f5d 100644 --- a/src/kernelrecord.cpp +++ b/src/kernelrecord.cpp @@ -15,11 +15,6 @@ bool KernelRecord::showTransaction(const CWalletTx &wtx) } } - if(!wtx.IsConfirmed()) - { - return false; - } - return true; } @@ -56,7 +51,7 @@ vector 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)); } } } diff --git a/src/kernelrecord.h b/src/kernelrecord.h index d54e5510..98721c83 100644 --- a/src/kernelrecord.h +++ b/src/kernelrecord.h @@ -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) { } diff --git a/src/qt/mintingtablemodel.cpp b/src/qt/mintingtablemodel.cpp index 5da17b27..5df15a72 100644 --- a/src/qt/mintingtablemodel.cpp +++ b/src/qt/mintingtablemodel.cpp @@ -133,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) @@ -156,21 +156,24 @@ class MintingTablePriv { // Updated -- remove spent coins from table std::vector toCheck = KernelRecord::decomposeOutput(wallet, mi->second); - BOOST_FOREACH(const KernelRecord &rec, toCheck) + if(!toCheck.empty()) { - if(rec.spent) + BOOST_FOREACH(const KernelRecord &rec, toCheck) { - for(int i = 0; i < cachedWallet.size(); i++) + if(rec.spent) { - KernelRecord cachedRec = cachedWallet.at(i); - if((rec.hash == cachedRec.hash) - && (rec.nTime == cachedRec.nTime) - && (rec.nValue == cachedRec.nValue)) + for(int i = lowerIndex; i < upperIndex; i++) { - parent->beginRemoveRows(QModelIndex(), i, i); - cachedWallet.removeAt(i); - parent->endRemoveRows(); - break; + 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; + } } } } @@ -246,16 +249,6 @@ 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(); }