Do key import serially so we only have to rescan once
This commit is contained in:
@@ -385,6 +385,27 @@ void MainWindow::donate() {
|
|||||||
ui->tabWidget->setCurrentIndex(1);
|
ui->tabWidget->setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::doImport(QList<QString>* 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() {
|
void MainWindow::importPrivKey() {
|
||||||
QDialog d(this);
|
QDialog d(this);
|
||||||
@@ -396,27 +417,22 @@ void MainWindow::importPrivKey() {
|
|||||||
"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()) {
|
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) {
|
auto keys = new QList<QString>();
|
||||||
qDebug() << "finished";
|
// Filter out all the empty keys.
|
||||||
ui->statusBar->showMessage("Key import rescan finished");
|
std::copy_if(rawkeys.begin(), rawkeys.end(), std::back_inserter(*keys), [=] (auto key) {
|
||||||
};
|
return !key.trimmed().isEmpty();
|
||||||
|
});
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Start the import
|
||||||
|
doImport(keys);
|
||||||
QMessageBox::information(this,
|
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.",
|
"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);
|
QMessageBox::Ok);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setupBalancesTab() {
|
void MainWindow::setupBalancesTab() {
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ private:
|
|||||||
|
|
||||||
void donate();
|
void donate();
|
||||||
void importPrivKey();
|
void importPrivKey();
|
||||||
|
void doImport(QList<QString>* keys);
|
||||||
|
|
||||||
RPC* rpc;
|
RPC* rpc;
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,8 @@ void RPC::importZPrivKey(QString addr, bool rescan, const std::function<void(jso
|
|||||||
{"method", "z_importkey"},
|
{"method", "z_importkey"},
|
||||||
{"params", { addr.toStdString(), (rescan? "yes" : "no") }},
|
{"params", { addr.toStdString(), (rescan? "yes" : "no") }},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
qDebug() << QString::fromStdString(payload.dump());
|
||||||
|
|
||||||
doRPC(payload, cb);
|
doRPC(payload, cb);
|
||||||
}
|
}
|
||||||
@@ -204,6 +206,7 @@ void RPC::importTPrivKey(QString addr, bool rescan, const std::function<void(jso
|
|||||||
{"params", { addr.toStdString(), (rescan? "yes" : "no") }},
|
{"params", { addr.toStdString(), (rescan? "yes" : "no") }},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
qDebug() << QString::fromStdString(payload.dump());
|
||||||
doRPC(payload, cb);
|
doRPC(payload, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user