diff --git a/build_msvc/libbitcoin_qt/libbitcoin_qt.vcxproj b/build_msvc/libbitcoin_qt/libbitcoin_qt.vcxproj index 9f9dc9d5fa0..25d5625f09c 100644 --- a/build_msvc/libbitcoin_qt/libbitcoin_qt.vcxproj +++ b/build_msvc/libbitcoin_qt/libbitcoin_qt.vcxproj @@ -58,6 +58,7 @@ + @@ -114,6 +115,7 @@ + diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index c235c3c4da7..30e7d175051 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -24,6 +24,7 @@ QT_FORMS_UI = \ qt/forms/modaloverlay.ui \ qt/forms/openuridialog.ui \ qt/forms/optionsdialog.ui \ + qt/forms/toolsdialog.ui \ qt/forms/overviewpage.ui \ qt/forms/psbtoperationsdialog.ui \ qt/forms/receivecoinsdialog.ui \ @@ -84,6 +85,7 @@ QT_MOC_CPP = \ qt/moc_transactiontablemodel.cpp \ qt/moc_transactionview.cpp \ qt/moc_utilitydialog.cpp \ + qt/moc_toolsdialog.cpp \ qt/moc_walletcontroller.cpp \ qt/moc_walletframe.cpp \ qt/moc_walletmodel.cpp \ @@ -161,6 +163,7 @@ BITCOIN_QT_H = \ qt/transactiontablemodel.h \ qt/transactionview.h \ qt/utilitydialog.h \ + qt/toolsdialog.h \ qt/walletcontroller.h \ qt/walletframe.h \ qt/walletmodel.h \ @@ -244,6 +247,7 @@ BITCOIN_QT_BASE_CPP = \ qt/rpcconsole.cpp \ qt/splashscreen.cpp \ qt/trafficgraphwidget.cpp \ + qt/toolsdialog.cpp \ qt/utilitydialog.cpp BITCOIN_QT_WINDOWS_CPP = qt/winshutdownmonitor.cpp diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index fd71938b606..d3d6bad4855 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #ifdef ENABLE_WALLET #include @@ -368,12 +369,17 @@ void BitcoinGUI::createActions() m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab")); m_mask_values_action->setCheckable(true); + getRawTransactionAction = new QAction(tr("&Verify external txid"), this); + getRawTransactionAction->setMenuRole(QAction::NoRole); + getRawTransactionAction->setStatusTip(tr("getrawtransaction RPC")); + connect(quitAction, &QAction::triggered, this, &BitcoinGUI::quitRequested); connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked); connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt); connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked); connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked); connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showDebugWindow); + connect(getRawTransactionAction, &QAction::triggered, this, &BitcoinGUI::getRawTransactionClicked); // prevents an open debug window from becoming stuck/unusable on client shutdown connect(quitAction, &QAction::triggered, rpcConsole, &QWidget::hide); @@ -555,6 +561,9 @@ void BitcoinGUI::createMenuBar() }); } + QMenu *tools = appMenuBar->addMenu(tr("&Tools")); + tools->addAction(getRawTransactionAction); + QMenu *help = appMenuBar->addMenu(tr("&Help")); help->addAction(showHelpMessageAction); help->addSeparator(); @@ -932,6 +941,12 @@ void BitcoinGUI::showHelpMessageClicked() GUIUtil::bringToFront(helpMessageDialog); } +void BitcoinGUI::getRawTransactionClicked() +{ + auto dlg = new ToolsDialog(this, ToolsDialog::GetRawTransactionMode, &m_node); + GUIUtil::ShowModalDialogAsynchronously(dlg); +} + #ifdef ENABLE_WALLET void BitcoinGUI::openClicked() { diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 6fdc4c60d8b..cf004732938 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -145,6 +145,7 @@ class BitcoinGUI : public QMainWindow QAction* m_load_psbt_action = nullptr; QAction* m_load_psbt_clipboard_action = nullptr; QAction* aboutAction = nullptr; + QAction* getRawTransactionAction = nullptr; QAction* receiveCoinsAction = nullptr; QAction* optionsAction = nullptr; QAction* encryptWalletAction = nullptr; @@ -308,6 +309,8 @@ public Q_SLOTS: void showDebugWindowActivateConsole(); /** Show help message dialog */ void showHelpMessageClicked(); + /** show getrawtransaction dialog*/ + void getRawTransactionClicked(); /** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */ void showNormalIfMinimized() { showNormalIfMinimized(false); } diff --git a/src/qt/forms/toolsdialog.ui b/src/qt/forms/toolsdialog.ui new file mode 100644 index 00000000000..4b18b1d798b --- /dev/null +++ b/src/qt/forms/toolsdialog.ui @@ -0,0 +1,151 @@ + + + ToolsDialog + + + + 0 + 0 + 780 + 400 + + + + + + + + + 12 + + + + + transaction id: + + + + + + + The transaction id + + + Enter a transaction id... + + + + + + + verbose + + + verbose + + + false + + + + + + + blockhash (optional): + + + + + + + The block in which to look for the transaction + + + Enter Blockhash... + + + + + + + + + true + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 4 + 4 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + + + QValidatedLineEdit + QLineEdit +
qt/qvalidatedlineedit.h
+
+
+ + + submitButton + accepted() + ToolsDialog + onSubmitForm() + + + 395 + 343 + + + 389 + 199 + + + + + submitButton + rejected() + ToolsDialog + reject() + + + 395 + 343 + + + 389 + 199 + + + + +
diff --git a/src/qt/toolsdialog.cpp b/src/qt/toolsdialog.cpp new file mode 100644 index 00000000000..5fc09768ab7 --- /dev/null +++ b/src/qt/toolsdialog.cpp @@ -0,0 +1,100 @@ +// Copyright (c) 2023-present The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#include +#include + +/** Tools dialog box */ +ToolsDialog::ToolsDialog(QWidget *parent, Mode _mode, interfaces::Node* _node) : + QDialog(parent, GUIUtil::dialog_flags), + ui(new Ui::ToolsDialog), + mode(_mode), + node(_node) +{ + ui->setupUi(this); + + switch (mode) { + case GetRawTransactionMode: + { + setWindowTitle(tr("getrawtransaction")); + break; + } + } + + GUIUtil::handleCloseWindowShortcut(this); +} + +ToolsDialog::~ToolsDialog() +{ + delete ui; +} + +QString ToolsDialog::txid() const +{ + return ui->txidEdit->text(); +} + +bool ToolsDialog::isVerboseChecked() const +{ + return ui->verboseCheckbox->isChecked(); +} + +QString ToolsDialog::blockhash() const +{ + return ui->blockHashEdit->text(); +} + +void ToolsDialog::onSubmitForm() +{ + std::string transaction_id = txid().toUtf8().constData(); + bool verbose = isVerboseChecked(); + std::string block_hash = blockhash().toUtf8().constData(); + std::string result; + + getrawtransactionRPC(transaction_id, verbose, block_hash, result); + + QTextDocument *document = ui->helpMessage->document(); + document->clear(); + QTextCursor cursor(document); + cursor.movePosition(QTextCursor::Start); + cursor.insertText(QString::fromStdString(result)); +} + +void ToolsDialog::getrawtransactionRPC(std::string txid, bool verbose, std::string blockhash, std::string& result) +{ + std::string command {"getrawtransaction"}; + std::vector args {txid}; + args.emplace_back(verbose ? "true" : "false"); + if (!blockhash.empty()) { + args.emplace_back(blockhash); + } + UniValue params {RPCConvertValues(command, args)}; + UniValue lastResult; + + try { + assert(node); + lastResult = node->executeRpc(command, params, ""); + + if (lastResult.isStr()) + result = lastResult.get_str(); + else + result = lastResult.write(2); + } catch (std::exception& e) { + result = "Error: " + std::string(e.what()); + } catch (...) { + result = "No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries. Use gettransaction for wallet transactions"; + } +} \ No newline at end of file diff --git a/src/qt/toolsdialog.h b/src/qt/toolsdialog.h new file mode 100644 index 00000000000..a5a4ab93b23 --- /dev/null +++ b/src/qt/toolsdialog.h @@ -0,0 +1,44 @@ +// Copyright (c) 2023-present The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_QT_TOOLSDIALOG_H +#define BITCOIN_QT_TOOLSDIALOG_H + +#include +#include +#include + +namespace Ui { + class ToolsDialog; +} + +/** Tools dialog box */ +class ToolsDialog : public QDialog +{ + Q_OBJECT + +public: + enum Mode { + GetRawTransactionMode + }; + + explicit ToolsDialog(QWidget *parent, Mode _mode, interfaces::Node* _node = nullptr); + ~ToolsDialog(); + + QString txid() const; + bool isVerboseChecked() const; + QString blockhash() const; + void getrawtransactionRPC(std::string txid, bool verbose, std::string blockhash, std::string& result); + +private: + Ui::ToolsDialog *ui; + QString text; + Mode mode; + interfaces::Node* node; + +private Q_SLOTS: + void onSubmitForm(); +}; + +#endif // BITCOIN_QT_TOOLSDIALOG_H