From 6b106b95fe21e291d3d2e50d67b0f2d0138d1fa9 Mon Sep 17 00:00:00 2001
From: "evgenii.tagiltsev" <tagiltsev.evgenii@gmail.com>
Date: Thu, 12 Dec 2019 16:30:22 +0100
Subject: [PATCH] [*] divided mempool and sending money

---
 CellFrameDashboardGUI/DapCommandController.cpp   |  7 ++++++-
 CellFrameDashboardGUI/DapCommandController.h     |  4 +++-
 CellFrameDashboardGUI/DapServiceController.cpp   |  3 ++-
 CellFrameDashboardGUI/DapTransaction.cpp         |  7 ++++++-
 CellFrameDashboardGUI/DapTransaction.h           |  5 ++++-
 .../DapChainDashboardService.cpp                 |  5 +++++
 .../DapChainDashboardService.h                   |  2 ++
 .../DapChainTransaction.cpp                      | 16 ++++++++++------
 CellFrameDashboardService/DapChainTransaction.h  |  2 ++
 9 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/CellFrameDashboardGUI/DapCommandController.cpp b/CellFrameDashboardGUI/DapCommandController.cpp
index 5c430992f..88d41c62c 100644
--- a/CellFrameDashboardGUI/DapCommandController.cpp
+++ b/CellFrameDashboardGUI/DapCommandController.cpp
@@ -79,12 +79,17 @@ void DapCommandController::changeCurrentNetwork(const QString& aNetwork)
     m_DAPRpcSocket->invokeRemoteMethod("RPCServer.changeCurrentNetwork", aNetwork);
 }
 
-void DapCommandController::sendTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue)
+void DapCommandController::sendMempool(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue)
 {
     DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.createTransaction", aFromWallet, aToAddress, aToken, aNetwork, aValue);
     connect(reply, SIGNAL(finished()), this, SLOT(processGetResultTransaction()));
 }
 
+void DapCommandController::takeFromMempool(const QString& aNetwork)
+{
+    m_DAPRpcSocket->invokeRemoteMethod("RPCServer.takeFromMempool", aNetwork);
+}
+
 void DapCommandController::setNewWalletData(const QVariant& aData)
 {
     emit sigWalletData(QByteArray::fromHex(aData.toByteArray()));
diff --git a/CellFrameDashboardGUI/DapCommandController.h b/CellFrameDashboardGUI/DapCommandController.h
index ea41c1a7c..285936209 100644
--- a/CellFrameDashboardGUI/DapCommandController.h
+++ b/CellFrameDashboardGUI/DapCommandController.h
@@ -180,7 +180,9 @@ public slots:
 
     void requestWalletData();
 
-    void sendTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue);
+    void sendMempool(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue);
+
+    void takeFromMempool(const QString& aNetwork);
 };
 
 #endif // COMMANDCONTROLLER_H
diff --git a/CellFrameDashboardGUI/DapServiceController.cpp b/CellFrameDashboardGUI/DapServiceController.cpp
index 1f21aa904..416dcc082 100644
--- a/CellFrameDashboardGUI/DapServiceController.cpp
+++ b/CellFrameDashboardGUI/DapServiceController.cpp
@@ -73,7 +73,8 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient)
 
     connect(m_pDapCommandController, &DapCommandController::sigWalletData, &DapChainWalletModel::instance(), &DapChainWalletModel::setWalletData);
 
-    connect(&DapTransaction::instance(), &DapTransaction::sendTransaction, m_pDapCommandController, &DapCommandController::sendTransaction);
+    connect(&DapTransaction::instance(), &DapTransaction::sendMempool, m_pDapCommandController, &DapCommandController::sendMempool);
+    connect(&DapTransaction::instance(), &DapTransaction::sendToken, m_pDapCommandController, &DapCommandController::takeFromMempool);
     connect(m_pDapCommandController, &DapCommandController::sendResponseTransaction, &DapTransaction::instance(), &DapTransaction::receiveResult);
 
 }
diff --git a/CellFrameDashboardGUI/DapTransaction.cpp b/CellFrameDashboardGUI/DapTransaction.cpp
index 858e352e3..372c3811f 100644
--- a/CellFrameDashboardGUI/DapTransaction.cpp
+++ b/CellFrameDashboardGUI/DapTransaction.cpp
@@ -13,7 +13,12 @@ DapTransaction& DapTransaction::instance()
 
 void DapTransaction::createRequestTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue)
 {
-    emit sendTransaction(aFromWallet, aToAddress, aToken, aNetwork, aValue);
+    emit sendMempool(aFromWallet, aToAddress, aToken, aNetwork, aValue);
+}
+
+void DapTransaction::sendToken(const QString& aNetwork)
+{
+    emit sendTransaction(aNetwork);
 }
 
 void DapTransaction::receiveResult(const bool aSuccessful)
