diff --git a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro index ed369e4dafc97b419da99227baf14f78996c88bf..65b84e5c3c28067773b0e0b1d722e77ee8f2885b 100755 --- a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro +++ b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro @@ -13,7 +13,7 @@ TARGET = $$BRAND VER_MAJ = 1 VER_MIN = 6 -VER_PAT = 1 +VER_PAT = 2 win32 { diff --git a/CellFrameDashboardGUI/DapChainWalletsModel.cpp b/CellFrameDashboardGUI/DapChainWalletsModel.cpp index ad72f4ef71480dc16a7c61151bc843551aa82715..86d4815bf87c97a026390d0487193dac5c7b69f8 100755 --- a/CellFrameDashboardGUI/DapChainWalletsModel.cpp +++ b/CellFrameDashboardGUI/DapChainWalletsModel.cpp @@ -1,7 +1,7 @@ #include "DapChainWalletsModel.h" -DapChainWalletsModel::DapChainWalletsModel(QObject *parent) +DapChainWalletsModel::DapChainWalletsModel(QObject *parent) : QAbstractListModel(parent) { } diff --git a/CellFrameDashboardGUI/DapCommandController.cpp b/CellFrameDashboardGUI/DapCommandController.cpp index 2bdd5a377bff6f669c51664a1a4c867a73789c18..e3f4591996bb3b07cdd4669fb4a95d206812742a 100755 --- a/CellFrameDashboardGUI/DapCommandController.cpp +++ b/CellFrameDashboardGUI/DapCommandController.cpp @@ -153,23 +153,9 @@ void DapCommandController::processGetWalletInfo() QString name = reply->response().toJsonValue().toVariant().toStringList().at(0); QString address = reply->response().toJsonValue().toVariant().toStringList().at(1); QStringList temp = reply->response().toJsonValue().toVariant().toStringList(); - QStringList tokens; - QStringList balance; - for(int x{2}; x < temp.count(); x++) - { - if(x%2) - { - tokens.append(temp[x]); - qDebug() << "TOKKEN " << temp[x]; - } - else - { - balance.append(temp[x]); - qDebug() << "BALANCE " << temp[x]; - } - } + QStringList tokens = temp.mid(3, temp.count()); - emit sigWalletInfoChanged(name, address, balance, tokens); + emit sigWalletInfoChanged(name, address, QStringList(), tokens); } void DapCommandController::processGetNodeNetwork() diff --git a/CellFrameDashboardGUI/DapServiceClientNativeLinux.cpp b/CellFrameDashboardGUI/DapServiceClientNativeLinux.cpp index fbb5af195eeea9f721b6d5e0cf22e6df8a4edfb4..3a8e46175266f5e91b9b0bd35327eb24626b2a2e 100644 --- a/CellFrameDashboardGUI/DapServiceClientNativeLinux.cpp +++ b/CellFrameDashboardGUI/DapServiceClientNativeLinux.cpp @@ -21,7 +21,7 @@ DapServiceClientNativeLinux::~DapServiceClientNativeLinux() bool DapServiceClientNativeLinux::isServiceRunning() { - m_isServiceRunning = (::system(m_checkIsServiceRunningCommand) == 0); + m_isServiceRunning =true;// (::system(m_checkIsServiceRunningCommand) == 0); return m_isServiceRunning; } diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBar.qml b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBar.qml index 044bd3652aecee5e6cee23c2008c831eedbf90fb..41877dd0e02ae9c940fee55ad928f76655d6ab0f 100644 --- a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBar.qml +++ b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBar.qml @@ -61,6 +61,11 @@ Rectangle { color: "#797979" } + DapUiQmlScreenDialogAddWallet + { + id: dialogAddWallet + } + DapUiQmlWidgetStatusBarButton { width: 130 * pt anchors.right: parent.right @@ -69,6 +74,9 @@ Rectangle { anchors.rightMargin: 20 * pt anchors.bottom: parent.bottom anchors.bottomMargin: 10 * pt + + onClicked: addWallet() + onAddWallet: dialogAddWallet.show() } } } diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarButton.ui.qml b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarButton.ui.qml index 704e93498b63a76242a79fb6481d4553fa3b9d62..5c9560a4f1d795176a2a680a9a1e913700b399c6 100644 --- a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarButton.ui.qml +++ b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarButton.ui.qml @@ -2,6 +2,8 @@ import QtQuick 2.0 import QtQuick.Controls 2.5 Button { + id: button + signal addWallet contentItem: Rectangle { anchors.fill: parent border.color: "#B5B5B5" diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxToken.qml b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxToken.qml index e6fa4db7f7e781fd8c9d5c0fd95f25c453ddc182..4f9e0f595eee3434940084a584a5daccbf677211 100644 --- a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxToken.qml +++ b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxToken.qml @@ -28,7 +28,7 @@ DapUiQmlWidgetStatusBarComboBoxTokenForm { fieldBalance.text = 0; else { - var money = dapChainWalletsModel.get(comboboxWallet.currentIndex).tokens[currentIndex * 2]; + var money = dapChainWalletsModel.get(comboboxWallet.currentIndex).tokens[currentIndex * 3]; fieldBalance.text = dapChainConvertor.toConvertCurrency(money); } } diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml index f6899f524c1ad8712ffa559acc4e9d0a199f26c1..d294cc0cb9bd2502a0eb0e5f00798b9c3edb7979 100644 --- a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml +++ b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml @@ -26,8 +26,8 @@ DapUiQmlWidgetStatusBarComboBoxWalletForm { onCurrentIndexChanged: { listToken.model.clear(); - for(var i = 0; i < dapChainWalletsModel.get(currentIndex).count; i++) - listToken.model.append({"tokenName": dapChainWalletsModel.get(currentIndex).tokens[++i]}); + for(var i = 2; i < dapChainWalletsModel.get(currentIndex).count; i += 3) + listToken.model.append({"tokenName": dapChainWalletsModel.get(currentIndex).tokens[i]}); if(listToken.model.count) listToken.currentIndex = 0; } diff --git a/CellFrameDashboardService/CellFrameDashboardService.pro b/CellFrameDashboardService/CellFrameDashboardService.pro index 252f53b225d249894d3d8f69b1af4a4c7ed717ec..8d5e4079a96a5f7c07a6eb4c970d614db99c40ec 100755 --- a/CellFrameDashboardService/CellFrameDashboardService.pro +++ b/CellFrameDashboardService/CellFrameDashboardService.pro @@ -14,7 +14,7 @@ TARGET = $${BRAND}Service VER_MAJ = 1 VER_MIN = 6 -VER_PAT = 1 +VER_PAT = 2 ICON = icon.ico diff --git a/CellFrameDashboardService/DapChainDashboardService.cpp b/CellFrameDashboardService/DapChainDashboardService.cpp index 42f14936bb9c8eec85cd81110b2b27dd345a7548..4b4dbda508e94f6a3470b2cb7df74edddfde5a4c 100755 --- a/CellFrameDashboardService/DapChainDashboardService.cpp +++ b/CellFrameDashboardService/DapChainDashboardService.cpp @@ -119,7 +119,12 @@ void DapChainDashboardService::changeCurrentNetwork(const QString& aNetwork) void DapChainDashboardService::doRequestWallets() { - m_pDapChainHistoryHandler->onRequestNewHistory(m_pDapChainWalletHandler->getWallets()); + QMap<QString, QVariant> wallets = m_pDapChainWalletHandler->getWallets(); + m_pDapChainHistoryHandler->onRequestNewHistory(wallets); + /// TODO: for future +// QVariantList params = QVariantList() << wallets; +// DapRpcMessage request = DapRpcMessage::createRequest("RPCClient.setNewWallets", QJsonArray::fromVariantList(params)); +// m_pServer->notifyConnectedClients(request); } void DapChainDashboardService::doSendNewHistory(const QVariant& aData) diff --git a/CellFrameDashboardService/DapChainWalletHandler.cpp b/CellFrameDashboardService/DapChainWalletHandler.cpp index 4da008ac980a5c0b0b36a7d7f7c5ae45b89b76c1..309c0988d1ddd7e3cf065f0313361509f010d1a4 100755 --- a/CellFrameDashboardService/DapChainWalletHandler.cpp +++ b/CellFrameDashboardService/DapChainWalletHandler.cpp @@ -1,5 +1,6 @@ #include "DapChainWalletHandler.h" #include <QDebug> +#include <QRegularExpression> DapChainWalletHandler::DapChainWalletHandler(QObject *parent) : QObject(parent) { @@ -42,25 +43,12 @@ QMap<QString, QVariant> DapChainWalletHandler::getWallets() QProcess process; process.start(QString("%1 wallet list").arg(CLI_PATH)); process.waitForFinished(-1); - QString str = QString::fromLatin1(process.readAll()); - QRegExp rx(":{1,1}([\\s\\w\\W]+)(\\n|\\r){1,1}" ); - rx.setMinimal(true); - int pos = 0; - int x {0}; - QString tempName; - while ((pos = rx.indexIn(str, pos)) != -1) - { - if(x == 0) - { - tempName = rx.cap(1); - ++x; - } - else - { - map.insert(tempName, rx.cap(1)); - x = 0; - } - pos += rx.matchedLength(); + QByteArray result = process.readAll(); + QRegularExpression rx("wallet:\\s(.+)\\s+addr:\\s(.+)", QRegularExpression::MultilineOption); + QRegularExpressionMatchIterator itr = rx.globalMatch(result); + while (itr.hasNext()) { + QRegularExpressionMatch match = itr.next(); + map[match.captured(1)] = match.captured(2); } return map; @@ -72,7 +60,7 @@ QStringList DapChainWalletHandler::getWalletInfo(const QString &asNameWallet) process.start(QString("%1 wallet info -w %2 -net private").arg(CLI_PATH).arg(asNameWallet)); process.waitForFinished(-1); QByteArray result = process.readAll(); - QRegExp rx("wallet: (\\w+)\\s+addr:\\s+(\\w+)\\s+(balance)|(\\d+.\\d+)\\s(\\(\\d+\\))\\s(\\w+)"); + QRegExp rx("wallet: (.+)\\s+addr:\\s+(\\w+)\\s+(balance)|(\\d+.\\d+)\\s(\\(\\d+\\))\\s(\\w+)"); QStringList list; int pos = 0; diff --git a/DapRPCProtocol/DapRpcServiceRequest.h b/DapRPCProtocol/DapRpcServiceRequest.h index aa689f8d143c761586c4808ead96f01c885ee427..0949ff6a386c20ff6bdb03efcb2685f613798fe8 100644 --- a/DapRPCProtocol/DapRpcServiceRequest.h +++ b/DapRPCProtocol/DapRpcServiceRequest.h @@ -8,24 +8,53 @@ #include "DapRpcMessage.h" class DapRpcSocket; +/** + * @brief The DapRpcServiceRequest class + * Class provides to operate with request message by socket interface + * @see DapRpcSocket + */ class DapRpcServiceRequest { + /// Request message DapRpcMessage m_request; + /// RPC socket QPointer<DapRpcSocket> m_socket; public: + /// Standard constructor DapRpcServiceRequest(); + /// Copy constructor DapRpcServiceRequest(const DapRpcServiceRequest &aDapRpcServiceRequest); + /// Overloaded constructor + /// @param aRequest Request message + /// @param apSocket Pointer to RPC socket DapRpcServiceRequest(const DapRpcMessage &aRequest, DapRpcSocket *apSocket); + /// Overloaded assignment operator + /// @param aDapRpcServiceRequest Other DapRpcServiceRequest object + /// @return Reference to this object DapRpcServiceRequest &operator=(const DapRpcServiceRequest &aDapRpcServiceRequest); + /// Standard destructor ~DapRpcServiceRequest(); + /// Validation of request message + /// @return If request message is valid or socket is not null return true. + /// Otherwise return false bool isValid() const; + /// Get request message + /// @return Request message DapRpcMessage request() const; + /// Get current socket + /// @return Socket DapRpcSocket *socket() const; - bool respond(const DapRpcMessage &aResponse); + /// Create response to following respont by socket + /// @param aReturnValue Return value from service + /// @return False if socket is closed bool respond(QVariant aReturnValue); + /// Send response to socket + /// @param aResponse Response message + /// @return False if socket is closed + bool respond(const DapRpcMessage &aResponse); }; #endif // DapRPCSERVICEREQUEST_H diff --git a/DapRPCProtocol/DapRpcSocket.h b/DapRPCProtocol/DapRpcSocket.h index 9a2836d9a52ed435d4b304b595c48297b7858153..b78103503219ab33bd517b39b1eaee5d30570292 100644 --- a/DapRPCProtocol/DapRpcSocket.h +++ b/DapRPCProtocol/DapRpcSocket.h @@ -15,54 +15,136 @@ #define DEFAULT_MSECS_REQUEST_TIMEOUT (30000) +/** + * @brief The DapRpcSocket class + * Realization socket interface: + * - Store information about device and data + * - Sending/receiving messages + * - Control sending request by timeout + */ class DapRpcSocket : public QObject { Q_OBJECT Q_DISABLE_COPY(DapRpcSocket) + /// Pointer to IO device QPointer<QIODevice> m_pDevice; + /// Buffer QByteArray m_aBuffer; + /// Storage to replies by id QHash<int, QPointer<DapRpcServiceReply>> m_replies; + /// Default request timeout int m_defaultRequestTimeout; protected: + /// TODO: not implement + /// @param asMessage Request message virtual void processRequestMessage(const DapRpcMessage &asMessage); public: + /// Standard constructor explicit DapRpcSocket(QObject *apParent = nullptr); + /// Overloaded constructor + /// @param apDevice Device whick provides both a common implementation and + /// an abstract interface for devices that support reading and writing of blocks of data explicit DapRpcSocket(QIODevice *apDevice, QObject *apParent = nullptr); + /// Virtual destructor virtual ~DapRpcSocket(); + /// Validation initialization and open device + /// @return True if device initilized and opened. Otherwise return false virtual bool isValid() const; + /// Set default request timeout + /// @param aiMsecs Miliseconds void setDefaultRequestTimeout(int aiMsecs); + /// Get default request timeout + /// @return Default request timeout int getDefaultRequestTimeout() const; - + /// Set IO Device + /// @param Pointer to IO device void setIODevice(QIODevice *pDevice); signals: + /// The signal emitted when message was received + /// @param asMessage Request message void messageReceived(const DapRpcMessage &asMessage); private slots: + /// Read data from device and prepare reply virtual void processIncomingData(); + /// Find end of Json document + /// @param aJsonData Json data where need to find end + /// @return Index of end json document. If file empty return -1 int findJsonDocumentEnd(const QByteArray &aJsonData); + /// Write data from message to device + /// @param asMessage Request message void writeData(const DapRpcMessage &asMessage); public slots: + /// Notify to new request message and try to send to device + /// @param asMessage Request message virtual void notify(const DapRpcMessage &asMessage); + /// Send message with delay for sending message + /// @param asMessage Request message + /// @param aMsecs Delay request timeout. If not pass parameter uses default value + /// @return Response from reply virtual DapRpcMessage sendMessageBlocking(const DapRpcMessage &asMessage, int aMsecs = DEFAULT_MSECS_REQUEST_TIMEOUT); + /// Send request message to device + /// @param asMessage Request message + /// @return Pointer of service reply virtual DapRpcServiceReply *sendMessage(const DapRpcMessage &asMessage); + /// Invoke remote method and create response to send to IO device with delay + /// @param asMethod Method's name + /// @param aMsecs Delay time for send + /// @param arg1 First argument + /// @param arg2 Second argument + /// @param arg3 Third argument + /// @param arg4 Fourth argument + /// @param arg5 Fifth argument + /// @param arg6 Six argument + /// @param arg7 Seven argument + /// @param arg8 Eight argument + /// @param arg9 Nine argument + /// @param arg10 Ten argument + /// @return Response from reply DapRpcMessage invokeRemoteMethodBlocking(const QString &asMethod, int aMsecs, 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()); + /// Invoke remote method and create response to send to IO device with default delay time + /// @param asMethod Method's name + /// @param arg1 First argument + /// @param arg2 Second argument + /// @param arg3 Third argument + /// @param arg4 Fourth argument + /// @param arg5 Fifth argument + /// @param arg6 Six argument + /// @param arg7 Seven argument + /// @param arg8 Eight argument + /// @param arg9 Nine argument + /// @param arg10 Ten argument + /// @return Response from reply DapRpcMessage invokeRemoteMethodBlocking(const QString &asMethod, 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()); + /// Invoke remote method and create response to send to IO device + /// @param asMethod Method's name + /// @param arg1 First argument + /// @param arg2 Second argument + /// @param arg3 Third argument + /// @param arg4 Fourth argument + /// @param arg5 Fifth argument + /// @param arg6 Six argument + /// @param arg7 Seven argument + /// @param arg8 Eight argument + /// @param arg9 Nine argument + /// @param arg10 Ten argument + /// @return Pointer to service reply DapRpcServiceReply *invokeRemoteMethod(const QString &asMethod, const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), const QVariant &arg5 = QVariant(), diff --git a/DapRPCProtocol/DapRpcTCPServer.h b/DapRPCProtocol/DapRpcTCPServer.h index 00b2e47085e3e781be265c039471c6b33374c133..d48b30400b74ecb5d161c2e49c6074e96c1473d8 100644 --- a/DapRPCProtocol/DapRpcTCPServer.h +++ b/DapRPCProtocol/DapRpcTCPServer.h @@ -8,36 +8,68 @@ #include "DapRpcSocket.h" #include "DapRpcAbstractServer.h" +/** + * @brief The DapRpcTCPServer class + * TCP server class realize interface DapRpcAbstractServer + * @see DapRpcAbstractServer + * @see QTcpServer + */ class DapRpcTCPServer : public QTcpServer, public DapRpcAbstractServer { Q_OBJECT Q_DISABLE_COPY(DapRpcTCPServer) - + /// Lookup's tcp sockets witj Rpc sockets QHash<QTcpSocket*, DapRpcSocket*> m_socketLookup; protected: + /// This virtual function is called by QTcpServer when a new connection is available + /// @param aSocketDescriptor The socketDescriptor argument is the native socket + /// descriptor for the accepted connection virtual void incomingConnection(qintptr aSocketDescriptor); public: + /// Standard constructor explicit DapRpcTCPServer(QObject *apParent = nullptr); + /// Virtual destructor virtual ~DapRpcTCPServer(); + /// Tells the server to listen for incoming connections on address + /// @param asAddress Address + /// @param aPort Port. If port is 0, a port is chosen automatically + /// @param If address is QHostAddress::Any, the server will listen on all network interfaces + /// @return Returns true on success; otherwise returns false. + /// @see isListening() virtual bool listen(const QString &asAddress = QString(), quint16 aPort = 0); - + /// Add new service + /// @param apService New service + /// @return If service add successfully return true. Otherwise return false bool addService(DapRpcService *apService); + /// Remove service + /// @param apService Service for removing + /// @return If service add successfully return true. Otherwise return false bool removeService(DapRpcService *apService); signals: + /// The signal is emitted when client was connected void onClientConnected(); + /// The signal is emitted when client was disconnected void onClientDisconnected(); protected slots: + /// Calls when client disconnected void clientDisconnected(); + /// When receive message from client prepare message by type of message + /// @param asMessage Message void messageProcessing(const DapRpcMessage &asMessage); // DapRpcAbstractServer interface public slots: + /// Notify connected clients. Send all message + /// @param message Message to client void notifyConnectedClients(const DapRpcMessage &message); + /// Notify connected clients. Send all message + /// @param method Method which clients were notified + /// @param params Parameters of message in JSON format void notifyConnectedClients(const QString &method, const QJsonArray ¶ms); }; diff --git a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri index 44882919b7139474ea4d7cf9f99b2a82352155f5..7bd94e5639947ac6e65d14200ec05149d9cbd168 100755 --- a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri +++ b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri @@ -9,7 +9,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -QT += quick quickwidgets +QT += qml quick quickwidgets CONFIG += c++11 SOURCES +=\ diff --git a/libdap b/libdap index 5b72cc303107680535c4591313033611b01c4a0b..efd69f3c297f64b4b48f0a9dfeaac3ad9e449d0b 160000 --- a/libdap +++ b/libdap @@ -1 +1 @@ -Subproject commit 5b72cc303107680535c4591313033611b01c4a0b +Subproject commit efd69f3c297f64b4b48f0a9dfeaac3ad9e449d0b diff --git a/libdap-crypto b/libdap-crypto index d2c567906d783f94e28ae2ca87acc875175da6a8..92a5f1f787b54790c00ec626d92e2b299bcf21c7 160000 --- a/libdap-crypto +++ b/libdap-crypto @@ -1 +1 @@ -Subproject commit d2c567906d783f94e28ae2ca87acc875175da6a8 +Subproject commit 92a5f1f787b54790c00ec626d92e2b299bcf21c7 diff --git a/libdap-qt b/libdap-qt index 948d0658552674cd2826bedae80341774a2101d1..abd55f41c4660d1e7101161616c537b3107d9abc 160000 --- a/libdap-qt +++ b/libdap-qt @@ -1 +1 @@ -Subproject commit 948d0658552674cd2826bedae80341774a2101d1 +Subproject commit abd55f41c4660d1e7101161616c537b3107d9abc