Browse Source

Export seed menu item

pull/9/head
Aditya Kulkarni 5 years ago
parent
commit
54c3971bed
  1. 6
      lib/Cargo.lock
  2. 10
      src/controller.h
  3. 7
      src/liteinterface.cpp
  4. 1
      src/liteinterface.h
  5. 77
      src/mainwindow.cpp
  6. 2
      src/mainwindow.h
  7. 6
      src/mainwindow.ui
  8. 6
      src/settings.h

6
lib/Cargo.lock

@ -1051,7 +1051,7 @@ version = "0.1.0"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=50d331b0cfe1b3c4b81e33fd6febb4b24264627a)",
"zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=3e1c61a4b0589be1ff7590cf4ddf025a9160c631)",
]
[[package]]
@ -2266,7 +2266,7 @@ dependencies = [
[[package]]
name = "zecwalletlitelib"
version = "0.1.0"
source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=50d331b0cfe1b3c4b81e33fd6febb4b24264627a#50d331b0cfe1b3c4b81e33fd6febb4b24264627a"
source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=3e1c61a4b0589be1ff7590cf4ddf025a9160c631#3e1c61a4b0589be1ff7590cf4ddf025a9160c631"
dependencies = [
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bellman 0.1.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)",
@ -2562,4 +2562,4 @@ dependencies = [
"checksum zcash_client_backend 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "<none>"
"checksum zcash_primitives 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "<none>"
"checksum zcash_proofs 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "<none>"
"checksum zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=50d331b0cfe1b3c4b81e33fd6febb4b24264627a)" = "<none>"
"checksum zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=3e1c61a4b0589be1ff7590cf4ddf025a9160c631)" = "<none>"

10
src/controller.h

@ -81,6 +81,7 @@ public:
cb({ {"error", "Failed to unlock wallet"} });
});
}
void fetchAllPrivKeys(const std::function<void(json)> cb) {
unlockIfEncrypted([=] () {
zrpc->fetchAllPrivKeys(cb);
@ -90,6 +91,15 @@ public:
});
}
void fetchSeed(const std::function<void(json)> cb) {
unlockIfEncrypted([=] () {
zrpc->fetchSeed(cb);
},
[=]() {
cb({ {"error", "Failed to unlock wallet"} });
});
}
// void importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) { zrpc->importZPrivKey(addr, rescan, cb); }
// void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) { zrpc->importTPrivKey(addr, rescan, cb); }

7
src/liteinterface.cpp

