6 #ifndef KAGOME_CORE_API_JRPC_JRPC_METHOD_HPP 7 #define KAGOME_CORE_API_JRPC_JRPC_METHOD_HPP 9 #include <jsonrpc-lean/dispatcher.h> 10 #include <jsonrpc-lean/request.h> 13 #include <type_traits> 19 template <
typename RequestType,
typename Api>
25 explicit Method(
const std::shared_ptr<Api> &api) : api_(api) {}
27 jsonrpc::Value
operator()(
const jsonrpc::Request::Parameters ¶ms) {
28 auto api = api_.lock();
30 throw jsonrpc::Fault(
"API not available");
33 RequestType request(api);
36 if (
auto &&init_result = request.init(params); not init_result) {
37 throw jsonrpc::Fault(init_result.error().message());
41 auto &&result = request.execute();
45 throw jsonrpc::Fault(result.error().message());
48 if constexpr (std::is_same_v<decltype(result.value()),
void>) {
57 #endif // KAGOME_CORE_API_JRPC_JRPC_METHOD_HPP
jsonrpc::Value operator()(const jsonrpc::Request::Parameters ¶ms)
jsonrpc::Value makeValue(const uint32_t &)
Method(const std::shared_ptr< Api > &api)
std::weak_ptr< Api > api_