Browse Source

Support disabling rescan or a custom rescan height when importing privkeys

pull/145/head
Duke 4 months ago
parent
commit
7db95fbf49
  1. 39
      src/mainwindow.cpp
  2. 4
      src/rpc.cpp

39
src/mainwindow.cpp

@ -1132,19 +1132,29 @@ void MainWindow::doImport(QList<QString>* keys) {
return; return;
} }
DEBUG(" keys.size= " << keys->size() );
if (keys->isEmpty()) { if (keys->isEmpty()) {
delete keys; 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; return;
} }
// Get the first key // Get the first key
QString key = keys->takeFirst(); QString key = keys->takeFirst();
bool rescan = keys->isEmpty();
bool rescan = false;
if (key.startsWith("SK") || Settings::getInstance()->isValidSaplingPrivateKey(key) ) { if (key.startsWith("SK") || Settings::getInstance()->isValidSaplingPrivateKey(key) ) {
DEBUG("importing zaddr privkey with rescan=" << rescan);
rpc->importZPrivKey(key, rescan, [=] (auto) { this->doImport(keys); }); rpc->importZPrivKey(key, rescan, [=] (auto) { this->doImport(keys); });
} else { } else {
DEBUG("importing taddr privkey with rescan=" << rescan);
rpc->importTPrivKey(key, rescan, [=] (auto) { this->doImport(keys); }); rpc->importTPrivKey(key, rescan, [=] (auto) { this->doImport(keys); });
} }
} }
@ -1280,12 +1290,33 @@ void MainWindow::importPrivKey() {
delete multiline; 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 // 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. // 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); 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);
}
} }
} }

4
src/rpc.cpp

@ -374,7 +374,7 @@ void RPC::importTPrivKey(QString privkey, bool rescan, const std::function<void(
{"jsonrpc", "1.0"}, {"jsonrpc", "1.0"},
{"id", "42"}, {"id", "42"},
{"method", "importprivkey"}, {"method", "importprivkey"},
{"params", QJsonArray { privkey, "", "false", "0", "128" }}, {"params", QJsonArray { privkey, "", rescan , "0", "128" }},
}; };
} else { } else {
qDebug() << "Detected new-style HUSH WIF"; qDebug() << "Detected new-style HUSH WIF";
@ -382,7 +382,7 @@ void RPC::importTPrivKey(QString privkey, bool rescan, const std::function<void(
{"jsonrpc", "1.0"}, {"jsonrpc", "1.0"},
{"id", "42"}, {"id", "42"},
{"method", "importprivkey"}, {"method", "importprivkey"},
{"params", QJsonArray { privkey, (rescan? "yes" : "no") }}, {"params", QJsonArray { privkey, "", rescan }},
}; };
} }

Loading…
Cancel
Save