Compile fixes
This commit is contained in:
@@ -40,85 +40,19 @@ void ConnectionLoader::doAutoConnect(bool tryEzcashdStart) {
|
||||
|
||||
// Initialize the library
|
||||
main->logger->write(QObject::tr("Attempting to initialize"));
|
||||
litelib_initialze(config->dangerous, config->server.toStdString());
|
||||
litelib_initialze(config->dangerous, config->server.toStdString().c_str());
|
||||
auto connection = makeConnection(config);
|
||||
|
||||
// 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
|
||||
d->hide();
|
||||
main->logger->write("Connection is online.");
|
||||
this->doRPCSetConnection(connection);
|
||||
}, [=](auto err, auto errJson) {});
|
||||
|
||||
|
||||
|
||||
if (config.get() != nullptr) {
|
||||
auto connection = makeConnection(config);
|
||||
|
||||
refreshZcashdState(connection, [=] () {
|
||||
// Refused connection. So try and start embedded zcashd
|
||||
if (Settings::getInstance()->useEmbedded()) {
|
||||
if (tryEzcashdStart) {
|
||||
this->showInformation(QObject::tr("Starting embedded zcashd"));
|
||||
if (this->startEmbeddedZcashd()) {
|
||||
// Embedded zcashd started up. Wait a second and then refresh the connection
|
||||
main->logger->write("Embedded zcashd started up, trying autoconnect in 1 sec");
|
||||
QTimer::singleShot(1000, [=]() { doAutoConnect(); } );
|
||||
} else {
|
||||
if (config->zcashDaemon) {
|
||||
// zcashd is configured to run as a daemon, so we must wait for a few seconds
|
||||
// to let it start up.
|
||||
main->logger->write("zcashd is daemon=1. Waiting for it to start up");
|
||||
this->showInformation(QObject::tr("zcashd is set to run as daemon"), QObject::tr("Waiting for zcashd"));
|
||||
QTimer::singleShot(5000, [=]() { doAutoConnect(/* don't attempt to start ezcashd */ false); });
|
||||
} else {
|
||||
// Something is wrong.
|
||||
// We're going to attempt to connect to the one in the background one last time
|
||||
// and see if that works, else throw an error
|
||||
main->logger->write("Unknown problem while trying to start zcashd");
|
||||
QTimer::singleShot(2000, [=]() { doAutoConnect(/* don't attempt to start ezcashd */ false); });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// We tried to start ezcashd previously, and it didn't work. So, show the error.
|
||||
main->logger->write("Couldn't start embedded zcashd for unknown reason");
|
||||
QString explanation;
|
||||
if (config->zcashDaemon) {
|
||||
explanation = QString() % QObject::tr("You have zcashd set to start as a daemon, which can cause problems "
|
||||
"with ZecWallet\n\n."
|
||||
"Please remove the following line from your zcash.conf and restart ZecWallet\n"
|
||||
"daemon=1");
|
||||
} else {
|
||||
explanation = QString() % QObject::tr("Couldn't start the embedded zcashd.\n\n"
|
||||
"Please try restarting.\n\nIf you previously started zcashd with custom arguments, you might need to reset zcash.conf.\n\n"
|
||||
"If all else fails, please run zcashd manually.") %
|
||||
(ezcashd ? QObject::tr("The process returned") + ":\n\n" % ezcashd->errorString() : QString(""));
|
||||
}
|
||||
|
||||
this->showError(explanation);
|
||||
}
|
||||
} else {
|
||||
// zcash.conf exists, there's no connection, and the user asked us not to start zcashd. Error!
|
||||
main->logger->write("Not using embedded and couldn't connect to zcashd");
|
||||
QString explanation = QString() % QObject::tr("Couldn't connect to zcashd configured in zcash.conf.\n\n"
|
||||
"Not starting embedded zcashd because --no-embedded was passed");
|
||||
this->showError(explanation);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (Settings::getInstance()->useEmbedded()) {
|
||||
// zcash.conf was not found, so create one
|
||||
createZcashConf();
|
||||
} else {
|
||||
// Fall back to manual connect
|
||||
doManualConnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionLoader::doRPCSetConnection(Connection* conn) {
|
||||
rpc->setEZcashd(ezcashd);
|
||||
rpc->setConnection(conn);
|
||||
|
||||
d->accept();
|
||||
@@ -159,8 +93,10 @@ void ConnectionLoader::showError(QString explanation) {
|
||||
d->close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Executor::run() {
|
||||
const char* resp = litelib_execute(this->cmd.toStdString().c_str());
|
||||
char* resp = litelib_execute(this->cmd.toStdString().c_str());
|
||||
QString reply = QString::fromStdString(resp);
|
||||
litelib_rust_free_string(resp);
|
||||
|
||||
@@ -193,12 +129,13 @@ void Connection::doRPC(const QString cmd, const QString args, const std::functio
|
||||
auto runner = new Executor(cmd, args);
|
||||
QObject::connect(runner, &Executor::responseReady, [=] (json resp) {
|
||||
cb(resp);
|
||||
})
|
||||
});
|
||||
|
||||
QThreadPool::globalInstance()->start(runner);
|
||||
}
|
||||
|
||||
void Connection::doRPCWithDefaultErrorHandling(const json& payload, const std::function<void(json)>& cb) {
|
||||
doRPC(payload, cb, [=] (auto reply, auto parsed) {
|
||||
void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(json)>& cb) {
|
||||
doRPC(cmd, args, cb, [=] (auto reply, auto parsed) {
|
||||
if (!parsed.is_discarded() && !parsed["error"]["message"].is_null()) {
|
||||
this->showTxError(QString::fromStdString(parsed["error"]["message"]));
|
||||
} else {
|
||||
@@ -207,8 +144,8 @@ void Connection::doRPCWithDefaultErrorHandling(const json& payload, const std::f
|
||||
});
|
||||
}
|
||||
|
||||
void Connection::doRPCIgnoreError(const json& payload, const std::function<void(json)>& cb) {
|
||||
doRPC(payload, cb, [=] (auto, auto) {
|
||||
void Connection::doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(json)>& cb) {
|
||||
doRPC(cmd, args, cb, [=] (auto, auto) {
|
||||
// Ignored error handling
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user