aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2018-03-26 12:57:14 -0500
committerluigi1111 <luigi1111w@gmail.com>2018-03-26 12:57:14 -0500
commite4d75c6680bb3ed7bccdf00e8e319b25b6a7be21 (patch)
tree593b10a28ca322ae36d582df236663f7e2a3f681 /src
parent278458bb646cbb0d4361106cff424807812e5bda (diff)
parentc8f0cf354390af1908b3f99e5621eed8c1fab9ed (diff)
downloadmonzero-gui-e4d75c6680bb3ed7bccdf00e8e319b25b6a7be21.tar.gz
monzero-gui-e4d75c6680bb3ed7bccdf00e8e319b25b6a7be21.tar.xz
monzero-gui-e4d75c6680bb3ed7bccdf00e8e319b25b6a7be21.zip
Merge pull request #1161
c8f0cf3 Stagenet
Diffstat (limited to 'src')
-rw-r--r--src/NetworkType.h17
-rw-r--r--src/daemon/DaemonManager.cpp44
-rw-r--r--src/daemon/DaemonManager.h15
-rw-r--r--src/libwalletqt/Wallet.cpp4
-rw-r--r--src/libwalletqt/Wallet.h7
-rw-r--r--src/libwalletqt/WalletManager.cpp36
-rw-r--r--src/libwalletqt/WalletManager.h19
7 files changed, 81 insertions, 61 deletions
diff --git a/src/NetworkType.h b/src/NetworkType.h
new file mode 100644
index 00000000..c0dd9bba
--- /dev/null
+++ b/src/NetworkType.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <QObject>
+#include <wallet/api/wallet2_api.h>
+
+class NetworkType : public QObject
+{
+ Q_OBJECT
+
+public:
+ enum Type : uint8_t {
+ MAINNET = Monero::MAINNET,
+ TESTNET = Monero::TESTNET,
+ STAGENET = Monero::STAGENET
+ };
+ Q_ENUM(Type)
+};
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<bool> future = QtConcurrent::run(this, &DaemonManager::startWatcher, testnet);
+ QFuture<bool> future = QtConcurrent::run(this, &DaemonManager::startWatcher, nettype);
QFutureWatcher<bool> * watcher = new QFutureWatcher<bool>();
connect(watcher, &QFutureWatcher<bool>::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<bool> future = QtConcurrent::run(this, &DaemonManager::stopWatcher, testnet);
+ QFuture<bool> future = QtConcurrent::run(this, &DaemonManager::stopWatcher, nettype);
QFutureWatcher<bool> * watcher = new QFutureWatcher<bool>();
connect(watcher, &QFutureWatcher<bool>::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 <QUrl>
#include <QProcess>
#include <QVariantMap>
+#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;
diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp
index c29de270..14541f65 100644
--- a/src/libwalletqt/Wallet.cpp
+++ b/src/libwalletqt/Wallet.cpp
@@ -102,9 +102,9 @@ Wallet::Status Wallet::status() const
return static_cast<Status>(m_walletImpl->status());
}
-bool Wallet::testnet() const
+NetworkType::Type Wallet::nettype() const
{
- return m_walletImpl->testnet();
+ return static_cast<NetworkType::Type>(m_walletImpl->nettype());
}
diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h
index c8e78339..82e11ec3 100644
--- a/src/libwalletqt/Wallet.h
+++ b/src/libwalletqt/Wallet.h
@@ -9,6 +9,7 @@
#include "wallet/api/wallet2_api.h" // we need to have an access to the Monero::Wallet::Status enum here;
#include "PendingTransaction.h" // we need to have an access to the PendingTransaction::Priority enum here;
#include "UnsignedTransaction.h"
+#include "NetworkType.h"
namespace Monero {
class Wallet; // forward declaration
@@ -29,7 +30,7 @@ class Wallet : public QObject
Q_PROPERTY(QString seed READ getSeed)
Q_PROPERTY(QString seedLanguage READ getSeedLanguage)
Q_PROPERTY(Status status READ status)
- Q_PROPERTY(bool testnet READ testnet)
+ Q_PROPERTY(NetworkType::Type nettype READ nettype)
// Q_PROPERTY(ConnectionStatus connected READ connected)
Q_PROPERTY(quint32 currentSubaddressAccount READ currentSubaddressAccount)
Q_PROPERTY(bool synchronized READ synchronized)
@@ -82,8 +83,8 @@ public:
//! returns last operation's status
Status status() const;
- //! returns true testnet wallet.
- bool testnet() const;
+ //! returns network type of the wallet.
+ NetworkType::Type nettype() const;
//! returns whether the wallet is connected, and version status
Q_INVOKABLE ConnectionStatus connected(bool forceCheck = false);
diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp
index 7985c32e..189c0499 100644
--- a/src/libwalletqt/WalletManager.cpp
+++ b/src/libwalletqt/WalletManager.cpp
@@ -25,7 +25,7 @@ WalletManager *WalletManager::instance()
}
Wallet *WalletManager::createWallet(const QString &path, const QString &password,
- const QString &language, bool testnet)
+ const QString &language, NetworkType::Type nettype)
{
QMutexLocker locker(&m_mutex);
if (m_currentWallet) {
@@ -33,22 +33,22 @@ Wallet *WalletManager::createWallet(const QString &path, const QString &password
delete m_currentWallet;
}
Monero::Wallet * w = m_pimpl->createWallet(path.toStdString(), password.toStdString(),
- language.toStdString(), testnet);
+ language.toStdString(), static_cast<Monero::NetworkType>(nettype));
m_currentWallet = new Wallet(w);
return m_currentWallet;
}
-Wallet *WalletManager::openWallet(const QString &path, const QString &password, bool testnet)
+Wallet *WalletManager::openWallet(const QString &path, const QString &password, NetworkType::Type nettype)
{
QMutexLocker locker(&m_mutex);
if (m_currentWallet) {
qDebug() << "Closing open m_currentWallet" << m_currentWallet;
delete m_currentWallet;
}
- qDebug("%s: opening wallet at %s, testnet = %d ",
- __PRETTY_FUNCTION__, qPrintable(path), testnet);
+ qDebug("%s: opening wallet at %s, nettype = %d ",
+ __PRETTY_FUNCTION__, qPrintable(path), nettype);
- Monero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), testnet);
+ Monero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), static_cast<Monero::NetworkType>(nettype));
qDebug("%s: opened wallet: %s, status: %d", __PRETTY_FUNCTION__, w->address(0, 0).c_str(), w->status());
m_currentWallet = new Wallet(w);
@@ -60,10 +60,10 @@ Wallet *WalletManager::openWallet(const QString &path, const QString &password,
return m_currentWallet;
}
-void WalletManager::openWalletAsync(const QString &path, const QString &password, bool testnet)
+void WalletManager::openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype)
{
QFuture<Wallet*> future = QtConcurrent::run(this, &WalletManager::openWallet,
- path, password, testnet);
+ path, password, nettype);
QFutureWatcher<Wallet*> * watcher = new QFutureWatcher<Wallet*>();
connect(watcher, &QFutureWatcher<Wallet*>::finished,
@@ -76,19 +76,19 @@ void WalletManager::openWalletAsync(const QString &path, const QString &password
}
-Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, bool testnet, quint64 restoreHeight)
+Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, NetworkType::Type nettype, quint64 restoreHeight)
{
QMutexLocker locker(&m_mutex);
if (m_currentWallet) {
qDebug() << "Closing open m_currentWallet" << m_currentWallet;
delete m_currentWallet;
}
- Monero::Wallet * w = m_pimpl->recoveryWallet(path.toStdString(), memo.toStdString(), testnet, restoreHeight);
+ Monero::Wallet * w = m_pimpl->recoveryWallet(path.toStdString(), memo.toStdString(), static_cast<Monero::NetworkType>(nettype), restoreHeight);
m_currentWallet = new Wallet(w);
return m_currentWallet;
}
-Wallet *WalletManager::createWalletFromKeys(const QString &path, const QString &language, bool testnet,
+Wallet *WalletManager::createWalletFromKeys(const QString &path, const QString &language, NetworkType::Type nettype,
const QString &address, const QString &viewkey, const QString &spendkey,
quint64 restoreHeight)
{
@@ -98,7 +98,7 @@ Wallet *WalletManager::createWalletFromKeys(const QString &path, const QString &
delete m_currentWallet;
m_currentWallet = NULL;
}
- Monero::Wallet * w = m_pimpl->createWalletFromKeys(path.toStdString(), language.toStdString(), testnet, restoreHeight,
+ Monero::Wallet * w = m_pimpl->createWalletFromKeys(path.toStdString(), language.toStdString(), static_cast<Monero::NetworkType>(nettype), restoreHeight,
address.toStdString(), viewkey.toStdString(), spendkey.toStdString());
m_currentWallet = new Wallet(w);
return m_currentWallet;
@@ -196,24 +196,24 @@ bool WalletManager::paymentIdValid(const QString &payment_id) const
return Monero::Wallet::paymentIdValid(payment_id.toStdString());
}
-bool WalletManager::addressValid(const QString &address, bool testnet) const
+bool WalletManager::addressValid(const QString &address, NetworkType::Type nettype) const
{
- return Monero::Wallet::addressValid(address.toStdString(), testnet);
+ return Monero::Wallet::addressValid(address.toStdString(), static_cast<Monero::NetworkType>(nettype));
}
-bool WalletManager::keyValid(const QString &key, const QString &address, bool isViewKey, bool testnet) const
+bool WalletManager::keyValid(const QString &key, const QString &address, bool isViewKey, NetworkType::Type nettype) const
{
std::string error;
- if(!Monero::Wallet::keyValid(key.toStdString(), address.toStdString(), isViewKey, testnet, error)){
+ if(!Monero::Wallet::keyValid(key.toStdString(), address.toStdString(), isViewKey, static_cast<Monero::NetworkType>(nettype), error)){
qDebug() << QString::fromStdString(error);
return false;
}
return true;
}
-QString WalletManager::paymentIdFromAddress(const QString &address, bool testnet) const
+QString WalletManager::paymentIdFromAddress(const QString &address, NetworkType::Type nettype) const
{
- return QString::fromStdString(Monero::Wallet::paymentIdFromAddress(address.toStdString(), testnet));
+ return QString::fromStdString(Monero::Wallet::paymentIdFromAddress(address.toStdString(), static_cast<Monero::NetworkType>(nettype)));
}
void WalletManager::setDaemonAddress(const QString &address)
diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h
index 75662710..ebf74a17 100644
--- a/src/libwalletqt/WalletManager.h
+++ b/src/libwalletqt/WalletManager.h
@@ -6,6 +6,7 @@
#include <wallet/api/wallet2_api.h>
#include <QMutex>
#include <QPointer>
+#include "NetworkType.h"
class Wallet;
namespace Monero {
@@ -32,30 +33,30 @@ public:
static WalletManager * instance();
// wizard: createWallet path;
Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password,
- const QString &language, bool testnet = false);
+ const QString &language, NetworkType::Type nettype = NetworkType::MAINNET);
/*!
* \brief openWallet - opens wallet by given path
* \param path - wallet filename
* \param password - wallet password. Empty string in wallet isn't password protected
- * \param testnet - determines if we running testnet
+ * \param nettype - type of network the wallet is running on
* \return wallet object pointer
*/
- Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, bool testnet = false);
+ Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET);
/*!
* \brief openWalletAsync - asynchronous version of "openWallet". Returns immediately. "walletOpened" signal
* emitted when wallet opened;
*/
- Q_INVOKABLE void openWalletAsync(const QString &path, const QString &password, bool testnet = false);
+ Q_INVOKABLE void openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET);
// wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = ""
Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo,
- bool testnet = false, quint64 restoreHeight = 0);
+ NetworkType::Type nettype = NetworkType::MAINNET, quint64 restoreHeight = 0);
Q_INVOKABLE Wallet * createWalletFromKeys(const QString &path,
const QString &language,
- bool testnet,
+ NetworkType::Type nettype,
const QString &address,
const QString &viewkey,
const QString &spendkey = "",
@@ -99,10 +100,10 @@ public:
Q_INVOKABLE QString maximumAllowedAmountAsSting() const;
Q_INVOKABLE bool paymentIdValid(const QString &payment_id) const;
- Q_INVOKABLE bool addressValid(const QString &address, bool testnet) const;
- Q_INVOKABLE bool keyValid(const QString &key, const QString &address, bool isViewKey, bool testnet) const;
+ Q_INVOKABLE bool addressValid(const QString &address, NetworkType::Type nettype) const;
+ Q_INVOKABLE bool keyValid(const QString &key, const QString &address, bool isViewKey, NetworkType::Type nettype) const;
- Q_INVOKABLE QString paymentIdFromAddress(const QString &address, bool testnet) const;
+ Q_INVOKABLE QString paymentIdFromAddress(const QString &address, NetworkType::Type nettype) const;
Q_INVOKABLE void setDaemonAddress(const QString &address);
Q_INVOKABLE bool connected() const;