Electroneum
Loading...
Searching...
No Matches
tools::t_rpc_client Class Referencefinal

#include <rpc_client.h>

Public Member Functions

 t_rpc_client (uint32_t ip, uint16_t port, boost::optional< epee::net_utils::http::login > user, epee::net_utils::ssl_options_t ssl_options)
template<typename T_req, typename T_res>
bool basic_json_rpc_request (T_req &req, T_res &res, std::string const &method_name)
template<typename T_req, typename T_res>
bool json_rpc_request (T_req &req, T_res &res, std::string const &method_name, std::string const &fail_msg)
template<typename T_req, typename T_res>
bool rpc_request (T_req &req, T_res &res, std::string const &relative_url, std::string const &fail_msg)
bool check_connection ()

Detailed Description

Definition at line 45 of file rpc_client.h.

Constructor & Destructor Documentation

◆ t_rpc_client()

tools::t_rpc_client::t_rpc_client ( uint32_t ip,
uint16_t port,
boost::optional< epee::net_utils::http::login > user,
epee::net_utils::ssl_options_t ssl_options )
inline

Definition at line 50 of file rpc_client.h.

56 : m_http_client{}
57 {
58 m_http_client.set_server(
59 epee::string_tools::get_ip_string_from_int32(ip), std::to_string(port), std::move(user), std::move(ssl_options)
60 );
61 }
std::string get_ip_string_from_int32(uint32_t ip)
Here is the call graph for this function:

Member Function Documentation

◆ basic_json_rpc_request()

template<typename T_req, typename T_res>
bool tools::t_rpc_client::basic_json_rpc_request ( T_req & req,
T_res & res,
std::string const & method_name )
inline

Definition at line 64 of file rpc_client.h.

69 {
70 t_http_connection connection(&m_http_client);
71
72 bool ok = connection.is_open();
73 if (!ok)
74 {
75 fail_msg_writer() << "Couldn't connect to daemon: " << m_http_client.get_host() << ":" << m_http_client.get_port();
76 return false;
77 }
78 ok = epee::net_utils::invoke_http_json_rpc("/json_rpc", method_name, req, res, m_http_client, t_http_connection::TIMEOUT());
79 if (!ok)
80 {
81 fail_msg_writer() << "basic_json_rpc_request: Daemon request failed";
82 return false;
83 }
84 else
85 {
86 return true;
87 }
88 }
connection(typename TProtocol::config_type &ref_config)
static constexpr std::chrono::seconds TIMEOUT()
const char * res
bool invoke_http_json_rpc(const boost::string_ref uri, std::string method_name, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref http_method="GET", const std::string &req_id="0")
scoped_message_writer fail_msg_writer()
Here is the call graph for this function:

◆ check_connection()

bool tools::t_rpc_client::check_connection ( )
inline

Definition at line 146 of file rpc_client.h.

147 {
148 t_http_connection connection(&m_http_client);
149 return connection.is_open();
150 }
Here is the call graph for this function:

◆ json_rpc_request()

template<typename T_req, typename T_res>
bool tools::t_rpc_client::json_rpc_request ( T_req & req,
T_res & res,
std::string const & method_name,
std::string const & fail_msg )
inline

Definition at line 91 of file rpc_client.h.

97 {
98 t_http_connection connection(&m_http_client);
99
100 bool ok = connection.is_open();
101 if (!ok)
102 {
103 fail_msg_writer() << "Couldn't connect to daemon: " << m_http_client.get_host() << ":" << m_http_client.get_port();
104 return false;
105 }
106 ok = epee::net_utils::invoke_http_json_rpc("/json_rpc", method_name, req, res, m_http_client, t_http_connection::TIMEOUT());
107 if (!ok || res.status != CORE_RPC_STATUS_OK) // TODO - handle CORE_RPC_STATUS_BUSY ?
108 {
109 fail_msg_writer() << fail_msg << " -- json_rpc_request: " << res.status;
110 return false;
111 }
112 else
113 {
114 return true;
115 }
116 }
#define CORE_RPC_STATUS_OK
Here is the call graph for this function:

◆ rpc_request()

template<typename T_req, typename T_res>
bool tools::t_rpc_client::rpc_request ( T_req & req,
T_res & res,
std::string const & relative_url,
std::string const & fail_msg )
inline

Definition at line 119 of file rpc_client.h.

125 {
126 t_http_connection connection(&m_http_client);
127
128 bool ok = connection.is_open();
129 if (!ok)
130 {
131 fail_msg_writer() << "Couldn't connect to daemon: " << m_http_client.get_host() << ":" << m_http_client.get_port();
132 return false;
133 }
134 ok = epee::net_utils::invoke_http_json(relative_url, req, res, m_http_client, t_http_connection::TIMEOUT());
135 if (!ok || res.status != CORE_RPC_STATUS_OK) // TODO - handle CORE_RPC_STATUS_BUSY ?
136 {
137 fail_msg_writer() << fail_msg << "-- rpc_request: " << res.status;
138 return false;
139 }
140 else
141 {
142 return true;
143 }
144 }
bool invoke_http_json(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
Here is the call graph for this function:

The documentation for this class was generated from the following file:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/common/rpc_client.h