Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow RPC clearorphans command to properly clear orphans in a QT wallet #428

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ static void handleRunawayException(std::exception *e)
exit(1);
}

/* Allow RPC clear orphans to work properly in QT as well
*/
void QTClearOrphans()
{
/* This is actually stored in bitcoingui.cpp because otherwise we have to
* instantiate multiple TransactionView classes which we really don't want
* to do (for obvious reasons). */
GUIClearOrphans();
}

#ifndef BITCOIN_QT_TEST
int main(int argc, char *argv[])
{
Expand Down
9 changes: 9 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@

#include <iostream>

// Global pointer to TransactionView so that we can clear orphans from RPC
static TransactionView *transactionview;

BitcoinGUI::BitcoinGUI(QWidget *parent):
QMainWindow(parent),
clientModel(0),
Expand Down Expand Up @@ -102,6 +105,8 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
transactionsPage = new QWidget(this);
QVBoxLayout *vbox = new QVBoxLayout();
transactionView = new TransactionView(this);
// Set our global pointer for RPC clear orphans support.
transactionview = transactionView;
vbox->addWidget(transactionView);
transactionsPage->setLayout(vbox);

Expand Down Expand Up @@ -963,3 +968,7 @@ void BitcoinGUI::editConfig()
mb.exec();
QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(GetConfigFile().string())));
}

void GUIClearOrphans() {
QMetaObject::invokeMethod(transactionview, "clearOrphans", Qt::QueuedConnection);
}
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,6 @@ private slots:
void editConfig();
};

void GUIClearOrphans();

#endif // BITCOINGUI_H
6 changes: 5 additions & 1 deletion src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "bitcoinrpc.h"
#include "kernelrecord.h"
#include "primenodes.h"
#include "ui_interface.h"
#include "wallet.h"
#include "walletdb.h"

Expand Down Expand Up @@ -1786,8 +1787,11 @@ Value clearorphans(const Array& params, bool fHelp)
"clearorphans\n"
"Clears orphaned transactions from the wallet file.");

#ifdef QT_GUI
QTClearOrphans();
#else
pwalletMain->ClearOrphans();

#endif
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ extern void QueueShutdown();
extern void InitMessage(const std::string &message);
extern std::string _(const char* psz);

/* This only exists here and not in noui.cpp as otherwise bitcoinrpc.cpp calls ClearOrphans directly in wallet.cpp */
extern void QTClearOrphans();

#endif