Electroneum
Loading...
Searching...
No Matches
tools::NodeRPCProxy Class Reference

#include <node_rpc_proxy.h>

Public Member Functions

 NodeRPCProxy (epee::net_utils::http::http_simple_client &http_client, boost::recursive_mutex &mutex)
void invalidate ()
void set_offline (bool offline)
boost::optional< std::string > get_rpc_version (uint32_t &version) const
boost::optional< std::string > get_height (uint64_t &height) const
void set_height (uint64_t h)
boost::optional< std::string > get_target_height (uint64_t &height) const
boost::optional< std::string > get_block_weight_limit (uint64_t &block_weight_limit) const
boost::optional< std::string > get_earliest_height (uint8_t version, uint64_t &earliest_height) const
boost::optional< std::string > get_dynamic_base_fee_estimate (uint64_t grace_blocks, uint64_t &fee) const
boost::optional< std::string > get_fee_quantization_mask (uint64_t &fee_quantization_mask) const

Detailed Description

Definition at line 40 of file node_rpc_proxy.h.

Constructor & Destructor Documentation

◆ NodeRPCProxy()

tools::NodeRPCProxy::NodeRPCProxy ( epee::net_utils::http::http_simple_client & http_client,
boost::recursive_mutex & mutex )

Definition at line 41 of file node_rpc_proxy.cpp.

42 : m_http_client(http_client)
43 , m_daemon_rpc_mutex(mutex)
44 , m_offline(false)
45{
46 invalidate();
47}
Here is the call graph for this function:

Member Function Documentation

◆ get_block_weight_limit()

boost::optional< std::string > tools::NodeRPCProxy::get_block_weight_limit ( uint64_t & block_weight_limit) const

Definition at line 132 of file node_rpc_proxy.cpp.

133{
134 auto res = get_info();
135 if (res)
136 return res;
137 block_weight_limit = m_block_weight_limit;
138 return boost::optional<std::string>();
139}
const char * res

◆ get_dynamic_base_fee_estimate()

boost::optional< std::string > tools::NodeRPCProxy::get_dynamic_base_fee_estimate ( uint64_t grace_blocks,
uint64_t & fee ) const

Definition at line 164 of file node_rpc_proxy.cpp.

165{
167
168 boost::optional<std::string> result = get_height(height);
169 if (result)
170 return result;
171
172 if (m_offline)
173 return boost::optional<std::string>("offline");
174 if (m_dynamic_base_fee_estimate_cached_height != height || m_dynamic_base_fee_estimate_grace_blocks != grace_blocks)
175 {
178
179 m_daemon_rpc_mutex.lock();
180 req_t.grace_blocks = grace_blocks;
181 bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_fee_estimate", req_t, resp_t, m_http_client, rpc_timeout);
182 m_daemon_rpc_mutex.unlock();
183 CHECK_AND_ASSERT_MES(r, std::string("Failed to connect to daemon"), "Failed to connect to daemon");
184 CHECK_AND_ASSERT_MES(resp_t.status != CORE_RPC_STATUS_BUSY, resp_t.status, "Failed to connect to daemon");
185 CHECK_AND_ASSERT_MES(resp_t.status == CORE_RPC_STATUS_OK, resp_t.status, "Failed to get fee estimate");
186 m_dynamic_base_fee_estimate = resp_t.fee;
187 m_dynamic_base_fee_estimate_cached_height = height;
188 m_dynamic_base_fee_estimate_grace_blocks = grace_blocks;
189 m_fee_quantization_mask = resp_t.quantization_mask;
190 }
191
192 fee = m_dynamic_base_fee_estimate;
193 return boost::optional<std::string>();
194}
uint64_t height
boost::optional< std::string > get_height(uint64_t &height) const
#define CORE_RPC_STATUS_OK
#define CORE_RPC_STATUS_BUSY
#define AUTO_VAL_INIT(v)
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
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")
unsigned __int64 uint64_t
Definition stdint.h:136
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ get_earliest_height()

boost::optional< std::string > tools::NodeRPCProxy::get_earliest_height ( uint8_t version,
uint64_t & earliest_height ) const

Definition at line 141 of file node_rpc_proxy.cpp.

142{
143 if (m_offline)
144 return boost::optional<std::string>("offline");
145 if (m_earliest_height[version] == 0)
146 {
149
150 m_daemon_rpc_mutex.lock();
151 req_t.version = version;
152 bool r = net_utils::invoke_http_json_rpc("/json_rpc", "hard_fork_info", req_t, resp_t, m_http_client, rpc_timeout);
153 m_daemon_rpc_mutex.unlock();
154 CHECK_AND_ASSERT_MES(r, std::string("Failed to connect to daemon"), "Failed to connect to daemon");
155 CHECK_AND_ASSERT_MES(resp_t.status != CORE_RPC_STATUS_BUSY, resp_t.status, "Failed to connect to daemon");
156 CHECK_AND_ASSERT_MES(resp_t.status == CORE_RPC_STATUS_OK, resp_t.status, "Failed to get hard fork status");
157 m_earliest_height[version] = resp_t.earliest_height;
158 }
159
160 earliest_height = m_earliest_height[version];
161 return boost::optional<std::string>();
162}
uint8_t version
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ get_fee_quantization_mask()

