diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 6a2d6b80..5a6aff30 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "constants.h" @@ -253,6 +254,22 @@ void MainWindow::initWidgets() { m_wallet->setCacheAttribute("wallet.notes", ui->notes->toPlainText()); }); + // [Mining] — wowlet: solo-mine to this wallet via the embedded local node (RandomWOW in wownerod) + auto *mineAction = new QAction("Mine to this wallet", this); + mineAction->setCheckable(true); + ui->menuWallet->addAction(mineAction); + connect(mineAction, &QAction::toggled, this, [this, mineAction](bool on) { + if (on) { + int threads = std::max(1, QThread::idealThreadCount() / 2); + if (!m_wallet->startMining(threads)) { + mineAction->setChecked(false); + QMessageBox::warning(this, "Mining", "Could not start mining — make sure the node is connected and synced."); + } + } else { + m_wallet->stopMining(); + } + }); + // [Plugins..] for (auto* plugin : m_plugins) { if (!plugin->hasParent()) { diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index c26e40d9..c6e297c2 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -113,6 +113,18 @@ bool Wallet::isConnected() const { return status == ConnectionStatus_Synchronizing || status == ConnectionStatus_Synchronized; } +bool Wallet::startMining(quint32 threads) { + return m_walletImpl->startMining(m_walletImpl->address(0, 0), threads); +} + +bool Wallet::stopMining() { + return m_walletImpl->stopMining(); +} + +bool Wallet::isMining() { + return m_walletImpl->isMining(); +} + QString Wallet::errorString() const { return QString::fromStdString(m_walletImpl->errorString()); } diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 20d21af4..3931aadf 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -126,6 +126,12 @@ public: //! returns true if wallet is currently synchronized bool isSynchronized() const; + // wowlet: solo-mine to this wallet's primary address via the connected daemon (the embedded + // local node). Mining runs inside wownerod (RandomWOW); these just toggle it over RPC. + bool startMining(quint32 threads = 1); + bool stopMining(); + bool isMining(); + //! return true if wallet is connected to a node bool isConnected() const;