checking if connection to deamon exists

master
moneroexamples 9 years ago
parent 10a264c03b
commit c388078432

@ -44,7 +44,6 @@ namespace xmreg {
class page {
MicroCore* mcore;
Blockchain* core_storage;
rpccalls rpc;
@ -56,14 +55,22 @@ namespace xmreg {
: mcore {_mcore},
core_storage {_core_storage},
server_timestamp {std::time(nullptr)}
{
}
string
index(uint64_t page_no = 0, bool refresh_page = false)
{
bool is_connected = rpc.check_connection();
cout << "check connection: " << is_connected << endl;
if (!is_connected)
{
return "Connection to the Monero demon does not exist or was lost!";
}
//get current server timestamp
server_timestamp = std::time(nullptr);
@ -87,7 +94,6 @@ namespace xmreg {
{"is_page_zero" , !bool(page_no)},
{"next_page" , fmt::format("{:d}", page_no + 1)},
{"prev_page" , fmt::format("{:d}", (page_no > 0 ? page_no - 1 : 0))},
};
@ -115,7 +121,11 @@ namespace xmreg {
// get block at the given height i
block blk;
mcore->get_block_by_height(i, blk);
if (!mcore->get_block_by_height(i, blk))
{
cerr << "Cant get block: " << i << endl;
continue;
}
// get block's hash
crypto::hash blk_hash = core_storage->get_block_id_by_height(i);
@ -238,7 +248,6 @@ namespace xmreg {
string
mempool()
{
std::vector<tx_info> mempool_txs;
if (!rpc.get_mempool(mempool_txs))
@ -313,7 +322,6 @@ namespace xmreg {
private:
uint64_t
sum_xmr_outputs(const string& json_str)
{

@ -23,27 +23,45 @@ namespace xmreg
class rpccalls
{
string deamon_url {"http:://127.0.0.1:18081"};
uint64_t timeout_time {200000};
uint64_t timeout_time {20000};
epee::net_utils::http::url_content url;
http_simple_client m_http_client;
boost::mutex m_daemon_rpc_mutex;
string port;
public:
rpccalls()
{
epee::net_utils::parse_url(deamon_url, url);
port = std::to_string(url.port);
}
bool
check_connection()
{
m_daemon_rpc_mutex.lock();
return m_http_client.connect(url.host,
port,
timeout_time);
}
uint64_t
get_current_height()
{
COMMAND_RPC_GET_HEIGHT::request req;
COMMAND_RPC_GET_HEIGHT::response res;
http_simple_client m_http_client;
// perform RPC call to deamon to get
// its transaction pull
boost::mutex m_daemon_rpc_mutex;
m_daemon_rpc_mutex.lock();
bool r = epee::net_utils::invoke_http_json_remote_command2(
deamon_url + "/getheight",
req, res, m_http_client, 200000);
req, res, m_http_client, timeout_time);
m_daemon_rpc_mutex.unlock();
@ -67,15 +85,11 @@ namespace xmreg
COMMAND_RPC_GET_TRANSACTION_POOL::request req;
COMMAND_RPC_GET_TRANSACTION_POOL::response res;
http_simple_client m_http_client;
boost::mutex m_daemon_rpc_mutex;
m_daemon_rpc_mutex.lock();
bool r = epee::net_utils::invoke_http_json_remote_command2(
deamon_url + "/get_transaction_pool",
req, res, m_http_client, 200000);
req, res, m_http_client, timeout_time);
m_daemon_rpc_mutex.unlock();

Loading…
Cancel
Save