Merge pull request #59 from fsb4000/ClearOrphan
authorCryptoManiac <CryptoManiac@users.noreply.github.com>
Thu, 20 Nov 2014 20:11:38 +0000 (23:11 +0300)
committerCryptoManiac <CryptoManiac@users.noreply.github.com>
Thu, 20 Nov 2014 20:11:38 +0000 (23:11 +0300)
Add a menu entry in the transaction view allowing...

src/qt/locale/bitcoin_ru.ts
src/qt/transactiontablemodel.cpp
src/qt/transactiontablemodel.h
src/qt/transactionview.cpp
src/qt/transactionview.h
src/qt/walletmodel.cpp
src/qt/walletmodel.h
src/wallet.cpp
src/wallet.h

index 2cd4930..4fbd50b 100644 (file)
@@ -2878,6 +2878,11 @@ This label turns red, if the priority is smaller than &quot;medium&quot;.
         <translation>Показать подробности транзакции</translation>
     </message>
     <message>
+        <location line="136"/>
+        <source>Clear orphans</source>
+        <translation>Удалить орфаны</translation>
+    </message>
+    <message>
         <location line="+144"/>
         <source>Export Transaction Data</source>
         <translation>Экспортировать данные транзакций</translation>
index 01efd1f..00a5884 100644 (file)
@@ -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);
index 0449303..d74f7fd 100644 (file)
@@ -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;
index 21eb1c7..61ddb26 100644 (file)
@@ -11,6 +11,7 @@
 #include "editaddressdialog.h"
 #include "optionsmodel.h"
 #include "guiutil.h"
+#include "wallet.h"
 
 #include <QScrollBar>
 #include <QComboBox>
@@ -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())
index e746c63..2fa1c39 100644 (file)
@@ -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:
index b8e5236..a8171df 100644 (file)
@@ -496,3 +496,8 @@ void WalletModel::listLockedCoins(std::vector<COutPoint>& vOutpts)
 {
     return;
 }
+
+void WalletModel::clearOrphans()
+{
+    wallet->ClearOrphans();
+}
\ No newline at end of file
index caeeb97..5eafe5d 100644 (file)
@@ -134,6 +134,7 @@ public:
     void lockCoin(COutPoint& output);
     void unlockCoin(COutPoint& output);
     void listLockedCoins(std::vector<COutPoint>& vOutpts);
+    void clearOrphans();
 
 private:
     CWallet *wallet;
index fd4ac6a..a78a76b 100644 (file)
@@ -2781,3 +2781,21 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64> &mapKeyBirth) const {
     for (std::map<CKeyID, CBlockIndex*>::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<uint256> orphans;
+
+    LOCK(cs_wallet);
+    for(map<uint256, CWalletTx>::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<uint256>::const_iterator it = orphans.begin(); it != orphans.end(); ++it)
+        EraseFromWallet(*it);
+}
\ No newline at end of file
index 7f6159c..c1b8f1a 100644 (file)
@@ -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);