From 1ef29207d5b14b62fe6caab14b2d1f2188c9d50d Mon Sep 17 00:00:00 2001 From: dsc Date: Fri, 16 Oct 2020 21:01:18 +0200 Subject: [PATCH] Xmrig: add support for TLS. Tor default off. Save username/password in wallet cache. Signed-off-by: dsc --- src/mainwindow.cpp | 13 ++-- src/mainwindow.h | 2 + src/mainwindow.ui | 10 +-- src/utils/config.cpp | 2 +- src/utils/xmrig.cpp | 12 +++- src/utils/xmrig.h | 2 +- src/widgets/xmrigwidget.cpp | 56 +++++++++++++-- src/widgets/xmrigwidget.h | 8 ++- src/widgets/xmrigwidget.ui | 131 ++++++++++++++++++++++-------------- 9 files changed, 161 insertions(+), 75 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bcbae29..422f7e7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -12,7 +12,6 @@ #include "mainwindow.h" #include "widgets/ccswidget.h" #include "widgets/redditwidget.h" -#include "widgets/xmrigwidget.h" #include "dialog/txconfdialog.h" #include "dialog/debuginfodialog.h" #include "dialog/walletinfodialog.h" @@ -168,11 +167,13 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) : connect(m_ctx->nodes, &Nodes::WSNodeExhausted, this, &MainWindow::showWSNodeExhaustedMessage); // XMRig - connect(m_ctx, &AppContext::XMRigDownloads, ui->xmrigWidget, &XMRigWidget::onDownloads); - connect(m_ctx, &AppContext::walletClosed, ui->xmrigWidget, &XMRigWidget::onStopClicked); - connect(m_ctx, &AppContext::walletClosed, ui->xmrigWidget, &XMRigWidget::onClearClicked); - connect(ui->xmrigWidget, &XMRigWidget::miningStarted, [=]{ m_ctx->setWindowTitle(true); }); - connect(ui->xmrigWidget, &XMRigWidget::miningEnded, [=]{ m_ctx->setWindowTitle(false); }); + m_xmrig = new XMRigWidget(m_ctx, this); + ui->xmrRigLayout->addWidget(m_xmrig); + connect(m_ctx, &AppContext::walletOpened, m_xmrig, &XMRigWidget::onWalletOpened); + connect(m_ctx, &AppContext::XMRigDownloads, m_xmrig, &XMRigWidget::onDownloads); + connect(m_ctx, &AppContext::walletClosed, m_xmrig, &XMRigWidget::onWalletClosed); + connect(m_xmrig, &XMRigWidget::miningStarted, [=]{ m_ctx->setWindowTitle(true); }); + connect(m_xmrig, &XMRigWidget::miningEnded, [=]{ m_ctx->setWindowTitle(false); }); // CCS/Reddit widget m_ccsWidget = new CCSWidget(this); diff --git a/src/mainwindow.h b/src/mainwindow.h index 5ccf827..e039bb7 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -19,6 +19,7 @@ #include "widgets/ccswidget.h" #include "widgets/redditwidget.h" #include "widgets/tickerwidget.h" +#include "widgets/xmrigwidget.h" #include "utils/networking.h" #include "appcontext.h" #include "utils/config.h" @@ -144,6 +145,7 @@ private: SignVerifyDialog *m_windowSignVerify = nullptr; RestoreDialog *m_restoreDialog = nullptr; AboutDialog *m_aboutDialog = nullptr; + XMRigWidget *m_xmrig = nullptr; bool m_windowSpawned = false; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 481cafc..878ee41 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -290,7 +290,7 @@ - + @@ -305,7 +305,7 @@ 0 0 894 - 30 + 22 @@ -655,12 +655,6 @@
calcwidget.h
1 - - XMRigWidget - QWidget -
widgets/xmrigwidget.h
- 1 -
diff --git a/src/utils/config.cpp b/src/utils/config.cpp index c3640dd..b3939a2 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -35,7 +35,7 @@ static const QHash configStrings = { {Config::autoOpenWalletPath,{QS("autoOpenWalletPath"), ""}}, {Config::walletPath,{QS("walletPath"), ""}}, {Config::xmrigPath,{QS("xmrigPath"), ""}}, - {Config::xmrigPool,{QS("xmrigPool"), "pool.xmr.pt:5555"}}, + {Config::xmrigPool,{QS("xmrigPool"), "pool.xmr.pt:9000"}}, {Config::nodes,{QS("nodes"), "{}"}}, {Config::websocketEnabled,{QS("websocketEnabled"), true}}, {Config::nodeSource,{QS("nodeSource"), 0}}, diff --git a/src/utils/xmrig.cpp b/src/utils/xmrig.cpp index ffbce2d..df2c0f9 100644 --- a/src/utils/xmrig.cpp +++ b/src/utils/xmrig.cpp @@ -33,7 +33,11 @@ void XMRig::terminate() { m_process.terminate(); } -void XMRig::start(unsigned int threads, const QString &pool_name, const QString &receiving_address, bool tor) { +void XMRig::start(unsigned int threads, + const QString &pool_name, + const QString &username, + const QString &password, + bool tor, bool tls) { auto state = m_process.state(); if (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting) { emit error("Can't start XMRig, already running or starting"); @@ -54,12 +58,14 @@ void XMRig::start(unsigned int threads, const QString &pool_name, const QString QStringList arguments; arguments << "-o" << pool_name; arguments << "-a" << "rx/0"; - arguments << "-u" << receiving_address; - arguments << "-p" << "featherwallet"; + arguments << "-u" << username; + 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"; QString cmd = QString("%1 %2").arg(path, arguments.join(" ")); emit output(cmd.toUtf8()); diff --git a/src/utils/xmrig.h b/src/utils/xmrig.h index 67350c8..42817f5 100644 --- a/src/utils/xmrig.h +++ b/src/utils/xmrig.h @@ -22,7 +22,7 @@ Q_OBJECT public: explicit XMRig(QObject *parent = nullptr); - void start(unsigned int threads, const QString &pool_name, const QString &receiving_address, bool tor = false); + void start(unsigned int threads, const QString &pool_name, const QString &username, const QString &password, bool tor = false, bool tls = true); void stop(); void terminate(); diff --git a/src/widgets/xmrigwidget.cpp b/src/widgets/xmrigwidget.cpp index 96c8064..f87fb03 100644 --- a/src/widgets/xmrigwidget.cpp +++ b/src/widgets/xmrigwidget.cpp @@ -15,9 +15,10 @@ #include "ui_xmrigwidget.h" #include "utils/utils.h" -XMRigWidget::XMRigWidget(QWidget *parent) : +XMRigWidget::XMRigWidget(AppContext *ctx, QWidget *parent) : QWidget(parent), ui(new Ui::XMRigWidget), + m_ctx(ctx), m_model(new QStandardItemModel(this)), m_contextMenu(new QMenu(this)) { @@ -56,8 +57,10 @@ XMRigWidget::XMRigWidget(QWidget *parent) : // defaults ui->btn_stop->setEnabled(false); ui->check_autoscroll->setChecked(true); - ui->relayTor->setChecked(true); + ui->relayTor->setChecked(false); + ui->check_tls->setChecked(true); ui->label_status->setTextInteractionFlags(Qt::TextSelectableByMouse); + // XMRig binary auto path = config()->get(Config::xmrigPath).toString(); ui->lineEdit_path->setText(path); @@ -79,6 +82,40 @@ XMRigWidget::XMRigWidget(QWidget *parent) : else ui->console->appendPlainText(QString("XMRig path set to %1").arg(path)); ui->console->appendPlainText("Ready to mine."); + + // username/password + connect(ui->lineEdit_password, &QLineEdit::editingFinished, [=]() { + m_ctx->currentWallet->setCacheAttribute("feather.xmrig_password", ui->lineEdit_password->text()); + m_ctx->currentWallet->store(); + }); + + connect(ui->lineEdit_address, &QLineEdit::editingFinished, [=]() { + m_ctx->currentWallet->setCacheAttribute("feather.xmrig_username", ui->lineEdit_address->text()); + m_ctx->currentWallet->store(); + }); +} + +void XMRigWidget::onWalletClosed() { + this->onStopClicked(); + this->onClearClicked(); + ui->lineEdit_password->setText(""); + ui->lineEdit_address->setText(""); +} + +void XMRigWidget::onWalletOpened(){ + // Xmrig username + auto username = m_ctx->currentWallet->getCacheAttribute("feather.xmrig_username"); + if(!username.isEmpty()) + ui->lineEdit_address->setText(username); + + // Xmrig passwd + auto password = m_ctx->currentWallet->getCacheAttribute("feather.xmrig_password"); + if(!password.isEmpty()) { + ui->lineEdit_password->setText(password); + } else { + ui->lineEdit_password->setText("featherwallet"); + m_ctx->currentWallet->setCacheAttribute("feather.xmrig_password", ui->lineEdit_password->text()); + } } void XMRigWidget::onThreadsValueChanged(int threads) { @@ -104,13 +141,22 @@ void XMRigWidget::onClearClicked() { void XMRigWidget::onStartClicked() { auto pool_name = config()->get(Config::xmrigPool).toString(); - auto addy = ui->lineEdit_address->text(); - if(addy.isEmpty()) { + + // fix error in config + if(!m_pools.contains(pool_name)) { + pool_name = m_pools.at(0); + config()->set(Config::xmrigPool, pool_name); + } + + auto username = m_ctx->currentWallet->getCacheAttribute("feather.xmrig_username"); + auto password = m_ctx->currentWallet->getCacheAttribute("feather.xmrig_password"); + + if(username.isEmpty()) { Utils::showMessageBox("Error", "Please specify a receiving address on the Settings screen", true); return; } - m_rig->start(m_threads, pool_name, addy, ui->relayTor->isChecked()); + m_rig->start(m_threads, pool_name, username, password, ui->relayTor->isChecked(), ui->check_tls->isChecked()); ui->btn_start->setEnabled(false); ui->btn_stop->setEnabled(true); emit miningStarted(); diff --git a/src/widgets/xmrigwidget.h b/src/widgets/xmrigwidget.h index 8602577..4517264 100644 --- a/src/widgets/xmrigwidget.h +++ b/src/widgets/xmrigwidget.h @@ -10,6 +10,7 @@ #include "utils/xmrig.h" #include "utils/config.h" +#include "appcontext.h" namespace Ui { class XMRigWidget; @@ -20,11 +21,13 @@ class XMRigWidget : public QWidget Q_OBJECT public: - explicit XMRigWidget(QWidget *parent = nullptr); + explicit XMRigWidget(AppContext *ctx, QWidget *parent = nullptr); ~XMRigWidget(); QStandardItemModel *model(); public slots: + void onWalletClosed(); + void onWalletOpened(); void onStartClicked(); void onStopClicked(); void onClearClicked(); @@ -46,12 +49,13 @@ signals: private: void showContextMenu(const QPoint &pos); + AppContext *m_ctx; Ui::XMRigWidget *ui; QStandardItemModel *m_model; QMenu *m_contextMenu; unsigned int m_threads; QStringList m_urls; - QStringList m_pools{"pool.xmr.pt:5555", "pool.supportxmr.com:3333", "mine.xmrpool.net:3333", "xmrpool.eu:5555", "xmr-eu1.nanopool.org:14444", "pool.minexmr.com:4444", "monerohash.com:2222"}; + QStringList m_pools{"pool.xmr.pt:9000", "pool.supportxmr.com:9000", "mine.xmrpool.net:443", "xmrpool.eu:9999", "xmr-eu1.nanopool.org:14433", "pool.minexmr.com:6666", "us-west.minexmr.com:6666", "monerohash.com:9999"}; XMRig *m_rig; }; diff --git a/src/widgets/xmrigwidget.ui b/src/widgets/xmrigwidget.ui index 6ae843a..ced7240 100644 --- a/src/widgets/xmrigwidget.ui +++ b/src/widgets/xmrigwidget.ui @@ -125,7 +125,7 @@ Settings - + @@ -152,67 +152,97 @@ - - - Receiving address - - - - - - - - - - Threads: - - - - - + - - - Qt::Horizontal - - + + + + + Pool + + + + + + + + + + 0 + 0 + + + + + + + + TLS + + + + + + + Tor + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + - - - Qt::Horizontal - - - - 40 - 20 - - - + + + + + Threads: + + + + + + + + + Qt::Horizontal + + + + + + - + - Pool + Pool worker name (optional) - + - - - - 0 - 0 - - - + - + Qt::Horizontal @@ -227,12 +257,15 @@ - + - Relay over Tor + Receiving address + + +