2016-04-12 22:20:14 +00:00
|
|
|
//
|
|
|
|
// Created by mwo on 13/04/16.
|
|
|
|
//
|
|
|
|
|
2016-04-15 21:48:37 +00:00
|
|
|
|
2016-04-12 22:20:14 +00:00
|
|
|
#ifndef CROWXMR_RPCCALLS_H
|
|
|
|
#define CROWXMR_RPCCALLS_H
|
|
|
|
|
|
|
|
#include "monero_headers.h"
|
|
|
|
|
2016-04-15 21:48:37 +00:00
|
|
|
#include <mutex>
|
2017-11-20 00:39:08 +00:00
|
|
|
#include <utility>
|
2016-04-15 21:48:37 +00:00
|
|
|
|
2017-06-20 01:00:55 +00:00
|
|
|
|
2017-06-20 06:21:56 +00:00
|
|
|
|
|
|
|
|
2017-06-20 01:00:55 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2017-06-20 06:21:56 +00:00
|
|
|
// can be used to check if given class/struct exist
|
|
|
|
// from: https://stackoverflow.com/a/10722840/248823
|
|
|
|
template <typename T>
|
|
|
|
struct has_destructor
|
|
|
|
{
|
|
|
|
// has destructor
|
|
|
|
template <typename A>
|
2017-11-20 00:39:08 +00:00
|
|
|
static std::true_type test(decltype(std::declval<A>().~A()) *)
|
2017-06-20 06:21:56 +00:00
|
|
|
{
|
|
|
|
return std::true_type();
|
|
|
|
}
|
|
|
|
|
|
|
|
// no constructor
|
|
|
|
template <typename A>
|
|
|
|
static std::false_type test(...)
|
2017-06-20 01:00:55 +00:00
|
|
|
{
|
2017-06-20 06:21:56 +00:00
|
|
|
return std::false_type();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This will be either `std::true_type` or `std::false_type` */
|
|
|
|
typedef decltype(test<T>(0)) type;
|
|
|
|
|
|
|
|
static const bool value = type::value;
|
|
|
|
};
|
2017-06-20 01:00:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-20 06:21:56 +00:00
|
|
|
namespace cryptonote
|
|
|
|
{
|
|
|
|
// declare struct in monero's cryptonote namespace.
|
|
|
|
// monero should provide definition for this,
|
|
|
|
// but we need to have it declared as we are going to
|
|
|
|
// check if its definition exist or not. depending on this
|
|
|
|
// we decide what gets to be defined as
|
|
|
|
// get_alt_blocks(vector<string>& alt_blocks_hashes);
|
|
|
|
struct COMMAND_RPC_GET_ALT_BLOCKS_HASHES;
|
|
|
|
}
|
|
|
|
|
2016-04-12 22:20:14 +00:00
|
|
|
namespace xmreg
|
|
|
|
{
|
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
using namespace cryptonote;
|
|
|
|
using namespace crypto;
|
|
|
|
using namespace std;
|
2016-04-12 22:20:14 +00:00
|
|
|
|
2017-06-20 06:21:56 +00:00
|
|
|
|
2016-04-12 22:20:14 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
class rpccalls
|
|
|
|
{
|
|
|
|
string deamon_url ;
|
|
|
|
uint64_t timeout_time;
|
2016-04-12 22:20:14 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
std::chrono::milliseconds timeout_time_ms;
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
epee::net_utils::http::url_content url;
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
epee::net_utils::http::http_simple_client m_http_client;
|
|
|
|
std::mutex m_daemon_rpc_mutex;
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
string port;
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
public:
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
rpccalls(string _deamon_url = "http:://127.0.0.1:18081",
|
|
|
|
uint64_t _timeout = 200000);
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
bool
|
|
|
|
connect_to_monero_deamon();
|
2017-02-07 00:56:17 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
uint64_t
|
|
|
|
get_current_height();
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
bool
|
|
|
|
get_mempool(vector<tx_info>& mempool_txs);
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
bool
|
|
|
|
commit_tx(tools::wallet2::pending_tx& ptx, string& error_msg);
|
2016-10-11 05:38:27 +00:00
|
|
|
|
2017-05-11 04:17:10 +00:00
|
|
|
bool
|
|
|
|
get_network_info(COMMAND_RPC_GET_INFO::response& info);
|
|
|
|
|
2017-05-15 06:19:57 +00:00
|
|
|
bool
|
|
|
|
get_dynamic_per_kb_fee_estimate(
|
|
|
|
uint64_t grace_blocks,
|
|
|
|
uint64_t& fee,
|
|
|
|
string& error_msg);
|
|
|
|
|
2017-06-20 01:00:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This must be in the header for now, as it will be tempalte function
|
|
|
|
*
|
|
|
|
* @param alt_blocks_hashes
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
template<typename T = COMMAND_RPC_GET_ALT_BLOCKS_HASHES>
|
|
|
|
typename enable_if<has_destructor<T>::value, bool>::type
|
|
|
|
get_alt_blocks(vector<string>& alt_blocks_hashes)
|
|
|
|
{
|
|
|
|
// definition of COMMAND_RPC_GET_ALT_BLOCKS_HASHES exist
|
|
|
|
// so perform rpc call to get this information
|
|
|
|
|
|
|
|
bool r {false};
|
|
|
|
|
|
|
|
typename T::request req;
|
|
|
|
typename T::response resp;
|
|
|
|
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(m_daemon_rpc_mutex);
|
|
|
|
|
|
|
|
if (!connect_to_monero_deamon())
|
|
|
|
{
|
2017-06-22 02:00:38 +00:00
|
|
|
cerr << "get_alt_blocks: not connected to deamon" << endl;
|
2017-06-20 01:00:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = epee::net_utils::invoke_http_json("/get_alt_blocks_hashes",
|
|
|
|
req, resp,
|
|
|
|
m_http_client);
|
|
|
|
}
|
|
|
|
|
|
|
|
string err;
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
if (resp.status == CORE_RPC_STATUS_BUSY)
|
|
|
|
{
|
|
|
|
err = "daemon is busy. Please try again later.";
|
|
|
|
}
|
|
|
|
else if (resp.status != CORE_RPC_STATUS_OK)
|
|
|
|
{
|
|
|
|
err = "daemon rpc failed. Please try again later.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!err.empty())
|
|
|
|
{
|
|
|
|
cerr << "Error connecting to Monero deamon due to "
|
|
|
|
<< err << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "Error connecting to Monero deamon at "
|
|
|
|
<< deamon_url << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
alt_blocks_hashes = resp.blks_hashes;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T = COMMAND_RPC_GET_ALT_BLOCKS_HASHES>
|
|
|
|
typename enable_if<!has_destructor<T>::value, bool>::type
|
|
|
|
get_alt_blocks(vector<string>& alt_blocks_hashes)
|
|
|
|
{
|
|
|
|
cerr << "COMMAND_RPC_GET_ALT_BLOCKS_HASHES does not exist!" << endl;
|
|
|
|
// definition of COMMAND_RPC_GET_ALT_BLOCKS_HASHES does NOT exist
|
|
|
|
// so dont do anything
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-22 02:00:38 +00:00
|
|
|
bool
|
|
|
|
get_block(string const& blk_hash, block& blk, string& error_msg);
|
|
|
|
|
2017-04-28 05:45:30 +00:00
|
|
|
};
|
2016-04-12 22:20:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif //CROWXMR_RPCCALLS_H
|