From d01f760404a03e4736cdc2159a957b985d89334b Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Thu, 28 Dec 2017 08:36:19 +0800 Subject: [PATCH] rpccalls::get_hardfork_info added https://github.com/moneroexamples/onion-monero-blockchain-explorer/issues/92 --- src/MempoolStatus.cpp | 9 ++++--- src/rpccalls.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ src/rpccalls.h | 3 +++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/MempoolStatus.cpp b/src/MempoolStatus.cpp index 4d186e0..660d9be 100644 --- a/src/MempoolStatus.cpp +++ b/src/MempoolStatus.cpp @@ -211,9 +211,7 @@ MempoolStatus::read_network_info() COMMAND_RPC_GET_INFO::response rpc_network_info; if (!rpc.get_network_info(rpc_network_info)) - { return false; - } uint64_t fee_estimated; @@ -229,6 +227,11 @@ MempoolStatus::read_network_info() (void) error_msg; + COMMAND_RPC_HARD_FORK_INFO::response rpc_hardfork_info; + + if (!rpc.get_hardfork_info(rpc_hardfork_info)) + return false; + network_info local_copy; @@ -254,7 +257,7 @@ MempoolStatus::read_network_info() local_copy.fee_per_kb = fee_estimated; local_copy.info_timestamp = static_cast(std::time(nullptr)); - local_copy.current_hf_version = core_storage->get_current_hard_fork_version(); + local_copy.current_hf_version = rpc_hardfork_info.version; local_copy.current = true; diff --git a/src/rpccalls.cpp b/src/rpccalls.cpp index 036b8ff..d9711be 100644 --- a/src/rpccalls.cpp +++ b/src/rpccalls.cpp @@ -207,6 +207,68 @@ rpccalls::get_network_info(COMMAND_RPC_GET_INFO::response& response) } +bool +rpccalls::get_hardfork_info(COMMAND_RPC_HARD_FORK_INFO::response& response) +{ + epee::json_rpc::request req_t = AUTO_VAL_INIT(req_t); + epee::json_rpc::response resp_t = AUTO_VAL_INIT(resp_t); + + + bool r {false}; + + req_t.jsonrpc = "2.0"; + req_t.id = epee::serialization::storage_entry(0); + req_t.method = "hard_fork_info"; + + { + std::lock_guard guard(m_daemon_rpc_mutex); + + if (!connect_to_monero_deamon()) + { + cerr << "get_hardfork_info: not connected to deamon" << endl; + return false; + } + + r = epee::net_utils::invoke_http_json("/json_rpc", + req_t, resp_t, + m_http_client); + } + + + string err; + + if (r) + { + if (resp_t.result.status == CORE_RPC_STATUS_BUSY) + { + err = "daemon is busy. Please try again later."; + } + else if (resp_t.result.status != CORE_RPC_STATUS_OK) + { + err = resp_t.result.status; + } + + if (!err.empty()) + { + cerr << "Error connecting to Monero deamon due to " + << err << endl; + return false; + } + } + else + { + cerr << "Error connecting to Monero deamon at " + << deamon_url << endl; + return false; + } + + response = resp_t.result; + + return true; +} + + + bool rpccalls::get_dynamic_per_kb_fee_estimate( uint64_t grace_blocks, diff --git a/src/rpccalls.h b/src/rpccalls.h index 1e8ef83..720936e 100644 --- a/src/rpccalls.h +++ b/src/rpccalls.h @@ -99,6 +99,9 @@ public: bool get_network_info(COMMAND_RPC_GET_INFO::response& info); + bool + get_hardfork_info( COMMAND_RPC_HARD_FORK_INFO::response& res); + bool get_dynamic_per_kb_fee_estimate( uint64_t grace_blocks,