From a41908f1c20fde00bbd59caed4df7f33e24c27ec Mon Sep 17 00:00:00 2001 From: "littletux89@gmail.com" <littletux89@gmail.com> Date: Thu, 23 Jan 2020 09:15:35 +0300 Subject: [PATCH] [+] Added commands. --- .../DapServiceController.cpp | 4 + CellFrameDashboardGUI/DapServiceController.h | 6 + .../screen/DapMainApplicationWindow.qml | 3 +- .../desktop/Dashboard/DapDashboardScreen.qml | 2 + .../Dashboard/DapDashboardTopPanel.qml | 16 +- .../DapServiceController.cpp | 4 + .../DapServiceController.h | 2 + .../DapChainWallet.cpp | 177 -------------- libCellFrameDashboardCommon/DapChainWallet.h | 228 ------------------ libCellFrameDashboardCommon/DapWallet.cpp | 47 ++++ libCellFrameDashboardCommon/DapWallet.h | 30 +++ .../DapWalletToken.cpp | 7 + libCellFrameDashboardCommon/DapWalletToken.h | 21 ++ .../Handlers/DapAddWalletCommand.cpp | 52 ++-- .../Handlers/DapAddWalletCommand.h | 13 +- .../Handlers/DapGetListWalletsCommand.cpp | 92 +++++++ .../Handlers/DapGetListWalletsCommand.h | 32 +++ .../libCellFrameDashboardCommon.pri | 8 +- 18 files changed, 286 insertions(+), 458 deletions(-) delete mode 100755 libCellFrameDashboardCommon/DapChainWallet.cpp delete mode 100755 libCellFrameDashboardCommon/DapChainWallet.h create mode 100644 libCellFrameDashboardCommon/DapWallet.cpp create mode 100644 libCellFrameDashboardCommon/DapWallet.h create mode 100644 libCellFrameDashboardCommon/DapWalletToken.cpp create mode 100644 libCellFrameDashboardCommon/DapWalletToken.h create mode 100644 libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp create mode 100644 libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.h diff --git a/CellFrameDashboardGUI/DapServiceController.cpp b/CellFrameDashboardGUI/DapServiceController.cpp index f5ef4b1..6f2a209 100644 --- a/CellFrameDashboardGUI/DapServiceController.cpp +++ b/CellFrameDashboardGUI/DapServiceController.cpp @@ -81,6 +81,10 @@ void DapServiceController::registerCommand() m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapActivateClientCommand("DapActivateClientCommand", m_DAPRpcSocket))), QString("clientActivated"))); // Log update command on the Logs tab m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapUpdateLogsCommand("DapUpdateLogsCommand", m_DAPRpcSocket))), QString("logUpdated"))); + // The team to create a new wallet on the Dashboard tab + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapAddWalletCommand("DapAddWalletCommand", m_DAPRpcSocket))), QString("walletCreated"))); + // The command to get a list of available wallets + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapGetListWalletsCommand("DapGetListWalletsCommand", m_DAPRpcSocket))), QString("walletsListReceived"))); registerEmmitedSignal(); } diff --git a/CellFrameDashboardGUI/DapServiceController.h b/CellFrameDashboardGUI/DapServiceController.h index 080fa97..fc2f658 100644 --- a/CellFrameDashboardGUI/DapServiceController.h +++ b/CellFrameDashboardGUI/DapServiceController.h @@ -13,6 +13,8 @@ #include "Handlers/DapQuitApplicationCommand.h" #include "Handlers/DapActivateClientCommand.h" #include "Handlers/DapUpdateLogsCommand.h" +#include "Handlers/DapAddWalletCommand.h" +#include "Handlers/DapGetListWalletsCommand.h" class DapServiceController : public QObject { @@ -84,6 +86,10 @@ signals: /// A signal that is used to transmit data to the log model. /// @param historyString QStringList void logUpdated(const QVariant& logs); + + void walletCreated(const QVariant& wallet); + + void walletsListReceived(const QVariant& wallet); private slots: /// Register command. diff --git a/CellFrameDashboardGUI/screen/DapMainApplicationWindow.qml b/CellFrameDashboardGUI/screen/DapMainApplicationWindow.qml index f7debc1..19caabf 100644 --- a/CellFrameDashboardGUI/screen/DapMainApplicationWindow.qml +++ b/CellFrameDashboardGUI/screen/DapMainApplicationWindow.qml @@ -23,7 +23,8 @@ DapMainApplicationWindowForm { id: modelMenuTab - Component.onCompleted: { + Component.onCompleted: + { append({ name: qsTr("Dashboard"), diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml index 7d0c1ea..59be756 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml @@ -3,4 +3,6 @@ import QtQuick 2.4 DapDashboardScreenForm { buttonTest.onClicked: textTest.text = "DESKTOP " + textTest.font.pointSize + " " + textTest.font.pixelSize + + } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml index 85c6f9e..7f84bb6 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml @@ -10,18 +10,24 @@ DapDashboardTopPanelForm Connections { target: dapServiceController - onAddWalletResponded: updateModel(wallet) + onWalletCreated: + { + if(wallet[0] === true) + updateModel(wallet) + else + console.log(wallet[1]) + } } function updateModel(wallet) { - console.log(wallet) - if(wallet[1] === "created") - modelWallets.append({ "name" : wallet[0] }) + console.log(wallet[2]) + modelWallets.append({ "name" : wallet[1]}) } dapAddWalletButton.onClicked: { - dapServiceController.requestToService("ADD", "MYNEWWALLET"); +// dapServiceController.requestToService("DapAddWalletCommand", "MYNEWWALLET5", "sig_dil", "kelvin-testnet", "0xad12dec5ab4f"); + dapServiceController.requestToService("DapGetListWalletsCommand", "kelvin-testnet"); } } diff --git a/CellFrameDashboardService/DapServiceController.cpp b/CellFrameDashboardService/DapServiceController.cpp index 2ce4115..26d6b7e 100755 --- a/CellFrameDashboardService/DapServiceController.cpp +++ b/CellFrameDashboardService/DapServiceController.cpp @@ -50,6 +50,10 @@ void DapServiceController::registerCommand() m_pServer->addService(new DapActivateClientCommand("DapActivateClientCommand", m_pServer)); // Log update command on the Logs tab m_pServer->addService(new DapUpdateLogsCommand("DapUpdateLogsCommand", m_pServer, LOG_FILE)); + // The team to create a new wallet on the Dashboard tab + m_pServer->addService(new DapAddWalletCommand("DapAddWalletCommand", m_pServer)); + // The command to get a list of available wallets + m_pServer->addService(new DapGetListWalletsCommand("DapGetListWalletsCommand", m_pServer)); } /// Initialize system tray. diff --git a/CellFrameDashboardService/DapServiceController.h b/CellFrameDashboardService/DapServiceController.h index 8a3c989..95fae1a 100755 --- a/CellFrameDashboardService/DapServiceController.h +++ b/CellFrameDashboardService/DapServiceController.h @@ -27,6 +27,8 @@ typedef class DapRpcLocalServer DapUiService; #include "Handlers/DapQuitApplicationCommand.h" #include "Handlers/DapActivateClientCommand.h" #include "Handlers/DapUpdateLogsCommand.h" +#include "Handlers/DapAddWalletCommand.h" +#include "Handlers/DapGetListWalletsCommand.h" #include "DapSystemTrayIcon.h" #include "DapToolTipWidget.h" diff --git a/libCellFrameDashboardCommon/DapChainWallet.cpp b/libCellFrameDashboardCommon/DapChainWallet.cpp deleted file mode 100755 index 2fa9c8c..0000000 --- a/libCellFrameDashboardCommon/DapChainWallet.cpp +++ /dev/null @@ -1,177 +0,0 @@ -#include "DapChainWallet.h" - -DapChainWalletTokenItem::DapChainWalletTokenItem(const QString& aWalletAddress, QObject* parent) : - QObject(parent), - m_wallet(aWalletAddress) -{ - -} - -DapChainWalletTokenItem::DapChainWalletTokenItem(const QString& aWalletAddress, const DapChainWalletTokenData& aData, QObject* parent) : - QObject(parent) -{ - m_wallet = aWalletAddress; - m_name = aData.Name; - m_balance = aData.Balance; - m_emission = aData.Emission; -} - -QString DapChainWalletTokenItem::name() const -{ - return m_name; -} - -double DapChainWalletTokenItem::balance() const -{ - return m_balance; -} - -quint64 DapChainWalletTokenItem::emission() const -{ - return m_emission; -} - -QString DapChainWalletTokenItem::wallet() const -{ - return m_wallet; -} - -void DapChainWalletTokenItem::setName(const QString& aName) -{ - if (m_name == aName) return; - m_name = aName; - emit nameChanged(aName); -} - -void DapChainWalletTokenItem::setBalance(const double aBalance) -{ - qWarning("Floating point comparison needs context sanity check"); - if (qFuzzyCompare(m_balance, aBalance)) - return; - - m_balance = aBalance; - emit balanceChanged(m_balance); -} - -void DapChainWalletTokenItem::setEmission(const quint64 aEmission) -{ - if (m_emission == aEmission) - return; - - m_emission = aEmission; - emit emissionChanged(m_emission); -} - -void DapChainWalletTokenItem::setData(const DapChainWalletTokenData& aData) -{ - setName(aData.Name); - setBalance(aData.Balance); - setEmission(aData.Emission); -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -DapChainWallet::DapChainWallet(const QString &asIconPath, const QString &asName, const QString &asAddress, const QStringList &aBalance, const QStringList &aTokens, QObject *parent) - : QObject(parent), m_sIconPath(asIconPath), m_sName(asName), m_sAddress(asAddress), m_balance(aBalance), m_tokens(aTokens) -{ - -} - -DapChainWallet::DapChainWallet(const QString &asIconPath, const QString &asName, const QString &asAddress, QObject *parent) - : DapChainWallet(asIconPath, asName, asAddress, QStringList(), QStringList(), parent) -{ - -} - -QString DapChainWallet::getIconPath() const -{ - return m_sIconPath; -} - -void DapChainWallet::setIconPath(const QString &asIconPath) -{ - m_sIconPath = asIconPath; - - emit iconPathChanged(m_sIconPath); -} - -QString DapChainWallet::getName() const -{ - return m_sName; -} - -void DapChainWallet::setName(const QString &asName) -{ - m_sName = asName; - - emit nameChanged(m_sName); -} - -QString DapChainWallet::getAddress() const -{ - return m_sAddress; -} - -void DapChainWallet::setAddress(const QString &asAddress) -{ - m_sAddress = asAddress; - - emit addressChanged(m_sAddress); -} - -QStringList DapChainWallet::getBalance() const -{ - return m_balance; -} - -void DapChainWallet::setBalance(const QStringList &aBalance) -{ - m_balance = aBalance; - - emit balanceChanged(m_balance); -} - -QStringList DapChainWallet::getTokens() const -{ - return m_tokens; -} - -void DapChainWallet::setTokens(const QStringList &aTokens) -{ - m_tokens = aTokens; - - emit tokensChanged(m_tokens); -} - -int DapChainWallet::getCount() const -{ - return m_tokens.count(); -} - - diff --git a/libCellFrameDashboardCommon/DapChainWallet.h b/libCellFrameDashboardCommon/DapChainWallet.h deleted file mode 100755 index cab79e5..0000000 --- a/libCellFrameDashboardCommon/DapChainWallet.h +++ /dev/null @@ -1,228 +0,0 @@ -#ifndef DAPCHAINWALLET_H -#define DAPCHAINWALLET_H - -#include <QObject> -#include <QString> -#include <QList> -#include <QDataStream> - -struct DapChainWalletData -{ - QString IconPath; - QString Name; - QString Address; - QString Network; - - friend QDataStream& operator << (QDataStream& aOut, const DapChainWalletData& aData) - { - aOut << aData.IconPath - << aData.Name - << aData.Address - << aData.Network; - return aOut; - } - - friend QDataStream& operator >> (QDataStream& aOut, DapChainWalletData& aData) - { - aOut >> aData.IconPath - >> aData.Name - >> aData.Address - >> aData.Network; - return aOut; - } - - DapChainWalletData& operator = (const DapChainWalletData& aData) - { - IconPath = aData.IconPath; - Name = aData.Name; - Address = aData.Address; - Network = aData.Network; - return *this; - } - - bool operator == (const DapChainWalletData& aData) const { - return IconPath == aData.IconPath && - Name == aData.Name && - Address == aData.Address && - Network == aData.Network; - } -}; - -struct DapChainWalletTokenData { - QString Name; - double Balance; - quint64 Emission; - - friend QDataStream& operator << (QDataStream& aOut, const DapChainWalletTokenData& aData) - { - aOut << aData.Name - << aData.Balance - << aData.Emission; - return aOut; - } - - friend QDataStream& operator >> (QDataStream& aOut, DapChainWalletTokenData& aData) - { - aOut >> aData.Name - >> aData.Balance - >> aData.Emission; - return aOut; - } - - DapChainWalletTokenData& operator = (const DapChainWalletTokenData& aData) - { - Name = aData.Name; - Balance = aData.Balance; - Emission = aData.Emission; - return *this; - } - - bool operator == (const DapChainWalletTokenData& aData) const { - return Name == aData.Name; - } -}; - -class DapChainWalletTokenItem : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(double balance READ balance WRITE setBalance NOTIFY balanceChanged) - Q_PROPERTY(quint64 emission READ emission WRITE setEmission NOTIFY emissionChanged) - Q_PROPERTY(QString wallet READ wallet) - -private: - QString m_wallet; - QString m_name; - double m_balance; - quint64 m_emission; - -public: - explicit DapChainWalletTokenItem(const QString& aWalletAddress, QObject *parent = nullptr); - explicit DapChainWalletTokenItem(const QString& aWalletAddress, const DapChainWalletTokenData& aData, QObject *parent = nullptr); - - QString name() const; - double balance() const; - quint64 emission() const; - QString wallet() const; - -public slots: - void setName(const QString& aName); - void setBalance(const double aBalance); - void setEmission(const quint64 aEmission); - void setData(const DapChainWalletTokenData& aData); - -signals: - void nameChanged(QString name); - void balanceChanged(double balance); - void emissionChanged(quint64 emission); -}; - -typedef QList<DapChainWalletTokenItem*> DapChainWalletTokenItemList; -typedef QList<DapChainWalletTokenData> DapChainWalletTokenList; -typedef QPair<DapChainWalletData, DapChainWalletTokenItemList> DapChainWalletPair; - - - - - - - - -class DapChainWallet : public QObject -{ - Q_OBJECT - - /// Icon path - QString m_sIconPath; - /// Name of wallet - QString m_sName; - /// Address of wallet - QString m_sAddress; - /// Balance - QStringList m_balance; - /// Tokens name - QStringList m_tokens; - /// number of tokens - int m_iCount; - -public: - /// Standard constructor - DapChainWallet(QObject *parent = nullptr) { Q_UNUSED(parent)} - /// overloaded constructor - /// @param asIconPath Path icon - /// @param asName Name of wallet - /// @param asAddresss Address for wallet - /// @param aBalance Balance - /// @param aTokens Tokens name - DapChainWallet(const QString& asIconPath, const QString &asName, const QString &asAddress, const QStringList &aBalance, const QStringList& aTokens, QObject * parent = nullptr); - /// overloaded constructor - /// @param asIconPath Path icon - /// @param asName Name of wallet - /// @param asAddresss Address for wallet - DapChainWallet(const QString& asIconPath, const QString &asName, const QString &asAddress, QObject * parent = nullptr); - - - Q_PROPERTY(QString iconPath MEMBER m_sIconPath READ getIconPath WRITE setIconPath NOTIFY iconPathChanged) - Q_PROPERTY(QString name MEMBER m_sName READ getName WRITE setName NOTIFY nameChanged) - Q_PROPERTY(QString address MEMBER m_sAddress READ getAddress WRITE setAddress NOTIFY addressChanged) - Q_PROPERTY(QStringList balance MEMBER m_balance READ getBalance WRITE setBalance NOTIFY balanceChanged) - Q_PROPERTY(QStringList tokens MEMBER m_tokens READ getTokens WRITE setTokens NOTIFY tokensChanged) - Q_PROPERTY(int count MEMBER m_iCount READ getCount) - - /// Get name of wallet - /// @return name of wallet - QString getName() const; - /// Set name of wallet - /// @param asName name of wallet - void setName(const QString &asName); - /// Get address of wallet - /// @return Address of wallet - QString getAddress() const; - /// Set address for wallet - /// @param asAddress address for wallet - void setAddress(const QString &asAddress); - - /// Get icon path - /// @return Icon path - QString getIconPath() const; - /// Set icon path - /// @param asIconPath Icon path - void setIconPath(const QString &asIconPath); - - /// Get balance - QStringList getBalance() const; - /// Set balance - void setBalance(const QStringList& aBalance); - - /// Get tokens name - /// @return tokens name - QStringList getTokens() const; - /// Set tokens name - /// @param aTokens tokens name - void setTokens(const QStringList& aTokens); - - /// get number of tokens - /// @return number of tokens - int getCount() const; - -signals: - /// Signal changes for icon path - /// @param asIconPath Icon path - void iconPathChanged(const QString& asIconPath); - /// Signal changes for name of wallet - /// @param asName name of wallet - void nameChanged(const QString& asName); - /// Signal changes for address of wallet - /// @param asAddress address of wallet - void addressChanged(const QString& asAddress); - /// Signal changes for balance - /// @param aBalance balance - void balanceChanged(const QStringList& aBalance); - /// Signal changes for tokens - /// @param aTokens tokens name - void tokensChanged(const QStringList& aTokens); - -}; - -#endif // DAPCHAINWALLET_H diff --git a/libCellFrameDashboardCommon/DapWallet.cpp b/libCellFrameDashboardCommon/DapWallet.cpp new file mode 100644 index 0000000..52c5904 --- /dev/null +++ b/libCellFrameDashboardCommon/DapWallet.cpp @@ -0,0 +1,47 @@ +#include "DapWallet.h" + +DapWallet::DapWallet(const QString &asName) + : m_name(asName) +{ + +} + +void DapWallet::addNetwork(const QString &asNetwork) +{ + m_networks.append(asNetwork); +} + +QList<QString> &DapWallet::getNetworks() +{ + return m_networks; +} + +void DapWallet::setAddress(const QString& aiAddress, const QString &asNetwork) +{ + m_iAddress.insert(asNetwork, aiAddress); +} + +QString DapWallet::getAddress(const QString &asNetwork) +{ + return m_iAddress.find(asNetwork).value(); +} + +void DapWallet::addToken(const DapWalletToken &aToken, const QString &asNetwork) +{ + m_aTokens.insert(asNetwork, aToken); +} + +QList<DapWalletToken *> DapWallet::getTokens(const QString &asNetwork) +{ + QList<DapWalletToken *> tokens; + auto begin = m_aTokens.begin(); + auto end = m_aTokens.end(); + for(;begin != end; ++begin) + { + if(begin.key() == asNetwork) + { + tokens.append(&begin.value()); + } + } + return tokens; +} diff --git a/libCellFrameDashboardCommon/DapWallet.h b/libCellFrameDashboardCommon/DapWallet.h new file mode 100644 index 0000000..faabd37 --- /dev/null +++ b/libCellFrameDashboardCommon/DapWallet.h @@ -0,0 +1,30 @@ +#ifndef DAPWALLET_H +#define DAPWALLET_H + +#include <QString> +#include <QList> + +#include "DapWalletToken.h" + +class DapWallet +{ + QString m_name; + QList<QString> m_networks; + QMap<QString, QString> m_iAddress; + QMultiMap<QString, DapWalletToken> m_aTokens; + +public: + DapWallet(const QString& asName); + + void addNetwork(const QString& asNetwork); + QList<QString>& getNetworks(); + void setAddress(const QString &aiAddress, const QString& asNetwork); + QString getAddress(const QString& asNetwork); + void addToken(const DapWalletToken& asName, const QString& asNetwork); + QList<DapWalletToken*> getTokens(const QString& asNetwork); + + + +}; + +#endif // DAPWALLET_H diff --git a/libCellFrameDashboardCommon/DapWalletToken.cpp b/libCellFrameDashboardCommon/DapWalletToken.cpp new file mode 100644 index 0000000..04b2def --- /dev/null +++ b/libCellFrameDashboardCommon/DapWalletToken.cpp @@ -0,0 +1,7 @@ +#include "DapWalletToken.h" + +DapWalletToken::DapWalletToken(const QString &asName) + : m_sName(asName) +{ + +} diff --git a/libCellFrameDashboardCommon/DapWalletToken.h b/libCellFrameDashboardCommon/DapWalletToken.h new file mode 100644 index 0000000..99eb270 --- /dev/null +++ b/libCellFrameDashboardCommon/DapWalletToken.h @@ -0,0 +1,21 @@ +#ifndef DAPWALLETTOKEN_H +#define DAPWALLETTOKEN_H + +#include <QString> + +struct DapWalletToken +{ + /// Token name. + QString m_sName; + /// Token balance. + double m_dBalance {0.0}; + /// Token emission. + quint64 m_iEmission {0}; + /// Network. + QString m_sNetwork; + +public: + explicit DapWalletToken(const QString& asName = QString()); +}; + +#endif // DAPWALLETTOKEN_H diff --git a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp index 8fd108a..514c596 100644 --- a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp +++ b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp @@ -2,37 +2,16 @@ /// Overloaded constructor. /// @param asServiceName Service name. -/// @param apSocket Client connection socket with service. /// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. DapAddWalletCommand::DapAddWalletCommand(const QString &asServicename, QObject *parent) : DapAbstractCommand(asServicename, parent) { } -/// Send a response to the service. -/// @param arg1...arg10 Parameters. -/// @return Reply to service. -QVariant DapAddWalletCommand::respondToService(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, - const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, - const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, - const QVariant &arg10) -{ - Q_UNUSED(arg1) - Q_UNUSED(arg2) - Q_UNUSED(arg3) - Q_UNUSED(arg4) - Q_UNUSED(arg5) - Q_UNUSED(arg6) - Q_UNUSED(arg7) - Q_UNUSED(arg8) - Q_UNUSED(arg9) - Q_UNUSED(arg10) - - return QVariant(); -} - /// Send a response to the client. +/// @details Performed on the service side. /// @param arg1...arg10 Parameters. /// @return Reply to client. QVariant DapAddWalletCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, @@ -40,10 +19,6 @@ QVariant DapAddWalletCommand::respondToClient(const QVariant &arg1, const QVaria const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) { - Q_UNUSED(arg1) - Q_UNUSED(arg2) - Q_UNUSED(arg3) - Q_UNUSED(arg4) Q_UNUSED(arg5) Q_UNUSED(arg6) Q_UNUSED(arg7) @@ -51,14 +26,21 @@ QVariant DapAddWalletCommand::respondToClient(const QVariant &arg1, const QVaria Q_UNUSED(arg9) Q_UNUSED(arg10) - QByteArray result; QProcess process; - process.start(QString("%1 wallet new -w %2").arg(CLI_PATH).arg(arg1.toString())); + QJsonArray result; + process.start(QString("%1 wallet new -w %2 -sign %3 -net %4 -restore %5").arg(CLI_PATH).arg(arg1.toString()).arg(arg2.toString()).arg(arg3.toString()).arg(arg4.toString())); process.waitForFinished(-1); - result = process.readAll(); - QStringList res = QString::fromLatin1(result).split(" "); - QStringList list; - list.append(arg1.toString()); - list.append(res.at(res.size()-1).trimmed()); - return result.isEmpty() ? QStringList() : list; + QString res = QString::fromLatin1(process.readAll()); + if(res.contains("already exists")) + { + result.append(QJsonValue(false)); + result.append(QJsonValue("Wallet already exists")); + } + else + { + result.append(QJsonValue(true)); + result.append(QJsonValue(arg1.toString())); + result.append(QJsonValue("Wallet successfully created")); + } + return result.toVariantList(); } diff --git a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h index f7892ca..ea649f5 100644 --- a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h +++ b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h @@ -2,7 +2,7 @@ ** ** This file is part of the libCellFrameDashboardClient library. ** -** The class implements the "Add wallet" command interface. +** The class implements the functionality of creating a new wallet. ** ****************************************************************************/ @@ -19,20 +19,13 @@ class DapAddWalletCommand : public DapAbstractCommand public: /// Overloaded constructor. /// @param asServiceName Service name. - /// @param apSocket Client connection socket with service. /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. explicit DapAddWalletCommand(const QString &asServicename, QObject *parent = nullptr); public slots: - /// Send a response to the service. - /// @param arg1...arg10 Parameters. - /// @return Reply to service. - QVariant respondToService(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), - const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), - const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), - const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), - const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()); /// Send a response to the client. + /// @details Performed on the service side. /// @param arg1...arg10 Parameters. /// @return Reply to client. QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), diff --git a/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp new file mode 100644 index 0000000..58a60b1 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp @@ -0,0 +1,92 @@ +#include "DapGetListWalletsCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +DapGetListWalletsCommand::DapGetListWalletsCommand(const QString &asServicename, QObject *parent) + : DapAbstractCommand(asServicename, parent) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetListWalletsCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, + const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg4) + Q_UNUSED(arg8) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QList<DapWallet> wallets; + + QStringList list = arg1.toStringList(); + QProcess process; + process.start(QString("%1 wallet list").arg(CLI_PATH)); + process.waitForFinished(-1); + QString res = QString::fromLatin1(process.readAll()); + QRegularExpression rx("wallet:\\s(.+)\\s", QRegularExpression::MultilineOption); + QRegularExpressionMatchIterator itr = rx.globalMatch(res); + while (itr.hasNext()) + { + QRegularExpressionMatch match = itr.next(); + QString walletName = match.captured(1); + + auto begin = list.begin(); + auto end = list.end(); + for(; begin != end; ++begin) + { + DapWallet wallet(walletName); + wallet.addNetwork(*begin); + + QProcess process_token; + process_token.start(QString("%1 wallet info -w %2 -net %3") + .arg(CLI_PATH) + .arg(walletName) + .arg(*begin)); + + process_token.waitForFinished(-1); + QByteArray result_tokens = process_token.readAll(); + QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); + + int pos = 0; + while((pos = regex.indexIn(result_tokens, pos)) != -1) + { + DapWalletToken token; + if(!regex.cap(2).isEmpty()) + { + wallet.setAddress(regex.cap(2), *begin); + } + else + { + + token.m_sName = regex.cap(6); + token.m_dBalance = regex.cap(4).toDouble(); + token.m_sNetwork = *begin; + token.m_iEmission = regex.cap(5).toUInt(); + } + + pos += regex.matchedLength(); + } + wallets.append(wallet); + } + } +// if(m_walletList != walletList) +// { +// m_walletList = walletList; +// emit walletDataChanged(walletData()); +// } + return QVariant(); +} diff --git a/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.h b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.h new file mode 100644 index 0000000..ff75853 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.h @@ -0,0 +1,32 @@ +#ifndef DAPGETLISTWALLETSCOMMAND_H +#define DAPGETLISTWALLETSCOMMAND_H + +#include <QProcess> +#include <QRegExp> +#include <QRegularExpression> + +#include "DapWallet.h" +#include "DapAbstractCommand.h" + +class DapGetListWalletsCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + DapGetListWalletsCommand(const QString &asServicename, QObject *parent = nullptr); + +public slots: + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()); +}; + +#endif // DAPGETLISTWALLETSCOMMAND_H diff --git a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri index 17f6e76..7b36bc1 100755 --- a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri +++ b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri @@ -18,10 +18,12 @@ SOURCES +=\ $$PWD/DapHistoryType.cpp \ $$PWD/DapSettings.cpp \ $$PWD/DapLogMessage.cpp \ - $$PWD/DapChainWallet.cpp \ $$PWD/DapSystemTrayIcon.cpp \ + $$PWD/DapWallet.cpp \ + $$PWD/DapWalletToken.cpp \ $$PWD/Handlers/DapAbstractCommand.cpp \ $$PWD/Handlers/DapActivateClientCommand.cpp \ + $$PWD/Handlers/DapGetListWalletsCommand.cpp \ $$PWD/Handlers/DapQuitApplicationCommand.cpp \ $$PWD/Handlers/DapAddWalletCommand.cpp \ $$PWD/Handlers/DapUpdateLogsCommand.cpp @@ -32,11 +34,13 @@ HEADERS +=\ $$PWD/DapHistoryType.h \ $$PWD/DapSettings.h \ $$PWD/DapLogMessage.h \ - $$PWD/DapChainWallet.h \ $$PWD/DapNodeType.h \ $$PWD/DapSystemTrayIcon.h \ + $$PWD/DapWallet.h \ + $$PWD/DapWalletToken.h \ $$PWD/Handlers/DapAbstractCommand.h \ $$PWD/Handlers/DapActivateClientCommand.h \ + $$PWD/Handlers/DapGetListWalletsCommand.h \ $$PWD/Handlers/DapQuitApplicationCommand.h \ $$PWD/Handlers/DapAddWalletCommand.h \ $$PWD/Handlers/DapUpdateLogsCommand.h -- GitLab