Browse Source

implement maxtry for all zrpc->connection

connection-errors
Deniod 7 months ago
parent
commit
6810800fa9
  1. 100
      src/controller.cpp

100
src/controller.cpp

@ -275,15 +275,28 @@ void Controller::noConnection()
}
/// This will refresh all the balance data from hushd
void Controller::refresh(bool force)
{
qDebug()<< __func__;
if (!zrpc->haveConnection())
return;
#include <thread>
void Controller::refresh(bool force) {
qDebug() << __func__;
getInfoThenRefresh(force);
int attempts = 0;
const int max_attempts = 10;
while (!zrpc->haveConnection()) {
if (attempts >= max_attempts) {
qDebug() << "Max retry reached";
return;
}
qDebug() << "Waiting for connection... try : " << attempts + 1;
std::this_thread::sleep_for(std::chrono::seconds(2 * attempts));
attempts++;
}
getInfoThenRefresh(force);
}
void Controller::processInfo(const json& info)
{
// Testnet?
@ -642,8 +655,19 @@ void Controller::setLag(int lag)
void Controller::refreshAddresses()
{
qDebug()<< __func__;
if (!zrpc->haveConnection())
return noConnection();
int attempts = 0;
const int max_attempts = 10;
while (!zrpc->haveConnection()) {
if (attempts >= max_attempts) {
qDebug() << "Max try reached";
return noConnection();
}
qDebug() << "Waiting for connection... try : " << attempts + 1;
std::this_thread::sleep_for(std::chrono::seconds(2 * attempts));
attempts++;
}
auto newzaddresses = new QList<QString>();
auto newtaddresses = new QList<QString>();
@ -897,8 +921,19 @@ void Controller::updateUIBalances()
void Controller::refreshBalances()
{
qDebug()<< __func__;
if (!zrpc->haveConnection())
return noConnection();
int attempts = 0;
const int max_attempts = 10;
while (!zrpc->haveConnection()) {
if (attempts >= max_attempts) {
qDebug() << "Max try reached";
return noConnection();
}
qDebug() << "Waiting for connection... try : " << attempts + 1;
std::this_thread::sleep_for(std::chrono::seconds(2 * attempts));
attempts++;
}
// 1. Get the Balances
zrpc->fetchBalance([=] (json reply) {
@ -973,8 +1008,19 @@ void printJsonValue(QTextStream& out, const nlohmann::json& j, int depth = 0) {
void Controller::refreshTransactions() {
qDebug()<< __func__;
if (!zrpc->haveConnection())
return noConnection();
int attempts = 0;
const int max_attempts = 10;
while (!zrpc->haveConnection()) {
if (attempts >= max_attempts) {
qDebug() << "Max try reached";
return noConnection();
}
qDebug() << "Waiting for connection... try : " << attempts + 1;
std::this_thread::sleep_for(std::chrono::seconds(2 * attempts));
attempts++;
}
qDebug() << __func__ << ": fetchTransactions";
zrpc->fetchTransactions([=] (json reply) {
@ -1574,8 +1620,19 @@ void Controller::checkForUpdate(bool silent)
qDebug()<< __func__;
// No checking for updates, needs testing with Gitea
return;
if (!zrpc->haveConnection())
return noConnection();
int attempts = 0;
const int max_attempts = 10;
while (!zrpc->haveConnection()) {
if (attempts >= max_attempts) {
qDebug() << "Max try reached";
return noConnection();
}
qDebug() << "Waiting for connection... try : " << attempts + 1;
std::this_thread::sleep_for(std::chrono::seconds(2 * attempts));
attempts++;
}
QUrl cmcURL("https://git.hush.is/repos/MyHush/SilentDragonLite/releases");
@ -1663,8 +1720,19 @@ void Controller::checkForUpdate(bool silent)
void Controller::refreshHUSHPrice()
{
qDebug()<< __func__;
if (!zrpc->haveConnection())
return;
int attempts = 0;
const int max_attempts = 10;
while (!zrpc->haveConnection()) {
if (attempts >= max_attempts) {
qDebug() << "Max try reached";
return noConnection();
}
qDebug() << "Waiting for connection... try : " << attempts + 1;
std::this_thread::sleep_for(std::chrono::seconds(2 * attempts));
attempts++;
}
// TODO: use/render all this data
QUrl cmcURL("https://api.coingecko.com/api/v3/simple/price?ids=hush&vs_currencies=btc%2Cusd%2Ceur%2Ceth%2Cgbp%2Ccny%2Cjpy%2Crub%2Ccad%2Csgd%2Cchf%2Cinr%2Caud%2Cinr&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true");

Loading…
Cancel
Save