Much DEBUG such wow
This commit is contained in:
@@ -34,7 +34,7 @@ ConnectionLoader::ConnectionLoader(MainWindow* main, Controller* rpc)
|
|||||||
connD->setupUi(d);
|
connD->setupUi(d);
|
||||||
|
|
||||||
auto theme = Settings::getInstance()->get_theme_name();
|
auto theme = Settings::getInstance()->get_theme_name();
|
||||||
qDebug() << theme << "theme " << theme << " has loaded";
|
DEBUG("theme " << theme << " has loaded");
|
||||||
auto size = QSize(512,512);
|
auto size = QSize(512,512);
|
||||||
|
|
||||||
if (theme == "Dark" || theme == "Midnight") {
|
if (theme == "Dark" || theme == "Midnight") {
|
||||||
@@ -64,6 +64,7 @@ ConnectionLoader::~ConnectionLoader()
|
|||||||
|
|
||||||
void ConnectionLoader::loadConnection()
|
void ConnectionLoader::loadConnection()
|
||||||
{
|
{
|
||||||
|
DEBUG("calling doAutoConnect");
|
||||||
QTimer::singleShot(1, [=]() { this->doAutoConnect(); });
|
QTimer::singleShot(1, [=]() { this->doAutoConnect(); });
|
||||||
if (!Settings::getInstance()->isHeadless())
|
if (!Settings::getInstance()->isHeadless())
|
||||||
d->exec();
|
d->exec();
|
||||||
@@ -73,6 +74,7 @@ void ConnectionLoader::loadProgress()
|
|||||||
{
|
{
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
QTimer::singleShot(1, [=]() mutable {
|
QTimer::singleShot(1, [=]() mutable {
|
||||||
|
DEBUG("failed=" << failed);
|
||||||
// continually retry ShowProgress() until it succeeds
|
// continually retry ShowProgress() until it succeeds
|
||||||
// by running without an exception
|
// by running without an exception
|
||||||
do {
|
do {
|
||||||
@@ -103,24 +105,27 @@ void ConnectionLoader::ShowProgress()
|
|||||||
|
|
||||||
isSyncing = new QAtomicInteger<bool>();
|
isSyncing = new QAtomicInteger<bool>();
|
||||||
isSyncing->store(true);
|
isSyncing->store(true);
|
||||||
main->logger->write("isSyncing");
|
DEBUG("isSyncing");
|
||||||
|
|
||||||
// Do a sync after import
|
// Do a sync after import
|
||||||
syncTimer = new QTimer(main);
|
syncTimer = new QTimer(main);
|
||||||
main->logger->write("Beginning sync after import wif");
|
DEBUG("Beginning sync after import wif");
|
||||||
connection->doRPCWithDefaultErrorHandling("sync", "", [=](auto) {
|
connection->doRPC("sync", "", [=](auto) {
|
||||||
|
DEBUG("finished syncing");
|
||||||
isSyncing->store(false);
|
isSyncing->store(false);
|
||||||
// Cancel the timer
|
// Cancel the timer
|
||||||
syncTimer->deleteLater();
|
syncTimer->deleteLater();
|
||||||
// When sync is done, set the connection
|
// When sync is done, set the connection
|
||||||
this->doRPCSetConnectionShield(connection);
|
this->doRPCSetConnectionShield(connection);
|
||||||
|
}, [=](auto) {
|
||||||
|
DEBUG("sync rpc error! server=" << config->server);
|
||||||
});
|
});
|
||||||
|
|
||||||
// While it is syncing, we'll show the status updates while it is alive.
|
// While it is syncing, we'll show the status updates while it is alive.
|
||||||
QObject::connect(syncTimer, &QTimer::timeout, [=]() {
|
QObject::connect(syncTimer, &QTimer::timeout, [=]() {
|
||||||
// Check the sync status
|
DEBUG("Check the sync status");
|
||||||
if (isSyncing != nullptr && isSyncing->load()) {
|
if (isSyncing != nullptr && isSyncing->load()) {
|
||||||
// Get the sync status
|
DEBUG("Get the sync status");
|
||||||
try {
|
try {
|
||||||
connection->doRPC("syncstatus", "", [=](json reply) {
|
connection->doRPC("syncstatus", "", [=](json reply) {
|
||||||
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) {
|
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) {
|
||||||
@@ -148,10 +153,10 @@ void ConnectionLoader::ShowProgress()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
syncTimer->setInterval(1*1000);
|
int interval = 1*1000;
|
||||||
|
syncTimer->setInterval(interval);
|
||||||
syncTimer->start();
|
syncTimer->start();
|
||||||
main->logger->write("Start sync timer");
|
DEBUG("Start sync timer with interval=" << interval);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionLoader::doAutoConnect()
|
void ConnectionLoader::doAutoConnect()
|
||||||
@@ -159,14 +164,14 @@ void ConnectionLoader::doAutoConnect()
|
|||||||
auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig());
|
auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig());
|
||||||
config->dangerous = false;
|
config->dangerous = false;
|
||||||
config->server = Settings::getInstance()->getSettings().server;
|
config->server = Settings::getInstance()->getSettings().server;
|
||||||
qDebug() << __func__ << " server=" << config->server;
|
DEBUG(" server=" << config->server);
|
||||||
|
|
||||||
// Initialize the library
|
// Initialize the library
|
||||||
main->logger->write(QObject::tr("Attempting to initialize library with ") + config->server);
|
DEBUG("Attempting to initialize library with "<< config->server);
|
||||||
|
|
||||||
// Check to see if there's an existing wallet
|
// Check to see if there's an existing wallet
|
||||||
if (litelib_wallet_exists(Settings::getDefaultChainName().toStdString().c_str())) {
|
if (litelib_wallet_exists(Settings::getDefaultChainName().toStdString().c_str())) {
|
||||||
qDebug() << __func__ << ": using existing wallet";
|
DEBUG("using existing wallet");
|
||||||
main->logger->write(QObject::tr("Using existing wallet."));
|
main->logger->write(QObject::tr("Using existing wallet."));
|
||||||
|
|
||||||
QString response = "";
|
QString response = "";
|
||||||
@@ -177,7 +182,7 @@ void ConnectionLoader::doAutoConnect()
|
|||||||
);
|
);
|
||||||
response = litelib_process_response(resp);
|
response = litelib_process_response(resp);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what();
|
DEBUG("caught an exception, ignoring: " << e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.toUpper().trimmed() != "OK") {
|
if (response.toUpper().trimmed() != "OK") {
|
||||||
@@ -190,7 +195,7 @@ void ConnectionLoader::doAutoConnect()
|
|||||||
);
|
);
|
||||||
response = litelib_process_response(resp);
|
response = litelib_process_response(resp);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what();
|
DEBUG("caught an exception, ignoring: " << e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.toUpper().trimmed() != "OK") {
|
if (response.toUpper().trimmed() != "OK") {
|
||||||
@@ -198,14 +203,14 @@ void ConnectionLoader::doAutoConnect()
|
|||||||
showError(resp);
|
showError(resp);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << __func__ << ": Successfully connected to random server: " << config->server << " !!!";
|
DEBUG("Successfully connected to random server: " << config->server << " !!!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << __func__ << ": Successfully connected to " << config->server << " !!!";
|
DEBUG("Successfully connected to " << config->server << " !!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << __func__ << ": no existing wallet";
|
DEBUG("no existing wallet");
|
||||||
main->logger->write(QObject::tr("Create/restore wallet."));
|
main->logger->write(QObject::tr("Create/restore wallet."));
|
||||||
createOrRestore(config->dangerous, config->server);
|
createOrRestore(config->dangerous, config->server);
|
||||||
d->show();
|
d->show();
|
||||||
@@ -216,61 +221,59 @@ void ConnectionLoader::doAutoConnect()
|
|||||||
qDebug() << __func__ << ": server=" << config->server
|
qDebug() << __func__ << ": server=" << config->server
|
||||||
<< " connection=" << connection << " me=" << me << endl;
|
<< " connection=" << connection << " me=" << me << endl;
|
||||||
|
|
||||||
|
|
||||||
// After the lib is initialized, try to do get info
|
// After the lib is initialized, try to do get info
|
||||||
connection->doRPC("info", "", [=](auto reply) {
|
connection->doRPC("info", "", [=](auto reply) {
|
||||||
// If success, set the connection
|
// If success, set the connection
|
||||||
main->logger->write("Connection is online.");
|
DEBUG("Connection is online.");
|
||||||
connection->setInfo(reply);
|
connection->setInfo(reply);
|
||||||
main->logger->write("getting Connection reply");
|
DEBUG("getting Connection reply");
|
||||||
isSyncing = new QAtomicInteger<bool>();
|
isSyncing = new QAtomicInteger<bool>();
|
||||||
isSyncing->store(true);
|
isSyncing->store(true);
|
||||||
main->logger->write("isSyncing");
|
DEBUG("isSyncing");
|
||||||
|
|
||||||
// Do a sync at startup
|
// Do a sync at startup
|
||||||
syncTimer = new QTimer(main);
|
syncTimer = new QTimer(main);
|
||||||
main->logger->write("Beginning sync");
|
DEBUG("Beginning sync");
|
||||||
connection->doRPCWithDefaultErrorHandling("sync", "", [=](auto) {
|
connection->doRPC("sync", "", [=](auto) {
|
||||||
|
DEBUG("finished syncing");
|
||||||
isSyncing->store(false);
|
isSyncing->store(false);
|
||||||
// Cancel the timer
|
// Cancel the timer
|
||||||
syncTimer->deleteLater();
|
syncTimer->deleteLater();
|
||||||
// When sync is done, set the connection
|
// When sync is done, set the connection
|
||||||
this->doRPCSetConnection(connection);
|
this->doRPCSetConnection(connection);
|
||||||
|
}, [=](auto) {
|
||||||
|
DEBUG("sync rpc error! server=" << config->server);
|
||||||
});
|
});
|
||||||
|
|
||||||
// While it is syncing, we'll show the status updates while it is alive.
|
// While it is syncing, we'll show the status updates while it is alive.
|
||||||
QObject::connect(syncTimer, &QTimer::timeout, [=]() {
|
QObject::connect(syncTimer, &QTimer::timeout, [=]() {
|
||||||
// Check the sync status
|
DEBUG("Check the sync status");
|
||||||
if (isSyncing != nullptr && isSyncing->load()) {
|
if (isSyncing != nullptr && isSyncing->load()) {
|
||||||
// Get the sync status
|
DEBUG("Getting the sync status");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection->doRPC("syncstatus", "", [=](json reply) {
|
connection->doRPC("syncstatus", "", [=](json reply) {
|
||||||
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end())
|
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) {
|
||||||
|
|
||||||
{
|
|
||||||
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
|
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
|
||||||
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
|
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
|
||||||
me->showInformation(
|
me->showInformation(
|
||||||
"Syncing... " + QString::number(synced) + " / " + QString::number(total)
|
"Syncing... " + QString::number(synced) + " / " + QString::number(total)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[=](QString err) {
|
[=](QString err) {
|
||||||
qDebug() << "Sync error" << err;
|
DEBUG("Sync error" << err);
|
||||||
});
|
});
|
||||||
}catch (...)
|
} catch (const std::exception& e) {
|
||||||
{
|
DEBUG("caught exception from syncstatus: " << e.what());
|
||||||
main->logger->write("catch sync progress reply");
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
syncTimer->setInterval(1* 1000);
|
int interval = 1*1000;
|
||||||
|
syncTimer->setInterval(interval);
|
||||||
syncTimer->start();
|
syncTimer->start();
|
||||||
main->logger->write("Start sync timer");
|
DEBUG("Start sync timer with interval=" << interval);
|
||||||
|
|
||||||
}, [=](QString err) {
|
}, [=](QString err) {
|
||||||
showError(err);
|
showError(err);
|
||||||
@@ -284,13 +287,13 @@ void ConnectionLoader::createOrRestore(bool dangerous, QString server)
|
|||||||
d->hide();
|
d->hide();
|
||||||
// Create a wizard
|
// Create a wizard
|
||||||
FirstTimeWizard wizard(dangerous,server);
|
FirstTimeWizard wizard(dangerous,server);
|
||||||
main->logger->write("Start new Wallet with FirstimeWizard");
|
DEBUG("Start new Wallet with FirstimeWizard");
|
||||||
wizard.exec();
|
wizard.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionLoader::doRPCSetConnection(Connection* conn)
|
void ConnectionLoader::doRPCSetConnection(Connection* conn)
|
||||||
{
|
{
|
||||||
qDebug() << "Connectionloader finished, setting connection";
|
DEBUG("Connectionloader finished, setting connection");
|
||||||
main->logger->write("Connectionloader finished, setting connection");
|
main->logger->write("Connectionloader finished, setting connection");
|
||||||
rpc->setConnection(conn);
|
rpc->setConnection(conn);
|
||||||
d->accept();
|
d->accept();
|
||||||
@@ -301,17 +304,16 @@ void ConnectionLoader::doRPCSetConnection(Connection* conn)
|
|||||||
main->logger->write("Path to Wallet.dat : " );
|
main->logger->write("Path to Wallet.dat : " );
|
||||||
qDebug() << __func__ << ": wallet path =" << plaintextWallet;
|
qDebug() << __func__ << ": wallet path =" << plaintextWallet;
|
||||||
plaintextWallet.remove();
|
plaintextWallet.remove();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
} catch (...) {
|
DEBUG("Caught exception" << e.what() );
|
||||||
qDebug() << "No plaintext wallet found! file=" << plaintextWallet;
|
DEBUG("No plaintext wallet found! file=" << plaintextWallet);
|
||||||
main->logger->write("no Plaintext wallet.dat");
|
main->logger->write("no Plaintext wallet.dat");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionLoader::doRPCSetConnectionShield(Connection* conn)
|
void ConnectionLoader::doRPCSetConnectionShield(Connection* conn)
|
||||||
{
|
{
|
||||||
qDebug() << "Importing finished, setting connection";
|
DEBUG("Importing finished, setting connection");
|
||||||
rpc->setConnection(conn);
|
rpc->setConnection(conn);
|
||||||
d->accept();
|
d->accept();
|
||||||
main->getRPC()->shield([=] (auto) {});
|
main->getRPC()->shield([=] (auto) {});
|
||||||
@@ -322,9 +324,10 @@ void ConnectionLoader::doRPCSetConnectionShield(Connection* conn)
|
|||||||
main->logger->write("Path to Wallet.dat : " );
|
main->logger->write("Path to Wallet.dat : " );
|
||||||
qDebug() << __func__ << ": wallet path =" << plaintextWallet;
|
qDebug() << __func__ << ": wallet path =" << plaintextWallet;
|
||||||
plaintextWallet.remove();
|
plaintextWallet.remove();
|
||||||
} catch (...) {
|
} catch (const std::exception& e) {
|
||||||
|
DEBUG("Caught exception" << e.what() );
|
||||||
main->logger->write("no Plaintext wallet.dat");
|
main->logger->write("no Plaintext wallet.dat");
|
||||||
qDebug() << "No plaintext wallet found! file=" << plaintextWallet;
|
DEBUG("No plaintext wallet found! file=" << plaintextWallet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,11 +449,12 @@ Connection::Connection(MainWindow* m, std::shared_ptr<ConnectionConfig> conf)
|
|||||||
|
|
||||||
void Connection::doRPC(const QString cmd, const QString args, const std::function<void(json)>& cb, const std::function<void(QString)>& errCb)
|
void Connection::doRPC(const QString cmd, const QString args, const std::function<void(json)>& cb, const std::function<void(QString)>& errCb)
|
||||||
{
|
{
|
||||||
if (shutdownInProgress)
|
if (shutdownInProgress) {
|
||||||
// Ignoring RPC because shutdown in progress
|
DEBUG("Ignoring RPC because shutdown in progress");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << __func__ << ": " << cmd;
|
DEBUG("cmd=" << cmd << " args=" << args);
|
||||||
|
|
||||||
// Create a runner.
|
// Create a runner.
|
||||||
auto runner = new Executor(cmd, args);
|
auto runner = new Executor(cmd, args);
|
||||||
@@ -465,7 +469,7 @@ void Connection::doRPC(const QString cmd, const QString args, const std::functio
|
|||||||
|
|
||||||
void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
||||||
{
|
{
|
||||||
qDebug() << __func__ << ": " << cmd;
|
DEBUG("cmd=" << cmd << " args=" << args);
|
||||||
doRPC(cmd, args, cb, [=] (QString err) {
|
doRPC(cmd, args, cb, [=] (QString err) {
|
||||||
this->showTxError(err);
|
this->showTxError(err);
|
||||||
});
|
});
|
||||||
@@ -473,7 +477,7 @@ void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString
|
|||||||
|
|
||||||
void Connection::doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
void Connection::doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
||||||
{
|
{
|
||||||
qDebug() << __func__ << ": " << cmd;
|
DEBUG("cmd=" << cmd << " args=" << args);
|
||||||
doRPC(cmd, args, cb, [=] (auto) {
|
doRPC(cmd, args, cb, [=] (auto) {
|
||||||
// Ignored error handling
|
// Ignored error handling
|
||||||
});
|
});
|
||||||
@@ -505,5 +509,6 @@ void Connection::showTxError(const QString& error)
|
|||||||
*/
|
*/
|
||||||
void Connection::shutdown()
|
void Connection::shutdown()
|
||||||
{
|
{
|
||||||
|
DEBUG("shutting down");
|
||||||
shutdownInProgress = true;
|
shutdownInProgress = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user