This commit is contained in:
DenioD
2019-10-26 00:00:29 +02:00
8 changed files with 87 additions and 44 deletions

View File

@@ -22,9 +22,12 @@ ConnectionLoader::ConnectionLoader(MainWindow* main, Controller* rpc) {
connD->setupUi(d);
QPixmap logo(":/img/res/logobig.gif");
connD->topIcon->setBasePixmap(logo.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation));
isSyncing = new QAtomicInteger<bool>();
}
ConnectionLoader::~ConnectionLoader() {
ConnectionLoader::~ConnectionLoader() {
delete isSyncing;
delete connD;
delete d;
}
@@ -52,16 +55,55 @@ void ConnectionLoader::doAutoConnect() {
} else {
main->logger->write(QObject::tr("Create/restore wallet."));
litelib_initialize_existing(config->dangerous, config->server.toStdString().c_str());
d->show();
}
auto connection = makeConnection(config);
// After the lib is initialized, try to do get info
connection->doRPC("info", "", [=](auto reply) {
// If success, set the connection
// If success, set the connection
main->logger->write("Connection is online.");
this->doRPCSetConnection(connection);
}, [=](auto err) {});
isSyncing = new QAtomicInteger<bool>();
isSyncing->store(true);
// Do a sync at startup
syncTimer = new QTimer(main);
connection->doRPCWithDefaultErrorHandling("sync", "", [=](auto) {
isSyncing->store(false);
// Cancel the timer
syncTimer->deleteLater();
// When sync is done, set the connection
this->doRPCSetConnection(connection);
});
// While it is syncing, we'll show the status updates while it is alive.
QObject::connect(syncTimer, &QTimer::timeout, [=]() {
// Check the sync status
if (isSyncing != nullptr && isSyncing->load()) {
// Get the sync status
connection->doRPC("syncstatus", "", [=](json reply) {
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) {
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
showInformation("Synced " + QString::number(synced) + " / " + QString::number(total));
}
},
[=](QString err) {
qDebug() << "Sync error" << err;
});
}
});
syncTimer->setInterval(1* 1000);
syncTimer->start();
}, [=](QString err) {
showError(err);
});
}
void ConnectionLoader::createOrRestore(bool dangerous, QString server) {
@@ -75,6 +117,7 @@ void ConnectionLoader::createOrRestore(bool dangerous, QString server) {
}
void ConnectionLoader::doRPCSetConnection(Connection* conn) {
qDebug() << "Connectionloader finished, setting connection";
rpc->setConnection(conn);
d->accept();
@@ -88,20 +131,9 @@ Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> c
// Update the UI with the status
void ConnectionLoader::showInformation(QString info, QString detail) {
static int rescanCount = 0;
if (detail.toLower().startsWith("rescan")) {
rescanCount++;
}
if (rescanCount > 10) {
detail = detail + "\n" + QObject::tr("This may take several hours");
}
qDebug() << "Showing info " << info << ":" << detail;
connD->status->setText(info);
connD->statusDetail->setText(detail);
if (rescanCount < 10)
main->logger->write(info + ":" + detail);
}
/**

View File

@@ -40,11 +40,14 @@ private:
void doRPCSetConnection(Connection* conn);
QDialog* d;
Ui_ConnectionDialog* connD;
QTimer* syncTimer = nullptr;
QAtomicInteger<bool>* isSyncing = nullptr;
MainWindow* main;
Controller* rpc;
QDialog* d = nullptr;
Ui_ConnectionDialog* connD = nullptr;
MainWindow* main = nullptr;
Controller* rpc = nullptr;
};
/**

View File

@@ -161,21 +161,25 @@ void Controller::getInfoThenRefresh(bool force) {
prevCallSucceeded = true;
// Testnet?
QString chainName;
if (!reply["chain_name"].is_null()) {
Settings::getInstance()->setTestnet(reply["chain_name"].get<json::string_t>() == "test");
chainName = QString::fromStdString(reply["chain_name"].get<json::string_t>());
Settings::getInstance()->setTestnet(chainName == "test");
};
// Recurring pamynets are testnet only
if (!Settings::getInstance()->isTestnet())
main->disableRecurring();
// Connected, so display checkmark.
QIcon i(":/icons/res/connected.gif");
main->statusIcon->setPixmap(i.pixmap(16, 16));
static int lastBlock = 0;
int curBlock = reply["latest_block_height"].get<json::number_integer_t>();
model->setLatestBlock(curBlock);
// Connected, so display checkmark.
QIcon i(":/icons/res/connected.gif");
main->statusLabel->setText(chainName + "(" + QString::number(curBlock) + ")");
main->statusIcon->setPixmap(i.pixmap(16, 16));
//int version = reply["version"].get<json::string_t>();
int version = 1;
Settings::getInstance()->sethushdVersion(version);

View File

@@ -127,7 +127,7 @@ RestoreSeedPage::RestoreSeedPage(FirstTimeWizard *parent) : QWizardPage(parent)
bool RestoreSeedPage::validatePage() {
// 1. Validate that we do have 24 words
QString seed = form.txtSeed->toPlainText().replace(QRegExp("[ \n\r]+"), " ");
QString seed = form.txtSeed->toPlainText().replace(QRegExp("[ \n\r\t]+"), " ");
if (seed.trimmed().split(" ").length() != 24) {
QMessageBox::warning(this, tr("Failed to restore wallet"),
tr("SilentDragonLite needs 24 words to restore wallet"),