|
|
@ -53,7 +53,10 @@ namespace xmreg {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
page(MicroCore* _mcore, Blockchain* _core_storage)
|
|
|
|
page(MicroCore* _mcore, Blockchain* _core_storage)
|
|
|
|
: mcore {_mcore}, core_storage {_core_storage}
|
|
|
|
: mcore {_mcore},
|
|
|
|
|
|
|
|
core_storage {_core_storage},
|
|
|
|
|
|
|
|
server_timestamp {std::time(nullptr)}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -69,8 +72,6 @@ namespace xmreg {
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t height = rpc.get_current_height() - 1;
|
|
|
|
uint64_t height = rpc.get_current_height() - 1;
|
|
|
|
|
|
|
|
|
|
|
|
fmt::print("Current height: {:d}\n", height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
mstch::map context {
|
|
|
|
mstch::map context {
|
|
|
|
{"refresh", refresh_page},
|
|
|
|
{"refresh", refresh_page},
|
|
|
@ -85,8 +86,6 @@ namespace xmreg {
|
|
|
|
// get reference to blocks template map to be field below
|
|
|
|
// get reference to blocks template map to be field below
|
|
|
|
mstch::array& blocks = boost::get<mstch::array>(context["blocks"]);
|
|
|
|
mstch::array& blocks = boost::get<mstch::array>(context["blocks"]);
|
|
|
|
|
|
|
|
|
|
|
|
time_t prev_blk_timestamp {0};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// iterate over last no_of_last_blocks of blocks
|
|
|
|
// iterate over last no_of_last_blocks of blocks
|
|
|
|
for (size_t i = height - no_of_last_blocks; i <= height; ++i)
|
|
|
|
for (size_t i = height - no_of_last_blocks; i <= height; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -100,30 +99,15 @@ namespace xmreg {
|
|
|
|
|
|
|
|
|
|
|
|
string blk_hash_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", blk_hash));
|
|
|
|
string blk_hash_str = REMOVE_HASH_BRAKETS(fmt::format("{:s}", blk_hash));
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t delta_hours {0};
|
|
|
|
// calculate difference between server and block timestamps
|
|
|
|
uint64_t delta_minutes {0};
|
|
|
|
|
|
|
|
uint64_t delta_seconds {0};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (prev_blk_timestamp > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// array<size_t, 5> delta_time = timestamp_difference(
|
|
|
|
|
|
|
|
// prev_blk_timestamp, blk.timestamp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
array<size_t, 5> delta_time = timestamp_difference(
|
|
|
|
array<size_t, 5> delta_time = timestamp_difference(
|
|
|
|
server_timestamp, blk.timestamp);
|
|
|
|
server_timestamp, blk.timestamp);
|
|
|
|
|
|
|
|
|
|
|
|
delta_hours = delta_time[2];
|
|
|
|
string timestamp_str = xmreg::timestamp_to_str(blk.timestamp);
|
|
|
|
delta_minutes = delta_time[3];
|
|
|
|
|
|
|
|
delta_seconds = delta_time[4];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string timestamp_str = xmreg::timestamp_to_str(blk.timestamp)
|
|
|
|
|
|
|
|
+ fmt::format(" ({:02d}:{:02d})",
|
|
|
|
|
|
|
|
delta_minutes, delta_seconds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
|
|
|
|
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
|
|
|
|
delta_hours, delta_minutes,
|
|
|
|
delta_time[2], delta_time[3],
|
|
|
|
delta_seconds);
|
|
|
|
delta_time[4]);
|
|
|
|
|
|
|
|
|
|
|
|
// get xmr in the block reward
|
|
|
|
// get xmr in the block reward
|
|
|
|
array<uint64_t, 2> coinbase_tx = sum_money_in_tx(blk.miner_tx);
|
|
|
|
array<uint64_t, 2> coinbase_tx = sum_money_in_tx(blk.miner_tx);
|
|
|
@ -182,8 +166,6 @@ namespace xmreg {
|
|
|
|
{"blksize" , fmt::format("{:0.2f}",
|
|
|
|
{"blksize" , fmt::format("{:0.2f}",
|
|
|
|
static_cast<double>(blk_size) / 1024.0)}
|
|
|
|
static_cast<double>(blk_size) / 1024.0)}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
prev_blk_timestamp = blk.timestamp;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// reverse blocks and remove last (i.e., oldest)
|
|
|
|
// reverse blocks and remove last (i.e., oldest)
|
|
|
@ -192,8 +174,10 @@ namespace xmreg {
|
|
|
|
std::reverse(blocks.begin(), blocks.end());
|
|
|
|
std::reverse(blocks.begin(), blocks.end());
|
|
|
|
blocks.pop_back();
|
|
|
|
blocks.pop_back();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get memory pool rendered template
|
|
|
|
string mempool_html = mempool();
|
|
|
|
string mempool_html = mempool();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// append mempool_html to the index context map
|
|
|
|
context["mempool_info"] = mempool_html;
|
|
|
|
context["mempool_info"] = mempool_html;
|
|
|
|
|
|
|
|
|
|
|
|
// read index.html
|
|
|
|
// read index.html
|
|
|
@ -236,7 +220,7 @@ namespace xmreg {
|
|
|
|
return "Error connecting to Monero deamon to get mempool";
|
|
|
|
return "Error connecting to Monero deamon to get mempool";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// initalise page tempate map with basic info about blockchain
|
|
|
|
// 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}", res.transactions.size())},
|
|
|
|
{"mempooltxs" , mstch::array()}
|
|
|
|
{"mempooltxs" , mstch::array()}
|
|
|
@ -245,27 +229,27 @@ namespace xmreg {
|
|
|
|
// get reference to blocks template map to be field below
|
|
|
|
// get reference to blocks template map to be field below
|
|
|
|
mstch::array& txs = boost::get<mstch::array>(context["mempooltxs"]);
|
|
|
|
mstch::array& txs = boost::get<mstch::array>(context["mempooltxs"]);
|
|
|
|
|
|
|
|
|
|
|
|
// std::sort(res.transactions.begin(), res.transactions.end(),
|
|
|
|
|
|
|
|
// [](const tx_info& _tx_info1, const tx_info& _tx_info2)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// return _tx_info1.receive_time > _tx_info2.receive_time;
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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 < res.transactions.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 = res.transactions.at(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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(
|
|
|
|
server_timestamp, _tx_info.receive_time);
|
|
|
|
server_timestamp,
|
|
|
|
|
|
|
|
_tx_info.receive_time);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// use only hours, so if we have days, add
|
|
|
|
|
|
|
|
// it to hours
|
|
|
|
uint64_t delta_hours {delta_time[1]*24 + delta_time[2]};
|
|
|
|
uint64_t delta_hours {delta_time[1]*24 + delta_time[2]};
|
|
|
|
|
|
|
|
|
|
|
|
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
|
|
|
|
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
|
|
|
|
delta_hours,
|
|
|
|
delta_hours,
|
|
|
|
delta_time[3], delta_time[4]);
|
|
|
|
delta_time[3], delta_time[4]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if more than 99 hourse, change formating
|
|
|
|
|
|
|
|
// for the template
|
|
|
|
if (delta_hours > 99)
|
|
|
|
if (delta_hours > 99)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
age_str = fmt::format("{:03d}:{:02d}:{:02d}",
|
|
|
|
age_str = fmt::format("{:03d}:{:02d}:{:02d}",
|
|
|
@ -273,10 +257,10 @@ namespace xmreg {
|
|
|
|
delta_time[3], delta_time[4]);
|
|
|
|
delta_time[3], delta_time[4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sum xmr in inputs and ouputs in the given tx
|
|
|
|
uint64_t sum_inputs = sum_xmr_inputs(_tx_info.tx_json);
|
|
|
|
uint64_t sum_inputs = sum_xmr_inputs(_tx_info.tx_json);
|
|
|
|
uint64_t sum_outputs = sum_xmr_outputs(_tx_info.tx_json);
|
|
|
|
uint64_t sum_outputs = sum_xmr_outputs(_tx_info.tx_json);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get mixin number in each transaction
|
|
|
|
// get mixin number in each transaction
|
|
|
|
vector<uint64_t> mixin_numbers = get_mixin_no_in_txs(_tx_info.tx_json);
|
|
|
|
vector<uint64_t> mixin_numbers = get_mixin_no_in_txs(_tx_info.tx_json);
|
|
|
|
|
|
|
|
|
|
|
@ -317,13 +301,11 @@ namespace xmreg {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get information about outputs
|
|
|
|
// get information about outputs
|
|
|
|
const rapidjson::Value& vout = json["vout"];
|
|
|
|
const rapidjson::Value& vout = json["vout"];
|
|
|
|
|
|
|
|
|
|
|
|
if (vout.IsArray())
|
|
|
|
if (vout.IsArray())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// print("Outputs:\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (rapidjson::SizeType i = 0; i < vout.Size(); ++i)
|
|
|
|
for (rapidjson::SizeType i = 0; i < vout.Size(); ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -351,7 +333,6 @@ namespace xmreg {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get information about inputs
|
|
|
|
// get information about inputs
|
|
|
|
const rapidjson::Value& vin = json["vin"];
|
|
|
|
const rapidjson::Value& vin = json["vin"];
|
|
|
|
|
|
|
|
|
|
|
@ -377,6 +358,7 @@ namespace xmreg {
|
|
|
|
return sum_xmr;
|
|
|
|
return sum_xmr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<uint64_t>
|
|
|
|
vector<uint64_t>
|
|
|
|
get_mixin_no_in_txs(const string& json_str)
|
|
|
|
get_mixin_no_in_txs(const string& json_str)
|
|
|
|
{
|
|
|
|
{
|
|
|
|