html updated

This commit is contained in:
moneroexamples 2016-04-14 07:58:01 +00:00
parent 890ce36121
commit a3aaa3f997
5 changed files with 64 additions and 74 deletions

View File

@ -11,7 +11,7 @@ using boost::filesystem::path;
using namespace std;
// needed for log system of momero
namespace epee {
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 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);
@ -41,18 +41,18 @@ int main(int ac, const char* av[]) {
// change timezone to Universtal time zone
char old_tz[128];
const char *tz_org = getenv("TZ");
// char old_tz[128];
// const char *tz_org = getenv("TZ");
if (tz_org)
{
strcpy(old_tz, tz_org);
}
// if (tz_org)
// {
// strcpy(old_tz, tz_org);
// }
// set new timezone
std::string tz = "TZ=Coordinated Universal Time";
putenv(const_cast<char *>(tz.c_str()));
tzset(); // Initialize timezone data
// // set new timezone
// std::string tz = "TZ=Coordinated Universal Time";
// putenv(const_cast<char *>(tz.c_str()));
// tzset(); // Initialize timezone data
// enable basic monero log output
@ -69,11 +69,14 @@ int main(int ac, const char* av[]) {
return 1;
}
// create instance of page class which
// coins logic for the website
xmreg::page xmrblocks(&mcore, core_storage);
// crow instance
crow::SimpleApp app;
CROW_ROUTE(app, "/")
([&]() {
return xmrblocks.index();
@ -90,15 +93,15 @@ int main(int ac, const char* av[]) {
return xmreg::read("./templates/css/style.css");
});
// run the crow http server
app.port(app_port).multithreaded().run();
// set timezone to orginal value
if (tz_org != 0)
{
setenv("TZ", old_tz, 1);
tzset();
}
// if (tz_org != 0)
// {
// setenv("TZ", old_tz, 1);
// tzset();
// }
return 0;
}

View File

@ -53,7 +53,10 @@ namespace xmreg {
public:
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;
fmt::print("Current height: {:d}\n", height);
// initalise page tempate map with basic info about blockchain
mstch::map context {
{"refresh", refresh_page},
@ -85,8 +86,6 @@ namespace xmreg {
// get reference to blocks template map to be field below
mstch::array& blocks = boost::get<mstch::array>(context["blocks"]);
time_t prev_blk_timestamp {0};
// iterate over last no_of_last_blocks of blocks
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));
uint64_t delta_hours {0};
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(
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);
// calculate difference between server and block timestamps
array<size_t, 5> delta_time = timestamp_difference(
server_timestamp, blk.timestamp);
string timestamp_str = xmreg::timestamp_to_str(blk.timestamp);
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
delta_hours, delta_minutes,
delta_seconds);
delta_time[2], delta_time[3],
delta_time[4]);
// get xmr in the block reward
array<uint64_t, 2> coinbase_tx = sum_money_in_tx(blk.miner_tx);
@ -182,8 +166,6 @@ namespace xmreg {
{"blksize" , fmt::format("{:0.2f}",
static_cast<double>(blk_size) / 1024.0)}
});
prev_blk_timestamp = blk.timestamp;
}
// reverse blocks and remove last (i.e., oldest)
@ -192,8 +174,10 @@ namespace xmreg {
std::reverse(blocks.begin(), blocks.end());
blocks.pop_back();
// get memory pool rendered template
string mempool_html = mempool();
// append mempool_html to the index context map
context["mempool_info"] = mempool_html;
// read index.html
@ -236,7 +220,7 @@ namespace xmreg {
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 {
{"mempool_size", fmt::format("{:d}", res.transactions.size())},
{"mempooltxs" , mstch::array()}
@ -245,27 +229,27 @@ namespace xmreg {
// get reference to blocks template map to be field below
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 (size_t i = 0; i < res.transactions.size(); ++i)
{
// get transaction info of the tx in the mempool
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(
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]};
string age_str = fmt::format("{:02d}:{:02d}:{:02d}",
delta_hours,
delta_time[3], delta_time[4]);
// if more than 99 hourse, change formating
// for the template
if (delta_hours > 99)
{
age_str = fmt::format("{:03d}:{:02d}:{:02d}",
@ -273,10 +257,10 @@ namespace xmreg {
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);
// get mixin number in each transaction
vector<uint64_t> mixin_numbers = get_mixin_no_in_txs(_tx_info.tx_json);
@ -317,19 +301,17 @@ namespace xmreg {
return 0;
}
// get information about outputs
const rapidjson::Value& vout = json["vout"];
if (vout.IsArray())
{
// print("Outputs:\n");
for (rapidjson::SizeType i = 0; i < vout.Size(); ++i)
{
//print(" - {:s}, {:0.8f} xmr\n",
// vout[i]["target"]["key"].GetString(),
// XMR_AMOUNT(vout[i]["amount"].GetUint64()));
// vout[i]["target"]["key"].GetString(),
// XMR_AMOUNT(vout[i]["amount"].GetUint64()));
sum_xmr += vout[i]["amount"].GetUint64();
}
@ -351,7 +333,6 @@ namespace xmreg {
return 0;
}
// get information about inputs
const rapidjson::Value& vin = json["vin"];
@ -377,6 +358,7 @@ namespace xmreg {
return sum_xmr;
}
vector<uint64_t>
get_mixin_no_in_txs(const string& json_str)
{

View File

@ -1,12 +1,6 @@
<div class="center">
<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>
</div>
</div>

View File

@ -5,7 +5,7 @@
{{#refresh}}
<meta http-equiv="refresh" content="10">
{{/refresh}}
<title>Hidden Monero Explorer</title>
<title>Onion Monero Explorer</title>
<link rel="stylesheet" type="text/css" href="/css/style.css">
</head>
<body>

View File

@ -1,7 +1,18 @@
<div class="center">
<h1 class="center">Hidden Monero Blockchain Explorer</h1>
<h3 style="font-size: 12px; margin-top: 0px">(no javascript - no web analytics trackers - no images - open sourced)</h3>
<h1 class="center">Onion Monero Blockchain Explorer</h1>
<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>