From c8f0cf354390af1908b3f99e5621eed8c1fab9ed Mon Sep 17 00:00:00 2001 From: stoffu Date: Tue, 6 Mar 2018 01:19:45 +0900 Subject: Stagenet --- src/daemon/DaemonManager.cpp | 44 ++++++++++++++++++++++---------------------- src/daemon/DaemonManager.h | 15 ++++++++------- 2 files changed, 30 insertions(+), 29 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp index 93e7a9a8..79db8cff 100644 --- a/src/daemon/DaemonManager.cpp +++ b/src/daemon/DaemonManager.cpp @@ -32,7 +32,7 @@ DaemonManager *DaemonManager::instance(const QStringList *args) return m_instance; } -bool DaemonManager::start(const QString &flags, bool testnet, const QString &dataDir, const QString &bootstrapNodeAddress) +bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const QString &dataDir, const QString &bootstrapNodeAddress) { // prepare command line arguments and pass to monerod QStringList arguments; @@ -42,8 +42,10 @@ bool DaemonManager::start(const QString &flags, bool testnet, const QString &dat arguments << "--detach"; #endif - if(testnet) + if (nettype == NetworkType::TESTNET) arguments << "--testnet"; + else if (nettype == NetworkType::STAGENET) + arguments << "--stagenet"; foreach (const QString &str, m_clArgs) { qDebug() << QString(" [%1] ").arg(str); @@ -60,11 +62,7 @@ bool DaemonManager::start(const QString &flags, bool testnet, const QString &dat // Custom data-dir if(!dataDir.isEmpty()) { - if(testnet) - arguments << "--testnet-data-dir"; - else - arguments << "--data-dir"; - arguments << dataDir; + arguments << "--data-dir" << dataDir; } // Bootstrap node address @@ -99,7 +97,7 @@ bool DaemonManager::start(const QString &flags, bool testnet, const QString &dat } // Start start watcher - QFuture future = QtConcurrent::run(this, &DaemonManager::startWatcher, testnet); + QFuture future = QtConcurrent::run(this, &DaemonManager::startWatcher, nettype); QFutureWatcher * watcher = new QFutureWatcher(); connect(watcher, &QFutureWatcher::finished, this, [this, watcher]() { @@ -116,14 +114,14 @@ bool DaemonManager::start(const QString &flags, bool testnet, const QString &dat return true; } -bool DaemonManager::stop(bool testnet) +bool DaemonManager::stop(NetworkType::Type nettype) { QString message; - sendCommand("exit",testnet,message); + sendCommand("exit", nettype, message); qDebug() << message; // Start stop watcher - Will kill if not shutting down - QFuture future = QtConcurrent::run(this, &DaemonManager::stopWatcher, testnet); + QFuture future = QtConcurrent::run(this, &DaemonManager::stopWatcher, nettype); QFutureWatcher * watcher = new QFutureWatcher(); connect(watcher, &QFutureWatcher::finished, this, [this, watcher]() { @@ -138,14 +136,14 @@ bool DaemonManager::stop(bool testnet) return true; } -bool DaemonManager::startWatcher(bool testnet) const +bool DaemonManager::startWatcher(NetworkType::Type nettype) const { // Check if daemon is started every 2 seconds QTime timer; timer.restart(); while(true && !m_app_exit && timer.elapsed() / 1000 < DAEMON_START_TIMEOUT_SECONDS ) { QThread::sleep(2); - if(!running(testnet)) { + if(!running(nettype)) { qDebug() << "daemon not running. checking again in 2 seconds."; } else { qDebug() << "daemon is started. Waiting 5 seconds to let daemon catch up"; @@ -156,14 +154,14 @@ bool DaemonManager::startWatcher(bool testnet) const return false; } -bool DaemonManager::stopWatcher(bool testnet) const +bool DaemonManager::stopWatcher(NetworkType::Type nettype) const { // Check if daemon is running every 2 seconds. Kill if still running after 10 seconds int counter = 0; while(true && !m_app_exit) { QThread::sleep(2); counter++; - if(running(testnet)) { + if(running(nettype)) { qDebug() << "Daemon still running. " << counter; if(counter >= 5) { qDebug() << "Killing it! "; @@ -211,10 +209,10 @@ void DaemonManager::printError() } } -bool DaemonManager::running(bool testnet) const +bool DaemonManager::running(NetworkType::Type nettype) const { QString status; - sendCommand("status",testnet, status); + sendCommand("status", nettype, status); qDebug() << status; // `./monerod status` returns BUSY when syncing. // Treat busy as connected, until fixed upstream. @@ -223,21 +221,23 @@ bool DaemonManager::running(bool testnet) const } return false; } -bool DaemonManager::sendCommand(const QString &cmd,bool testnet) const +bool DaemonManager::sendCommand(const QString &cmd, NetworkType::Type nettype) const { QString message; - return sendCommand(cmd, testnet, message); + return sendCommand(cmd, nettype, message); } -bool DaemonManager::sendCommand(const QString &cmd,bool testnet, QString &message) const +bool DaemonManager::sendCommand(const QString &cmd, NetworkType::Type nettype, QString &message) const { QProcess p; QStringList external_cmd; external_cmd << cmd; - // Add testnet flag if needed - if (testnet) + // Add network type flag if needed + if (nettype == NetworkType::TESTNET) external_cmd << "--testnet"; + else if (nettype == NetworkType::STAGENET) + external_cmd << "--stagenet"; qDebug() << "sending external cmd: " << external_cmd; diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h index d081ad7d..1c904a23 100644 --- a/src/daemon/DaemonManager.h +++ b/src/daemon/DaemonManager.h @@ -5,6 +5,7 @@ #include #include #include +#include "NetworkType.h" class DaemonManager : public QObject { @@ -14,21 +15,21 @@ public: static DaemonManager * instance(const QStringList *args); - Q_INVOKABLE bool start(const QString &flags, bool testnet, const QString &dataDir = "", const QString &bootstrapNodeAddress = ""); - Q_INVOKABLE bool stop(bool testnet); + Q_INVOKABLE bool start(const QString &flags, NetworkType::Type nettype, const QString &dataDir = "", const QString &bootstrapNodeAddress = ""); + Q_INVOKABLE bool stop(NetworkType::Type nettype); // return true if daemon process is started - Q_INVOKABLE bool running(bool testnet) const; + Q_INVOKABLE bool running(NetworkType::Type nettype) const; // Send daemon command from qml and prints output in console window. - Q_INVOKABLE bool sendCommand(const QString &cmd, bool testnet) const; + Q_INVOKABLE bool sendCommand(const QString &cmd, NetworkType::Type nettype) const; Q_INVOKABLE void exit(); Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const; private: - bool sendCommand(const QString &cmd, bool testnet, QString &message) const; - bool startWatcher(bool testnet) const; - bool stopWatcher(bool testnet) const; + bool sendCommand(const QString &cmd, NetworkType::Type nettype, QString &message) const; + bool startWatcher(NetworkType::Type nettype) const; + bool stopWatcher(NetworkType::Type nettype) const; signals: void daemonStarted() const; void daemonStopped() const; -- cgit v1.2.3