diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bcc60b2..4ad0eaa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -385,6 +385,27 @@ void MainWindow::donate() { ui->tabWidget->setCurrentIndex(1); } +void MainWindow::doImport(QList* keys) { + qDebug() << keys->size(); + if (keys->isEmpty()) { + delete keys; + ui->statusBar->showMessage("Private key import rescan finished"); + return; + } + + // Pop the first key + QString key = keys->first(); + keys->pop_front(); + bool rescan = keys->isEmpty(); + + if (key.startsWith("S") || + key.startsWith("secret")) { // Z key + rpc->importZPrivKey(key, rescan, [=] (auto) { doImport(keys); }); + } else { + rpc->importTPrivKey(key, rescan, [=] (auto) { doImport(keys); }); + } +} + void MainWindow::importPrivKey() { QDialog d(this); @@ -396,27 +417,22 @@ void MainWindow::importPrivKey() { "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 rawkeys = 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, i == key.length() -1, fnFinished); - } else { // T Key - rpc->importTPrivKey(key, i == key.length() -1, fnFinished); - } - } + auto keys = new QList(); + // Filter out all the empty keys. + std::copy_if(rawkeys.begin(), rawkeys.end(), std::back_inserter(*keys), [=] (auto key) { + return !key.trimmed().isEmpty(); + }); + // Start the import + doImport(keys); 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/mainwindow.h b/src/mainwindow.h index 256a6bc..0dce7c9 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -80,6 +80,7 @@ private: void donate(); void importPrivKey(); + void doImport(QList* keys); RPC* rpc; diff --git a/src/rpc.cpp b/src/rpc.cpp index 74c8c92..10a3f62 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -191,6 +191,8 @@ void RPC::importZPrivKey(QString addr, bool rescan, const std::function