Kagome
Polkadot Runtime Engine in C++17
jrpc_server.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_API_JRPC_SERVER_HPP
7 #define KAGOME_API_JRPC_SERVER_HPP
8 
9 #include <functional>
10 
11 #include <jsonrpc-lean/dispatcher.h>
12 #include <jsonrpc-lean/response.h>
13 #include <jsonrpc-lean/value.h>
14 
15 #include "outcome/outcome.hpp"
16 
17 namespace kagome::api {
18 
23  class JRpcServer {
24  public:
25  using Method = jsonrpc::MethodWrapper::Method;
26 
27  virtual ~JRpcServer() = default;
28 
34  virtual void registerHandler(const std::string &name, Method method) = 0;
35 
39  virtual std::vector<std::string> getHandlerNames() = 0;
40 
44  using ResponseHandler = std::function<void(std::string_view)>;
45  using FormatterHandler =
46  std::function<void(outcome::result<std::string_view>)>;
47 
54  virtual void processJsonData(std::string method_name,
55  const jsonrpc::Request::Parameters &from,
56  const FormatterHandler &cb) = 0;
57 
63  virtual void processData(std::string_view request,
64  const ResponseHandler &cb) = 0;
65  };
66 
67 } // namespace kagome::api
68 
69 #endif // KAGOME_API_JRPC_SERVER_HPP
virtual std::vector< std::string > getHandlerNames()=0
virtual void processJsonData(std::string method_name, const jsonrpc::Request::Parameters &from, const FormatterHandler &cb)=0
creates valid jsonrpc response
std::function< void(outcome::result< std::string_view >)> FormatterHandler
Definition: jrpc_server.hpp:46
virtual void registerHandler(const std::string &name, Method method)=0
registers rpc request handler lambda
std::function< void(std::string_view)> ResponseHandler
Definition: jrpc_server.hpp:44
jsonrpc::MethodWrapper::Method Method
Definition: jrpc_server.hpp:25
virtual ~JRpcServer()=default
virtual void processData(std::string_view request, const ResponseHandler &cb)=0
handles decoded network message