|
|
@ -2,11 +2,14 @@
|
|
|
|
// Created by mwo on 13/04/16.
|
|
|
|
// Created by mwo on 13/04/16.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CROWXMR_RPCCALLS_H
|
|
|
|
#ifndef CROWXMR_RPCCALLS_H
|
|
|
|
#define CROWXMR_RPCCALLS_H
|
|
|
|
#define CROWXMR_RPCCALLS_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "monero_headers.h"
|
|
|
|
#include "monero_headers.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
|
|
namespace xmreg
|
|
|
|
namespace xmreg
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
@ -15,26 +18,23 @@ namespace xmreg
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using request = cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::request;
|
|
|
|
|
|
|
|
using response = cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::response;
|
|
|
|
|
|
|
|
using http_simple_client = epee::net_utils::http::http_simple_client;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class rpccalls
|
|
|
|
class rpccalls
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string deamon_url {"http:://127.0.0.1:18081"};
|
|
|
|
string deamon_url ;
|
|
|
|
uint64_t timeout_time {200000};
|
|
|
|
uint64_t timeout_time;
|
|
|
|
|
|
|
|
|
|
|
|
epee::net_utils::http::url_content url;
|
|
|
|
epee::net_utils::http::url_content url;
|
|
|
|
|
|
|
|
|
|
|
|
http_simple_client m_http_client;
|
|
|
|
epee::net_utils::http::http_simple_client m_http_client;
|
|
|
|
boost::mutex m_daemon_rpc_mutex;
|
|
|
|
std::mutex m_daemon_rpc_mutex;
|
|
|
|
|
|
|
|
|
|
|
|
string port;
|
|
|
|
string port;
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
rpccalls()
|
|
|
|
rpccalls(string _deamon_url = "http:://127.0.0.1:18081",
|
|
|
|
|
|
|
|
uint64_t _timeout = 200000)
|
|
|
|
|
|
|
|
: deamon_url {_deamon_url}, timeout_time {_timeout}
|
|
|
|
{
|
|
|
|
{
|
|
|
|
epee::net_utils::parse_url(deamon_url, url);
|
|
|
|
epee::net_utils::parse_url(deamon_url, url);
|
|
|
|
|
|
|
|
|
|
|
@ -42,9 +42,14 @@ namespace xmreg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
check_connection()
|
|
|
|
connect_to_monero_deamon()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> guard(m_daemon_rpc_mutex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(m_http_client.is_connected())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_daemon_rpc_mutex.lock();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return m_http_client.connect(url.host,
|
|
|
|
return m_http_client.connect(url.host,
|
|
|
|
port,
|
|
|
|
port,
|
|
|
@ -57,14 +62,12 @@ namespace xmreg
|
|
|
|
COMMAND_RPC_GET_HEIGHT::request req;
|
|
|
|
COMMAND_RPC_GET_HEIGHT::request req;
|
|
|
|
COMMAND_RPC_GET_HEIGHT::response res;
|
|
|
|
COMMAND_RPC_GET_HEIGHT::response res;
|
|
|
|
|
|
|
|
|
|
|
|
m_daemon_rpc_mutex.lock();
|
|
|
|
std::lock_guard<std::mutex> guard(m_daemon_rpc_mutex);
|
|
|
|
|
|
|
|
|
|
|
|
bool r = epee::net_utils::invoke_http_json_remote_command2(
|
|
|
|
bool r = epee::net_utils::invoke_http_json_remote_command2(
|
|
|
|
deamon_url + "/getheight",
|
|
|
|
deamon_url + "/getheight",
|
|
|
|
req, res, m_http_client, timeout_time);
|
|
|
|
req, res, m_http_client, timeout_time);
|
|
|
|
|
|
|
|
|
|
|
|
m_daemon_rpc_mutex.unlock();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!r)
|
|
|
|
if (!r)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cerr << "Error connecting to Monero deamon at "
|
|
|
|
cerr << "Error connecting to Monero deamon at "
|
|
|
@ -85,14 +88,12 @@ namespace xmreg
|
|
|
|
COMMAND_RPC_GET_TRANSACTION_POOL::request req;
|
|
|
|
COMMAND_RPC_GET_TRANSACTION_POOL::request req;
|
|
|
|
COMMAND_RPC_GET_TRANSACTION_POOL::response res;
|
|
|
|
COMMAND_RPC_GET_TRANSACTION_POOL::response res;
|
|
|
|
|
|
|
|
|
|
|
|
m_daemon_rpc_mutex.lock();
|
|
|
|
std::lock_guard<std::mutex> guard(m_daemon_rpc_mutex);
|
|
|
|
|
|
|
|
|
|
|
|
bool r = epee::net_utils::invoke_http_json_remote_command2(
|
|
|
|
bool r = epee::net_utils::invoke_http_json_remote_command2(
|
|
|
|
deamon_url + "/get_transaction_pool",
|
|
|
|
deamon_url + "/get_transaction_pool",
|
|
|
|
req, res, m_http_client, timeout_time);
|
|
|
|
req, res, m_http_client, timeout_time);
|
|
|
|
|
|
|
|
|
|
|
|
m_daemon_rpc_mutex.unlock();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!r)
|
|
|
|
if (!r)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cerr << "Error connecting to Monero deamon at "
|
|
|
|
cerr << "Error connecting to Monero deamon at "
|
|
|
|