-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChainSimServer.h
41 lines (33 loc) · 1.04 KB
/
ChainSimServer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef CHAINSIM_SERVER_H
#define CHAINSIM_SERVER_H
#include <QObject>
#include <QTcpServer>
#include <QHttpServer>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <memory>
#include "ChainSim.h"
#include "utils/ChainLogger.hpp"
namespace qz
{
class ChainSimServer : public QObject
{
Q_OBJECT
public:
explicit ChainSimServer(QObject *parent = nullptr);
bool start(quint16 port = 47761);
private:
QHttpServer m_server;
std::unique_ptr<QTcpServer> m_tcpServer;
ChainLogger m_logger;
// Helper methods
QJsonObject runSimulation(const QUrlQuery ¶ms);
QJsonObject simulationRecordsToJson(const ChainSim::simulation_records_t &records);
std::unique_ptr<PurchasePolicy> createPolicy(const QUrlQuery ¶ms);
void validateParameters(const QUrlQuery ¶ms);
void printRequestDetails(const QUrlQuery ¶ms);
bool isAllowedOrigin(const QString &origin);
};
} // namespace qz
#endif // CHAINSIM_SERVER_H