Kagome
Polkadot Runtime Engine in C++17
kagome::api::JRpcServerImpl Class Reference

#include <jrpc_server_impl.hpp>

Inheritance diagram for kagome::api::JRpcServerImpl:
Collaboration diagram for kagome::api::JRpcServerImpl:

Public Types

enum  Error { Error::JSON_FORMAT_FAILED = 1 }
 
- Public Types inherited from kagome::api::JRpcServer
using Method = jsonrpc::MethodWrapper::Method
 
using ResponseHandler = std::function< void(std::string_view)>
 
using FormatterHandler = std::function< void(outcome::result< std::string_view >)>
 

Public Member Functions

 JRpcServerImpl ()
 
 ~JRpcServerImpl () override=default
 
void registerHandler (const std::string &name, Method method) override
 registers rpc request handler lambda More...
 
std::vector< std::string > getHandlerNames () override
 
void processData (std::string_view request, const ResponseHandler &cb) override
 handles decoded network message More...
 
void processJsonData (std::string method_name, const jsonrpc::Request::Parameters &from, const FormatterHandler &cb) override
 creates a valid jsonrpc response and passes it to More...
 
- Public Member Functions inherited from kagome::api::JRpcServer
virtual ~JRpcServer ()=default
 

Private Attributes

jsonrpc::Server jsonrpc_handler_ {}
 json rpc server instance More...
 
jsonrpc::JsonFormatHandler format_handler_ {}
 format handler instance More...
 
metrics::RegistryPtr metrics_registry_ = metrics::createRegistry()
 
metrics::Countermetric_rpc_requests_count_
 

Detailed Description

Definition at line 16 of file jrpc_server_impl.hpp.

Member Enumeration Documentation

Enumerator
JSON_FORMAT_FAILED 

Definition at line 18 of file jrpc_server_impl.hpp.

Constructor & Destructor Documentation

kagome::api::JRpcServerImpl::JRpcServerImpl ( )

Definition at line 26 of file jrpc_server_impl.cpp.

kagome::api::JRpcServerImpl::~JRpcServerImpl ( )
overridedefault

Member Function Documentation

std::vector< std::string > kagome::api::JRpcServerImpl::getHandlerNames ( )
overridevirtual
Returns
name of handlers

Implements kagome::api::JRpcServer.

Definition at line 43 of file jrpc_server_impl.cpp.

void kagome::api::JRpcServerImpl::processData ( std::string_view  request,
const ResponseHandler cb 
)
overridevirtual

handles decoded network message

Parameters
requestjson request string
cbcallback

Implements kagome::api::JRpcServer.

Definition at line 81 of file jrpc_server_impl.cpp.

void kagome::api::JRpcServerImpl::processJsonData ( std::string  method_name,
const jsonrpc::Request::Parameters &  from,
const FormatterHandler cb 
)
overridevirtual

creates a valid jsonrpc response and passes it to

  • cb
    Parameters
    fromis a data source
    cbcallback

Notification must omit "id" field. But jsonrpc-lean writes "id" field if id is null/int/string. So we pass bool. https://github.com/xDimon/jsonrpc-lean/blob/6c093da8670d7bf56555f166f8b8151f33a5d741/include/jsonrpc-lean/jsonwriter.h#L169

Implements kagome::api::JRpcServer.

Definition at line 48 of file jrpc_server_impl.cpp.

void kagome::api::JRpcServerImpl::registerHandler ( const std::string &  name,
Method  method 
)
overridevirtual

registers rpc request handler lambda

Parameters
namerpc method name
methodhandler functor

Implements kagome::api::JRpcServer.

Definition at line 38 of file jrpc_server_impl.cpp.

Member Data Documentation

jsonrpc::JsonFormatHandler kagome::api::JRpcServerImpl::format_handler_ {}
private

format handler instance

Definition at line 59 of file jrpc_server_impl.hpp.

jsonrpc::Server kagome::api::JRpcServerImpl::jsonrpc_handler_ {}
private

json rpc server instance

Definition at line 57 of file jrpc_server_impl.hpp.

metrics::Counter* kagome::api::JRpcServerImpl::metric_rpc_requests_count_
private

Definition at line 63 of file jrpc_server_impl.hpp.

metrics::RegistryPtr kagome::api::JRpcServerImpl::metrics_registry_ = metrics::createRegistry()
private

Definition at line 62 of file jrpc_server_impl.hpp.


The documentation for this class was generated from the following files: