From 3f8ae1f9d75766331e3d1bb7689e7b18850061e1 Mon Sep 17 00:00:00 2001 From: Duke Date: Sat, 25 Mar 2023 22:11:22 -0700 Subject: [PATCH] Try another server if current is down when creating new seed --- src/firsttimewizard.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/firsttimewizard.cpp b/src/firsttimewizard.cpp index c69632f..0e6df79 100644 --- a/src/firsttimewizard.cpp +++ b/src/firsttimewizard.cpp @@ -293,10 +293,26 @@ void NewSeedPage::initializePage() { // Call the library to create a new wallet. qDebug() << __func__; - char* resp = litelib_initialize_new(parent->dangerous,parent->server.toStdString().c_str()); - QString reply = litelib_process_response(resp); + QString reply = ""; + try { + char* resp = litelib_initialize_new(parent->dangerous,parent->server.toStdString().c_str()); + 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); + } + auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false); if (parsed.is_discarded() || parsed.is_null() || parsed.find("seed") == parsed.end()) { form.txtSeed->setPlainText(tr("Error creating a wallet") + "\n" + reply);