-
Notifications
You must be signed in to change notification settings - Fork 262
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
getrawtransaction implementation #777
Open
BrandonOdiwuor
wants to merge
1
commit into
bitcoin-core:master
Choose a base branch
from
BrandonOdiwuor:getrawtransactions_helperspage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
or |
||||||
</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> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
</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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
Some thoughts: perhaps we use a more generic naming here and in the form we indicate if it's a wallet transaction with a checkbox (and then we change the form removing the blockhash option and call
gettransaction
?). Or maybe just on a follow-up.