Skip to content

Commit 9659890

Browse files
Gui: getrawtransaction Implementation
Add getrawtransaction RPC to GUI to tools > getrawtransactions
1 parent 29c2c90 commit 9659890

File tree

7 files changed

+319
-0
lines changed

7 files changed

+319
-0
lines changed

build_msvc/libbitcoin_qt/libbitcoin_qt.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<ClCompile Include="..\..\src\qt\transactiontablemodel.cpp" />
5959
<ClCompile Include="..\..\src\qt\transactionview.cpp" />
6060
<ClCompile Include="..\..\src\qt\utilitydialog.cpp" />
61+
<ClCompile Include="..\..\src\qt\toolsdialog.cpp" />
6162
<ClCompile Include="..\..\src\qt\walletcontroller.cpp" />
6263
<ClCompile Include="..\..\src\qt\walletframe.cpp" />
6364
<ClCompile Include="..\..\src\qt\walletmodel.cpp" />
@@ -114,6 +115,7 @@
114115
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_transactiontablemodel.cpp" />
115116
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_transactionview.cpp" />
116117
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_utilitydialog.cpp" />
118+
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_toolsdialog.cpp" />
117119
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_walletcontroller.cpp" />
118120
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_walletframe.cpp" />
119121
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_walletmodel.cpp" />

src/Makefile.qt.include

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ QT_FORMS_UI = \
2424
qt/forms/modaloverlay.ui \
2525
qt/forms/openuridialog.ui \
2626
qt/forms/optionsdialog.ui \
27+
qt/forms/toolsdialog.ui \
2728
qt/forms/overviewpage.ui \
2829
qt/forms/psbtoperationsdialog.ui \
2930
qt/forms/receivecoinsdialog.ui \
@@ -84,6 +85,7 @@ QT_MOC_CPP = \
8485
qt/moc_transactiontablemodel.cpp \
8586
qt/moc_transactionview.cpp \
8687
qt/moc_utilitydialog.cpp \
88+
qt/moc_toolsdialog.cpp \
8789
qt/moc_walletcontroller.cpp \
8890
qt/moc_walletframe.cpp \
8991
qt/moc_walletmodel.cpp \
@@ -161,6 +163,7 @@ BITCOIN_QT_H = \
161163
qt/transactiontablemodel.h \
162164
qt/transactionview.h \
163165
qt/utilitydialog.h \
166+
qt/toolsdialog.h \
164167
qt/walletcontroller.h \
165168
qt/walletframe.h \
166169
qt/walletmodel.h \
@@ -244,6 +247,7 @@ BITCOIN_QT_BASE_CPP = \
244247
qt/rpcconsole.cpp \
245248
qt/splashscreen.cpp \
246249
qt/trafficgraphwidget.cpp \
250+
qt/toolsdialog.cpp \
247251
qt/utilitydialog.cpp
248252

249253
BITCOIN_QT_WINDOWS_CPP = qt/winshutdownmonitor.cpp

src/qt/bitcoingui.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <qt/platformstyle.h>
1919
#include <qt/rpcconsole.h>
2020
#include <qt/utilitydialog.h>
21+
#include <qt/toolsdialog.h>
2122

2223
#ifdef ENABLE_WALLET
2324
#include <qt/walletcontroller.h>
@@ -368,12 +369,17 @@ void BitcoinGUI::createActions()
368369
m_mask_values_action->setStatusTip(tr("Mask the values in the Overview tab"));
369370
m_mask_values_action->setCheckable(true);
370371

372+
getRawTransactionAction = new QAction(tr("&Verify external txid"), this);
373+
getRawTransactionAction->setMenuRole(QAction::NoRole);
374+
getRawTransactionAction->setStatusTip(tr("getrawtransaction RPC"));
375+
371376
connect(quitAction, &QAction::triggered, this, &BitcoinGUI::quitRequested);
372377
connect(aboutAction, &QAction::triggered, this, &BitcoinGUI::aboutClicked);
373378
connect(aboutQtAction, &QAction::triggered, qApp, QApplication::aboutQt);
374379
connect(optionsAction, &QAction::triggered, this, &BitcoinGUI::optionsClicked);
375380
connect(showHelpMessageAction, &QAction::triggered, this, &BitcoinGUI::showHelpMessageClicked);
376381
connect(openRPCConsoleAction, &QAction::triggered, this, &BitcoinGUI::showDebugWindow);
382+
connect(getRawTransactionAction, &QAction::triggered, this, &BitcoinGUI::getRawTransactionClicked);
377383
// prevents an open debug window from becoming stuck/unusable on client shutdown
378384
connect(quitAction, &QAction::triggered, rpcConsole, &QWidget::hide);
379385

