moneroexamples 5 years ago
parent 9f49adba01
commit 26bb36e3c8

@ -7,88 +7,86 @@
namespace xmreg
{
RPCCalls::RPCCalls(string _deamon_url, uint64_t _timeout)
: deamon_url {_deamon_url}, timeout_time {_timeout}
RPCCalls::RPCCalls(string _deamon_url, chrono::seconds _timeout)
: deamon_url {_deamon_url}, rpc_timeout {_timeout}
{
epee::net_utils::parse_url(deamon_url, url);
port = std::to_string(url.port);
timeout_time_ms = std::chrono::milliseconds {timeout_time};
m_http_client.set_server(
deamon_url,
boost::optional<epee::net_utils::http::login>{});
}
RPCCalls::RPCCalls(RPCCalls&& a)
{
std::lock_guard<std::mutex> guard(a.m_daemon_rpc_mutex);
//RPCCalls::RPCCalls(RPCCalls&& a)
//{
//std::lock_guard<std::mutex> guard(a.m_daemon_rpc_mutex);
deamon_url = std::move(a.deamon_url);
timeout_time = a.timeout_time;
timeout_time_ms = a.timeout_time_ms;
//deamon_url = std::move(a.deamon_url);
//timeout_time = a.timeout_time;
//timeout_time_ms = a.timeout_time_ms;
url = std::move(a.url);
port = std::move(port);
//url = std::move(a.url);
//port = std::move(port);
// we can't move or copy m_http_client,
// so we just initialize it from zero
m_http_client.set_server(
deamon_url,
boost::optional<epee::net_utils::http::login>{});
//// we can't move or copy m_http_client,
//// so we just initialize it from zero
//m_http_client.set_server(
//deamon_url,
//boost::optional<epee::net_utils::http::login>{});
// after the move, disconned the a object
a.m_http_client.disconnect();
//// after the move, disconned the a object
//a.m_http_client.disconnect();
cout << "\n RPCCalls(RPCCalls&& a) " << endl;
}
//cout << "\n RPCCalls(RPCCalls&& a) " << endl;
//}
RPCCalls&
RPCCalls::operator=(RPCCalls&& a)
{
if (*this == a)
return *this;
//RPCCalls&
//RPCCalls::operator=(RPCCalls&& a)
//{
//if (*this == a)
//return *this;
std::unique_lock<std::mutex> lhs_lk(m_daemon_rpc_mutex, std::defer_lock);
std::unique_lock<std::mutex> rhs_lk(a.m_daemon_rpc_mutex, std::defer_lock);
//std::unique_lock<std::mutex> lhs_lk(m_daemon_rpc_mutex, std::defer_lock);
//std::unique_lock<std::mutex> rhs_lk(a.m_daemon_rpc_mutex, std::defer_lock);
std::lock(lhs_lk, rhs_lk);
//std::lock(lhs_lk, rhs_lk);
deamon_url = std::move(a.deamon_url);
timeout_time = a.timeout_time;
timeout_time_ms = a.timeout_time_ms;
//deamon_url = std::move(a.deamon_url);
//timeout_time = a.timeout_time;
//timeout_time_ms = a.timeout_time_ms;
url = std::move(a.url);
port = std::move(port);
//url = std::move(a.url);
//port = std::move(port);
// we can't move or copy m_http_client,
// so we just initialize it from zero
m_http_client.set_server(
deamon_url,
boost::optional<epee::net_utils::http::login>{});
//// we can't move or copy m_http_client,
//// so we just initialize it from zero
//m_http_client.set_server(
//deamon_url,
//boost::optional<epee::net_utils::http::login>{});
// after the move, disconned the a object
a.m_http_client.disconnect();
//// after the move, disconned the a object
//a.m_http_client.disconnect();
cout << "\n RPCCalls& operator=(RPCCalls&& a) " << endl;
//cout << "\n RPCCalls& operator=(RPCCalls&& a) " << endl;
return *this;
}
//return *this;
//}
bool
RPCCalls::operator==(RPCCalls const& a)
{
return deamon_url == a.deamon_url;
}
//bool
//RPCCalls::operator==(RPCCalls const& a)
//{
//return deamon_url == a.deamon_url;
//}
bool
RPCCalls::operator!=(RPCCalls const& a)
{
return !(*this == a);
}
//bool
//RPCCalls::operator!=(RPCCalls const& a)
//{
//return !(*this == a);
//}
bool
@ -99,7 +97,7 @@ RPCCalls::connect_to_monero_deamon()
return true;
}
return m_http_client.connect(timeout_time_ms);
return m_http_client.connect(rpc_timeout);
}
@ -121,13 +119,16 @@ RPCCalls::commit_tx(
if (!connect_to_monero_deamon())
{
cerr << "get_current_height: not connected to deamon" << endl;
cerr << "commit_tx: not connected to deamon" << endl;
error_msg = "Can't connect to Monero daemon";
return false;
}
bool r = epee::net_utils::invoke_http_json(
"/sendrawtransaction", req, res,
m_http_client, timeout_time_ms);
m_http_client, rpc_timeout);
if (!r || res.status == "Failed")
{

@ -9,6 +9,7 @@
#include "monero_headers.h"
#include <mutex>
#include <chrono>
namespace xmreg
{
@ -17,13 +18,15 @@ using namespace cryptonote;
using namespace crypto;
using namespace std;
using namespace std::chrono_literals;
class RPCCalls
{
string deamon_url;
uint64_t timeout_time;
std::chrono::milliseconds timeout_time_ms;
//std::chrono::milliseconds timeout_time_ms;
chrono::seconds rpc_timeout;
epee::net_utils::http::url_content url;
@ -36,18 +39,18 @@ class RPCCalls
public:
RPCCalls(string _deamon_url = "http:://127.0.0.1:18081",
uint64_t _timeout = 200000);
chrono::seconds _timeout = 3min + 30s);
RPCCalls(RPCCalls&& a);
//RPCCalls(RPCCalls&& a);
RPCCalls&
operator=(RPCCalls&& a);
//RPCCalls&
//operator=(RPCCalls&& a);
virtual bool
operator==(RPCCalls const& a);
//virtual bool
//operator==(RPCCalls const& a);
virtual bool
operator!=(RPCCalls const& a);
//virtual bool
//operator!=(RPCCalls const& a);
virtual bool
connect_to_monero_deamon();

@ -85,8 +85,17 @@ TxSearch::operator()()
if (blocks.empty())
{
OMINFO << "Cant get blocks from " << h1
<< " to " << h2;
if (h1 <= h2)
{
OMERROR << "Cant get blocks from " << h1
<< " to " << h2;
stop();
}
else
{
OMINFO << "Waiting for new block. Last scanned was " << h2;
}
std::this_thread::sleep_for(
std::chrono::seconds(
@ -615,8 +624,8 @@ TxSearch::get_current_timestamp() const
void
TxSearch::ping()
{
OMINFO << "New last_ping_timestamp: "
<< last_ping_timestamp.count();
//OMINFO << "New last_ping_timestamp: "
// << last_ping_timestamp.count();
last_ping_timestamp = chrono::duration_cast<seconds>(
chrono::system_clock::now().time_since_epoch());

Loading…
Cancel
Save