From: fsb4000 Date: Thu, 20 Nov 2014 06:55:23 +0000 (+0600) Subject: Add a menu entry in the transaction view allowing... X-Git-Tag: nvc-v0.5.0~33^2~3 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=a51b421f76da8bfb88dedd159789eec0063d3087 Add a menu entry in the transaction view allowing... to clear orphan minted/mined blocks. Взято отсюда: https://github.com/Peerunity/Peerunity/commit/e10a6cda928525b495de53f02cd0eee128c2c5bf --- 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/transactionview.cpp b/src/qt/transactionview.cpp index 21eb1c7..38afba6 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,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()) diff --git a/src/qt/transactionview.h b/src/qt/transactionview.h index e746c63..012b0c8 100644 --- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -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);