Try another server if current is down when restoring a wallet from seed or saving a wallet
This commit is contained in:
@@ -623,21 +623,49 @@ bool NewSeedPage::validatePage() {
|
|||||||
|
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
|
|
||||||
if ((verifyseed.verify->toPlainText() == seed) && (verifyseed.verifyBirthday->toPlainText() == birthday))
|
QString reply = "";
|
||||||
{
|
if ((verifyseed.verify->toPlainText() == seed) && (verifyseed.verifyBirthday->toPlainText() == birthday)) {
|
||||||
char* resp = litelib_execute("save", "");
|
try {
|
||||||
QString reply = litelib_process_response(resp);
|
char* resp = litelib_execute("save", "");
|
||||||
|
reply = litelib_process_response(resp);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what();
|
||||||
|
}
|
||||||
|
|
||||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
qDebug() << __func__ << ": reply=" << reply;
|
||||||
if (parsed.is_discarded() || parsed.is_null() || parsed.find("result") == parsed.end()) {
|
|
||||||
|
|
||||||
QMessageBox::warning(this, tr("Failed to save wallet"),
|
// TODO: this is duplicated code that should be refactored
|
||||||
tr("Couldn't save the wallet") + "\n" + reply,
|
// into a dedicated function
|
||||||
QMessageBox::Ok);
|
if (reply.toUpper().trimmed() != "OK") {
|
||||||
return false;
|
qDebug() << "Lite server " << parent->server << " is down, getting a random one";
|
||||||
} else {
|
parent->server = Settings::getRandomServer();
|
||||||
return true;
|
qDebug() << __func__ << ": new server is " << parent->server;
|
||||||
}
|
|
||||||
|
// make a new connection to the new server
|
||||||
|
char* resp = litelib_initialize_new(parent->dangerous,parent->server.toStdString().c_str());
|
||||||
|
reply = litelib_process_response(resp);
|
||||||
|
|
||||||
|
// retry with the new server
|
||||||
|
try {
|
||||||
|
resp = litelib_execute("save", "");
|
||||||
|
reply = litelib_process_response(resp);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
qDebug() << __func__ << ": caught an exception with new server, something is fucky: " << e.what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << __func__ << ": reply=" << reply;
|
||||||
|
|
||||||
|
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||||
|
if (parsed.is_discarded() || parsed.is_null() || parsed.find("result") == parsed.end()) {
|
||||||
|
|
||||||
|
QMessageBox::warning(this, tr("Failed to save wallet"),
|
||||||
|
tr("Couldn't save the wallet") + "\n" + reply,
|
||||||
|
QMessageBox::Ok);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
qDebug()<<"Wrong Seed";
|
qDebug()<<"Wrong Seed";
|
||||||
QFile file(dirwalletencfirst);
|
QFile file(dirwalletencfirst);
|
||||||
@@ -645,9 +673,7 @@ bool NewSeedPage::validatePage() {
|
|||||||
|
|
||||||
file.remove();
|
file.remove();
|
||||||
file1.remove();
|
file1.remove();
|
||||||
QMessageBox::warning(this, tr("Wrong Seed"),
|
QMessageBox::warning(this, tr("Wrong Seed"), tr("Please try again") + "\n" , QMessageBox::Ok);
|
||||||
tr("Please try again") + "\n" ,
|
|
||||||
QMessageBox::Ok);
|
|
||||||
form.birthday->setVisible(true);
|
form.birthday->setVisible(true);
|
||||||
form.txtSeed->setVisible(true);
|
form.txtSeed->setVisible(true);
|
||||||
return false;
|
return false;
|
||||||
@@ -702,9 +728,27 @@ bool RestoreSeedPage::validatePage() {
|
|||||||
qint64 number = number_str.toUInt();
|
qint64 number = number_str.toUInt();
|
||||||
// 3. Attempt to restore wallet with the seed phrase
|
// 3. Attempt to restore wallet with the seed phrase
|
||||||
{
|
{
|
||||||
char* resp = litelib_initialize_new_from_phrase(parent->dangerous, parent->server.toStdString().c_str(),
|
QString reply = "";
|
||||||
seed.toStdString().c_str(), birthday, number);
|
try {
|
||||||
QString reply = litelib_process_response(resp);
|
char* resp = litelib_initialize_new_from_phrase(parent->dangerous, parent->server.toStdString().c_str(),
|
||||||
|
seed.toStdString().c_str(), birthday, number);
|
||||||
|
reply = litelib_process_response(resp);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what();
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << __func__ << ": reply=" << reply;
|
||||||
|
|
||||||
|
if (reply.toUpper().trimmed() != "OK") {
|
||||||
|
qDebug() << "Lite server " << parent->server << " is down, getting a random one";
|
||||||
|
parent->server = Settings::getRandomServer();
|
||||||
|
qDebug() << __func__ << ": new server is " << parent->server;
|
||||||
|
|
||||||
|
// retry with the new server
|
||||||
|
char* resp = litelib_initialize_new(parent->dangerous,parent->server.toStdString().c_str());
|
||||||
|
reply = litelib_process_response(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (reply.toUpper().trimmed() != "OK") {
|
if (reply.toUpper().trimmed() != "OK") {
|
||||||
QMessageBox::warning(this, tr("Failed to restore wallet"),
|
QMessageBox::warning(this, tr("Failed to restore wallet"),
|
||||||
@@ -716,8 +760,35 @@ bool RestoreSeedPage::validatePage() {
|
|||||||
|
|
||||||
// 4. Finally attempt to save the wallet
|
// 4. Finally attempt to save the wallet
|
||||||
{
|
{
|
||||||
char* resp = litelib_execute("save", "");
|
QString reply = "";
|
||||||
QString reply = litelib_process_response(resp);
|
try {
|
||||||
|
char* resp = litelib_execute("save", "");
|
||||||
|
reply = litelib_process_response(resp);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: this is duplicated code that should be refactored
|
||||||
|
// into a dedicated function
|
||||||
|
if (reply.toUpper().trimmed() != "OK") {
|
||||||
|
qDebug() << "Lite server " << parent->server << " is down, getting a random one";
|
||||||
|
parent->server = Settings::getRandomServer();
|
||||||
|
qDebug() << __func__ << ": new server is " << parent->server;
|
||||||
|
|
||||||
|
// make a new connection to the new server
|
||||||
|
char* resp = litelib_initialize_new(parent->dangerous,parent->server.toStdString().c_str());
|
||||||
|
reply = litelib_process_response(resp);
|
||||||
|
|
||||||
|
// retry with the new server
|
||||||
|
try {
|
||||||
|
resp = litelib_execute("save", "");
|
||||||
|
reply = litelib_process_response(resp);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
qDebug() << __func__ << ": caught an exception with new server, something is fucky: " << e.what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << __func__ << ": reply=" << reply;
|
||||||
|
|
||||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||||
if (parsed.is_discarded() || parsed.is_null() || parsed.find("result") == parsed.end()) {
|
if (parsed.is_discarded() || parsed.is_null() || parsed.find("result") == parsed.end()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user