From f3d35e7d0a8fd0161c31d9f61d29485a772bc69c Mon Sep 17 00:00:00 2001 From: "andrey.daragan" <daragan.andrey@demlabs.net> Date: Thu, 27 Feb 2020 15:18:54 +0000 Subject: [PATCH] Features 3161 --- handlers/DapGetListWalletsCommand.cpp | 144 +------------------------- handlers/DapGetListWalletsCommand.h | 4 - handlers/DapGetWalletInfoCommand.cpp | 107 +++++++++++++++++++ handlers/DapGetWalletInfoCommand.h | 37 +++++++ libdap-qt-ui-chain-wallet.pri | 2 + resources/QML/DapFontRoboto.qml | 38 +++---- 6 files changed, 169 insertions(+), 163 deletions(-) create mode 100644 handlers/DapGetWalletInfoCommand.cpp create mode 100644 handlers/DapGetWalletInfoCommand.h diff --git a/handlers/DapGetListWalletsCommand.cpp b/handlers/DapGetListWalletsCommand.cpp index 82c11e96..9da645d1 100644 --- a/handlers/DapGetListWalletsCommand.cpp +++ b/handlers/DapGetListWalletsCommand.cpp @@ -31,84 +31,7 @@ QVariant DapGetListWalletsCommand::respondToClient(const QVariant &arg1, const Q Q_UNUSED(arg9) Q_UNUSED(arg10) -// DapWallet wallet; -// wallet.setName("VASY"); -// wallet.setBalance(25.5); -// wallet.setIcon("/fsghdhjghjufkigl"); -// wallet.addNetwork("Kelvin-testnet"); -// wallet.addNetwork("Private"); -// wallet.addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Kelvin-testnet"); -// wallet.addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Private"); - -// DapWalletToken token1("KLV", &wallet); -// token1.setBalance(5.5); -// token1.setNetwork("Kelvin-testnet"); -// token1.setEmission(464645646546); -// DapWalletToken token2("CELL", &wallet); -// token2.setBalance(100); -// token2.setNetwork("Private"); -// token2.setEmission(121212121); -// wallet.addToken(&token1); -// wallet.addToken(&token2); - -// QByteArray datas; -// QDataStream out(&datas, QIODevice::WriteOnly); -// out << wallet; - -// qDebug() << "balance after:\t" << wallet.getBalance(); -// qDebug() << "icon after:\t" << wallet.getIcon(); -// qDebug() << "networks after:\t" << wallet.getNetworks(); -// qDebug() << "m_aAddresses after:\t" << wallet.getAddresses(); -// qDebug() << "m_aTokens after:\t" << wallet.getTokens(); - - -// DapWallet wallet2; -// QByteArray d (datas); -// QDataStream in(&d, QIODevice::ReadOnly); -// in >> wallet2; - -// qDebug() << endl; -// qDebug() << "name before:\t" << wallet2.getName(); -// qDebug() << "balance before:\t" << wallet2.getBalance(); -// qDebug() << "icon before:\t" << wallet2.getIcon(); -// qDebug() << "networks before:\t" << wallet2.getNetworks(); -// qDebug() << "m_aAddresses before:\t" << wallet2.getAddresses(); -// // qDebug() << "m_aTokens before:\t" << wallet2.m_aTokens; - -// foreach (auto w, wallet2.getTokens()) { -// qDebug() << static_cast<DapWalletToken*>(w)->getName() << endl; -// qDebug() << static_cast<DapWalletToken*>(w)->getBalance() << endl; -// qDebug() << static_cast<DapWalletToken*>(w)->getEmission() << endl; -// qDebug() << static_cast<DapWalletToken*>(w)->getNetwork() << endl; - -// } - - -// QJsonValue str = QJsonValue::fromVariant(datas.toHex()); - - - -// QByteArray b = QByteArray::fromHex(str.toVariant().toByteArray()); -// std::string s = datas.toStdString(); -// QString str = QString::fromStdString(s); - -// DapWallet w; -// QByteArray d; -// QDataStream in(&datas, QIODevice::ReadOnly); -// in>>w; - - QList<DapWallet> wallets; - - QStringList list; - QProcess processN; - processN.start(QString("%1 net list").arg(m_sCliPath)); - processN.waitForFinished(-1); - QString result = QString::fromLatin1(processN.readAll()); - result.remove(' '); - if(!(result.isEmpty() || result.isNull() || result.contains('\''))) - { - list = result.remove("\n").remove("\r").split(":").at(1).split(","); - } + QStringList wallets; QProcess process; process.start(QString("%1 wallet list").arg(m_sCliPath)); @@ -119,69 +42,8 @@ QVariant DapGetListWalletsCommand::respondToClient(const QVariant &arg1, const Q while (itr.hasNext()) { QRegularExpressionMatch match = itr.next(); - QString walletName = match.captured(1); - DapWallet wallet; - wallet.setName(walletName); - auto begin = list.begin(); - auto end = list.end(); - for(; begin != end; ++begin) - { - - wallet.addNetwork(*begin); - - QProcess process_token; - process_token.start(QString("%1 wallet info -w %2 -net %3") - .arg(m_sCliPath) - .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; - DapWalletToken *token {nullptr}; - while((pos = regex.indexIn(result_tokens, pos)) != -1) - { - - if(!regex.cap(2).isEmpty()) - { - wallet.addAddress(regex.cap(2), *begin); - } - else - { - token = new DapWalletToken(); - token->setName(regex.cap(6).trimmed()); - token->setBalance(regex.cap(4).toDouble()); - QString str = regex.cap(5); - token->setEmission(regex.cap(5).toULongLong()); - token->setNetwork(*begin); - wallet.addToken(token); - } - - pos += regex.matchedLength(); - } - - } - wallets.append(wallet); + wallets.append(match.captured(1)); } - QByteArray datas; - QDataStream out(&datas, QIODevice::WriteOnly); - out << wallets; - - return QJsonValue::fromVariant(datas.toHex()); -} - - -/// Reply from service. -/// @details Performed on the service side. -/// @return Service reply. -QVariant DapGetListWalletsCommand::replyFromService() -{ - DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); - - emit serviceResponded(reply->response().toJsonValue().toVariant().toByteArray()); - - return reply->response().toJsonValue().toVariant(); + return wallets; } diff --git a/handlers/DapGetListWalletsCommand.h b/handlers/DapGetListWalletsCommand.h index 6d7c2282..9805de41 100644 --- a/handlers/DapGetListWalletsCommand.h +++ b/handlers/DapGetListWalletsCommand.h @@ -5,9 +5,6 @@ #include <QRegExp> #include <QRegularExpression> #include <QByteArray> -#include <QDataStream> -#include <QBuffer> -#include <QTextCodec> #include "DapWallet.h" #include "DapAbstractCommand.h" @@ -32,7 +29,6 @@ public slots: const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; - QVariant replyFromService() override; }; #endif // DAPGETLISTWALLETSCOMMAND_H diff --git a/handlers/DapGetWalletInfoCommand.cpp b/handlers/DapGetWalletInfoCommand.cpp new file mode 100644 index 00000000..689a0bce --- /dev/null +++ b/handlers/DapGetWalletInfoCommand.cpp @@ -0,0 +1,107 @@ +#include "DapGetWalletInfoCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +/// @param asCliPath The path to cli nodes. +DapGetWalletInfoCommand::DapGetWalletInfoCommand(const QString &asServicename, QObject *parent, const QString &asCliPath) + : DapAbstractCommand(asServicename, parent, asCliPath) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetWalletInfoCommand::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(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QStringList list; + QProcess processGetNetworks; + processGetNetworks.start(QString("%1 net list").arg(m_sCliPath)); + processGetNetworks.waitForFinished(-1); + QString result = QString::fromLatin1(processGetNetworks.readAll()); + result.remove(' '); + if(!(result.isEmpty() || result.isNull() || result.contains('\''))) + { + list = result.remove("\n").remove("\r").split(":").at(1).split(","); + } + + DapWallet wallet; + wallet.setName(arg1.toString()); + auto begin = list.begin(); + auto end = list.end(); + for(; begin != end; ++begin) + { + + wallet.addNetwork(*begin); + + QProcess processGetTokkens; + processGetTokkens.start(QString("%1 wallet info -w %2 -net %3") + .arg(m_sCliPath) + .arg(wallet.getName()) + .arg(*begin)); + + processGetTokkens.waitForFinished(-1); + QByteArray result_tokens = processGetTokkens.readAll(); + QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); + + int pos = 0; + DapWalletToken *token {nullptr}; + while((pos = regex.indexIn(result_tokens, pos)) != -1) + { + + if(!regex.cap(2).isEmpty()) + { + wallet.addAddress(regex.cap(2), *begin); + } + else + { + token = new DapWalletToken(); + token->setName(regex.cap(6).trimmed()); + token->setBalance(regex.cap(4).toDouble()); + QString str = regex.cap(5); + token->setEmission(regex.cap(5).toULongLong()); + token->setNetwork(*begin); + wallet.addToken(token); + } + + pos += regex.matchedLength(); + } + } + + QByteArray datas; + QDataStream out(&datas, QIODevice::WriteOnly); + out << wallet; + + return QJsonValue::fromVariant(datas.toHex()); +} + + +/// Reply from service. +/// @details Performed on the service side. +/// @return Service reply. +QVariant DapGetWalletInfoCommand::replyFromService() +{ + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + + emit serviceResponded(reply->response().toJsonValue().toVariant().toByteArray()); + + return reply->response().toJsonValue().toVariant(); +} + diff --git a/handlers/DapGetWalletInfoCommand.h b/handlers/DapGetWalletInfoCommand.h new file mode 100644 index 00000000..d92f5a09 --- /dev/null +++ b/handlers/DapGetWalletInfoCommand.h @@ -0,0 +1,37 @@ +#ifndef DAPGETWALLETINFOCOMMAND_H +#define DAPGETWALLETINFOCOMMAND_H + +#include <QProcess> +#include <QRegExp> +#include <QRegularExpression> +#include <QByteArray> +#include <QDataStream> +#include <QBuffer> +#include <QTextCodec> + +#include "DapWallet.h" +#include "DapAbstractCommand.h" + +class DapGetWalletInfoCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + /// @param asCliPath The path to cli nodes. + DapGetWalletInfoCommand(const QString &asServicename, QObject *parent = nullptr, const QString &asCliPath = QString()); +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()) override; + QVariant replyFromService() override; +}; + +#endif // DAPGETWALLETINFOCOMMAND_H diff --git a/libdap-qt-ui-chain-wallet.pri b/libdap-qt-ui-chain-wallet.pri index 47ae284e..060b342f 100644 --- a/libdap-qt-ui-chain-wallet.pri +++ b/libdap-qt-ui-chain-wallet.pri @@ -32,6 +32,7 @@ HEADERS += \ $$PWD/handlers/DapGetListWalletsCommand.h \ $$PWD/handlers/DapGetWalletAddressesCommand.h \ $$PWD/handlers/DapGetWalletHistoryCommand.h \ + $$PWD/handlers/DapGetWalletInfoCommand.h \ $$PWD/handlers/DapGetWalletTokenInfoCommand.h \ $$PWD/handlers/DapMempoolProcessCommand.h \ $$PWD/handlers/DapQuitApplicationCommand.h \ @@ -65,6 +66,7 @@ SOURCES += \ $$PWD/handlers/DapGetListWalletsCommand.cpp \ $$PWD/handlers/DapGetWalletAddressesCommand.cpp \ $$PWD/handlers/DapGetWalletHistoryCommand.cpp \ + $$PWD/handlers/DapGetWalletInfoCommand.cpp \ $$PWD/handlers/DapGetWalletTokenInfoCommand.cpp \ $$PWD/handlers/DapMempoolProcessCommand.cpp \ $$PWD/handlers/DapQuitApplicationCommand.cpp \ diff --git a/resources/QML/DapFontRoboto.qml b/resources/QML/DapFontRoboto.qml index a9f787f9..42e0b2c7 100644 --- a/resources/QML/DapFontRoboto.qml +++ b/resources/QML/DapFontRoboto.qml @@ -3,8 +3,10 @@ import "qrc:/" Item { - ///@details dapMainFontTheme ID of item with all project fonts + ///@details dapMainFontTheme ID of item with all project fonts. property alias dapMainFontTheme: dapFontsObjects + ///@details dapFactor Scaling factor. + property int dapFactor: 1 //Add Font Loader DapFont @@ -28,7 +30,7 @@ Item family: dapFonts.dapProjectFonts[0].name, bold: false, italic: false, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoBlackCustom Font of Roboto font family (black, without parameters) @@ -39,7 +41,7 @@ Item family: dapFonts.dapProjectFonts[0].name, bold: false, italic: true, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoBlackItalicCustom Font of Roboto font family (black-italic, without parameters) @@ -53,7 +55,7 @@ Item family: dapFonts.dapProjectFonts[3].name, bold: true, italic: false, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoBoldCustom Font of Roboto font family (bold, without parameters) @@ -67,7 +69,7 @@ Item family: dapFonts.dapProjectFonts[3].name, bold: true, italic: true, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoBoldItalicCustom Font of Roboto font family (bold-italic, without parameters) @@ -82,7 +84,7 @@ Item family: dapFonts.dapProjectFonts[1].name, bold: false, italic: false, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoLightCustom Font of Roboto font family (light, without parameters) @@ -93,7 +95,7 @@ Item family: dapFonts.dapProjectFonts[1].name, bold: false, italic: true, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoLightItalicCustom Font of Roboto font family (light-italic, without parameters) @@ -106,7 +108,7 @@ Item family: dapFonts.dapProjectFonts[2].name, bold: false, italic: false, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoMediumCustom Font of Roboto font family (medium, without parameters) @@ -117,7 +119,7 @@ Item family: dapFonts.dapProjectFonts[2].name, bold: false, italic: true, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoMediumItalicCustom Font of Roboto font family (medium-italic, without parameters) @@ -131,7 +133,7 @@ Item family: dapFonts.dapProjectFonts[3].name, bold: false, italic: true, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoItalicCustom Font of Roboto font family (italic, without parameters) @@ -145,7 +147,7 @@ Item family: dapFonts.dapProjectFonts[3].name, bold: false, italic: false, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoRegular12 Font of Roboto font family (regular, 12pt) @@ -153,7 +155,7 @@ Item family: dapFonts.dapProjectFonts[3].name, bold: false, italic: false, - pixelSize: 12 + pixelSize: 12 * dapFactor }) ///@details dapFontRobotoRegular16 Font of Roboto font family (regular, 16pt) @@ -161,7 +163,7 @@ Item family: dapFonts.dapProjectFonts[3].name, bold: false, italic: false, - pixelSize: 16 + pixelSize: 16 * dapFactor }) ///@details dapFontRobotoRegular18 Font of Roboto font family (regular, 18pt) @@ -169,7 +171,7 @@ Item family: dapFonts.dapProjectFonts[3].name, bold: false, italic: false, - pixelSize: 18 + pixelSize: 18 * dapFactor }) ///@details dapFontRobotoRegularCustom Font of Roboto font family (regular, without parameters) @@ -180,7 +182,7 @@ Item family: dapFonts.dapProjectFonts[4].name, bold: false, italic: false, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoThinCustom Font of Roboto font family (thin, without parameters) @@ -191,7 +193,7 @@ Item family: dapFonts.dapProjectFonts[4].name, bold: false, italic: true, - pixelSize: 14 + pixelSize: 14 * dapFactor }) ///@details dapFontRobotoThinItalicCustom Font of Roboto font family (thin-italic, without parameters) @@ -205,7 +207,7 @@ Item family: dapFonts.dapProjectFonts[3].name, bold: false, italic: false, - pixelSize: 11 + pixelSize: 11 * dapFactor }) ///@details dapFontRobotoRegular10 Font of Roboto font family (regular, 10pt) @@ -213,7 +215,7 @@ Item family: dapFonts.dapProjectFonts[3].name, bold: false, italic: false, - pixelSize: 10 + pixelSize: 10 * dapFactor }) } } -- GitLab