Compile fixes

This commit is contained in:
Aditya Kulkarni
2019-10-15 14:01:11 -07:00
parent 3de363cbb5
commit 306c39bb09
13 changed files with 719 additions and 1693 deletions

View File

@@ -12,6 +12,7 @@ class Controller;
struct ConnectionConfig {
QString server;
bool dangerous;
QString proxy;
};
class Connection;
@@ -31,42 +32,22 @@ private:
Connection* makeConnection(std::shared_ptr<ConnectionConfig> config);
void doAutoConnect(bool tryEzcashdStart = true);
void doManualConnect();
void createZcashConf();
QString locateZcashConfFile();
QString zcashConfWritableLocation();
QString zcashParamsDir();
bool verifyParams();
void downloadParams(std::function<void(void)> cb);
void doNextDownload(std::function<void(void)> cb);
bool startEmbeddedZcashd();
void refreshZcashdState(Connection* connection, std::function<void(void)> refused);
void showError(QString explanation);
void showInformation(QString info, QString detail = "");
void doRPCSetConnection(Connection* conn);
QProcess* ezcashd = nullptr;
QDialog* d;
Ui_ConnectionDialog* connD;
MainWindow* main;
Controller* rpc;
QNetworkReply* currentDownload = nullptr;
QFile* currentOutput = nullptr;
QQueue<QUrl>* downloadQueue = nullptr;
QNetworkAccessManager* client = nullptr;
QTime downloadTime;
};
class Executor : public QRunnable {
class Executor : public QObject, public QRunnable {
Q_OBJECT
public:
Executor(QString cmd, QString args) {
this->cmd = cmd;
@@ -84,7 +65,7 @@ signals:
private:
QString cmd;
QString args;
}
};
/**
* Represents a connection to a zcashd. It may even start a new zcashd if needed.
@@ -100,85 +81,13 @@ public:
void shutdown();
void doRPC(const json& payload, const std::function<void(json)>& cb,
void doRPC(const QString cmd, const QString args, const std::function<void(json)>& cb,
const std::function<void(QNetworkReply*, const json&)>& ne);
void doRPCWithDefaultErrorHandling(const json& payload, const std::function<void(json)>& cb);
void doRPCIgnoreError(const json& payload, const std::function<void(json)>& cb) ;
void doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(json)>& cb);
void doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(json)>& cb) ;
void showTxError(const QString& error);
// Batch method. Note: Because of the template, it has to be in the header file.
template<class T>
void doBatchRPC(const QList<T>& payloads,
std::function<json(T)> payloadGenerator,
std::function<void(QMap<T, json>*)> cb) {
auto responses = new QMap<T, json>(); // zAddr -> list of responses for each call.
int totalSize = payloads.size();
if (totalSize == 0)
return;
// Keep track of all pending method calls, so as to prevent
// any overlapping calls
static QMap<QString, bool> inProgress;
QString method = QString::fromStdString(payloadGenerator(payloads[0])["method"]);
//if (inProgress.value(method, false)) {
// qDebug() << "In progress batch, skipping";
// return;
//}
for (auto item: payloads) {
json payload = payloadGenerator(item);
inProgress[method] = true;
QNetworkReply *reply = restclient->post(*request, QByteArray::fromStdString(payload.dump()));
QObject::connect(reply, &QNetworkReply::finished, [=] {
reply->deleteLater();
if (shutdownInProgress) {
// Ignoring callback because shutdown in progress
return;
}
auto all = reply->readAll();
auto parsed = json::parse(all.toStdString(), nullptr, false);
if (reply->error() != QNetworkReply::NoError) {
qDebug() << QString::fromStdString(parsed.dump());
qDebug() << reply->errorString();
(*responses)[item] = json::object(); // Empty object
} else {
if (parsed.is_discarded()) {
(*responses)[item] = json::object(); // Empty object
} else {
(*responses)[item] = parsed["result"];
}
}
});
}
auto waitTimer = new QTimer(main);
QObject::connect(waitTimer, &QTimer::timeout, [=]() {
if (shutdownInProgress) {
waitTimer->stop();
waitTimer->deleteLater();
return;
}
// If all responses have arrived, return
if (responses->size() == totalSize) {
waitTimer->stop();
cb(responses);
inProgress[method] = false;
waitTimer->deleteLater();
}
});
waitTimer->start(100);
}
private:
bool shutdownInProgress = false;
};