boost::optional< std::string > tools::NodeRPCProxy::get_fee_quantization_mask ( uint64_t & fee_quantization_mask) const

Definition at line 196 of file node_rpc_proxy.cpp.

197{
199
200 boost::optional<std::string> result = get_height(height);
201 if (result)
202 return result;
203
204 if (m_offline)
205 return boost::optional<std::string>("offline");
206 if (m_dynamic_base_fee_estimate_cached_height != height)
207 {
210
211 m_daemon_rpc_mutex.lock();
212 req_t.grace_blocks = m_dynamic_base_fee_estimate_grace_blocks;
213 bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_fee_estimate", req_t, resp_t, m_http_client, rpc_timeout);
214 m_daemon_rpc_mutex.unlock();
215 CHECK_AND_ASSERT_MES(r, std::string("Failed to connect to daemon"), "Failed to connect to daemon");
216 CHECK_AND_ASSERT_MES(resp_t.status != CORE_RPC_STATUS_BUSY, resp_t.status, "Failed to connect to daemon");
217 CHECK_AND_ASSERT_MES(resp_t.status == CORE_RPC_STATUS_OK, resp_t.status, "Failed to get fee estimate");
218 m_dynamic_base_fee_estimate = resp_t.fee;
219 m_dynamic_base_fee_estimate_cached_height = height;
220 m_fee_quantization_mask = resp_t.quantization_mask;
221 }
222
223 fee_quantization_mask = m_fee_quantization_mask;
224 if (fee_quantization_mask == 0)
225 {
226 MERROR("Fee quantization mask is 0, forcing to 1");
227 fee_quantization_mask = 1;
228 }
229 return boost::optional<std::string>();
230}
#define MERROR(x)
Definition misc_log_ex.h:73
Here is the call graph for this function:

◆ get_height()

boost::optional< std::string > tools::NodeRPCProxy::get_height ( uint64_t & height) const

Definition at line 114 of file node_rpc_proxy.cpp.

115{
116 auto res = get_info();
117 if (res)
118 return res;
119 height = m_height;
120 return boost::optional<std::string>();
121}
Here is the caller graph for this function:

◆ get_rpc_version()

boost::optional< std::string > tools::NodeRPCProxy::get_rpc_version ( uint32_t & version) const

Definition at line 64 of file node_rpc_proxy.cpp.

65{
66 if (m_offline)
67 return boost::optional<std::string>("offline");
68 if (m_rpc_version == 0)
69 {
72 m_daemon_rpc_mutex.lock();
73 bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_version", req_t, resp_t, m_http_client, rpc_timeout);
74 m_daemon_rpc_mutex.unlock();
75 CHECK_AND_ASSERT_MES(r, std::string("Failed to connect to daemon"), "Failed to connect to daemon");
76 CHECK_AND_ASSERT_MES(resp_t.status != CORE_RPC_STATUS_BUSY, resp_t.status, "Failed to connect to daemon");
77 CHECK_AND_ASSERT_MES(resp_t.status == CORE_RPC_STATUS_OK, resp_t.status, "Failed to get daemon RPC version");
78 m_rpc_version = resp_t.version;
79 }
80 rpc_version = m_rpc_version;
81 return boost::optional<std::string>();
82}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ get_target_height()

boost::optional< std::string > tools::NodeRPCProxy::get_target_height ( uint64_t & height) const

Definition at line 123 of file node_rpc_proxy.cpp.

124{
125 auto res = get_info();
126 if (res)
127 return res;
128 height = m_target_height;
129 return boost::optional<std::string>();
130}

◆ invalidate()

void tools::NodeRPCProxy::invalidate ( )

Definition at line 49 of file node_rpc_proxy.cpp.

50{
51 m_height = 0;
52 for (size_t n = 0; n < 256; ++n)
53 m_earliest_height[n] = 0;
54 m_dynamic_base_fee_estimate = 0;
55 m_dynamic_base_fee_estimate_cached_height = 0;
56 m_dynamic_base_fee_estimate_grace_blocks = 0;
57 m_fee_quantization_mask = 1;
58 m_rpc_version = 0;
59 m_target_height = 0;
60 m_block_weight_limit = 0;
61 m_get_info_time = 0;
62}
Here is the caller graph for this function:

◆ set_height()

void tools::NodeRPCProxy::set_height ( uint64_t h)

Definition at line 84 of file node_rpc_proxy.cpp.

85{
86 m_height = h;
87}

◆ set_offline()

void tools::NodeRPCProxy::set_offline ( bool offline)
inline

Definition at line 46 of file node_rpc_proxy.h.

46{ m_offline = offline; }

The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/wallet/node_rpc_proxy.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/wallet/node_rpc_proxy.cpp