Browse Source

Try another server if current is down when saving wallet via a rescan

pull/125/head
Duke 1 year ago
parent
commit
9befa3450f
  1. 9
      src/connection.cpp
  2. 29
      src/mainwindow.cpp

9
src/connection.cpp

@ -364,12 +364,11 @@ void Executor::run()
nullptr,
false
);
if (parsed.is_discarded() || parsed.is_null())
if (parsed.is_discarded() || parsed.is_null()) {
emit handleError(reply);
else
emit responseReady(parsed);
} else {
emit responseReady(parsed);
}
}
void Callback::processRPCCallback(json resp)

29
src/mainwindow.cpp

@ -217,6 +217,7 @@ MainWindow::MainWindow(QWidget *parent) :
} catch (const std::exception& e) {
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what();
}
if (reply.toUpper().trimmed() != "OK") {
qDebug() << "Lite server " << config->server << " is down, getting a random one";
config->server = Settings::getRandomServer();
@ -237,8 +238,32 @@ MainWindow::MainWindow(QWidget *parent) :
// 4. Finally attempt to save the wallet
{
char* resp = litelib_execute("save", "");
QString reply = litelib_process_response(resp);
QString reply = "";
try {
char* resp = litelib_execute("save", "");
QString reply = litelib_process_response(resp);
} catch (const std::exception& e) {
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what();
}
if (reply.toUpper().trimmed() != "OK") {
qDebug() << "Lite server " << config->server << " is down, getting a random one";
config->server = Settings::getRandomServer();
qDebug() << __func__ << ": new server is " << config->server;
// make a new connection to the new server
char* resp = litelib_initialize_new_from_phrase(config->dangerous,config->server.toStdString().c_str(),
seed.toStdString().c_str(), birthday, number);
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();
}
}
QByteArray ba_reply = reply.toUtf8();
QJsonDocument jd_reply = QJsonDocument::fromJson(ba_reply);

Loading…
Cancel
Save