Browse Source

Implement GUI menu option to get the viewing key of a zaddr in balances tab

importviewkey
Duke Leto 4 years ago
parent
commit
73dba4a190
  1. 1
      silentdragon.pro
  2. 71
      src/mainwindow.cpp
  3. 1
      src/mainwindow.h
  4. 2
      src/privkey.ui
  5. 5
      src/rpc.cpp
  6. 1
      src/rpc.h

1
silentdragon.pro

@ -96,6 +96,7 @@ FORMS += \
src/about.ui \
src/confirm.ui \
src/privkey.ui \
src/viewkey.ui \
src/memodialog.ui \
src/viewalladdresses.ui \
src/validateaddress.ui \

71
src/mainwindow.cpp

@ -8,6 +8,7 @@
#include "ui_mobileappconnector.h"
#include "ui_addressbook.h"
#include "ui_privkey.h"
#include "ui_viewkey.h"
#include "ui_about.h"
#include "ui_settings.h"
#include "ui_viewalladdresses.h"
@ -774,6 +775,69 @@ void MainWindow::exportAllKeys() {
exportKeys("");
}
void MainWindow::getViewKey(QString addr) {
QDialog d(this);
Ui_ViewKey vui;
vui.setupUi(&d);
// Make the window big by default
auto ps = this->geometry();
QMargins margin = QMargins() + 50;
d.setGeometry(ps.marginsRemoved(margin));
Settings::saveRestore(&d);
vui.viewKeyTxt->setPlainText(tr("Loading..."));
vui.viewKeyTxt->setReadOnly(true);
vui.viewKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
// Disable the save button until it finishes loading
vui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
vui.buttonBox->button(QDialogButtonBox::Ok)->setVisible(false);
bool allKeys = false; //addr.isEmpty() ? true : false;
// Wire up save button
QObject::connect(vui.buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=] () {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
allKeys ? "hush-all-viewkeys.txt" : "hush-viewkey.txt");
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"), file.errorString());
return;
}
QTextStream out(&file);
// TODO: Output in address, viewkey CSV format?
out << vui.viewKeyTxt->toPlainText();
});
// TODO: actually get the viewkey of zaddr
auto isDialogAlive = std::make_shared<bool>(true);
auto fnUpdateUIWithKeys = [=](QList<QPair<QString, QString>> viewKeys) {
// Check to see if we are still showing.
if (! *(isDialogAlive.get()) ) return;
QString allKeysTxt;
for (auto keypair : viewKeys) {
allKeysTxt = allKeysTxt % keypair.second % " # addr=" % keypair.first % "\n";
}
vui.viewKeyTxt->setPlainText(allKeysTxt);
vui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
};
auto fnAddKey = [=](json key) {
QList<QPair<QString, QString>> singleAddrKey;
singleAddrKey.push_back(QPair<QString, QString>(addr, QString::fromStdString(key.get<json::string_t>())));
fnUpdateUIWithKeys(singleAddrKey);
};
rpc->getZViewKey(addr, fnAddKey);
d.exec();
*isDialogAlive = false;
}
void MainWindow::exportKeys(QString addr) {
bool allKeys = addr.isEmpty() ? true : false;
@ -842,8 +906,7 @@ void MainWindow::exportKeys(QString addr) {
if (Settings::getInstance()->isZAddress(addr)) {
rpc->getZPrivKey(addr, fnAddKey);
}
else {
} else {
rpc->getTPrivKey(addr, fnAddKey);
}
}
@ -912,6 +975,10 @@ void MainWindow::setupBalancesTab() {
this->exportKeys(addr);
});
menu.addAction(tr("Get viewing key"), [=] () {
this->getViewKey(addr);
});
menu.addAction("Send from " % addr.left(40) % (addr.size() > 40 ? "..." : ""), [=]() {
fnDoSendFrom(addr);
});

1
src/mainwindow.h

@ -124,6 +124,7 @@ private:
void importPrivKey();
void exportAllKeys();
void exportKeys(QString addr = "");
void getViewKey(QString addr = "");
void backupWalletDat();
void exportTransactions();

2
src/privkey.ui

@ -34,7 +34,7 @@
<item row="0" column="0">
<widget class="QLabel" name="helpLbl">
<property name="text">
<string notr="true">TextLabel</string>
<string notr="true">Private Key(s). Keep Secure!</string>
</property>
</widget>
</item>

5
src/rpc.cpp

@ -171,6 +171,11 @@ void RPC::newTaddr(const std::function<void(json)>& cb) {
conn->doRPCWithDefaultErrorHandling(makePayload(method), cb);
}
void RPC::getZViewKey(QString addr, const std::function<void(json)>& cb) {
std::string method = "z_exportviewingkey";
conn->doRPCWithDefaultErrorHandling(makePayload(method, addr.toStdString()), cb);
}
void RPC::getZPrivKey(QString addr, const std::function<void(json)>& cb) {
std::string method = "z_exportkey";
conn->doRPCWithDefaultErrorHandling(makePayload(method, addr.toStdString()), cb);

1
src/rpc.h

@ -72,6 +72,7 @@ public:
void newTaddr(const std::function<void(json)>& cb);
void getZPrivKey(QString addr, const std::function<void(json)>& cb);
void getZViewKey(QString addr, const std::function<void(json)>& cb);
void getTPrivKey(QString addr, const std::function<void(json)>& cb);
void importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);

Loading…
Cancel
Save