From 26bb36e3c8c641ec2bd56d9a5242e014cdaaa7f8 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Wed, 9 Jan 2019 11:04:39 +0800 Subject: [PATCH] RPCCalls modification towards checking Failed to SEND https://github.com/moneroexamples/openmonero/issues/118 https://github.com/moneroexamples/openmonero/commit/cf4857268125cf32f55c8aea3281574755ea91e6#commitcomment-31875685 --- src/RPCCalls.cpp | 115 ++++++++++++++++++++++++----------------------- src/RPCCalls.h | 21 +++++---- src/TxSearch.cpp | 17 +++++-- 3 files changed, 83 insertions(+), 70 deletions(-) diff --git a/src/RPCCalls.cpp b/src/RPCCalls.cpp index 784dc3f..14baf7f 100755 --- a/src/RPCCalls.cpp +++ b/src/RPCCalls.cpp @@ -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{}); } -RPCCalls::RPCCalls(RPCCalls&& a) -{ - std::lock_guard guard(a.m_daemon_rpc_mutex); +//RPCCalls::RPCCalls(RPCCalls&& a) +//{ + //std::lock_guard 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{}); + //// 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{}); - // 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 lhs_lk(m_daemon_rpc_mutex, std::defer_lock); - std::unique_lock rhs_lk(a.m_daemon_rpc_mutex, std::defer_lock); + //std::unique_lock lhs_lk(m_daemon_rpc_mutex, std::defer_lock); + //std::unique_lock 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{}); + //// 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{}); - // 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") { diff --git a/src/RPCCalls.h b/src/RPCCalls.h index 425e224..f8fdc29 100755 --- a/src/RPCCalls.h +++ b/src/RPCCalls.h @@ -9,6 +9,7 @@ #include "monero_headers.h" #include +#include 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(); diff --git a/src/TxSearch.cpp b/src/TxSearch.cpp index 71144b5..3cc21c0 100755 --- a/src/TxSearch.cpp +++ b/src/TxSearch.cpp @@ -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( chrono::system_clock::now().time_since_epoch());