Browse Source

export priv key in the addresses dialog

recurring
adityapk00 6 years ago
parent
commit
5ed7cee480
  1. 73
      src/mainwindow.cpp
  2. 1
      src/mainwindow.h
  3. 73
      src/mainwindow.ui
  4. 2
      src/qrcodelabel.cpp
  5. 1
      src/rpc.cpp

73
src/mainwindow.cpp

@ -677,6 +677,12 @@ void MainWindow::backupWalletDat() {
}
void MainWindow::exportAllKeys() {
exportKeys("");
}
void MainWindow::exportKeys(QString addr) {
bool allKeys = addr.isEmpty() ? true : false;
QDialog d(this);
Ui_PrivKey pui;
pui.setupUi(&d);
@ -691,7 +697,11 @@ void MainWindow::exportAllKeys() {
pui.privKeyTxt->setPlainText("Loading...");
pui.privKeyTxt->setReadOnly(true);
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
pui.helpLbl->setText("These are all the private keys for all the addresses in your wallet");
if (allKeys)
pui.helpLbl->setText("These are all the private keys for all the addresses in your wallet");
else
pui.helpLbl->setText("Private key for " + addr);
// Disable the save button until it finishes loading
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
@ -700,7 +710,7 @@ void MainWindow::exportAllKeys() {
// Wire up save button
QObject::connect(pui.buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=] () {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
"zcash-all-privatekeys.txt");
allKeys ? "zcash-all-privatekeys.txt" : "zcash-privatekey.txt");
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"), file.errorString());
@ -712,9 +722,10 @@ void MainWindow::exportAllKeys() {
// Call the API
auto isDialogAlive = std::make_shared<bool>(true);
rpc->getAllPrivKeys([=] (auto privKeys) {
auto fnUpdateUIWithKeys = [=](QList<QPair<QString, QString>> privKeys) {
// Check to see if we are still showing.
if (! *isDialogAlive.get()) return;
if (!isDialogAlive) return;
QString allKeysTxt;
for (auto keypair : privKeys) {
@ -723,10 +734,28 @@ void MainWindow::exportAllKeys() {
pui.privKeyTxt->setPlainText(allKeysTxt);
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
});
};
if (allKeys) {
rpc->getAllPrivKeys(fnUpdateUIWithKeys);
}
else {
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);
};
if (Settings::getInstance()->isZAddress(addr)) {
rpc->getZPrivKey(addr, fnAddKey);
}
else {
rpc->getTPrivKey(addr, fnAddKey);
}
}
d.exec();
*isDialogAlive.get() = false;
*isDialogAlive = false;
}
void MainWindow::setupBalancesTab() {
@ -786,26 +815,7 @@ void MainWindow::setupBalancesTab() {
});
menu.addAction("Get private key", [=] () {
auto fnCB = [=] (const json& reply) {
auto privKey = QString::fromStdString(reply.get<json::string_t>());
QDialog d(this);
Ui_PrivKey pui;
pui.setupUi(&d);
pui.helpLbl->setText("Private Key:");
pui.privKeyTxt->setPlainText(privKey);
pui.privKeyTxt->setReadOnly(true);
pui.privKeyTxt->selectAll();
pui.buttonBox->button(QDialogButtonBox::Save)->setVisible(false);
pui.buttonBox->button(QDialogButtonBox::Ok)->setVisible(false);
d.exec();
};
if (Settings::getInstance()->isZAddress(addr))
rpc->getZPrivKey(addr, fnCB);
else
rpc->getTPrivKey(addr, fnCB);
this->exportKeys(addr);
});
menu.addAction("Send from " % addr.left(40) % (addr.size() > 40 ? "..." : ""), [=]() {
@ -1072,6 +1082,9 @@ void MainWindow::setupRecieveTab() {
auto curLabel = AddressBook::getInstance()->getLabelForAddress(addr);
auto label = ui->rcvLabel->text().trimmed();
if (curLabel == label) // Nothing to update
return;
QString info;
if (!curLabel.isEmpty() && label.isEmpty()) {
@ -1101,6 +1114,14 @@ void MainWindow::setupRecieveTab() {
}
});
// Recieve Export Key
QObject::connect(ui->exportKey, &QPushButton::clicked, [=]() {
QString addr = ui->listRecieveAddresses->currentText();
if (addr.isEmpty())
return;
this->exportKeys(addr);
});
}
MainWindow::~MainWindow()

1
src/mainwindow.h

@ -92,6 +92,7 @@ private:
void postToZBoard();
void importPrivKey();
void exportAllKeys();
void exportKeys(QString addr = "");
void backupWalletDat();
void doImport(QList<QString>* keys);

73
src/mainwindow.ui

@ -22,7 +22,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -35,7 +35,7 @@
<widget class="QGroupBox" name="groupBox">
<property name="minimumSize">
<size>
<width>300</width>
<width>250</width>
<height>0</height>
</size>
</property>
@ -52,6 +52,12 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Shielded</string>
</property>
@ -73,6 +79,12 @@
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Transparent</string>
</property>
@ -101,6 +113,12 @@
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
@ -145,6 +163,12 @@
</item>
<item>
<widget class="QLabel" name="unconfirmedWarning">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">color: red;</string>
</property>
@ -160,6 +184,12 @@
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Address Balances</string>
</property>
@ -672,6 +702,13 @@
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLabel" name="rcvBal">
<property name="text">
<string> </string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
@ -684,12 +721,8 @@
<property name="maxLength">
<number>40</number>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLabel" name="rcvBal">
<property name="text">
<string>TextLabel</string>
<property name="placeholderText">
<string>Optional</string>
</property>
</widget>
</item>
@ -716,6 +749,30 @@
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QPushButton" name="exportKey">
<property name="text">
<string>Export Private Key</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>

2
src/qrcodelabel.cpp

@ -3,7 +3,7 @@
QRCodeLabel::QRCodeLabel(QWidget *parent) :
QLabel(parent)
{
this->setMinimumSize(1,1);
this->setMinimumSize(100, 100);
setScaledContents(false);
}

1
src/rpc.cpp

@ -285,7 +285,6 @@ void RPC::getAllPrivKeys(const std::function<void(QList<QPair<QString, QString>>
});
};
// First get all the t and z addresses.
json payloadT = {
{"jsonrpc", "1.0"},

Loading…
Cancel
Save