autostart zcashd
This commit is contained in:
@@ -66,7 +66,11 @@ void ConnectionLoader::createZcashConf() {
|
|||||||
QDir().mkdir(fi.dir().absolutePath());
|
QDir().mkdir(fi.dir().absolutePath());
|
||||||
|
|
||||||
QFile file(confLocation);
|
QFile file(confLocation);
|
||||||
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
|
if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
|
||||||
|
qDebug() << "Could not create zcash.conf, returning";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QTextStream out(&file);
|
QTextStream out(&file);
|
||||||
|
|
||||||
out << "server=1\n";
|
out << "server=1\n";
|
||||||
@@ -113,6 +117,53 @@ void ConnectionLoader::createZcashConf() {
|
|||||||
// stdout: "renamed '/home/adityapk/.zcash-params/sprout-groth16.params.dl' -> '/home/adityapk/.zcash-params/sprout-groth16.params'\n"
|
// stdout: "renamed '/home/adityapk/.zcash-params/sprout-groth16.params.dl' -> '/home/adityapk/.zcash-params/sprout-groth16.params'\n"
|
||||||
// finished with code 0
|
// finished with code 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
startEmbeddedZcashd();
|
||||||
|
|
||||||
|
auto config = autoDetectZcashConf();
|
||||||
|
if (config.get() != nullptr) {
|
||||||
|
auto connection = makeConnection(config);
|
||||||
|
refreshZcashdState(connection);
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
qDebug() << "Coulnd't get embedded startup zcashd";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConnectionLoader::startEmbeddedZcashd() {
|
||||||
|
static bool erroredOut = false;
|
||||||
|
|
||||||
|
if (erroredOut) {
|
||||||
|
qDebug() << "Last zcashd start attempted errored, so not restarting";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, start zcashd
|
||||||
|
qDebug() << "Starting zcashd";
|
||||||
|
QFileInfo fi(Settings::getInstance()->getExecName());
|
||||||
|
auto zcashdProgram = fi.dir().filePath("zcashd");
|
||||||
|
|
||||||
|
QProcess* p = new QProcess(main);
|
||||||
|
QObject::connect(p, &QProcess::started, [=] () {
|
||||||
|
Settings::getInstance()->setEmbeddedZcashdRunning(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(p, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
|
[=](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
|
qDebug() << "zcashd finished with code " << exitCode;
|
||||||
|
p->deleteLater();
|
||||||
|
});
|
||||||
|
|
||||||
|
QObject::connect(p, &QProcess::errorOccurred, [&] (auto error) mutable {
|
||||||
|
qDebug() << "Couldn't start zcashd: " << error;
|
||||||
|
erroredOut = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
p->start(zcashdProgram);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionLoader::doManualConnect() {
|
void ConnectionLoader::doManualConnect() {
|
||||||
@@ -178,15 +229,26 @@ void ConnectionLoader::refreshZcashdState(Connection* connection) {
|
|||||||
// Failed, see what it is.
|
// Failed, see what it is.
|
||||||
//qDebug() << err << ":" << QString::fromStdString(res.dump());
|
//qDebug() << err << ":" << QString::fromStdString(res.dump());
|
||||||
|
|
||||||
if (err == QNetworkReply::NetworkError::ConnectionRefusedError) {
|
if (err == QNetworkReply::NetworkError::ConnectionRefusedError) {
|
||||||
auto isZcashConfFound = connection->config.get()->usingZcashConf;
|
// Start embedded zcasd
|
||||||
QString explanation = QString()
|
this->showInformation("Starting Embedded zcashd");
|
||||||
% (isZcashConfFound ? "A zcash.conf file was found, but a" : "A")
|
if (this->startEmbeddedZcashd()) {
|
||||||
% " connection to zcashd could not be established.\n\n"
|
// Refresh after one second
|
||||||
% "If you are connecting to a remote/non-standard node "
|
QTimer::singleShot(1000, [=]() { this->refreshZcashdState(connection); });
|
||||||
% "please set the host/port and user/password in the File->Settings menu";
|
} else {
|
||||||
|
// Errored out, show error and exit
|
||||||
|
QString explanation = "Couldn't start zcashd";
|
||||||
|
this->showError(explanation);
|
||||||
|
}
|
||||||
|
|
||||||
this->showError(explanation);
|
// auto isZcashConfFound = connection->config.get()->usingZcashConf;
|
||||||
|
// QString explanation = QString()
|
||||||
|
// % (isZcashConfFound ? "A zcash.conf file was found, but a" : "A")
|
||||||
|
// % " connection to zcashd could not be established.\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";
|
||||||
|
|
||||||
|
// this->showError(explanation);
|
||||||
} else if (err == QNetworkReply::NetworkError::AuthenticationRequiredError) {
|
} else if (err == QNetworkReply::NetworkError::AuthenticationRequiredError) {
|
||||||
QString explanation = QString()
|
QString explanation = QString()
|
||||||
% "Authentication failed. The username / password you specified was "
|
% "Authentication failed. The username / password you specified was "
|
||||||
@@ -196,10 +258,7 @@ void ConnectionLoader::refreshZcashdState(Connection* connection) {
|
|||||||
} else if (err == QNetworkReply::NetworkError::InternalServerError && !res.is_discarded()) {
|
} else if (err == QNetworkReply::NetworkError::InternalServerError && !res.is_discarded()) {
|
||||||
// The server is loading, so just poll until it succeeds
|
// The server is loading, so just poll until it succeeds
|
||||||
QString status = QString::fromStdString(res["error"]["message"]);
|
QString status = QString::fromStdString(res["error"]["message"]);
|
||||||
|
showInformation("Your zcashd is starting up. Please wait.\n\n" % status);
|
||||||
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation);
|
|
||||||
connD->icon->setPixmap(icon.pixmap(128, 128));
|
|
||||||
connD->status->setText("Your zcashd is starting up. Please wait.\n\n" % status);
|
|
||||||
|
|
||||||
// Refresh after one second
|
// Refresh after one second
|
||||||
QTimer::singleShot(1000, [=]() { this->refreshZcashdState(connection); });
|
QTimer::singleShot(1000, [=]() { this->refreshZcashdState(connection); });
|
||||||
@@ -208,6 +267,12 @@ void ConnectionLoader::refreshZcashdState(Connection* connection) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionLoader::showInformation(QString info) {
|
||||||
|
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation);
|
||||||
|
connD->icon->setPixmap(icon.pixmap(128, 128));
|
||||||
|
connD->status->setText(info);
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectionLoader::showError(QString explanation) {
|
void ConnectionLoader::showError(QString explanation) {
|
||||||
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical);
|
QIcon icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical);
|
||||||
connD->icon->setPixmap(icon.pixmap(128, 128));
|
connD->icon->setPixmap(icon.pixmap(128, 128));
|
||||||
|
|||||||
@@ -48,10 +48,13 @@ private:
|
|||||||
QString locateZcashConfFile();
|
QString locateZcashConfFile();
|
||||||
QString zcashConfWritableLocation();
|
QString zcashConfWritableLocation();
|
||||||
|
|
||||||
|
bool startEmbeddedZcashd();
|
||||||
|
|
||||||
void refreshZcashdState(Connection* connection);
|
void refreshZcashdState(Connection* connection);
|
||||||
int getProgressFromStatus(QString status);
|
int getProgressFromStatus(QString status);
|
||||||
|
|
||||||
void showError(QString explanation);
|
void showError(QString explanation);
|
||||||
|
void showInformation(QString info);
|
||||||
|
|
||||||
void doRPCSetConnection(Connection* conn);
|
void doRPCSetConnection(Connection* conn);
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,10 @@ void MainWindow::closeEvent(QCloseEvent* event) {
|
|||||||
s.setValue("baltablegeometry", ui->balancesTable->horizontalHeader()->saveState());
|
s.setValue("baltablegeometry", ui->balancesTable->horizontalHeader()->saveState());
|
||||||
s.setValue("tratablegeometry", ui->transactionsTable->horizontalHeader()->saveState());
|
s.setValue("tratablegeometry", ui->transactionsTable->horizontalHeader()->saveState());
|
||||||
|
|
||||||
|
// Let the RPC know to shutdown any running service.
|
||||||
|
rpc->closeEvent();
|
||||||
|
|
||||||
|
// Bubble up
|
||||||
QMainWindow::closeEvent(event);
|
QMainWindow::closeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/rpc.cpp
16
src/rpc.cpp
@@ -807,3 +807,19 @@ void RPC::refreshZECPrice() {
|
|||||||
Settings::getInstance()->setZECPrice(0);
|
Settings::getInstance()->setZECPrice(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RPC::shutdownZcashd() {
|
||||||
|
json payload = {
|
||||||
|
{"jsonrpc", "1.0"},
|
||||||
|
{"id", "someid"},
|
||||||
|
{"method", "stop"}
|
||||||
|
};
|
||||||
|
|
||||||
|
conn->doRPCWithDefaultErrorHandling(payload, [=](auto) {});
|
||||||
|
}
|
||||||
|
|
||||||
|
void RPC::closeEvent() {
|
||||||
|
if (Settings::getInstance()->isEmbeddedZcashdRunning()) {
|
||||||
|
shutdownZcashd();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,11 +56,15 @@ public:
|
|||||||
void importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
|
void importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
|
||||||
void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
|
void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
|
||||||
|
|
||||||
|
void shutdownZcashd();
|
||||||
|
|
||||||
void getAllPrivKeys(const std::function<void(QList<QPair<QString, QString>>)>);
|
void getAllPrivKeys(const std::function<void(QList<QPair<QString, QString>>)>);
|
||||||
|
|
||||||
Turnstile* getTurnstile() { return turnstile; }
|
Turnstile* getTurnstile() { return turnstile; }
|
||||||
Connection* getConnection() { return conn; }
|
Connection* getConnection() { return conn; }
|
||||||
|
|
||||||
|
void closeEvent();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void noConnection();
|
void noConnection();
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ public:
|
|||||||
QString getExecName() { return _executable; }
|
QString getExecName() { return _executable; }
|
||||||
void setExecName(QString name) { _executable = name; }
|
void setExecName(QString name) { _executable = name; }
|
||||||
|
|
||||||
|
void setEmbeddedZcashdRunning(bool r) { _isEmbeddedZcashd = r; }
|
||||||
|
bool isEmbeddedZcashdRunning() { return _isEmbeddedZcashd; }
|
||||||
|
|
||||||
int getBlockNumber();
|
int getBlockNumber();
|
||||||
void setBlockNumber(int number);
|
void setBlockNumber(int number);
|
||||||
|
|
||||||
@@ -63,10 +66,11 @@ private:
|
|||||||
|
|
||||||
QString _confLocation;
|
QString _confLocation;
|
||||||
QString _executable;
|
QString _executable;
|
||||||
bool _isTestnet = false;
|
bool _isTestnet = false;
|
||||||
bool _isSyncing = false;
|
bool _isSyncing = false;
|
||||||
int _blockNumber = 0;
|
int _blockNumber = 0;
|
||||||
bool _manualConn = false;
|
bool _manualConn = false;
|
||||||
|
bool _isEmbeddedZcashd = false;
|
||||||
|
|
||||||
double zecPrice = 0.0;
|
double zecPrice = 0.0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user