6#ifndef OPENCBDC_TX_SRC_RPC_JSON_RPC_HTTP_CLIENT_H_
7#define OPENCBDC_TX_SRC_RPC_JSON_RPC_HTTP_CLIENT_H_
18#include <unordered_map>
44 std::shared_ptr<logging::log> log);
63 void call(
const std::string& method,
70 [[nodiscard]]
auto pump() -> bool;
73 std::vector<std::string> m_endpoints;
75 std::unique_ptr<event_handler> m_ev_handler;
77 Json::StreamWriterBuilder m_builder;
79 CURLM* m_multi_handle{};
81 std::queue<CURL*> m_handles;
84 std::stringstream m_result;
86 std::string m_payload;
89 std::unordered_map<CURL*, std::unique_ptr<transfer>> m_transfers;
91 curl_slist* m_headers{};
92 Json::Value m_payload;
99 write_data(
void* ptr,
size_t size,
size_t nmemb,
struct transfer* t)
102 static auto socket_callback(CURL* handle,
106 void* socketp) -> int;
108 static auto timer_callback(CURLM* multi_handle,
113 std::shared_ptr<cbdc::logging::log>
m_log;
Class for performing libcurl global initialization.
~curl_initializer()
Deinitializes libcurl.
curl_initializer()
Initializes libcurl.
Asynchronous HTTP JSON-RPC client implemented using libcurl.
void call(const std::string &method, Json::Value params, callback_type result_fn)
Calls the requested JSON-RPC method with the given parameters and returns the response asynchronously...
std::function< void(std::optional< Json::Value >)> callback_type
Type alias for the response callback function.
json_rpc_http_client(json_rpc_http_client &&)=delete
std::shared_ptr< cbdc::logging::log > m_log
json_rpc_http_client(const json_rpc_http_client &)=delete
auto operator=(json_rpc_http_client &&) -> json_rpc_http_client &=delete
~json_rpc_http_client()
Cancels any existing requests and stops the client.
auto pump() -> bool
Process events raised by the underlying libcurl implementation.
json_rpc_http_client(std::vector< std::string > endpoints, long timeout, std::shared_ptr< logging::log > log)
Construct a new client.
auto operator=(const json_rpc_http_client &) -> json_rpc_http_client &=delete