Export seed menu item
This commit is contained in:
6
lib/Cargo.lock
generated
6
lib/Cargo.lock
generated
@@ -1051,7 +1051,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
@@ -2266,7 +2266,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "zecwalletlitelib"
|
name = "zecwalletlitelib"
|
||||||
version = "0.1.0"
|
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 = [
|
dependencies = [
|
||||||
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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_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_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 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>"
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ public:
|
|||||||
cb({ {"error", "Failed to unlock wallet"} });
|
cb({ {"error", "Failed to unlock wallet"} });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void fetchAllPrivKeys(const std::function<void(json)> cb) {
|
void fetchAllPrivKeys(const std::function<void(json)> cb) {
|
||||||
unlockIfEncrypted([=] () {
|
unlockIfEncrypted([=] () {
|
||||||
zrpc->fetchAllPrivKeys(cb);
|
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 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); }
|
// void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) { zrpc->importTPrivKey(addr, rescan, cb); }
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,13 @@ void LiteInterface::fetchPrivKey(QString addr, const std::function<void(json)>&
|
|||||||
conn->doRPCWithDefaultErrorHandling("export", addr, cb);
|
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) {
|
void LiteInterface::fetchBalance(const std::function<void(json)>& cb) {
|
||||||
if (conn == nullptr)
|
if (conn == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public:
|
|||||||
|
|
||||||
void fetchPrivKey(QString addr, const std::function<void(json)>& cb);
|
void fetchPrivKey(QString addr, const std::function<void(json)>& cb);
|
||||||
void fetchAllPrivKeys(const std::function<void(json)>);
|
void fetchAllPrivKeys(const std::function<void(json)>);
|
||||||
|
void fetchSeed(const std::function<void(json)>&);
|
||||||
|
|
||||||
void saveWallet(const std::function<void(json)>& cb);
|
void saveWallet(const std::function<void(json)>& cb);
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
QObject::connect(ui->actionExport_All_Private_Keys, &QAction::triggered, this, &MainWindow::exportAllKeys);
|
QObject::connect(ui->actionExport_All_Private_Keys, &QAction::triggered, this, &MainWindow::exportAllKeys);
|
||||||
|
|
||||||
// Backup wallet.dat
|
// 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
|
// Export transactions
|
||||||
QObject::connect(ui->actionExport_transactions, &QAction::triggered, this, &MainWindow::exportTransactions);
|
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
|
* Export the seed phrase.
|
||||||
* This might fail for various reasons - Remote zcashd, non-standard locations, custom params passed to zcashd, many others
|
|
||||||
*/
|
*/
|
||||||
void MainWindow::backupWalletDat() {
|
void MainWindow::exportSeed() {
|
||||||
if (!rpc->getConnection())
|
if (!rpc->getConnection())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// QDir zcashdir(rpc->getConnection()->config->zcashDir);
|
QDialog d(this);
|
||||||
// QString backupDefaultName = "zcash-wallet-backup-" + QDateTime::currentDateTime().toString("yyyyMMdd") + ".dat";
|
Ui_PrivKey pui;
|
||||||
|
pui.setupUi(&d);
|
||||||
// if (Settings::getInstance()->isTestnet()) {
|
|
||||||
// zcashdir.cd("testnet3");
|
|
||||||
// backupDefaultName = "testnet-" + backupDefaultName;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// QFile wallet(zcashdir.filePath("wallet.dat"));
|
// Make the window big by default
|
||||||
// if (!wallet.exists()) {
|
auto ps = this->geometry();
|
||||||
// QMessageBox::critical(this, tr("No wallet.dat"), tr("Couldn't find the wallet.dat on this computer") + "\n" +
|
QMargins margin = QMargins() + 50;
|
||||||
// tr("You need to back it up from the machine zcashd is running on"), QMessageBox::Ok);
|
d.setGeometry(ps.marginsRemoved(margin));
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// QUrl backupName = QFileDialog::getSaveFileUrl(this, tr("Backup wallet.dat"), backupDefaultName, "Data file (*.dat)");
|
|
||||||
// if (backupName.isEmpty())
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// if (!wallet.copy(backupName.toLocalFile())) {
|
Settings::saveRestore(&d);
|
||||||
// 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);
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
d.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::exportAllKeys() {
|
void MainWindow::exportAllKeys() {
|
||||||
@@ -685,6 +709,9 @@ void MainWindow::exportAllKeys() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::exportKeys(QString addr) {
|
void MainWindow::exportKeys(QString addr) {
|
||||||
|
if (!rpc->getConnection())
|
||||||
|
return;
|
||||||
|
|
||||||
bool allKeys = addr.isEmpty() ? true : false;
|
bool allKeys = addr.isEmpty() ? true : false;
|
||||||
|
|
||||||
QDialog d(this);
|
QDialog d(this);
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ private:
|
|||||||
void importPrivKey();
|
void importPrivKey();
|
||||||
void exportAllKeys();
|
void exportAllKeys();
|
||||||
void exportKeys(QString addr = "");
|
void exportKeys(QString addr = "");
|
||||||
void backupWalletDat();
|
void exportSeed();
|
||||||
void exportTransactions();
|
void exportTransactions();
|
||||||
|
|
||||||
void doImport(QList<QString>* keys);
|
void doImport(QList<QString>* keys);
|
||||||
|
|||||||
@@ -1099,7 +1099,7 @@
|
|||||||
<addaction name="actionPay_URI"/>
|
<addaction name="actionPay_URI"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionExport_All_Private_Keys"/>
|
<addaction name="actionExport_All_Private_Keys"/>
|
||||||
<addaction name="actionBackup_wallet_dat"/>
|
<addaction name="actionExport_Seed"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionExport_transactions"/>
|
<addaction name="actionExport_transactions"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
@@ -1178,9 +1178,9 @@
|
|||||||
<string>Ctrl+B</string>
|
<string>Ctrl+B</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionBackup_wallet_dat">
|
<action name="actionExport_Seed">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Backup wallet.dat</string>
|
<string>&Export seed phrase</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionExport_transactions">
|
<action name="actionExport_transactions">
|
||||||
|
|||||||
@@ -127,4 +127,10 @@ inline bool isJsonSuccess(const json& res) {
|
|||||||
QString::fromStdString(res["result"].get<json::string_t>()) == "success";
|
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
|
#endif // SETTINGS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user