Browse Source

prevent overlapping batch calls

recurring
adityapk00 6 years ago
parent
commit
b572dfadef
  1. 16
      src/connection.h
  2. 1
      src/mainwindow.cpp
  3. 3
      src/rpc.h

16
src/connection.h

@ -106,9 +106,22 @@ public:
std::function<void(QMap<T, json>*)> cb) {
auto responses = new QMap<T, json>(); // zAddr -> list of responses for each call.
int totalSize = payloads.size();
if (totalSize == 0)
return;
// Keep track of all pending method calls, so as to prevent
// any overlapping calls
static QMap<QString, bool> inProgress;
QString method = QString::fromStdString(payloadGenerator(payloads[0])["method"]);
if (inProgress.value(method, false)) {
qDebug() << "In progress batch, skipping";
return;
}
for (auto item: payloads) {
json payload = payloadGenerator(item);
inProgress[method] = true;
QNetworkReply *reply = restclient->post(*request, QByteArray::fromStdString(payload.dump()));
@ -148,7 +161,10 @@ public:
// If all responses have arrived, return
if (responses->size() == totalSize) {
waitTimer->stop();
cb(responses);
inProgress[method] = false;
waitTimer->deleteLater();
}
});

1
src/mainwindow.cpp

@ -16,7 +16,6 @@
#include "senttxstore.h"
#include "connection.h"
#include "precompiled.h"
using json = nlohmann::json;

3
src/rpc.h

@ -88,9 +88,6 @@ private:
void getTransactions (const std::function<void(json)>& cb);
void getZAddresses (const std::function<void(json)>& cb);
void handleConnectionError (const QString& error);
void handleTxError (const QString& error);
Connection* conn = nullptr;
QProcess* ezcashd = nullptr;

Loading…
Cancel
Save