From 98f150a8bda764e4d828c829d85a043e9ee59db0 Mon Sep 17 00:00:00 2001 From: "denis.sumin" <denis.sumin@demlabs.net> Date: Tue, 25 Oct 2022 11:56:36 +0300 Subject: [PATCH 1/3] [*] reworked all wallet history command --- .../DapGetAllWalletHistoryCommand.cpp | 105 +++++++++++++----- .../handlers/DapGetAllWalletHistoryCommand.h | 10 +- 2 files changed, 83 insertions(+), 32 deletions(-) diff --git a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp index 0a5c82de..30934355 100644 --- a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp +++ b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp @@ -17,8 +17,8 @@ DapGetAllWalletHistoryCommand::DapGetAllWalletHistoryCommand(const QString &asSe /// @return Reply to client. QVariant DapGetAllWalletHistoryCommand::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(arg1) +// Q_UNUSED(arg2) Q_UNUSED(arg3) Q_UNUSED(arg4) Q_UNUSED(arg5) @@ -30,60 +30,105 @@ QVariant DapGetAllWalletHistoryCommand::respondToClient(const QVariant &arg1, co qDebug() << "DapGetAllWalletHistoryCommand::respondToClient"; // << arg1.toString(); - QList<DapWalletHistoryEvent> events; + QJsonArray txHistory; QStringList networks = arg1.toString().split("/"); + QString tempResult; + + bool update = arg2.toBool(); + + for (QString str : networks) { QStringList networkinfo = str.split(":"); - if (networkinfo.size() == 3) + if (networkinfo.size() == 2) { QProcess process; - QString command = QString("%1 tx_history -net %2 -chain %3 -addr %4").arg(m_sCliPath) - .arg(networkinfo.at(0)).arg(networkinfo.at(1)).arg(networkinfo.at(2)); + QString command = QString("%1 tx_history -net %2 -w %3").arg(m_sCliPath) + .arg(networkinfo.at(0)).arg(networkinfo.at(1)); qInfo() << "command:" << command; process.start(command); process.waitForFinished(-1); - QByteArray result = process.readAll(); + QString result = QString::fromLatin1(process.readAll()); + + tempResult.append(result); + // qInfo() << "result:" << result; if(!result.isEmpty()) { - QRegularExpression regular(R"(^TX hash (\S+) (.+)\n\t(.+)\n\trecv (\S+) (\S+) (\S+) (\S+))", QRegularExpression::MultilineOption); + QRegularExpression regular(R"(^(\S+) TX hash (\S+) (.+)\n\t(.+)(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?)", QRegularExpression::MultilineOption); QRegularExpressionMatchIterator matchItr = regular.globalMatch(result); while (matchItr.hasNext()) { - DapWalletHistoryEvent event; - QRegularExpressionMatch match = matchItr.next(); - - QDateTime date = QDateTime::fromString(match.captured(3)); - QLocale setLocale = QLocale(QLocale::English, QLocale::UnitedStates); - event.setDate(date.toString("yyyy-MM-dd")); - event.setStatus(match.captured(7) == "send" ? "Sent" : "Received"); - event.setDatoshi(match.captured(4)); - event.setName(match.captured(5)); - event.setWallet(arg2.toString()); - event.setNetwork(networkinfo.at(0)); - event.setSecsSinceEpoch(date.toSecsSinceEpoch()); - - QStringList s = match.capturedTexts(); - QString txHash = s[0].split(" ")[0].split("\n")[0]; - event.setHash(match.captured(1)); - - events.append(event); + /* + * * ---- header block ---- + * 1 - status (ACCEPTED | DECLINED) + * 2 - tx_hash + * 3 - atom + * 4 - data + * * ---- data block ---- + * 5 - full data + * 6 - send|recv + * 7 - value + * 8 - token + * 9 - from|to + * 10 - addr or flag (STAKE_LOCK | FEE) + */ + QRegularExpressionMatch match = matchItr.next(); + + QJsonArray historyObj; + QJsonObject txHeader, txData; + + QDateTime date = QDateTime::fromString(match.captured(4)); + + txHeader.insert("tx_status", match.captured(1)); + txHeader.insert("tx_hash", match.captured(2)); + txHeader.insert("atom", match.captured(3)); + txHeader.insert("network", networkinfo.at(0)); + txHeader.insert("wallet_name", networkinfo.at(1)); + txHeader.insert("date", date.toString("yyyy-MM-dd")); + txHeader.insert("date_to_secs", date.toSecsSinceEpoch()); + + historyObj.append(txHeader); + + bool flagMatch = match.captured(5).length(); + int itr = 5; + + while(flagMatch) + { + itr++; + txData.insert("status", match.captured(itr) == "send" ? "Sent" : "Received"); + txData.insert("value", match.captured(itr+1)); + txData.insert("token", match.captured(itr+2)); + txData.insert("direction", match.captured(itr+3)); + txData.insert("addr_or_flag", match.captured(itr+4)); + + itr+=5; + flagMatch = match.captured(itr).length(); + + historyObj.append(txData); + } + txHistory.append(historyObj); } } } } - QByteArray datas; - QDataStream out(&datas, QIODevice::WriteOnly); - out << events; + if (tempResult != lastResult | update) + { + lastResult = tempResult; + + QJsonDocument docResult; + docResult.setArray(txHistory); - return QJsonValue::fromVariant(datas.toHex()); + return docResult.toJson(); + } + else + return QVariant(QString("isEqual")); } diff --git a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.h b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.h index da7ddfa7..ec1bf74b 100644 --- a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.h +++ b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.h @@ -5,9 +5,12 @@ #include <QRegExp> #include <QRegularExpression> #include <QDate> +#include <QJsonArray> +#include <QJsonObject> +#include <QJsonDocument> -#include "DapWallet.h" -#include "DapWalletHistoryEvent.h" +//#include "DapWallet.h" +//#include "DapWalletHistoryEvent.h" #include "DapAbstractCommand.h" class DapGetAllWalletHistoryCommand : public DapAbstractCommand @@ -30,6 +33,9 @@ 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; + +private: + QString lastResult; }; #endif // DAPGETALLWALLETHISTORYCOMMAND_H -- GitLab From 988a590c5c897f9cf549681e989c5e9deefb9a36 Mon Sep 17 00:00:00 2001 From: Nikolay Veprikov <nikolai.veprikov@demlabs.net> Date: Sun, 30 Oct 2022 17:40:12 +0300 Subject: [PATCH 2/3] Fixed DapGetAllWalletHistoryCommand. Fixed DapGetWordBook. --- .../DapGetAllWalletHistoryCommand.cpp | 123 ++++++++++++------ .../handlers/DapGetAllWalletHistoryCommand.h | 4 + chain/wallet/handlers/DapGetWordBook.cpp | 4 + 3 files changed, 91 insertions(+), 40 deletions(-) diff --git a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp index 30934355..327b8452 100644 --- a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp +++ b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp @@ -8,7 +8,8 @@ DapGetAllWalletHistoryCommand::DapGetAllWalletHistoryCommand(const QString &asServicename, QObject *parent, const QString &asCliPath) : DapAbstractCommand(asServicename, parent, asCliPath) { - + feeFlags = {"DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE", + "DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE_STAKE"}; } /// Send a response to the client. @@ -38,7 +39,6 @@ QVariant DapGetAllWalletHistoryCommand::respondToClient(const QVariant &arg1, co bool update = arg2.toBool(); - for (QString str : networks) { QStringList networkinfo = str.split(":"); @@ -49,6 +49,8 @@ QVariant DapGetAllWalletHistoryCommand::respondToClient(const QVariant &arg1, co QString command = QString("%1 tx_history -net %2 -w %3").arg(m_sCliPath) .arg(networkinfo.at(0)).arg(networkinfo.at(1)); + if (networkinfo.at(0) == "private") + command += " -chain zero"; qInfo() << "command:" << command; process.start(command); process.waitForFinished(-1); @@ -60,67 +62,108 @@ QVariant DapGetAllWalletHistoryCommand::respondToClient(const QVariant &arg1, co if(!result.isEmpty()) { - - QRegularExpression regular(R"(^(\S+) TX hash (\S+) (.+)\n\t(.+)(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?)", QRegularExpression::MultilineOption); +// QRegularExpression regular(R"(^(\S+) TX hash (\S+) (.+)\n\t(.+)(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))?)", QRegularExpression::MultilineOption); + QRegularExpression regular( + R"(^(\S+) TX hash (\S+) (.+)\n\t(.+)\n\t)", QRegularExpression::MultilineOption); QRegularExpressionMatchIterator matchItr = regular.globalMatch(result); while (matchItr.hasNext()) { /* * * ---- header block ---- - * 1 - status (ACCEPTED | DECLINED) + * 1 - tx_status (ACCEPTED | DECLINED) * 2 - tx_hash * 3 - atom - * 4 - data - * * ---- data block ---- - * 5 - full data - * 6 - send|recv - * 7 - value - * 8 - token - * 9 - from|to - * 10 - addr or flag (STAKE_LOCK | FEE) + * 4 - network + * 5 - wallet_name + * 6 - date + * 7 - date_to_secs + * 8 - address + * 9 - status + * 10 - value + * 11 - token + * 12 - direction + * 13 - fee */ - QRegularExpressionMatch match = matchItr.next(); + QRegularExpressionMatch match = matchItr.next(); - QJsonArray historyObj; - QJsonObject txHeader, txData; +// QJsonArray historyObj; + QJsonObject txHeader; - QDateTime date = QDateTime::fromString(match.captured(4)); + QDateTime date = QDateTime::fromString(match.captured(4)); - txHeader.insert("tx_status", match.captured(1)); - txHeader.insert("tx_hash", match.captured(2)); - txHeader.insert("atom", match.captured(3)); - txHeader.insert("network", networkinfo.at(0)); - txHeader.insert("wallet_name", networkinfo.at(1)); - txHeader.insert("date", date.toString("yyyy-MM-dd")); - txHeader.insert("date_to_secs", date.toSecsSinceEpoch()); + txHeader.insert("tx_status", match.captured(1)); + txHeader.insert("tx_hash", match.captured(2)); + txHeader.insert("atom", match.captured(3)); + txHeader.insert("network", networkinfo.at(0)); + txHeader.insert("wallet_name", networkinfo.at(1)); + txHeader.insert("date", date.toString("yyyy-MM-dd")); + txHeader.insert("date_to_secs", date.toSecsSinceEpoch()); - historyObj.append(txHeader); + int posDataBegin = match.capturedEnd(); + int posDataEnd = result.indexOf("TX hash", posDataBegin); - bool flagMatch = match.captured(5).length(); - int itr = 5; + if (posDataEnd < 0) + posDataEnd = result.length(); - while(flagMatch) - { - itr++; - txData.insert("status", match.captured(itr) == "send" ? "Sent" : "Received"); - txData.insert("value", match.captured(itr+1)); - txData.insert("token", match.captured(itr+2)); - txData.insert("direction", match.captured(itr+3)); - txData.insert("addr_or_flag", match.captured(itr+4)); + QString data = result.mid(posDataBegin-2, + posDataEnd - posDataBegin + 2); + + QRegularExpression regularData( + R"(\n\t(recv|send) (\S+) (\S+) (\S+) (\S+))", QRegularExpression::MultilineOption); + QRegularExpressionMatchIterator matchItrData = regularData.globalMatch(data); - itr+=5; - flagMatch = match.captured(itr).length(); +// qlonglong fee = 0; - historyObj.append(txData); +// qlonglong value = 0; + + uint256_t fee = dap_cvt_str_to_uint256("0"); + uint256_t value = dap_cvt_str_to_uint256("0"); + + while (matchItrData.hasNext()) + { + QRegularExpressionMatch match = matchItrData.next(); + + if (feeFlags.contains(match.captured(5))) + { + SUM_256_256(fee, + dap_cvt_str_to_uint256(match.captured(2).toStdString().data()), + &fee); +// fee += match.captured(2).toLongLong(); } - txHistory.append(historyObj); + else + { + txHeader.insert("address", match.captured(5)); + txHeader.insert("status", match.captured(1) == "send" ? "Sent" : "Received"); +// txHeader.insert("value", match.captured(2)); + txHeader.insert("token", match.captured(3)); + txHeader.insert("direction", match.captured(4)); +// value = match.captured(2).toLongLong(); + value = dap_cvt_str_to_uint256(match.captured(2).toStdString().data()); + } + +// qDebug() << match.captured(5) << feeFlags.contains(match.captured(5)); + + } + + SUM_256_256(value, fee, &value); + + txHeader.insert("value", dap_chain_balance_to_coins(value)); + txHeader.insert("fee", dap_chain_balance_to_coins(fee)); +// txHeader.insert("value", QString::number(value+fee)); +// txHeader.insert("fee", QString::number(fee)); + + qDebug() << "txHeader" << txHeader; + +// historyObj.append(txHeader); + + txHistory.append(txHeader); } } } } - if (tempResult != lastResult | update) + if (tempResult != lastResult || update) { lastResult = tempResult; diff --git a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.h b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.h index ec1bf74b..c80c7156 100644 --- a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.h +++ b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.h @@ -13,6 +13,8 @@ //#include "DapWalletHistoryEvent.h" #include "DapAbstractCommand.h" +#include <dap_chain_common.h> + class DapGetAllWalletHistoryCommand : public DapAbstractCommand { public: @@ -36,6 +38,8 @@ public slots: private: QString lastResult; + + QSet<QString> feeFlags; }; #endif // DAPGETALLWALLETHISTORYCOMMAND_H diff --git a/chain/wallet/handlers/DapGetWordBook.cpp b/chain/wallet/handlers/DapGetWordBook.cpp index 8f3da0ec..a87dce60 100644 --- a/chain/wallet/handlers/DapGetWordBook.cpp +++ b/chain/wallet/handlers/DapGetWordBook.cpp @@ -42,6 +42,7 @@ QVariant DapGetWordBook::respondToClient(const QVariant &arg1, const QVariant &a { res = getTreeWords(arg1.toString()); } + QByteArray resByte; QDataStream streamer(&resByte, QIODevice::WriteOnly); streamer << res; @@ -568,6 +569,9 @@ void DapGetWordBook::_getChains() QStringList list = result.split("\t"); list.removeAll(""); + if (list.isEmpty()) + return; + QString netKey = list[0]; QStringList chainList; -- GitLab From 4dcd02ba6684502f6a64383fd4e8487e4435d455 Mon Sep 17 00:00:00 2001 From: "denis.sumin" <denis.sumin@demlabs.net> Date: Wed, 2 Nov 2022 12:48:53 +0300 Subject: [PATCH 3/3] update all wallet history and wallet info command --- .../DapGetAllWalletHistoryCommand.cpp | 5 +- .../handlers/DapGetWalletInfoCommand.cpp | 63 ------------------- 2 files changed, 4 insertions(+), 64 deletions(-) diff --git a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp index 327b8452..9dcef4ca 100644 --- a/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp +++ b/chain/wallet/handlers/DapGetAllWalletHistoryCommand.cpp @@ -94,7 +94,7 @@ QVariant DapGetAllWalletHistoryCommand::respondToClient(const QVariant &arg1, co txHeader.insert("tx_status", match.captured(1)); txHeader.insert("tx_hash", match.captured(2)); - txHeader.insert("atom", match.captured(3)); + txHeader.insert("atom", match.captured(3).split("(")[1].split(")")[0].remove("atom ")); txHeader.insert("network", networkinfo.at(0)); txHeader.insert("wallet_name", networkinfo.at(1)); txHeader.insert("date", date.toString("yyyy-MM-dd")); @@ -119,6 +119,7 @@ QVariant DapGetAllWalletHistoryCommand::respondToClient(const QVariant &arg1, co uint256_t fee = dap_cvt_str_to_uint256("0"); uint256_t value = dap_cvt_str_to_uint256("0"); + QString feeToken = ""; while (matchItrData.hasNext()) { @@ -129,6 +130,7 @@ QVariant DapGetAllWalletHistoryCommand::respondToClient(const QVariant &arg1, co SUM_256_256(fee, dap_cvt_str_to_uint256(match.captured(2).toStdString().data()), &fee); + feeToken = match.captured(3); // fee += match.captured(2).toLongLong(); } else @@ -150,6 +152,7 @@ QVariant DapGetAllWalletHistoryCommand::respondToClient(const QVariant &arg1, co txHeader.insert("value", dap_chain_balance_to_coins(value)); txHeader.insert("fee", dap_chain_balance_to_coins(fee)); + txHeader.insert("fee_token", feeToken); // txHeader.insert("value", QString::number(value+fee)); // txHeader.insert("fee", QString::number(fee)); diff --git a/chain/wallet/handlers/DapGetWalletInfoCommand.cpp b/chain/wallet/handlers/DapGetWalletInfoCommand.cpp index 0a15e6e5..a84567c5 100755 --- a/chain/wallet/handlers/DapGetWalletInfoCommand.cpp +++ b/chain/wallet/handlers/DapGetWalletInfoCommand.cpp @@ -36,69 +36,6 @@ QVariant DapGetWalletInfoCommand::respondToClient(const QVariant &arg1, const QV Q_UNUSED(arg9) Q_UNUSED(arg10) -/* QString walletName = arg1.toString(); - - QStringList networkLists; - if (!arg2.canConvert<QStringList>()) - networkLists.append(arg2.toString()); - else - networkLists = arg2.toStringList(); - - - QProcess process; - QString command(QString("%1 wallet info -w %2 -net %3") - .arg(m_sCliPath) - .arg(walletName)); - - QJsonObject returnValue; - QJsonObject networks; - for (const QString& network: networkLists) - { - QString networkCommand = command.arg(network); - process.start(networkCommand); - - process.waitForFinished(-1); - QString result(process.readAll()); - - - //Name: -#ifdef Q_OS_WIN - QRegularExpression regex(R"(^wallet: (\S+)\r\naddr: (\S+)\r\nnetwork: (\S+)\r\nbalance:)"); -#else - QRegularExpression regex(R"(^wallet: (\S+)\naddr: (\S+)\nnetwork: (\S+)\nbalance:)"); -#endif - QRegularExpressionMatch match = regex.match(result); - if (!match.hasMatch()) { - qWarning() << "Can't parse result" << result; - return {}; - } - returnValue.insert(WALLET_NAME, match.captured(1)); - - QString networkName = match.captured(3); - QJsonObject networkInfo {{ - ADDRESS, match.captured(2) - }}; - - //Balance: - QRegularExpression balanceRegex(R"((\d+.\d+) \((\d+)\) (\w+))"); - QRegularExpressionMatchIterator matchIt = balanceRegex.globalMatch(result); - - QJsonObject balance; - while (matchIt.hasNext()) - { - QRegularExpressionMatch match = matchIt.next(); - QString amount = match.captured(2); - QString token = match.captured(3); - balance.insert(token, amount); - } - - networkInfo.insert(BALANCE, balance); - networks.insert(networkName, networkInfo); - } - returnValue.insert(NETWORKS_INFO, networks); - return returnValue; - */ - qDebug() << "DapGetWalletInfoCommand::respondToClient"; QString walletName = arg1.toString(); -- GitLab