mirror of
https://github.com/wownero/wowlet.git
synced 2026-11-27 18:44:06 +01:00
Brings back the mining tab and adds support for solo mining.
- Automatically sets the receiving address and spendkey to the current wallet - The ability to specify CPU threads - The ability to download the latest wownerod release from within wowlet (via: https://git.wownero.com/wowlet/wowlet-backend/pulls/18) - Explanation on how to mine via the 'How-To' tab - Console has a buffer of 2000 lines (auto-clears)
This commit is contained in:
+58
-43
@@ -7,10 +7,17 @@
|
||||
|
||||
#include "utils/utils.h"
|
||||
#include "utils/xmrig.h"
|
||||
#include "appcontext.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
XmRig::XmRig(const QString &configDir, QObject *parent) : QObject(parent) {
|
||||
this->rigDir = QDir(configDir).filePath("xmrig");
|
||||
XmRig::XmRig(const QString &configDir, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_statusTimer(new QTimer(this))
|
||||
{
|
||||
m_statusTimer->setInterval(5000);
|
||||
connect(m_statusTimer, &QTimer::timeout, [this]{
|
||||
if(mining_started && m_process.state() == QProcess::Running)
|
||||
m_process.write("status\n");
|
||||
});
|
||||
}
|
||||
|
||||
void XmRig::prepare() {
|
||||
@@ -28,74 +35,82 @@ void XmRig::stop() {
|
||||
m_process.terminate();
|
||||
#endif
|
||||
}
|
||||
m_statusTimer->stop();
|
||||
}
|
||||
|
||||
void XmRig::start(const QString &path,
|
||||
int threads,
|
||||
const QString &address,
|
||||
const QString &username,
|
||||
const QString &password,
|
||||
bool tor, bool tls) {
|
||||
bool XmRig::start(const QString &path, int threads) {
|
||||
m_ctx = MainWindow::getContext();
|
||||
|
||||
auto state = m_process.state();
|
||||
if (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting) {
|
||||
emit error("Can't start XMRig, already running or starting");
|
||||
return;
|
||||
emit error("Can't start wownerod, already running or starting");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(path.isEmpty()) {
|
||||
emit error("XmRig->Start path parameter missing.");
|
||||
return;
|
||||
emit error("wownerod path seems to be empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!Utils::fileExists(path)) {
|
||||
emit error(QString("Path to XMRig binary invalid; file does not exist: %1").arg(path));
|
||||
return;
|
||||
emit error(QString("Path to wownerod binary is invalid; file does not exist: %1").arg(path));
|
||||
return false;
|
||||
}
|
||||
|
||||
auto privateSpendKey = m_ctx->currentWallet->getSecretSpendKey();
|
||||
QStringList arguments;
|
||||
arguments << "-o" << address;
|
||||
arguments << "-a" << "rx/wow";
|
||||
arguments << "-u" << username;
|
||||
if(!password.isEmpty())
|
||||
arguments << "-p" << password;
|
||||
arguments << "--no-color";
|
||||
arguments << "-t" << QString::number(threads);
|
||||
if(tor)
|
||||
arguments << "-x" << QString("%1:%2").arg(Tor::torHost).arg(Tor::torPort);
|
||||
if(tls)
|
||||
arguments << "--tls";
|
||||
arguments << "--donate-level" << "1";
|
||||
arguments << "--mining-threads" << QString::number(threads);
|
||||
arguments << "--start-mining" << m_ctx->currentWallet->address(0, 0);
|
||||
arguments << "--spendkey" << privateSpendKey;
|
||||
|
||||
QString cmd = QString("%1 %2").arg(path, arguments.join(" "));
|
||||
cmd = cmd.replace(privateSpendKey, "[redacted]");
|
||||
emit output(cmd.toUtf8());
|
||||
|
||||
m_process.start(path, arguments);
|
||||
m_statusTimer->start();
|
||||
return true;
|
||||
}
|
||||
|
||||
void XmRig::stateChanged(QProcess::ProcessState state) {
|
||||
if(state == QProcess::ProcessState::Running)
|
||||
emit output("XMRig started");
|
||||
else if (state == QProcess::ProcessState::NotRunning)
|
||||
emit output("XMRig stopped");
|
||||
emit output("wownerod started");
|
||||
else if (state == QProcess::ProcessState::NotRunning) {
|
||||
emit output("wownerod stopped");
|
||||
this->mining_started = false;
|
||||
emit stopped();
|
||||
}
|
||||
}
|
||||
|
||||
void XmRig::handleProcessOutput() {
|
||||
QByteArray _output = m_process.readAllStandardOutput();
|
||||
if(_output.contains("miner") && _output.contains("speed")) {
|
||||
// detect hashrate
|
||||
auto str = Utils::barrayToString(_output);
|
||||
auto spl = str.mid(str.indexOf("speed")).split(" ");
|
||||
auto rate = spl.at(2) + "H/s";
|
||||
qDebug() << "mining hashrate: " << rate;
|
||||
emit hashrate(rate);
|
||||
}
|
||||
QByteArray data = m_process.readAllStandardOutput();
|
||||
|
||||
emit output(_output);
|
||||
for(auto &line: data.split('\n')) {
|
||||
if(line.indexOf("\tI") >= 20)
|
||||
line = line.remove(0, line.indexOf("\tI") + 2);
|
||||
if(line.trimmed().isEmpty() || line.startsWith("status")) continue;
|
||||
if(line.contains("Mining started. Good luck"))
|
||||
this->mining_started = true;
|
||||
else if(line.contains("you won a block reward"))
|
||||
emit blockReward();
|
||||
else if(line.contains("mining at")) {
|
||||
auto rate = line.remove(0, line.indexOf("mining at"));
|
||||
rate = rate.remove(rate.indexOf(","), rate.length());
|
||||
rate = rate.remove(0, 9);
|
||||
rate = rate.trimmed();
|
||||
emit hashrate(rate);
|
||||
}
|
||||
|
||||
emit output(line);
|
||||
}
|
||||
}
|
||||
|
||||
void XmRig::handleProcessError(QProcess::ProcessError err) {
|
||||
if (err == QProcess::ProcessError::Crashed)
|
||||
emit error("XMRig crashed or killed");
|
||||
emit error("wownerod crashed or killed");
|
||||
else if (err == QProcess::ProcessError::FailedToStart) {
|
||||
auto path = config()->get(Config::xmrigPath).toString();
|
||||
emit error(QString("XMRig binary failed to start: %1").arg(path));
|
||||
auto path = config()->get(Config::wownerodPath).toString();
|
||||
emit error(QString("wownerod binary failed to start: %1").arg(path));
|
||||
}
|
||||
this->mining_started = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user