From 7db95fbf49f9e2340fb1bff706d9ac68a70a47e1 Mon Sep 17 00:00:00 2001 From: Duke Date: Thu, 28 Dec 2023 15:57:58 -0500 Subject: [PATCH] Support disabling rescan or a custom rescan height when importing privkeys --- src/mainwindow.cpp | 39 +++++++++++++++++++++++++++++++++++---- src/rpc.cpp | 4 ++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d1406b0..e37e092 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1132,19 +1132,29 @@ void MainWindow::doImport(QList* keys) { return; } + DEBUG(" keys.size= " << keys->size() ); + if (keys->isEmpty()) { delete keys; - ui->statusBar->showMessage(tr("Private key import rescan finished")); + /* + if (rescan) { + ui->statusBar->showMessage(tr("Private key import with rescan finished")); + } else { + ui->statusBar->showMessage(tr("Private key import finished")); + } + */ return; } // Get the first key QString key = keys->takeFirst(); - bool rescan = keys->isEmpty(); + bool rescan = false; if (key.startsWith("SK") || Settings::getInstance()->isValidSaplingPrivateKey(key) ) { + DEBUG("importing zaddr privkey with rescan=" << rescan); rpc->importZPrivKey(key, rescan, [=] (auto) { this->doImport(keys); }); } else { + DEBUG("importing taddr privkey with rescan=" << rescan); rpc->importTPrivKey(key, rescan, [=] (auto) { this->doImport(keys); }); } } @@ -1280,12 +1290,33 @@ void MainWindow::importPrivKey() { delete multiline; } + //TODO: if rescan is not checked, disable the rescan height input + bool rescan = pui.chkrescan->isChecked(); + // Start the import. The function takes ownership of keys - QTimer::singleShot(1, [=]() {doImport(keys);}); + QTimer::singleShot(1, [=]() { + // we import all keys without rescanning and then finally decide if we will rescan once + doImport(keys); + + if (rescan) { + rpc->rescan(pui.rescanfrom->text().toInt() , [=] (QJsonValue response){ + qDebug() << __func__ << ":rescanning from height " << pui.rescanfrom << " finished" << response; + ui->statusBar->showMessage(tr("Rescanning finished"), 5000); + }); + } + + }); // Show the dialog that keys will be imported. - QMessageBox::information(this, "Imported", tr("The keys were imported! It may take several hours to rescan the blockchain. Until then, functionality may be limited"), + if(rescan) { + QMessageBox::information(this, "Imported", + tr("The keys were imported! It may take several hours to rescan the blockchain. Until then, functionality may be limited"), QMessageBox::Ok); + } else { + QMessageBox::information(this, "Imported", + tr("The keys were imported! You chose to not rescan, so funds in that address will not show up in your wallet yet."), + QMessageBox::Ok); + } } } diff --git a/src/rpc.cpp b/src/rpc.cpp index 6181e54..9ecd34e 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -374,7 +374,7 @@ void RPC::importTPrivKey(QString privkey, bool rescan, const std::function