-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gui: getrawtransaction Implementation
Add getrawtransaction RPC to GUI to tools > getrawtransactions
- Loading branch information
1 parent
29c2c90
commit a17fb06
Showing
7 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>ToolsDialog</class> | ||
<widget class="QDialog" name="ToolsDialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>780</width> | ||
<height>400</height> | ||
</rect> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<layout class="QVBoxLayout" name="verticalLayout_2"> | ||
<item> | ||
<layout class="QFormLayout" name="formLayout"> | ||
<property name="bottomMargin"> | ||
<number>12</number> | ||
</property> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="labelTxId"> | ||
<property name="text"> | ||
<string>transaction id: </string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QValidatedLineEdit" name="txidEdit"> | ||
<property name="toolTip"> | ||
<string>The transaction id</string> | ||
</property> | ||
<property name="placeholderText"> | ||
<string notr="true">Enter a transaction id...</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QCheckBox" name="verboseCheckbox"> | ||
<property name="toolTip"> | ||
<string>verbose</string> | ||
</property> | ||
<property name="text"> | ||
<string>verbose</string> | ||
</property> | ||
<property name="checked"> | ||
<bool>false</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="0"> | ||
<widget class="QLabel" name="labelBlockHash"> | ||
<property name="text"> | ||
<string>blockhash (optional): </string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="1"> | ||
<widget class="QValidatedLineEdit" name="blockHashEdit"> | ||
<property name="toolTip"> | ||
<string>The block in which to look for the transaction</string> | ||
</property> | ||
<property name="placeholderText"> | ||
<string notr="true">Enter Blockhash...</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<widget class="QTextEdit" name="helpMessage"> | ||
<property name="readOnly"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeType"> | ||
<enum>QSizePolicy::Fixed</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>4</width> | ||
<height>4</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="submitButton"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources> | ||
<include location="../bitcoin.qrc"/> | ||
</resources> | ||
<customwidgets> | ||
<customwidget> | ||
<class>QValidatedLineEdit</class> | ||
<extends>QLineEdit</extends> | ||
<header>qt/qvalidatedlineedit.h</header> | ||
</customwidget> | ||
</customwidgets> | ||
<connections> | ||
<connection> | ||
<sender>submitButton</sender> | ||
<signal>accepted()</signal> | ||
<receiver>ToolsDialog</receiver> | ||
<slot>onSubmitForm()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>395</x> | ||
<y>343</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>389</x> | ||
<y>199</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>submitButton</sender> | ||
<signal>rejected()</signal> | ||
<receiver>ToolsDialog</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>395</x> | ||
<y>343</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>389</x> | ||
<y>199</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <qt/toolsdialog.h> | ||
#include <qt/forms/ui_toolsdialog.h> | ||
|
||
#include <qt/guiutil.h> | ||
|
||
#include <univalue.h> | ||
#include <rpc/client.h> | ||
|
||
#include <QString> | ||
#include <QTextDocument> | ||
#include <QTextCursor> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
/** 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<std::string> 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"; | ||
} | ||
} |
Oops, something went wrong.