@ -56,6 +56,13 @@ void LiteInterface::fetchPrivKey(QString addr, const std::function<void(json)>&
conn->doRPCWithDefaultErrorHandling("export", addr, cb);
}
void LiteInterface::fetchSeed(const std::function<void(json)>& cb) {
if (conn == nullptr)
return;
conn->doRPCWithDefaultErrorHandling("seed", "", cb);
}
void LiteInterface::fetchBalance(const std::function<void(json)>& cb) {
if (conn == nullptr)
return;

1
src/liteinterface.h

@ -52,6 +52,7 @@ public:
void fetchPrivKey(QString addr, const std::function<void(json)>& cb);
void fetchAllPrivKeys(const std::function<void(json)>);
void fetchSeed(const std::function<void(json)>&);
void saveWallet(const std::function<void(json)>& cb);

77
src/mainwindow.cpp

@ -91,7 +91,7 @@ MainWindow::MainWindow(QWidget *parent) :
QObject::connect(ui->actionExport_All_Private_Keys, &QAction::triggered, this, &MainWindow::exportAllKeys);
// Backup wallet.dat
QObject::connect(ui->actionBackup_wallet_dat, &QAction::triggered, this, &MainWindow::backupWalletDat);
QObject::connect(ui->actionExport_Seed, &QAction::triggered, this, &MainWindow::exportSeed);
// Export transactions
QObject::connect(ui->actionExport_transactions, &QAction::triggered, this, &MainWindow::exportTransactions);
@ -648,36 +648,60 @@ void MainWindow::exportTransactions() {
}
/**
* Backup the wallet.dat file. This is kind of a hack, since it has to read from the filesystem rather than an RPC call
* This might fail for various reasons - Remote zcashd, non-standard locations, custom params passed to zcashd, many others
* Export the seed phrase.
*/
void MainWindow::backupWalletDat() {
void MainWindow::exportSeed() {
if (!rpc->getConnection())
return;
// QDir zcashdir(rpc->getConnection()->config->zcashDir);
// QString backupDefaultName = "zcash-wallet-backup-" + QDateTime::currentDateTime().toString("yyyyMMdd") + ".dat";
// if (Settings::getInstance()->isTestnet()) {
// zcashdir.cd("testnet3");
// backupDefaultName = "testnet-" + backupDefaultName;
// }
QDialog d(this);
Ui_PrivKey pui;
pui.setupUi(&d);
// QFile wallet(zcashdir.filePath("wallet.dat"));
// if (!wallet.exists()) {
// QMessageBox::critical(this, tr("No wallet.dat"), tr("Couldn't find the wallet.dat on this computer") + "\n" +
// tr("You need to back it up from the machine zcashd is running on"), QMessageBox::Ok);
// return;
// }
// Make the window big by default
auto ps = this->geometry();
QMargins margin = QMargins() + 50;
d.setGeometry(ps.marginsRemoved(margin));
Settings::saveRestore(&d);
pui.privKeyTxt->setPlainText(tr("This might take several minutes. Loading..."));
pui.privKeyTxt->setReadOnly(true);
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
pui.helpLbl->setText(tr("This is your wallet seed. Please back it up carefully and safely."));
// Disable the save button until it finishes loading
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
pui.buttonBox->button(QDialogButtonBox::Ok)->setVisible(false);
// Wire up save button
QObject::connect(pui.buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=] () {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
"zcash-seed.txt");
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Unable to open file"), file.errorString());
return;
}
QTextStream out(&file);
out << pui.privKeyTxt->toPlainText();
});
rpc->fetchSeed([=](json reply) {
if (isJsonError(reply)) {
pui.privKeyTxt->setPlainText(tr("Error loading wallet seed: ") + QString::fromStdString(reply["error"]));
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
return;
}
pui.privKeyTxt->setPlainText(QString::fromStdString(reply.dump()));
pui.buttonBox->button(QDialogButtonBox::Save)->setEnabled(true);
});
// QUrl backupName = QFileDialog::getSaveFileUrl(this, tr("Backup wallet.dat"), backupDefaultName, "Data file (*.dat)");
// if (backupName.isEmpty())
// return;
// if (!wallet.copy(backupName.toLocalFile())) {
// QMessageBox::critical(this, tr("Couldn't backup"), tr("Couldn't backup the wallet.dat file.") +
// tr("You need to back it up manually."), QMessageBox::Ok);
// }
d.exec();
}
void MainWindow::exportAllKeys() {
@ -685,6 +709,9 @@ void MainWindow::exportAllKeys() {
}
void MainWindow::exportKeys(QString addr) {
if (!rpc->getConnection())
return;
bool allKeys = addr.isEmpty() ? true : false;
QDialog d(this);

2
src/mainwindow.h

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

6
src/mainwindow.ui

@ -1099,7 +1099,7 @@
<addaction name="actionPay_URI"/>
<addaction name="separator"/>
<addaction name="actionExport_All_Private_Keys"/>
<addaction name="actionBackup_wallet_dat"/>
<addaction name="actionExport_Seed"/>
<addaction name="separator"/>
<addaction name="actionExport_transactions"/>
<addaction name="separator"/>
@ -1178,9 +1178,9 @@
<string>Ctrl+B</string>
</property>
</action>
<action name="actionBackup_wallet_dat">
<action name="actionExport_Seed">
<property name="text">
<string>&amp;Backup wallet.dat</string>
<string>&amp;Export seed phrase</string>
</property>
</action>
<action name="actionExport_transactions">

6
src/settings.h

@ -127,4 +127,10 @@ inline bool isJsonSuccess(const json& res) {
QString::fromStdString(res["result"].get<json::string_t>()) == "success";
}
inline bool isJsonError(const json& res) {
return res.find("result") != res.end() &&
QString::fromStdString(res["result"].get<json::string_t>()) == "error";
}
#endif // SETTINGS_H

Loading…
Cancel
Save