@@ -555,6 +561,9 @@ void BitcoinGUI::createMenuBar()
555561
});
556562
}
557563

564+
QMenu *tools = appMenuBar->addMenu(tr("&Tools"));
565+
tools->addAction(getRawTransactionAction);
566+
558567
QMenu *help = appMenuBar->addMenu(tr("&Help"));
559568
help->addAction(showHelpMessageAction);
560569
help->addSeparator();
@@ -932,6 +941,12 @@ void BitcoinGUI::showHelpMessageClicked()
932941
GUIUtil::bringToFront(helpMessageDialog);
933942
}
934943

944+
void BitcoinGUI::getRawTransactionClicked()
945+
{
946+
auto dlg = new ToolsDialog(this, ToolsDialog::GetRawTransactionMode, &m_node);
947+
GUIUtil::ShowModalDialogAsynchronously(dlg);
948+
}
949+
935950
#ifdef ENABLE_WALLET
936951
void BitcoinGUI::openClicked()
937952
{

src/qt/bitcoingui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class BitcoinGUI : public QMainWindow
145145
QAction* m_load_psbt_action = nullptr;
146146
QAction* m_load_psbt_clipboard_action = nullptr;
147147
QAction* aboutAction = nullptr;
148+
QAction* getRawTransactionAction = nullptr;
148149
QAction* receiveCoinsAction = nullptr;
149150
QAction* optionsAction = nullptr;
150151
QAction* encryptWalletAction = nullptr;
@@ -308,6 +309,8 @@ public Q_SLOTS:
308309
void showDebugWindowActivateConsole();
309310
/** Show help message dialog */
310311
void showHelpMessageClicked();
312+
/** show getrawtransaction dialog*/
313+
void getRawTransactionClicked();
311314

312315
/** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */
313316
void showNormalIfMinimized() { showNormalIfMinimized(false); }

src/qt/forms/toolsdialog.ui

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>ToolsDialog</class>
4+
<widget class="QDialog" name="ToolsDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>780</width>
10+
<height>400</height>
11+
</rect>
12+
</property>
13+
<layout class="QVBoxLayout" name="verticalLayout">
14+
<item>
15+
<layout class="QVBoxLayout" name="verticalLayout_2">
16+
<item>
17+
<layout class="QFormLayout" name="formLayout">
18+
<property name="bottomMargin">
19+
<number>12</number>
20+
</property>
21+
<item row="0" column="0">
22+
<widget class="QLabel" name="labelTxId">
23+
<property name="text">
24+
<string>transaction id: </string>
25+
</property>
26+
</widget>
27+
</item>
28+
<item row="0" column="1">
29+
<widget class="QValidatedLineEdit" name="txidEdit">
30+
<property name="toolTip">
31+
<string>The transaction id</string>
32+
</property>
33+
<property name="placeholderText">
34+
<string notr="true">Enter a transaction id...</string>
35+
</property>
36+
</widget>
37+
</item>
38+
<item row="1" column="0">
39+
<widget class="QCheckBox" name="verboseCheckbox">
40+
<property name="toolTip">
41+
<string>verbose</string>
42+
</property>
43+
<property name="text">
44+
<string>verbose</string>
45+
</property>
46+
<property name="checked">
47+
<bool>false</bool>
48+
</property>
49+
</widget>
50+
</item>
51+
<item row="2" column="0">
52+
<widget class="QLabel" name="labelBlockHash">
53+
<property name="text">
54+
<string>blockhash (optional): </string>
55+
</property>
56+
</widget>
57+
</item>
58+
<item row="2" column="1">
59+
<widget class="QValidatedLineEdit" name="blockHashEdit">
60+
<property name="toolTip">
61+
<string>The block in which to look for the transaction</string>
62+
</property>
63+
<property name="placeholderText">
64+
<string notr="true">Enter Blockhash...</string>
65+
</property>
66+
</widget>
67+
</item>
68+
</layout>
69+
</item>
70+
<item>
71+
<widget class="QTextEdit" name="helpMessage">
72+
<property name="readOnly">
73+
<bool>true</bool>
74+
</property>
75+
</widget>
76+
</item>
77+
<item>
78+
<spacer name="verticalSpacer">
79+
<property name="orientation">
80+
<enum>Qt::Vertical</enum>
81+
</property>
82+
<property name="sizeType">
83+
<enum>QSizePolicy::Fixed</enum>
84+
</property>
85+
<property name="sizeHint" stdset="0">
86+
<size>
87+
<width>4</width>
88+
<height>4</height>
89+
</size>
90+
</property>
91+
</spacer>
92+
</item>
93+
<item>
94+
<widget class="QDialogButtonBox" name="submitButton">
95+
<property name="orientation">
96+
<enum>Qt::Horizontal</enum>
97+
</property>
98+
<property name="standardButtons">
99+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
100+
</property>
101+
</widget>
102+
</item>
103+
</layout>
104+
</item>
105+
</layout>
106+
</widget>
107+
<resources>
108+
<include location="../bitcoin.qrc"/>
109+
</resources>
110+
<customwidgets>
111+
<customwidget>
112+
<class>QValidatedLineEdit</class>
113+
<extends>QLineEdit</extends>
114+
<header>qt/qvalidatedlineedit.h</header>
115+
</customwidget>
116+
</customwidgets>
117+
<connections>
118+
<connection>
119+
<sender>submitButton</sender>
120+
<signal>accepted()</signal>
121+
<receiver>ToolsDialog</receiver>
122+
<slot>onSubmitForm()</slot>
123+
<hints>
124+
<hint type="sourcelabel">
125+
<x>395</x>
126+
<y>343</y>
127+
</hint>
128+
<hint type="destinationlabel">
129+
<x>389</x>
130+
<y>199</y>
131+
</hint>
132+
</hints>
133+
</connection>
134+
<connection>
135+
<sender>submitButton</sender>
136+
<signal>rejected()</signal>
137+
<receiver>ToolsDialog</receiver>
138+
<slot>reject()</slot>
139+
<hints>
140+
<hint type="sourcelabel">
141+
<x>395</x>
142+
<y>343</y>
143+
</hint>
144+
<hint type="destinationlabel">
145+
<x>389</x>
146+
<y>199</y>
147+
</hint>
148+
</hints>
149+
</connection>
150+
</connections>
151+
</ui>

src/qt/toolsdialog.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) 2023-present The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <qt/toolsdialog.h>
6+
#include <qt/forms/ui_toolsdialog.h>
7+
8+
#include <qt/guiutil.h>
9+
10+
#include <univalue.h>
11+
#include <rpc/client.h>
12+
13+
#include <QString>
14+
#include <QTextDocument>
15+
#include <QTextCursor>
16+
17+
#include <string>
18+
#include <vector>
19+
20+
/** Tools dialog box */
21+
ToolsDialog::ToolsDialog(QWidget *parent, Mode _mode, interfaces::Node* _node) :
22+
QDialog(parent, GUIUtil::dialog_flags),
23+
ui(new Ui::ToolsDialog),
24+
mode(_mode),
25+
node(_node)
26+
{
27+
ui->setupUi(this);
28+
29+
switch (mode) {
30+
case GetRawTransactionMode:
31+
{
32+
setWindowTitle(tr("getrawtransaction"));
33+
break;
34+
}
35+
}
36+
37+
GUIUtil::handleCloseWindowShortcut(this);
38+
}
39+
40+
ToolsDialog::~ToolsDialog()
41+
{
42+
delete ui;
43+
}
44+
45+
QString ToolsDialog::txid() const
46+
{
47+
return ui->txidEdit->text();
48+
}
49+
50+
bool ToolsDialog::isVerboseChecked() const
51+
{
52+
return ui->verboseCheckbox->isChecked();
53+
}
54+
55+
QString ToolsDialog::blockhash() const
56+
{
57+
return ui->blockHashEdit->text();
58+
}
59+
60+
void ToolsDialog::onSubmitForm()
61+
{
62+
std::string transaction_id = txid().toUtf8().constData();
63+
bool verbose = isVerboseChecked();
64+
std::string block_hash = blockhash().toUtf8().constData();
65+
std::string result;
66+
67+
getrawtransactionRPC(transaction_id, verbose, block_hash, result);
68+
69+
QTextDocument *document = ui->helpMessage->document();
70+
document->clear();
71+
QTextCursor cursor(document);
72+
cursor.movePosition(QTextCursor::Start);
73+
cursor.insertText(QString::fromStdString(result));
74+
}
75+
76+
void ToolsDialog::getrawtransactionRPC(std::string txid, bool verbose, std::string blockhash, std::string& result)
77+
{
78+
std::string command {"getrawtransaction"};
79+
std::vector<std::string> args {txid};
80+
args.emplace_back(verbose ? "true" : "false");
81+
if (!blockhash.empty()) {
82+
args.emplace_back(blockhash);
83+
}
84+
UniValue params {RPCConvertValues(command, args)};
85+
UniValue lastResult;
86+
87+
try {
88+
assert(node);
89+
lastResult = node->executeRpc(command, params, "");
90+
91+
if (lastResult.isStr())
92+
result = lastResult.get_str();
93+
else
94+
result = lastResult.write(2);
95+
} catch (std::exception& e) {
96+
result = "Error: " + std::string(e.what());
97+
} catch (...) {
98+
result = "No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries. Use gettransaction for wallet transactions";
99+
}
100+
}

0 commit comments

Comments
 (0)