OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::rpc::json_rpc_http_client Class Reference

Asynchronous HTTP JSON-RPC client implemented using libcurl. More...

#include <json_rpc_http_client.hpp>

Public Types

using callback_type = std::function<void(std::optional<Json::Value>)>
 Type alias for the response callback function.
 

Public Member Functions

 json_rpc_http_client (std::vector< std::string > endpoints, long timeout, std::shared_ptr< logging::log > log)
 Construct a new client.
 
 ~json_rpc_http_client ()
 Cancels any existing requests and stops the client.
 
 json_rpc_http_client (const json_rpc_http_client &)=delete
 
auto operator= (const json_rpc_http_client &) -> json_rpc_http_client &=delete
 
 json_rpc_http_client (json_rpc_http_client &&)=delete
 
auto operator= (json_rpc_http_client &&) -> json_rpc_http_client &=delete
 
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 via a callback function.
 
auto pump () -> bool
 Process events raised by the underlying libcurl implementation.
 

Protected Attributes

std::shared_ptr< cbdc::logging::logm_log
 

Detailed Description

Asynchronous HTTP JSON-RPC client implemented using libcurl.

Supports randomized load balancing across multiple RPC endpoints.

Definition at line 36 of file json_rpc_http_client.hpp.

Member Typedef Documentation

◆ callback_type

using cbdc::rpc::json_rpc_http_client::callback_type = std::function<void(std::optional<Json::Value>)>

Type alias for the response callback function.

Definition at line 56 of file json_rpc_http_client.hpp.

Constructor & Destructor Documentation

◆ json_rpc_http_client() [1/3]

cbdc::rpc::json_rpc_http_client::json_rpc_http_client ( std::vector< std::string > endpoints,
long timeout,
std::shared_ptr< logging::log > log )

Construct a new client.

Parameters
endpointslist of RPC endpoints to load balance between.
timeoutresponse timeout in milliseconds. 0 for no timeout.
loglog instance.

Definition at line 27 of file json_rpc_http_client.cpp.

◆ ~json_rpc_http_client()

cbdc::rpc::json_rpc_http_client::~json_rpc_http_client ( )

Cancels any existing requests and stops the client.

Definition at line 60 of file json_rpc_http_client.cpp.

References m_log.

◆ json_rpc_http_client() [2/3]

cbdc::rpc::json_rpc_http_client::json_rpc_http_client ( const json_rpc_http_client & )
delete

◆ json_rpc_http_client() [3/3]

cbdc::rpc::json_rpc_http_client::json_rpc_http_client ( json_rpc_http_client && )
delete

Member Function Documentation

◆ call()

void cbdc::rpc::json_rpc_http_client::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 via a callback function.

Parameters
methodmethod to call.
paramscall parameters.
result_fnfunction to call with response.

Definition at line 79 of file json_rpc_http_client.cpp.

References m_log.

◆ operator=() [1/2]

auto cbdc::rpc::json_rpc_http_client::operator= ( const json_rpc_http_client & ) -> json_rpc_http_client &=delete
delete

◆ operator=() [2/2]

auto cbdc::rpc::json_rpc_http_client::operator= ( json_rpc_http_client && ) -> json_rpc_http_client &=delete
delete

◆ pump()

auto cbdc::rpc::json_rpc_http_client::pump ( ) -> bool
nodiscard

Process events raised by the underlying libcurl implementation.

Returns
true if the last pump was successful and should be continued.

Definition at line 130 of file json_rpc_http_client.cpp.

Field Documentation

◆ m_log

std::shared_ptr<cbdc::logging::log> cbdc::rpc::json_rpc_http_client::m_log
protected

Definition at line 113 of file json_rpc_http_client.hpp.

Referenced by call(), and ~json_rpc_http_client().


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