diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e693c7b..bcc60b2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -393,23 +393,30 @@ void MainWindow::importPrivKey() { pui.helpLbl->setText(QString() % "Please paste your private keys (z-Addr or t-Addr) here, one per line.\n" % - "The keys will be imported into your connected zcashd node"); + "The keys will be imported into your connected zcashd node"); + if (d.exec() == QDialog::Accepted && !pui.privKeyTxt->toPlainText().trimmed().isEmpty()) { auto keys = pui.privKeyTxt->toPlainText().trimmed().split("\n"); + + auto fnFinished = [=] (auto) { + qDebug() << "finished"; + ui->statusBar->showMessage("Key import rescan finished"); + }; + for (int i=0; i < keys.length(); i++) { auto key = keys[i].trimmed(); if (key.startsWith("S") || key.startsWith("secret")) { // Z key - rpc->importZPrivKey(key, [=] (auto) {} ); + rpc->importZPrivKey(key, i == key.length() -1, fnFinished); } else { // T Key - rpc->importTPrivKey(key, [=] (auto) {} ); + rpc->importTPrivKey(key, i == key.length() -1, fnFinished); } } - } - QMessageBox::information(this, - "Imported", "The keys were imported. It may be a while to rescan the blockchain with the new keys.", - QMessageBox::Ok); + QMessageBox::information(this, + "Imported", "The keys were imported. It may take several minutes to rescan the blockchain with the new keys for your balance to be shown accurately.", + QMessageBox::Ok); + } } void MainWindow::setupBalancesTab() { diff --git a/src/rpc.cpp b/src/rpc.cpp index c483fe2..74c8c92 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -184,24 +184,24 @@ void RPC::getTPrivKey(QString addr, const std::function& cb) { doRPC(payload, cb); } -void RPC::importZPrivKey(QString addr, const std::function& cb) { +void RPC::importZPrivKey(QString addr, bool rescan, const std::function& cb) { json payload = { {"jsonrpc", "1.0"}, {"id", "someid"}, {"method", "z_importkey"}, - {"params", { addr.toStdString() }}, + {"params", { addr.toStdString(), (rescan? "yes" : "no") }}, }; doRPC(payload, cb); } -void RPC::importTPrivKey(QString addr, const std::function& cb) { +void RPC::importTPrivKey(QString addr, bool rescan, const std::function& cb) { json payload = { {"jsonrpc", "1.0"}, {"id", "someid"}, {"method", "importprivkey"}, - {"params", { addr.toStdString() }}, + {"params", { addr.toStdString(), (rescan? "yes" : "no") }}, }; doRPC(payload, cb); diff --git a/src/rpc.h b/src/rpc.h index ae7ed82..fb9d01f 100644 --- a/src/rpc.h +++ b/src/rpc.h @@ -53,8 +53,8 @@ public: void getZPrivKey(QString addr, const std::function& cb); void getTPrivKey(QString addr, const std::function& cb); - void importZPrivKey(QString addr, const std::function& cb); - void importTPrivKey(QString addr, const std::function& cb); + void importZPrivKey(QString addr, bool rescan, const std::function& cb); + void importTPrivKey(QString addr, bool rescan, const std::function& cb); Turnstile* getTurnstile() { return turnstile; }