X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fmintingtablemodel.cpp;h=5f8257802c48a7689c36914f558d8483686839bb;hb=HEAD;hp=a6ab89b70aac061b845bb0a2251600c56b8a9649;hpb=3172f77ecb720d462a2fa6b5e78f8460ce2c9cfe;p=novacoin.git diff --git a/src/qt/mintingtablemodel.cpp b/src/qt/mintingtablemodel.cpp index a6ab89b..5f82578 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" @@ -26,10 +27,11 @@ extern double GetDifficulty(const CBlockIndex* blockindex); static int column_alignments[] = { Qt::AlignLeft|Qt::AlignVCenter, Qt::AlignLeft|Qt::AlignVCenter, - Qt::AlignRight|Qt::AlignVCenter, - Qt::AlignRight|Qt::AlignVCenter, - Qt::AlignRight|Qt::AlignVCenter, - Qt::AlignRight|Qt::AlignVCenter + Qt::AlignLeft|Qt::AlignVCenter, + Qt::AlignLeft|Qt::AlignVCenter, + Qt::AlignLeft|Qt::AlignVCenter, + Qt::AlignLeft|Qt::AlignVCenter, + Qt::AlignLeft|Qt::AlignVCenter }; struct TxLessThan @@ -72,7 +74,7 @@ public: for(std::map::iterator it = wallet->mapWallet.begin(); it != wallet->mapWallet.end(); ++it) { std::vector txList = KernelRecord::decomposeOutput(wallet, it->second); - BOOST_FOREACH(KernelRecord& kr, txList) { + for (KernelRecord& kr : txList) { if(!kr.spent) { cachedWallet.append(kr); } @@ -134,16 +136,17 @@ public: 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) + for (const KernelRecord &rec : toInsert) { - if(!rec.spent) { + if(!rec.spent) + { + parent->beginInsertRows(QModelIndex(), insert_idx, insert_idx); cachedWallet.insert(insert_idx, rec); + parent->endInsertRows(); insert_idx += 1; } } - parent->endInsertRows(); } } else if(!inWallet && inModel) @@ -155,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 toCheck = KernelRecord::decomposeOutput(wallet, mi->second); + for (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; + } + } + } + } } } } @@ -202,7 +225,7 @@ MintingTableModel::MintingTableModel(CWallet *wallet, WalletModel *parent): mintingInterval(10), priv(new MintingTablePriv(wallet, this)) { - columns << tr("Transaction") << tr("Address") << tr("Age") << tr("Balance") << tr("CoinDay") << tr("MintProbability"); + columns << tr("Transaction") << tr("Address") << tr("Balance") << tr("Age") << tr("CoinDay") << tr("MintProbability") << tr("MintReward"); priv->refreshWallet(); QTimer *timer = new QTimer(this); @@ -224,9 +247,19 @@ void MintingTableModel::update() TRY_LOCK(wallet->cs_wallet, lockWallet); if (lockWallet && !wallet->vMintingWalletUpdated.empty()) { - BOOST_FOREACH(uint256 hash, wallet->vMintingWalletUpdated) + for (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)) + { + for (const CTxIn& txin : wtx.vin) + { + updated.append(txin.prevout.hash); + } + } } wallet->vMintingWalletUpdated.clear(); } @@ -235,10 +268,15 @@ void MintingTableModel::update() if(!updated.empty()) { priv->updateWallet(updated); - priv->refreshWallet(); + mintingProxyModel->invalidate(); // Force deletion of empty rows } } +void MintingTableModel::setMintingProxyModel(MintingFilterProxy *mintingProxy) +{ + mintingProxyModel = mintingProxy; +} + int MintingTableModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); @@ -274,6 +312,8 @@ QVariant MintingTableModel::data(const QModelIndex &index, int role) const return formatTxCoinDay(rec); case MintProbability: return formatDayToMint(rec); + case MintReward: + return formatTxPoSReward(rec); } break; case Qt::TextAlignmentRole: @@ -310,13 +350,15 @@ QVariant MintingTableModel::data(const QModelIndex &index, int role) const case TxHash: return formatTxHash(rec); case Age: - return rec->getAge(); + return static_cast(rec->getAge()); case CoinDay: - return rec->coinAge; + return static_cast(rec->getCoinDay()); case Balance: - return rec->nValue; + return static_cast(rec->nValue); case MintProbability: return getDayToMint(rec); + case MintReward: + return formatTxPoSReward(rec); } break; case Qt::BackgroundColorRole: @@ -360,6 +402,15 @@ QString MintingTableModel::lookupAddress(const std::string &address, bool toolti return description; } +QString MintingTableModel::formatTxPoSReward(KernelRecord *wtx) const +{ + QString posReward; + int nBits = GetLastBlockIndex(pindexBest, true)->nBits; + posReward += QString(QObject::tr("from %1 to %2")).arg(BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), wtx->getPoSReward(nBits, 0)), + BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), wtx->getPoSReward(nBits, mintingInterval))); + return posReward; +} + double MintingTableModel::getDayToMint(KernelRecord *wtx) const { const CBlockIndex *p = GetLastBlockIndex(pindexBest, true); @@ -388,18 +439,18 @@ QString MintingTableModel::formatTxHash(const KernelRecord *wtx) const QString MintingTableModel::formatTxCoinDay(const KernelRecord *wtx) const { - return QString::number(wtx->coinAge); + return QString::number(wtx->getCoinDay()); } QString MintingTableModel::formatTxAge(const KernelRecord *wtx) const { - int64 nAge = wtx->getAge(); + int64_t nAge = wtx->getAge(); return QString::number(nAge); } QString MintingTableModel::formatTxBalance(const KernelRecord *wtx) const { - return BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), wtx->nValue); + return BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(), wtx->nValue); } QVariant MintingTableModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -429,6 +480,8 @@ QVariant MintingTableModel::headerData(int section, Qt::Orientation orientation, return tr("Coin age in the output."); case MintProbability: return tr("Chance to mint a block within given time interval."); + case MintReward: + return tr("The size of the potential rewards if the block is found at the beginning and the end given time interval."); } } } @@ -448,4 +501,3 @@ QModelIndex MintingTableModel::index(int row, int column, const QModelIndex &par return QModelIndex(); } } -