Add a menu entry in the transaction view allowing...
authorfsb4000 <fsb4000@yandex.ru>
Thu, 20 Nov 2014 06:55:23 +0000 (12:55 +0600)
committerfsb4000 <fsb4000@yandex.ru>
Thu, 20 Nov 2014 06:55:23 +0000 (12:55 +0600)
to clear orphan minted/mined blocks.
Взято отсюда:
https://github.com/Peerunity/Peerunity/commit/e10a6cda928525b495de53f02cd0eee128c2c5bf

src/qt/locale/bitcoin_ru.ts
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 21eb1c7..38afba6 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,6 +164,7 @@ 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)
@@ -414,6 +419,14 @@ void TransactionView::showDetails()
     }
 }
 
+void TransactionView::clearOrphans()
+{
+    if(!model)
+        return;
+
+    model->clearOrphans();
+}
+
 void TransactionView::openThirdPartyTxUrl(QString url)
 {
     if(!transactionView->selectionModel())
index e746c63..012b0c8 100644 (file)
@@ -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);