Browse Source

Only import valid zaddr+taddr privkeys and only rescan if there was at least 1 valid privkey

pull/145/head
Duke 5 months ago
parent
commit
68bd0db44c
  1. 27
      src/mainwindow.cpp

27
src/mainwindow.cpp

@ -1270,16 +1270,18 @@ void MainWindow::importPrivKey() {
auto rawkeys = pui.privKeyTxt->toPlainText().trimmed().split("\n");
QList<QString> keysTmp;
// Filter out all the empty keys.
// Filter out all the empty keys and comment lines
std::copy_if(rawkeys.begin(), rawkeys.end(), std::back_inserter(keysTmp), [=] (auto key) {
return !key.startsWith("#") && !key.trimmed().isEmpty();
});
auto keys = new QList<QString>();
// split multiple privkeys seperated by spaces on a single line
std::transform(keysTmp.begin(), keysTmp.end(), std::back_inserter(*keys), [=](auto key) {
return key.trimmed().split(" ")[0];
});
// Special case.
// Sometimes, when importing from a paperwallet or such, the key is split by newlines, and might have
// been pasted like that. So check to see if the whole thing is one big private key
@ -1290,6 +1292,16 @@ void MainWindow::importPrivKey() {
delete multiline;
}
// Finally, validate all keys, removing any which are invalid
auto keysValidated = new QList<QString>();
auto settings = Settings::getInstance();
std::copy_if(keys->begin(), keys->end(), std::back_inserter(*keysValidated), [=] (auto key) {
bool isValid = settings->isValidSaplingPrivateKey(key) || settings->isValidTransparentPrivateKey(key);
if (!isValid) { DEBUG("privkey " << key << " is not valid"); }
return isValid;
});
DEBUG("found " << keysValidated->size() << " valid privkeys");
bool rescan = pui.chkrescan->isChecked();
//TODO: if rescan is not checked, disable the rescan height input
@ -1302,12 +1314,21 @@ void MainWindow::importPrivKey() {
pui.rescanfrom->setReadOnly(true);
}
// Start the import. The function takes ownership of keys
// avoid giving invalid data to RPCs and a rescan if there were no valid privkeys
if(keysValidated->size() == 0) {
QMessageBox::information(this, "No valid keys",
tr("No valid private keys were found, please make sure you copy and pasted correctly"),
QMessageBox::Ok);
return;
}
// Start the import. The function takes ownership of keysValidated
QTimer::singleShot(1, [=]() {
// we import all keys without rescanning and then finally decide if we will rescan once
doImport(keys);
doImport(keysValidated);
if (rescan) {
//TODO: verify rescanfrom is a valid integer and trim whitespace
rpc->rescan(pui.rescanfrom->text().toInt() , [=] (QJsonValue response){
qDebug() << __func__ << ":rescanning from height " << pui.rescanfrom->text().toInt() << " finished" << response;
ui->statusBar->showMessage(tr("Rescanning finished"), 5000);

Loading…
Cancel
Save