Download Params
This commit is contained in:
@@ -81,44 +81,7 @@ void ConnectionLoader::createZcashConf() {
|
|||||||
|
|
||||||
// Fetch params.
|
// Fetch params.
|
||||||
{
|
{
|
||||||
QFileInfo fi(Settings::getInstance()->getExecName());
|
downloadParams([=] () {
|
||||||
auto fetchParamsProgram = fi.dir().filePath("zcash-fetch-params");
|
|
||||||
|
|
||||||
QProcess* p = new QProcess(main);
|
|
||||||
QObject::connect(p, &QProcess::readyReadStandardOutput, [=] () {
|
|
||||||
qDebug() << "stdout:" << p->readAllStandardOutput();
|
|
||||||
});
|
|
||||||
QObject::connect(p, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
|
||||||
[=](int exitCode, QProcess::ExitStatus exitStatus) {
|
|
||||||
qDebug() << "finished with code " << exitCode;
|
|
||||||
p->deleteLater();
|
|
||||||
});
|
|
||||||
p->start(fetchParamsProgram);
|
|
||||||
|
|
||||||
// stdout: "Zcash - fetch-params.sh\n\nThis script will fetch the Zcash zkSNARK parameters and verify their\nintegrity with sha256sum.\n\nIf they already exist locally, it will exit now and do nothing else.\nThe parameters are currently just under 911MB in size, so plan accordingly\nfor your bandwidth constraints. If the files are already present and\nhave the correct sha256sum, no networking is used.\n\nCreating params directory. For details about this directory, see:\n/home/adityapk/.zcash-params/README\n\n\nRetrieving (wget): https://z.cash/downloads/sprout-proving.key\n"
|
|
||||||
// stdout: "Download successful!\n"
|
|
||||||
// stdout: "/home/adityapk/.zcash-params/sprout-proving.key.dl: OK\n"
|
|
||||||
// stdout: "renamed '/home/adityapk/.zcash-params/sprout-proving.key.dl' -> '/home/adityapk/.zcash-params/sprout-proving.key'\n"
|
|
||||||
// stdout: "\nRetrieving (wget): https://z.cash/downloads/sprout-verifying.key\n"
|
|
||||||
// stdout: "Download successful!\n"
|
|
||||||
// stdout: "/home/adityapk/.zcash-params/sprout-verifying.key.dl: OK\n"
|
|
||||||
// stdout: "renamed '/home/adityapk/.zcash-params/sprout-verifying.key.dl' -> '/home/adityapk/.zcash-params/sprout-verifying.key'\n"
|
|
||||||
// stdout: "\nRetrieving (wget): https://z.cash/downloads/sapling-spend.params\n"
|
|
||||||
// stdout: "Download successful!\n"
|
|
||||||
// stdout: "/home/adityapk/.zcash-params/sapling-spend.params.dl: OK\n"
|
|
||||||
// stdout: "renamed '/home/adityapk/.zcash-params/sapling-spend.params.dl' -> '/home/adityapk/.zcash-params/sapling-spend.params'\n"
|
|
||||||
// stdout: "\nRetrieving (wget): https://z.cash/downloads/sapling-output.params\n"
|
|
||||||
// stdout: "Download successful!\n"
|
|
||||||
// stdout: "/home/adityapk/.zcash-params/sapling-output.params.dl: OK\n"
|
|
||||||
// stdout: "renamed '/home/adityapk/.zcash-params/sapling-output.params.dl' -> '/home/adityapk/.zcash-params/sapling-output.params'\n"
|
|
||||||
// stdout: "\nRetrieving (wget): https://z.cash/downloads/sprout-groth16.params\n"
|
|
||||||
// stdout: "Download successful!\n"
|
|
||||||
// stdout: "/home/adityapk/.zcash-params/sprout-groth16.params.dl: OK\n"
|
|
||||||
// stdout: "renamed '/home/adityapk/.zcash-params/sprout-groth16.params.dl' -> '/home/adityapk/.zcash-params/sprout-groth16.params'\n"
|
|
||||||
// finished with code 0
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
startEmbeddedZcashd();
|
startEmbeddedZcashd();
|
||||||
|
|
||||||
auto config = autoDetectZcashConf();
|
auto config = autoDetectZcashConf();
|
||||||
@@ -130,9 +93,101 @@ void ConnectionLoader::createZcashConf() {
|
|||||||
} else {
|
} else {
|
||||||
qDebug() << "Coulnd't get embedded startup zcashd";
|
qDebug() << "Coulnd't get embedded startup zcashd";
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionLoader::downloadParams(std::function<void(void)> cb) {
|
||||||
|
// Add all the files to the download queue
|
||||||
|
downloadQueue = new QQueue<QUrl>();
|
||||||
|
client = new QNetworkAccessManager(main);
|
||||||
|
|
||||||
|
downloadQueue->enqueue(QUrl("https://z.cash/downloads/sapling-output.params"));
|
||||||
|
downloadQueue->enqueue(QUrl("https://z.cash/downloads/sapling-spend.params"));
|
||||||
|
downloadQueue->enqueue(QUrl("https://z.cash/downloads/sprout-proving.key"));
|
||||||
|
downloadQueue->enqueue(QUrl("https://z.cash/downloads/sprout-verifying.key"));
|
||||||
|
downloadQueue->enqueue(QUrl("https://z.cash/downloads/sprout-groth16.params"));
|
||||||
|
|
||||||
|
doNextDownload(cb);
|
||||||
|
|
||||||
|
d->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionLoader::doNextDownload(std::function<void(void)> cb) {
|
||||||
|
qDebug() << "Attempting download";
|
||||||
|
|
||||||
|
auto fnSaveFileName = [&] (QUrl url) {
|
||||||
|
QString path = url.path();
|
||||||
|
QString basename = QFileInfo(path).fileName();
|
||||||
|
|
||||||
|
return basename;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (downloadQueue->isEmpty()) {
|
||||||
|
delete downloadQueue;
|
||||||
|
client->deleteLater();
|
||||||
|
|
||||||
|
this->showInformation("All Downloads Finished Successfully!");
|
||||||
|
cb();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl url = downloadQueue->dequeue();
|
||||||
|
int filesRemaining = downloadQueue->size();
|
||||||
|
|
||||||
|
QString filename = fnSaveFileName(url);
|
||||||
|
QString paramsDir = zcashParamsDir();
|
||||||
|
currentOutput = new QFile(QDir(paramsDir).filePath(filename));
|
||||||
|
|
||||||
|
if (!currentOutput->open(QIODevice::WriteOnly)) {
|
||||||
|
this->showError("Couldn't download params. Please check the help site for more info.");
|
||||||
|
}
|
||||||
|
qDebug() << "Downloading " << url << " to " << filename;
|
||||||
|
|
||||||
|
QNetworkRequest request(url);
|
||||||
|
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||||
|
currentDownload = client->get(request);
|
||||||
|
downloadTime.start();
|
||||||
|
|
||||||
|
// Download Progress
|
||||||
|
QObject::connect(currentDownload, &QNetworkReply::downloadProgress, [=] (auto done, auto total) {
|
||||||
|
// calculate the download speed
|
||||||
|
double speed = done * 1000.0 / downloadTime.elapsed();
|
||||||
|
QString unit;
|
||||||
|
if (speed < 1024) {
|
||||||
|
unit = "bytes/sec";
|
||||||
|
} else if (speed < 1024*1024) {
|
||||||
|
speed /= 1024;
|
||||||
|
unit = "kB/s";
|
||||||
|
} else {
|
||||||
|
speed /= 1024*1024;
|
||||||
|
unit = "MB/s";
|
||||||
|
}
|
||||||
|
|
||||||
|
this->showInformation(
|
||||||
|
"Downloading " % filename % (filesRemaining > 1 ? " ( +" % QString::number(filesRemaining) % " more remaining )" : QString("")),
|
||||||
|
QString::number(done/1024/1024, 'f', 0) % "MB of " % QString::number(total/1024/1024, 'f', 0) + "MB at " % QString::number(speed, 'f', 2) % unit);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Download Finished
|
||||||
|
QObject::connect(currentDownload, &QNetworkReply::finished, [=] () {
|
||||||
|
currentOutput->close();
|
||||||
|
currentDownload->deleteLater();
|
||||||
|
currentOutput->deleteLater();
|
||||||
|
|
||||||
|
if (currentDownload->error()) {
|
||||||
|
this->showError("Downloading " + filename + " failed/ Please check the help site for more info");
|
||||||
|
} else {
|
||||||
|
doNextDownload(cb);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Download new data available.
|
||||||
|
QObject::connect(currentDownload, &QNetworkReply::readyRead, [=] () {
|
||||||
|
currentOutput->write(currentDownload->readAll());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool ConnectionLoader::startEmbeddedZcashd() {
|
bool ConnectionLoader::startEmbeddedZcashd() {
|
||||||
if (ezcashd != nullptr) {
|
if (ezcashd != nullptr) {
|
||||||
if (ezcashd->state() == QProcess::NotRunning) {
|
if (ezcashd->state() == QProcess::NotRunning) {
|
||||||
@@ -310,6 +365,22 @@ QString ConnectionLoader::zcashConfWritableLocation() {
|
|||||||
return confLocation;
|
return confLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ConnectionLoader::zcashParamsDir() {
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
auto paramsLocation = QDir(QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".zcash-params"));
|
||||||
|
#elif defined(Q_OS_DARWIN)
|
||||||
|
//auto paramsLocation = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath("/Library/Application Support/Zcash/zcash.conf");
|
||||||
|
#else
|
||||||
|
auto paramsLocation = QDir(QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("../../ZcashParams"));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!paramsLocation.exists()) {
|
||||||
|
QDir().mkpath(paramsLocation.absolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
return paramsLocation.absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to automatically detect a zcash.conf file in the correct location and load parameters
|
* Try to automatically detect a zcash.conf file in the correct location and load parameters
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -47,7 +47,10 @@ private:
|
|||||||
void createZcashConf();
|
void createZcashConf();
|
||||||
QString locateZcashConfFile();
|
QString locateZcashConfFile();
|
||||||
QString zcashConfWritableLocation();
|
QString zcashConfWritableLocation();
|
||||||
|
QString zcashParamsDir();
|
||||||
|
|
||||||
|
void downloadParams(std::function<void(void)> cb);
|
||||||
|
void doNextDownload(std::function<void(void)> cb);
|
||||||
bool startEmbeddedZcashd();
|
bool startEmbeddedZcashd();
|
||||||
|
|
||||||
void refreshZcashdState(Connection* connection);
|
void refreshZcashdState(Connection* connection);
|
||||||
@@ -65,6 +68,13 @@ private:
|
|||||||
|
|
||||||
MainWindow* main;
|
MainWindow* main;
|
||||||
RPC* rpc;
|
RPC* rpc;
|
||||||
|
|
||||||
|
QNetworkReply* currentDownload = nullptr;
|
||||||
|
QFile* currentOutput = nullptr;
|
||||||
|
QQueue<QUrl>* downloadQueue = nullptr;
|
||||||
|
|
||||||
|
QNetworkAccessManager* client = nullptr;
|
||||||
|
QTime downloadTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QQueue>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QtNetwork/QNetworkRequest>
|
#include <QtNetwork/QNetworkRequest>
|
||||||
|
|||||||
@@ -836,7 +836,6 @@ void RPC::shutdownZcashd() {
|
|||||||
d.setWindowTitle("Waiting for zcashd to exit");
|
d.setWindowTitle("Waiting for zcashd to exit");
|
||||||
d.setText("Please wait for zcashd to exit. Don't click OK!");
|
d.setText("Please wait for zcashd to exit. Don't click OK!");
|
||||||
d.setStandardButtons(QMessageBox::NoButton);
|
d.setStandardButtons(QMessageBox::NoButton);
|
||||||
//d.setWindowFlags(Qt::SplashScreen);
|
|
||||||
|
|
||||||
QTimer waiter(main);
|
QTimer waiter(main);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user