Browse Source

View Transaction

View basic transaction data. We will need more code to render some properties which are arrays
but this renders most basic info. There is a huge amount of low-level data in the full output,
I am not sure if we will show it all.
custom_themes
Duke 4 months ago
parent
commit
fb67b86d0d
  1. 1
      silentdragon.pro
  2. 1
      silentdragonx.pro
  3. 3
      src/connection.cpp
  4. 65
      src/mainwindow.cpp
  5. 1
      src/mainwindow.h
  6. 6
      src/mainwindow.ui
  7. 2
      src/rpc.cpp

1
silentdragon.pro

@ -90,6 +90,7 @@ HEADERS += \
FORMS += \
src/getblock.ui \
src/viewtransaction.ui \
src/mainwindow.ui \
src/qrcode.ui \
src/rescandialog.ui \

1
silentdragonx.pro

@ -89,6 +89,7 @@ HEADERS += \
FORMS += \
src/getblock.ui \
src/viewtransaction.ui \
src/mainwindow.ui \
src/qrcode.ui \
src/rescandialog.ui \

3
src/connection.cpp

@ -8,6 +8,7 @@
#include "rpc.h"
#include "precompiled.h"
#include "version.h"
#include "sd.h"
extern bool isdragonx;
@ -936,8 +937,10 @@ void Connection::doRPC(const QJsonValue& payload, const std::function<void(QJson
void Connection::doRPCWithDefaultErrorHandling(const QJsonValue& payload, const std::function<void(QJsonValue)>& cb) {
doRPC(payload, cb, [=] (QNetworkReply* reply, const QJsonValue &parsed) {
if (!parsed.isUndefined() && !parsed["error"].toObject()["message"].isNull()) {
DEBUG("got a parse error");
this->showTxError(parsed["error"].toObject()["message"].toString());
} else {
DEBUG("got a reply error");
this->showTxError(reply->errorString());
}
});

65
src/mainwindow.cpp

@ -13,6 +13,7 @@
#include "ui_settings.h"
#include "ui_viewalladdresses.h"
#include "ui_validateaddress.h"
#include "ui_viewtransaction.h"
#include "ui_rescandialog.h"
#include "ui_getblock.h"
#include "rpc.h"
@ -99,6 +100,9 @@ MainWindow::MainWindow(QWidget *parent) :
// Get Block
QObject::connect(ui->actionGet_Block, &QAction::triggered, this, &MainWindow::getBlock);
// View tx
QObject::connect(ui->actionView_Transaction, &QAction::triggered, this, &MainWindow::viewTransaction);
// Address Book
QObject::connect(ui->action_Address_Book, &QAction::triggered, this, &MainWindow::addressBook);
@ -903,6 +907,67 @@ void MainWindow::validateAddress() {
});
}
// View tx
void MainWindow::viewTransaction() {
// Make sure everything is up and running
if (!getRPC() || !getRPC()->getConnection())
return;
// First thing is ask the user for a txid
bool ok;
QString txid = QInputDialog::getText(this, tr("View Transaction"),
tr("Enter Transaction ID (txid):"), QLineEdit::Normal, "", &ok);
if (!ok)
return;
// ignore leading and trailing whitespace
txid = txid.trimmed();
QRegExp rx("^[0-9a-f]{64}$");
if(!rx.exactMatch(txid)) {
DEBUG("invalid txid " << txid );
return;
}
// ok, we were given a valid txid
getRPC()->getrawtransaction(txid, [=] (QJsonValue props) {
// getRPC()->z_viewtransaction(txid, [=] (QJsonValue props) {
QDialog d(this);
Ui_ViewTransaction vt;
vt.setupUi(&d);
Settings::saveRestore(&d);
Settings::saveRestoreTableHeader(vt.tblProps, &d, "getblockprops");
vt.tblProps->horizontalHeader()->setStretchLastSection(true);
vt.lblHeight->setText(txid);
QList<QPair<QString, QString>> propsList;
for (QString property_name: props.toObject().keys()) {
QString property_value;
DEBUG("property " << property_name << "=" << props.toObject()[property_name] );
if (props.toObject()[property_name].isString()) {
property_value = props.toObject()[property_name].toString();
} else if (props.toObject()[property_name].isDouble()) {
property_value = QString::number( props.toObject()[property_name].toDouble(), 'f', 0);
} else if (props.toObject()[property_name].isBool()) {
property_value = props.toObject()[property_name].toBool() ? "true" : "false" ;
} else if (props.toObject()[property_name].isArray()) {
DEBUG( property_name << " is an array");
} else if (props.toObject()[property_name].isObject()) {
DEBUG( property_name << " is an object");
}
propsList.append( QPair<QString, QString>( property_name, property_value ));
}
ValidateAddressesModel model(vt.tblProps, propsList);
vt.tblProps->setModel(&model);
d.exec();
});
}
// Get block info
void MainWindow::getBlock() {
// Make sure everything is up and running

1
src/mainwindow.h

@ -53,6 +53,7 @@ public:
void validateAddress();
void getBlock();
void viewTransaction();
void updateLabels();
void updateTAddrCombo(bool checked);

6
src/mainwindow.ui

@ -1641,6 +1641,7 @@
<string>&amp;Apps</string>
</property>
<addaction name="actionGet_Block"/>
<addaction name="actionView_Transaction"/>
<addaction name="actionValidate_Address"/>
<addaction name="separator"/>
</widget>
@ -1751,6 +1752,11 @@
<string>Get Block Info</string>
</property>
</action>
<action name="actionView_Transaction">
<property name="text">
<string>View Transaction Info</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

2
src/rpc.cpp

@ -291,7 +291,7 @@ void RPC::getrawtransaction(QString txid, const std::function<void(QJsonValue)>&
{"jsonrpc", "1.0"},
{"id", "42"},
{"method", "getrawtransaction"},
{"params", QJsonArray {txid, "1"}}
{"params", QJsonArray {txid, 1}}
};
conn->doRPCWithDefaultErrorHandling(payload, cb);

Loading…
Cancel
Save