Skip to content

Commit

Permalink
update syncing status
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptoForge committed Aug 19, 2023
1 parent 7af61db commit ccc87bd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ void Controller::setConnection(Connection* c) {
isSyncing = new QAtomicInteger<bool>();
isSyncing->storeRelaxed(true);

syncingCounter = new QAtomicInteger<int>();
syncingCounter->storeRelaxed(0);

Settings::getInstance()->setSyncing(true);

infoEndBlocks = new QAtomicInteger<int>();
infoEndBlocks->storeRelaxed(0);

Expand All @@ -98,6 +103,17 @@ void Controller::setConnection(Connection* c) {
price = new QAtomicInteger<int>();
price->storeRelaxed(0);

QTimer::singleShot(1, [=]() {
zrpc->syncWallet([=] (const json& reply) {

}, [=](QString err) {

QMessageBox::critical(main, QObject::tr("Connection Error"), QObject::tr("There was an error connecting to zcashd. The error was") + ": \n\n"
+ err, QMessageBox::StandardButton::Ok);

});
});

synctimer = new QTimer(main);
QObject::connect(synctimer, &QTimer::timeout, [=]() {

Expand Down Expand Up @@ -130,11 +146,17 @@ void Controller::setConnection(Connection* c) {
zrpc->syncStatus([=] (const json& reply) {

if (reply.find("end_block") != reply.end()) {
isSyncing->storeRelaxed(true);
syncingCounter->storeRelaxed(0);
if (reply["end_block"].get<json::number_unsigned_t>() > 0)
infoEndBlocks->storeRelaxed(reply["end_block"].get<json::number_unsigned_t>());
} else {
isSyncing->storeRelaxed(false);
int counter = syncingCounter->loadRelaxed();
counter++;
syncingCounter->storeRelaxed(counter);
}

if (Settings::getInstance()->isSyncing() && syncingCounter->loadRelaxed() > 30) {
Settings::getInstance()->setSyncing(false);
}

if (reply.find("synced_blocks") != reply.end()) {
Expand All @@ -151,6 +173,13 @@ void Controller::setConnection(Connection* c) {


QObject::connect(synctimer, &QTimer::timeout, [=]() {

if (walletHeight->loadRelaxed() + 5 < chainHeight->loadRelaxed()) {
isSyncing->storeRelaxed(true);
} else {
isSyncing->storeRelaxed(false);
}

if (isSyncing->loadRelaxed() && (infoEndBlocks->loadRelaxed() + infoSyncdBlocks->loadRelaxed() + 10 < chainHeight->loadRelaxed())) {
main->statusLabel->setText(" Syncing: " + QString::number(infoEndBlocks->loadRelaxed() + infoSyncdBlocks->loadRelaxed()) + " / " + QString::number(chainHeight->loadRelaxed()) );
} else {
Expand Down Expand Up @@ -264,6 +293,12 @@ void Controller::getInfoThenRefresh(bool force) {

static bool prevCallSucceeded = false;

if (!isSyncing->loadRelaxed()) {
Settings::getInstance()->setSyncing(false);
} else {
Settings::getInstance()->setSyncing(true);
}

if (!Settings::getInstance()->isSyncing()) {
main->logger->write(QString("Run Sync Wallet "));
zrpc->syncWallet([=] (const json& reply) {
Expand Down
1 change: 1 addition & 0 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Controller
MainWindow* main;

QAtomicInteger<bool>* isSyncing = nullptr;
QAtomicInteger<int>* syncingCounter = nullptr;
QAtomicInteger<int>* infoEndBlocks = nullptr;
QAtomicInteger<int>* infoSyncdBlocks = nullptr;
QAtomicInteger<int>* walletHeight = nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ MainWindow::MainWindow(QWidget *parent) :
this->getRPC()->stopWallet([=] (auto) {
// This will start a sync, and show the scanning status.
this->getRPC()->rescanWallet([=] (auto) {
Settings::getInstance()->setSyncing(true);
//do nothing
});
});
Expand Down

0 comments on commit ccc87bd

Please sign in to comment.