mirror of
https://git.wownero.com/wownero/onion-wownero-blockchain-explorer.git
synced 2024-08-15 00:33:12 +00:00
get_mempool added to rpccalls class
This commit is contained in:
parent
85e698e615
commit
f6d43c0111
2 changed files with 21 additions and 52 deletions
37
src/page.h
37
src/page.h
|
@ -99,6 +99,7 @@ namespace xmreg {
|
||||||
uint64_t end_height = height - no_of_last_blocks * (page_no);
|
uint64_t end_height = height - no_of_last_blocks * (page_no);
|
||||||
|
|
||||||
// check few conditions to make sure we are whithin the avaliable range
|
// check few conditions to make sure we are whithin the avaliable range
|
||||||
|
//@TODO its too messed up. needs to find cleaner way.
|
||||||
start_height = start_height > 0 ? start_height : 0;
|
start_height = start_height > 0 ? start_height : 0;
|
||||||
end_height = end_height < height ? end_height : height;
|
end_height = end_height < height ? end_height : height;
|
||||||
start_height = start_height > end_height ? 0 : start_height;
|
start_height = start_height > end_height ? 0 : start_height;
|
||||||
|
@ -127,6 +128,7 @@ namespace xmreg {
|
||||||
|
|
||||||
string timestamp_str = xmreg::timestamp_to_str(blk.timestamp);
|
string timestamp_str = xmreg::timestamp_to_str(blk.timestamp);
|
||||||
|
|
||||||
|
// default format for age
|
||||||
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
|
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
|
||||||
delta_time[2], delta_time[3],
|
delta_time[2], delta_time[3],
|
||||||
delta_time[4]);
|
delta_time[4]);
|
||||||
|
@ -134,10 +136,10 @@ namespace xmreg {
|
||||||
// if have days or years, change age format
|
// if have days or years, change age format
|
||||||
if (delta_time[0] > 0)
|
if (delta_time[0] > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
age_str = fmt::format("{:02d}:{:02d}:{:02d}:{:02d}:{:02d}",
|
age_str = fmt::format("{:02d}:{:02d}:{:02d}:{:02d}:{:02d}",
|
||||||
delta_time[0], delta_time[1], delta_time[2],
|
delta_time[0], delta_time[1], delta_time[2],
|
||||||
delta_time[3], delta_time[4]);
|
delta_time[3], delta_time[4]);
|
||||||
|
|
||||||
context["age_format"] = string("[y:d:h:m:s]");
|
context["age_format"] = string("[y:d:h:m:s]");
|
||||||
}
|
}
|
||||||
else if (delta_time[1] > 0)
|
else if (delta_time[1] > 0)
|
||||||
|
@ -145,6 +147,7 @@ namespace xmreg {
|
||||||
age_str = fmt::format("{:02d}:{:02d}:{:02d}:{:02d}",
|
age_str = fmt::format("{:02d}:{:02d}:{:02d}:{:02d}",
|
||||||
delta_time[1], delta_time[2],
|
delta_time[1], delta_time[2],
|
||||||
delta_time[3], delta_time[4]);
|
delta_time[3], delta_time[4]);
|
||||||
|
|
||||||
context["age_format"] = string("[d:h:m:s]");
|
context["age_format"] = string("[d:h:m:s]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +179,7 @@ namespace xmreg {
|
||||||
*max_element(mixin_numbers.begin(), mixin_numbers.end()));
|
*max_element(mixin_numbers.begin(), mixin_numbers.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mixing format for the templates
|
||||||
auto mixin_format = [=]() -> mstch::node
|
auto mixin_format = [=]() -> mstch::node
|
||||||
{
|
{
|
||||||
if (mixin_min < 0)
|
if (mixin_min < 0)
|
||||||
|
@ -185,6 +189,7 @@ namespace xmreg {
|
||||||
return fmt::format("{:d}-{:d}", mixin_min - 1, mixin_max - 1);
|
return fmt::format("{:d}-{:d}", mixin_min - 1, mixin_max - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// get block size in bytes
|
||||||
uint64_t blk_size = get_object_blobsize(blk);
|
uint64_t blk_size = get_object_blobsize(blk);
|
||||||
|
|
||||||
// set output page template map
|
// set output page template map
|
||||||
|
@ -233,35 +238,17 @@ namespace xmreg {
|
||||||
string
|
string
|
||||||
mempool()
|
mempool()
|
||||||
{
|
{
|
||||||
string deamon_url {"http:://127.0.0.1:18081"};
|
|
||||||
|
|
||||||
// perform RPC call to deamon to get
|
std::vector<tx_info> mempool_txs;
|
||||||
// its transaction pull
|
|
||||||
boost::mutex m_daemon_rpc_mutex;
|
|
||||||
|
|
||||||
request req;
|
if (!rpc.get_mempool(mempool_txs))
|
||||||
response res;
|
|
||||||
|
|
||||||
http_simple_client m_http_client;
|
|
||||||
|
|
||||||
m_daemon_rpc_mutex.lock();
|
|
||||||
|
|
||||||
bool r = epee::net_utils::invoke_http_json_remote_command2(
|
|
||||||
deamon_url + "/get_transaction_pool",
|
|
||||||
req, res, m_http_client, 200000);
|
|
||||||
|
|
||||||
m_daemon_rpc_mutex.unlock();
|
|
||||||
|
|
||||||
if (!r)
|
|
||||||
{
|
{
|
||||||
cerr << "Error connecting to Monero deamon at "
|
return "Getting mempool failed";
|
||||||
<< deamon_url << endl;
|
|
||||||
return "Error connecting to Monero deamon to get mempool";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// initalise page tempate map with basic info about mempool
|
// initalise page tempate map with basic info about mempool
|
||||||
mstch::map context {
|
mstch::map context {
|
||||||
{"mempool_size", fmt::format("{:d}", res.transactions.size())},
|
{"mempool_size", fmt::format("{:d}", mempool_txs.size())},
|
||||||
{"mempooltxs" , mstch::array()}
|
{"mempooltxs" , mstch::array()}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -269,10 +256,10 @@ namespace xmreg {
|
||||||
mstch::array& txs = boost::get<mstch::array>(context["mempooltxs"]);
|
mstch::array& txs = boost::get<mstch::array>(context["mempooltxs"]);
|
||||||
|
|
||||||
// for each transaction in the memory pool
|
// for each transaction in the memory pool
|
||||||
for (size_t i = 0; i < res.transactions.size(); ++i)
|
for (size_t i = 0; i < mempool_txs.size(); ++i)
|
||||||
{
|
{
|
||||||
// get transaction info of the tx in the mempool
|
// get transaction info of the tx in the mempool
|
||||||
tx_info _tx_info = res.transactions.at(i);
|
tx_info _tx_info = mempool_txs.at(i);
|
||||||
|
|
||||||
// calculate difference between tx in mempool and server timestamps
|
// calculate difference between tx in mempool and server timestamps
|
||||||
array<size_t, 5> delta_time = timestamp_difference(
|
array<size_t, 5> delta_time = timestamp_difference(
|
||||||
|
|
|
@ -59,32 +59,22 @@ namespace xmreg
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.height;
|
return res.height;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//@TODO not finished
|
bool
|
||||||
vector<block>
|
get_mempool(vector<tx_info>& mempool_txs) {
|
||||||
get_blocks(uint64_t start_height)
|
|
||||||
{
|
|
||||||
|
|
||||||
vector<block> blocks;
|
|
||||||
|
|
||||||
COMMAND_RPC_GET_BLOCKS_FAST::request req;
|
|
||||||
COMMAND_RPC_GET_BLOCKS_FAST::response res;
|
|
||||||
|
|
||||||
req.start_height = start_height;
|
|
||||||
|
|
||||||
|
COMMAND_RPC_GET_TRANSACTION_POOL::request req;
|
||||||
|
COMMAND_RPC_GET_TRANSACTION_POOL::response res;
|
||||||
|
|
||||||
http_simple_client m_http_client;
|
http_simple_client m_http_client;
|
||||||
|
|
||||||
// perform RPC call to deamon to get
|
|
||||||
// its transaction pull
|
|
||||||
boost::mutex m_daemon_rpc_mutex;
|
boost::mutex m_daemon_rpc_mutex;
|
||||||
|
|
||||||
m_daemon_rpc_mutex.lock();
|
m_daemon_rpc_mutex.lock();
|
||||||
|
|
||||||
bool r = epee::net_utils::invoke_http_json_remote_command2(
|
bool r = epee::net_utils::invoke_http_json_remote_command2(
|
||||||
deamon_url + "/getblocks.bin",
|
deamon_url + "/get_transaction_pool",
|
||||||
req, res, m_http_client, 200000);
|
req, res, m_http_client, 200000);
|
||||||
|
|
||||||
m_daemon_rpc_mutex.unlock();
|
m_daemon_rpc_mutex.unlock();
|
||||||
|
@ -93,24 +83,16 @@ namespace xmreg
|
||||||
{
|
{
|
||||||
cerr << "Error connecting to Monero deamon at "
|
cerr << "Error connecting to Monero deamon at "
|
||||||
<< deamon_url << endl;
|
<< deamon_url << endl;
|
||||||
return blocks;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::list<block_complete_entry>& blocks_entries = res.blocks;
|
mempool_txs = res.transactions;
|
||||||
|
|
||||||
for (const auto& be: blocks_entries)
|
|
||||||
{
|
|
||||||
// blocks.push_back(block_)
|
|
||||||
}
|
|
||||||
|
|
||||||
return blocks;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue