cretae zcash.conf and get params
This commit is contained in:
@@ -30,26 +30,105 @@ ConnectionLoader::~ConnectionLoader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionLoader::loadConnection() {
|
void ConnectionLoader::loadConnection() {
|
||||||
|
// Load from settings if it is a manual connection.
|
||||||
|
if (Settings::getInstance()->getIsManualConnection()) {
|
||||||
|
doManualConnect();
|
||||||
|
} else {
|
||||||
|
doAutoConnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionLoader::doAutoConnect() {
|
||||||
// Priority 1: Try to connect to detect zcash.conf and connect to it.
|
// Priority 1: Try to connect to detect zcash.conf and connect to it.
|
||||||
auto config = autoDetectZcashConf();
|
auto config = autoDetectZcashConf();
|
||||||
|
|
||||||
// If not autodetected, go and read the UI Settings
|
if (config.get() != nullptr) {
|
||||||
if (config.get() == nullptr) {
|
auto connection = makeConnection(config);
|
||||||
config = loadFromSettings();
|
refreshZcashdState(connection);
|
||||||
|
|
||||||
if (config.get() == nullptr) {
|
return;
|
||||||
d->show();
|
} else {
|
||||||
// Nothing configured, show an error
|
// zcash.conf was not found, so create one
|
||||||
QString explanation = QString()
|
createZcashConf();
|
||||||
% "A zcash.conf was not found on this machine.\n\n"
|
}
|
||||||
% "If you are connecting to a remote/non-standard node "
|
}
|
||||||
% "please set the host/port and user/password in the File->Settings menu.";
|
|
||||||
|
|
||||||
showError(explanation);
|
/**
|
||||||
doRPCSetConnection(nullptr);
|
* This will create a new zcash.conf, download zcash parameters.
|
||||||
|
*/
|
||||||
|
void ConnectionLoader::createZcashConf() {
|
||||||
|
// Create zcash.conf
|
||||||
|
{
|
||||||
|
auto confLocation = zcashConfWritableLocation();
|
||||||
|
qDebug() << "Creating file " << confLocation;
|
||||||
|
|
||||||
return;
|
QFileInfo fi(confLocation);
|
||||||
}
|
QDir().mkdir(fi.dir().absolutePath());
|
||||||
|
|
||||||
|
QFile file(confLocation);
|
||||||
|
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
|
||||||
|
QTextStream out(&file);
|
||||||
|
|
||||||
|
out << "server=1\n";
|
||||||
|
out << "rpcuser=zec-qt-wallet\n";
|
||||||
|
out << "rpcpassword=" % QString::number(std::rand()) << "\n";
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch params.
|
||||||
|
{
|
||||||
|
QFileInfo fi(Settings::getInstance()->getExecName());
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionLoader::doManualConnect() {
|
||||||
|
auto config = loadFromSettings();
|
||||||
|
|
||||||
|
if (config.get() == nullptr) {
|
||||||
|
d->show();
|
||||||
|
// Nothing configured, show an error
|
||||||
|
QString explanation = QString()
|
||||||
|
% "A manual connection was requested, but the settings are not configured.\n\n"
|
||||||
|
% "Please set the host/port and user/password in the File->Settings menu.";
|
||||||
|
|
||||||
|
showError(explanation);
|
||||||
|
doRPCSetConnection(nullptr);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto connection = makeConnection(config);
|
auto connection = makeConnection(config);
|
||||||
@@ -137,12 +216,7 @@ void ConnectionLoader::showError(QString explanation) {
|
|||||||
connD->buttonBox->setEnabled(true);
|
connD->buttonBox->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ConnectionLoader::locateZcashConfFile() {
|
||||||
/**
|
|
||||||
* Try to automatically detect a zcash.conf file in the correct location and load parameters
|
|
||||||
*/
|
|
||||||
std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
|
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
auto confLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, ".zcash/zcash.conf");
|
auto confLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, ".zcash/zcash.conf");
|
||||||
#elif defined(Q_OS_DARWIN)
|
#elif defined(Q_OS_DARWIN)
|
||||||
@@ -150,8 +224,26 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
|
|||||||
#else
|
#else
|
||||||
auto confLocation = QStandardPaths::locate(QStandardPaths::AppDataLocation, "../../Zcash/zcash.conf");
|
auto confLocation = QStandardPaths::locate(QStandardPaths::AppDataLocation, "../../Zcash/zcash.conf");
|
||||||
#endif
|
#endif
|
||||||
|
return QDir::cleanPath(confLocation);
|
||||||
|
}
|
||||||
|
|
||||||
confLocation = QDir::cleanPath(confLocation);
|
QString ConnectionLoader::zcashConfWritableLocation() {
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
auto confLocation = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".zcash/zcash.conf");
|
||||||
|
#elif defined(Q_OS_DARWIN)
|
||||||
|
auto confLocation = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath("/Library/Application Support/Zcash/zcash.conf");
|
||||||
|
#else
|
||||||
|
auto confLocation = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("../../Zcash/zcash.conf");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return confLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to automatically detect a zcash.conf file in the correct location and load parameters
|
||||||
|
*/
|
||||||
|
std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
|
||||||
|
auto confLocation = locateZcashConfFile();
|
||||||
|
|
||||||
if (confLocation.isNull()) {
|
if (confLocation.isNull()) {
|
||||||
// No zcash file, just return with nothing
|
// No zcash file, just return with nothing
|
||||||
|
|||||||
@@ -41,6 +41,13 @@ private:
|
|||||||
|
|
||||||
Connection* makeConnection(std::shared_ptr<ConnectionConfig> config);
|
Connection* makeConnection(std::shared_ptr<ConnectionConfig> config);
|
||||||
|
|
||||||
|
void doAutoConnect();
|
||||||
|
void doManualConnect();
|
||||||
|
|
||||||
|
void createZcashConf();
|
||||||
|
QString locateZcashConfFile();
|
||||||
|
QString zcashConfWritableLocation();
|
||||||
|
|
||||||
void refreshZcashdState(Connection* connection);
|
void refreshZcashdState(Connection* connection);
|
||||||
int getProgressFromStatus(QString status);
|
int getProgressFromStatus(QString status);
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ int main(int argc, char *argv[])
|
|||||||
std::srand(std::time(nullptr));
|
std::srand(std::time(nullptr));
|
||||||
Settings::init();
|
Settings::init();
|
||||||
|
|
||||||
|
if (argc >= 2 && QString::fromStdString(argv[1]) == "-manual") {
|
||||||
|
Settings::getInstance()->setManualConnection(true);
|
||||||
|
}
|
||||||
|
|
||||||
QCoreApplication::setOrganizationName("zec-qt-wallet-org");
|
QCoreApplication::setOrganizationName("zec-qt-wallet-org");
|
||||||
QCoreApplication::setApplicationName("zec-qt-wallet");
|
QCoreApplication::setApplicationName("zec-qt-wallet");
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QProcess>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QtNetwork/QNetworkRequest>
|
#include <QtNetwork/QNetworkRequest>
|
||||||
#include <QtNetwork/QNetworkAccessManager>
|
#include <QtNetwork/QNetworkAccessManager>
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ public:
|
|||||||
bool isSyncing();
|
bool isSyncing();
|
||||||
void setSyncing(bool syncing);
|
void setSyncing(bool syncing);
|
||||||
|
|
||||||
|
bool getIsManualConnection() { return _manualConn; }
|
||||||
|
void setManualConnection(bool manual) {_manualConn = manual;}
|
||||||
|
|
||||||
|
QString getExecName() { return _executable; }
|
||||||
|
void setExecName(QString name) { _executable = name; }
|
||||||
|
|
||||||
int getBlockNumber();
|
int getBlockNumber();
|
||||||
void setBlockNumber(int number);
|
void setBlockNumber(int number);
|
||||||
|
|
||||||
@@ -56,9 +62,11 @@ private:
|
|||||||
static Settings* instance;
|
static Settings* instance;
|
||||||
|
|
||||||
QString _confLocation;
|
QString _confLocation;
|
||||||
|
QString _executable;
|
||||||
bool _isTestnet = false;
|
bool _isTestnet = false;
|
||||||
bool _isSyncing = false;
|
bool _isSyncing = false;
|
||||||
int _blockNumber = 0;
|
int _blockNumber = 0;
|
||||||
|
bool _manualConn = false;
|
||||||
|
|
||||||
double zecPrice = 0.0;
|
double zecPrice = 0.0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user