2015-09-18 11:55:31 +00:00
|
|
|
// Copyright (c) 2011-2015 The Cryptonote developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2015-05-27 12:08:46 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-07-15 12:23:00 +00:00
|
|
|
#include <system_error>
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
#include <System/Dispatcher.h>
|
|
|
|
#include <System/Event.h>
|
|
|
|
#include "Logging/ILogger.h"
|
|
|
|
#include "Logging/LoggerRef.h"
|
2015-07-30 15:22:07 +00:00
|
|
|
#include "Rpc/HttpServer.h"
|
2015-05-27 12:08:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace CryptoNote {
|
|
|
|
class HttpResponse;
|
|
|
|
class HttpRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
class JsonValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace System {
|
|
|
|
class TcpConnection;
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
namespace CryptoNote {
|
2015-05-27 12:08:46 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
class JsonRpcServer : HttpServer {
|
2015-05-27 12:08:46 +00:00
|
|
|
public:
|
2015-07-30 15:22:07 +00:00
|
|
|
JsonRpcServer(System::Dispatcher& sys, System::Event& stopEvent, Logging::ILogger& loggerGroup);
|
2015-05-27 12:08:46 +00:00
|
|
|
JsonRpcServer(const JsonRpcServer&) = delete;
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
void start(const std::string& bindAddress, uint16_t bindPort);
|
2015-05-27 12:08:46 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
protected:
|
|
|
|
static void makeErrorResponse(const std::error_code& ec, Common::JsonValue& resp);
|
|
|
|
static void makeMethodNotFoundResponse(Common::JsonValue& resp);
|
|
|
|
static void makeGenericErrorReponse(Common::JsonValue& resp, const char* what, int errorCode = -32001);
|
|
|
|
static void fillJsonResponse(const Common::JsonValue& v, Common::JsonValue& resp);
|
|
|
|
static void prepareJsonResponse(const Common::JsonValue& req, Common::JsonValue& resp);
|
|
|
|
static void makeJsonParsingErrorResponse(Common::JsonValue& resp);
|
|
|
|
|
|
|
|
virtual void processJsonRpcRequest(const Common::JsonValue& req, Common::JsonValue& resp) = 0;
|
2015-05-27 12:08:46 +00:00
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
private:
|
2015-07-15 12:23:00 +00:00
|
|
|
// HttpServer
|
|
|
|
virtual void processRequest(const CryptoNote::HttpRequest& request, CryptoNote::HttpResponse& response) override;
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
System::Dispatcher& system;
|
|
|
|
System::Event& stopEvent;
|
|
|
|
Logging::LoggerRef logger;
|
|
|
|
};
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
} //namespace CryptoNote
|