Browse Source

cretae zcash.conf and get params

recurring
Aditya Kulkarni 6 years ago
parent
commit
1e9289095f
  1. 134
      src/connection.cpp
  2. 7
      src/connection.h
  3. 4
      src/main.cpp
  4. 1
      src/precompiled.h
  5. 8
      src/settings.h

134
src/connection.cpp

@ -30,26 +30,105 @@ ConnectionLoader::~ConnectionLoader() {
}
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.
auto config = autoDetectZcashConf();
// If not autodetected, go and read the UI Settings
if (config.get() == nullptr) {
config = loadFromSettings();
if (config.get() != nullptr) {
auto connection = makeConnection(config);
refreshZcashdState(connection);
if (config.get() == nullptr) {
d->show();
// Nothing configured, show an error
QString explanation = QString()
% "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.";
return;
} else {
// zcash.conf was not found, so create one
createZcashConf();
}
}
/**
* This will create a new zcash.conf, download zcash parameters.
*/
void ConnectionLoader::createZcashConf() {
// Create zcash.conf
{
auto confLocation = zcashConfWritableLocation();
qDebug() << "Creating file " << confLocation;
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();
}
showError(explanation);
doRPCSetConnection(nullptr);
// 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
}
}
return;
}
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);
@ -137,12 +216,7 @@ void ConnectionLoader::showError(QString explanation) {
connD->buttonBox->setEnabled(true);
}
/**
* Try to automatically detect a zcash.conf file in the correct location and load parameters
*/
std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
QString ConnectionLoader::locateZcashConfFile() {
#ifdef Q_OS_LINUX
auto confLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, ".zcash/zcash.conf");
#elif defined(Q_OS_DARWIN)
@ -150,8 +224,26 @@ std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {
#else
auto confLocation = QStandardPaths::locate(QStandardPaths::AppDataLocation, "../../Zcash/zcash.conf");
#endif
return 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;
}
confLocation = QDir::cleanPath(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()) {
// No zcash file, just return with nothing

7
src/connection.h

@ -41,6 +41,13 @@ private:
Connection* makeConnection(std::shared_ptr<ConnectionConfig> config);
void doAutoConnect();
void doManualConnect();
void createZcashConf();
QString locateZcashConfFile();
QString zcashConfWritableLocation();
void refreshZcashdState(Connection* connection);
int getProgressFromStatus(QString status);

4
src/main.cpp

@ -21,6 +21,10 @@ int main(int argc, char *argv[])
std::srand(std::time(nullptr));
Settings::init();
if (argc >= 2 && QString::fromStdString(argv[1]) == "-manual") {
Settings::getInstance()->setManualConnection(true);
}
QCoreApplication::setOrganizationName("zec-qt-wallet-org");
QCoreApplication::setApplicationName("zec-qt-wallet");

1
src/precompiled.h

@ -35,6 +35,7 @@
#include <QFileDialog>
#include <QDebug>
#include <QUrl>
#include <QProcess>
#include <QDesktopServices>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkAccessManager>

8
src/settings.h

@ -29,6 +29,12 @@ public:
bool isSyncing();
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();
void setBlockNumber(int number);
@ -56,9 +62,11 @@ private:
static Settings* instance;
QString _confLocation;
QString _executable;
bool _isTestnet = false;
bool _isSyncing = false;
int _blockNumber = 0;
bool _manualConn = false;
double zecPrice = 0.0;
};

Loading…
Cancel
Save