diff --git a/CellFrameDashboardGUI/DapTransaction.h b/CellFrameDashboardGUI/DapTransaction.h
index a370b0d24..23fa41ff0 100644
--- a/CellFrameDashboardGUI/DapTransaction.h
+++ b/CellFrameDashboardGUI/DapTransaction.h
@@ -6,17 +6,20 @@
 class DapTransaction : public QObject
 {
     Q_OBJECT
+
 public:
     explicit DapTransaction(QObject *parent = nullptr);
     static DapTransaction& instance();
 
 public slots:
     void createRequestTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aToken, const QString& aNetwork, const quint64 aValue);
+    void sendToken(const QString& aNetwork);
     void receiveResult(const bool aSuccessful);
 
 signals:
     void sendResult(bool result);
-    void sendTransaction(const QString& fromWallet, const QString& toAddress, const QString& token, const QString& network, const quint64 value);
+    void sendMempool(const QString& fromWallet, const QString& toAddress, const QString& token, const QString& network, const quint64 value);
+    void sendTransaction(const QString& network);
 };
 
 #endif // DAPTRANSACTION_H
diff --git a/CellFrameDashboardService/DapChainDashboardService.cpp b/CellFrameDashboardService/DapChainDashboardService.cpp
index 28aa41c49..d33f84b96 100755
--- a/CellFrameDashboardService/DapChainDashboardService.cpp
+++ b/CellFrameDashboardService/DapChainDashboardService.cpp
@@ -229,3 +229,8 @@ bool DapChainDashboardService::createTransaction(const QString& aFromWallet, con
 {
     return m_pDapChainTransaction->createTransaction(aFromWallet, aToAddress, aTokenName, aNetwork, aValue);
 }
+
+void DapChainDashboardService::takeFromMempool(const QString& aNetwork)
+{
+    m_pDapChainTransaction->takeFromMempool(aNetwork);
+}
diff --git a/CellFrameDashboardService/DapChainDashboardService.h b/CellFrameDashboardService/DapChainDashboardService.h
index 825e5b2d5..e6e039b8b 100755
--- a/CellFrameDashboardService/DapChainDashboardService.h
+++ b/CellFrameDashboardService/DapChainDashboardService.h
@@ -143,6 +143,8 @@ public slots:
 
     bool createTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aTokenName, const QString& aNetwork, const quint64 aValue);
 
+    void takeFromMempool(const QString& aNetwork);
+
 private slots:
     /// Request new history request by handle wallet's name
     void doRequestWallets();
diff --git a/CellFrameDashboardService/DapChainTransaction.cpp b/CellFrameDashboardService/DapChainTransaction.cpp
index 4bbc0f5ff..62f0ef963 100644
--- a/CellFrameDashboardService/DapChainTransaction.cpp
+++ b/CellFrameDashboardService/DapChainTransaction.cpp
@@ -21,14 +21,18 @@ bool DapChainTransaction::createTransaction(const QString& aFromWallet, const QS
     QRegExp rx("transfer=(\\w+)");
     rx.indexIn(result, 0);
 
-    if(rx.cap(1) == "Ok") {
-
-        QProcess processMempool;
-        processMempool.start(QString("%1 mempool_proc -net " + aNetwork +" -chain gdb").arg(CLI_PATH));
-        processMempool.waitForFinished(-1);
-        processMempool.readAll();
+    if(rx.cap(1) == "Ok")
+    {
         return true;
     }
 
     return false;
 }
+
+void DapChainTransaction::takeFromMempool(const QString& aNetwork)
+{
+    QProcess processMempool;
+    processMempool.start(QString("%1 mempool_proc -net " + aNetwork +" -chain gdb").arg(CLI_PATH));
+    processMempool.waitForFinished(-1);
+    processMempool.readAll();
+}
diff --git a/CellFrameDashboardService/DapChainTransaction.h b/CellFrameDashboardService/DapChainTransaction.h
index 0434dee20..7b1330792 100644
--- a/CellFrameDashboardService/DapChainTransaction.h
+++ b/CellFrameDashboardService/DapChainTransaction.h
@@ -20,6 +20,8 @@ public:
     /// @param sum for transaction
     /// @return result of trying to do transaction
     bool createTransaction(const QString& aFromWallet, const QString& aToAddress, const QString& aTokenName, const QString& aNetwork, const quint64 aValue) const;
+
+    void takeFromMempool(const QString& aNetwork);
 };
 
 #endif // DAPCHAINTRANSACTION_H
-- 
GitLab