|
|
|
@ -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")
|
|
|
|
|
{
|
|
|
|
|