html updated
This commit is contained in:
parent
890ce36121
commit
a3aaa3f997
41
main.cpp
41
main.cpp
|
@ -11,7 +11,7 @@ using boost::filesystem::path;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// needed for log system of momero
|
||||||
namespace epee {
|
namespace epee {
|
||||||
unsigned int g_test_dbg_lock_sleep = 0;
|
unsigned int g_test_dbg_lock_sleep = 0;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ int main(int ac, const char* av[]) {
|
||||||
auto port_opt = opts.get_option<string>("port");
|
auto port_opt = opts.get_option<string>("port");
|
||||||
auto bc_path_opt = opts.get_option<string>("bc-path");
|
auto bc_path_opt = opts.get_option<string>("bc-path");
|
||||||
|
|
||||||
|
//cast port number in string to uint16
|
||||||
uint16_t app_port = boost::lexical_cast<uint16_t>(*port_opt);
|
uint16_t app_port = boost::lexical_cast<uint16_t>(*port_opt);
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,18 +41,18 @@ int main(int ac, const char* av[]) {
|
||||||
|
|
||||||
|
|
||||||
// change timezone to Universtal time zone
|
// change timezone to Universtal time zone
|
||||||
char old_tz[128];
|
// char old_tz[128];
|
||||||
const char *tz_org = getenv("TZ");
|
// const char *tz_org = getenv("TZ");
|
||||||
|
|
||||||
if (tz_org)
|
// if (tz_org)
|
||||||
{
|
// {
|
||||||
strcpy(old_tz, tz_org);
|
// strcpy(old_tz, tz_org);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// set new timezone
|
// // set new timezone
|
||||||
std::string tz = "TZ=Coordinated Universal Time";
|
// std::string tz = "TZ=Coordinated Universal Time";
|
||||||
putenv(const_cast<char *>(tz.c_str()));
|
// putenv(const_cast<char *>(tz.c_str()));
|
||||||
tzset(); // Initialize timezone data
|
// tzset(); // Initialize timezone data
|
||||||
|
|
||||||
|
|
||||||
// enable basic monero log output
|
// enable basic monero log output
|
||||||
|
@ -69,11 +69,14 @@ int main(int ac, const char* av[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create instance of page class which
|
||||||
|
// coins logic for the website
|
||||||
xmreg::page xmrblocks(&mcore, core_storage);
|
xmreg::page xmrblocks(&mcore, core_storage);
|
||||||
|
|
||||||
|
// crow instance
|
||||||
crow::SimpleApp app;
|
crow::SimpleApp app;
|
||||||
|
|
||||||
|
|
||||||
CROW_ROUTE(app, "/")
|
CROW_ROUTE(app, "/")
|
||||||
([&]() {
|
([&]() {
|
||||||
return xmrblocks.index();
|
return xmrblocks.index();
|
||||||
|
@ -90,15 +93,15 @@ int main(int ac, const char* av[]) {
|
||||||
return xmreg::read("./templates/css/style.css");
|
return xmreg::read("./templates/css/style.css");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// run the crow http server
|
||||||
app.port(app_port).multithreaded().run();
|
app.port(app_port).multithreaded().run();
|
||||||
|
|
||||||
// set timezone to orginal value
|
// set timezone to orginal value
|
||||||
if (tz_org != 0)
|
// if (tz_org != 0)
|
||||||
{
|
// {
|
||||||
setenv("TZ", old_tz, 1);
|
// setenv("TZ", old_tz, 1);
|
||||||
tzset();
|
// tzset();
|
||||||
}
|
// }
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
72
src/page.h
72
src/page.h
|
@ -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};
|
array<size_t, 5> delta_time = timestamp_difference(
|
||||||
uint64_t delta_seconds {0};
|
server_timestamp, blk.timestamp);
|
||||||
|
|
||||||
if (prev_blk_timestamp > 0)
|
string timestamp_str = xmreg::timestamp_to_str(blk.timestamp);
|
||||||
{
|
|
||||||
// array<size_t, 5> delta_time = timestamp_difference(
|
|
||||||
// prev_blk_timestamp, blk.timestamp);
|
|
||||||
|
|
||||||
array<size_t, 5> delta_time = timestamp_difference(
|
|
||||||
server_timestamp, blk.timestamp);
|
|
||||||
|
|
||||||
delta_hours = delta_time[2];
|
|
||||||
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t sum_inputs = sum_xmr_inputs(_tx_info.tx_json);
|
// sum xmr in inputs and ouputs in the given tx
|
||||||
|
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,19 +301,17 @@ 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)
|
||||||
{
|
{
|
||||||
//print(" - {:s}, {:0.8f} xmr\n",
|
//print(" - {:s}, {:0.8f} xmr\n",
|
||||||
// vout[i]["target"]["key"].GetString(),
|
// vout[i]["target"]["key"].GetString(),
|
||||||
// XMR_AMOUNT(vout[i]["amount"].GetUint64()));
|
// XMR_AMOUNT(vout[i]["amount"].GetUint64()));
|
||||||
|
|
||||||
sum_xmr += vout[i]["amount"].GetUint64();
|
sum_xmr += vout[i]["amount"].GetUint64();
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
<div class="center">
|
<div class="center">
|
||||||
<h5>
|
<h5>
|
||||||
Server time {{server_timestamp}} |
|
|
||||||
{{#refresh}}
|
|
||||||
<a href="/">Autorefresh is ON (10 s)</a>
|
|
||||||
{{/refresh}}
|
|
||||||
{{^refresh}}
|
|
||||||
<a href="/autorefresh">Autorefresh is OFF</a>
|
|
||||||
{{/refresh}}
|
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
{{#refresh}}
|
{{#refresh}}
|
||||||
<meta http-equiv="refresh" content="10">
|
<meta http-equiv="refresh" content="10">
|
||||||
{{/refresh}}
|
{{/refresh}}
|
||||||
<title>Hidden Monero Explorer</title>
|
<title>Onion Monero Explorer</title>
|
||||||
<link rel="stylesheet" type="text/css" href="/css/style.css">
|
<link rel="stylesheet" type="text/css" href="/css/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
|
|
||||||
<div class="center">
|
<div class="center">
|
||||||
<h1 class="center">Hidden Monero Blockchain Explorer</h1>
|
<h1 class="center">Onion Monero Blockchain Explorer</h1>
|
||||||
<h3 style="font-size: 12px; margin-top: 0px">(no javascript - no web analytics trackers - no images - open sourced)</h3>
|
<h4 style="font-size: 15px; margin: 0px">(no javascript - no web analytics trackers - no images - open sourced)</h4>
|
||||||
|
<h3 style="font-size: 12px; margin-top: 20px">
|
||||||
|
|
||||||
|
Server time: {{server_timestamp}} |
|
||||||
|
|
||||||
|
{{#refresh}}
|
||||||
|
<a href="/">Autorefresh is ON (10 s)</a>
|
||||||
|
{{/refresh}}
|
||||||
|
{{^refresh}}
|
||||||
|
<a href="/autorefresh">Autorefresh is OFF</a>
|
||||||
|
{{/refresh}}
|
||||||
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue