From: CryptoManiac Date: Thu, 20 Nov 2014 20:11:38 +0000 (+0300) Subject: Merge pull request #59 from fsb4000/ClearOrphan X-Git-Tag: nvc-v0.5.0~33 X-Git-Url: https://git.novaco.in/?a=commitdiff_plain;h=de1fddd6f375ba8d72eac40b5782be348d906f07;hp=0a227c457a7a6b02c3d6fac9ba4789d8656492b5;p=novacoin.git Merge pull request #59 from fsb4000/ClearOrphan Add a menu entry in the transaction view allowing... --- diff --git a/src/qt/locale/bitcoin_ru.ts b/src/qt/locale/bitcoin_ru.ts index 2cd4930..4fbd50b 100644 --- a/src/qt/locale/bitcoin_ru.ts +++ b/src/qt/locale/bitcoin_ru.ts @@ -2878,6 +2878,11 @@ This label turns red, if the priority is smaller than "medium". Показать подробности транзакции + + Clear orphans + Удалить орфаны + + Export Transaction Data Экспортировать данные транзакций diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 01efd1f..00a5884 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -261,6 +261,12 @@ void TransactionTableModel::updateConfirmations() } } +void TransactionTableModel::refresh() +{ + priv->refreshWallet(); + emit dataChanged(index(0, 0), index(priv->size() - 1, Amount)); +} + int TransactionTableModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); diff --git a/src/qt/transactiontablemodel.h b/src/qt/transactiontablemodel.h index 0449303..d74f7fd 100644 --- a/src/qt/transactiontablemodel.h +++ b/src/qt/transactiontablemodel.h @@ -57,6 +57,7 @@ public: QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; + void refresh(); private: CWallet* wallet; WalletModel *walletModel; diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 21eb1c7..61ddb26 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -11,6 +11,7 @@ #include "editaddressdialog.h" #include "optionsmodel.h" #include "guiutil.h" +#include "wallet.h" #include #include @@ -132,6 +133,7 @@ TransactionView::TransactionView(QWidget *parent) : QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this); QAction *editLabelAction = new QAction(tr("Edit label"), this); QAction *showDetailsAction = new QAction(tr("Show transaction details"), this); + QAction *clearOrphansAction = new QAction(tr("Clear orphans"), this); contextMenu = new QMenu(); contextMenu->addAction(copyAddressAction); @@ -140,6 +142,8 @@ TransactionView::TransactionView(QWidget *parent) : contextMenu->addAction(copyTxIDAction); contextMenu->addAction(editLabelAction); contextMenu->addAction(showDetailsAction); + contextMenu->addSeparator(); + contextMenu->addAction(clearOrphansAction); mapperThirdPartyTxUrls = new QSignalMapper(this); @@ -160,9 +164,10 @@ TransactionView::TransactionView(QWidget *parent) : connect(copyTxIDAction, SIGNAL(triggered()), this, SLOT(copyTxID())); connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel())); connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails())); + connect(clearOrphansAction, SIGNAL(triggered()), this, SLOT(clearOrphans())); } -void TransactionView::setModel(WalletModel *model) +void TransactionView::setModel(WalletModel *model, bool fShoudAddThirdPartyURL) { this->model = model; if(model) @@ -199,7 +204,7 @@ void TransactionView::setModel(WalletModel *model) transactionView->horizontalHeader()->resizeSection( TransactionTableModel::Amount, 100); - if (model->getOptionsModel()) + if (model->getOptionsModel() && fShoudAddThirdPartyURL) { // Add third party transaction URLs to context menu QStringList listUrls = model->getOptionsModel()->getThirdPartyTxUrls().split("|", QString::SkipEmptyParts); @@ -414,6 +419,19 @@ void TransactionView::showDetails() } } +void TransactionView::clearOrphans() +{ + if(!model) + return; + + model->clearOrphans(); + model->getTransactionTableModel()->refresh(); + delete transactionProxyModel; + setModel(model, false); + transactionView->sortByColumn(TransactionTableModel::Status, Qt::DescendingOrder); + transactionView->sortByColumn(TransactionTableModel::Date, Qt::DescendingOrder); +} + void TransactionView::openThirdPartyTxUrl(QString url) { if(!transactionView->selectionModel()) diff --git a/src/qt/transactionview.h b/src/qt/transactionview.h index e746c63..2fa1c39 100644 --- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -26,7 +26,7 @@ class TransactionView : public QWidget public: explicit TransactionView(QWidget *parent = 0); - void setModel(WalletModel *model); + void setModel(WalletModel *model, bool fShoudAddThirdPartyURL = true); // Date ranges for filter enum DateEnum @@ -68,6 +68,7 @@ private slots: void copyLabel(); void copyAmount(); void copyTxID(); + void clearOrphans(); void openThirdPartyTxUrl(QString url); signals: diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index b8e5236..a8171df 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -496,3 +496,8 @@ void WalletModel::listLockedCoins(std::vector& vOutpts) { return; } + +void WalletModel::clearOrphans() +{ + wallet->ClearOrphans(); +} \ No newline at end of file diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index caeeb97..5eafe5d 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -134,6 +134,7 @@ public: void lockCoin(COutPoint& output); void unlockCoin(COutPoint& output); void listLockedCoins(std::vector& vOutpts); + void clearOrphans(); private: CWallet *wallet; diff --git a/src/wallet.cpp b/src/wallet.cpp index fd4ac6a..a78a76b 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -2781,3 +2781,21 @@ void CWallet::GetKeyBirthTimes(std::map &mapKeyBirth) const { for (std::map::const_iterator it = mapKeyFirstBlock.begin(); it != mapKeyFirstBlock.end(); it++) mapKeyBirth[it->first] = it->second->nTime - 7200; // block times can be 2h off } + +void CWallet::ClearOrphans() +{ + list orphans; + + LOCK(cs_wallet); + for(map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + { + const CWalletTx *wtx = &(*it).second; + if((wtx->IsCoinBase() || wtx->IsCoinStake()) && !wtx->IsInMainChain()) + { + orphans.push_back(wtx->GetHash()); + } + } + + for(list::const_iterator it = orphans.begin(); it != orphans.end(); ++it) + EraseFromWallet(*it); +} \ No newline at end of file diff --git a/src/wallet.h b/src/wallet.h index 7f6159c..c1b8f1a 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -182,6 +182,7 @@ public: bool AddToWallet(const CWalletTx& wtxIn); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false, bool fFindBlock = false); bool EraseFromWallet(uint256 hash); + void ClearOrphans(); void WalletUpdateSpent(const CTransaction& prevout, bool fBlock = false); int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); int ScanForWalletTransaction(const uint256& hashTx);