diff --git a/silentdragon.pro b/silentdragon.pro index 49790a3..74eaede 100644 --- a/silentdragon.pro +++ b/silentdragon.pro @@ -90,6 +90,7 @@ HEADERS += \ FORMS += \ src/getblock.ui \ + src/viewtransaction.ui \ src/mainwindow.ui \ src/qrcode.ui \ src/rescandialog.ui \ diff --git a/silentdragonx.pro b/silentdragonx.pro index 3fae846..18cfe00 100644 --- a/silentdragonx.pro +++ b/silentdragonx.pro @@ -89,6 +89,7 @@ HEADERS += \ FORMS += \ src/getblock.ui \ + src/viewtransaction.ui \ src/mainwindow.ui \ src/qrcode.ui \ src/rescandialog.ui \ diff --git a/src/connection.cpp b/src/connection.cpp index bf981a9..acad8bd 100644 --- a/src/connection.cpp +++ b/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& 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()); } }); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d908414..935f719 100755 --- a/src/mainwindow.cpp +++ b/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> 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( 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 diff --git a/src/mainwindow.h b/src/mainwindow.h index 0c39a3a..43a2d5f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -53,6 +53,7 @@ public: void validateAddress(); void getBlock(); + void viewTransaction(); void updateLabels(); void updateTAddrCombo(bool checked); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index d2eebe4..e7e3734 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1641,6 +1641,7 @@ &Apps + @@ -1751,6 +1752,11 @@ Get Block Info + + + View Transaction Info + + diff --git a/src/rpc.cpp b/src/rpc.cpp index 4e23de8..6181e54 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -291,7 +291,7 @@ void RPC::getrawtransaction(QString txid, const std::function& {"jsonrpc", "1.0"}, {"id", "42"}, {"method", "getrawtransaction"}, - {"params", QJsonArray {txid, "1"}} + {"params", QJsonArray {txid, 1}} }; conn->doRPCWithDefaultErrorHandling(payload, cb);