From a3aaa3f99718d800de8b46e372a13fe24d69467d Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Thu, 14 Apr 2016 07:58:01 +0000 Subject: [PATCH] html updated --- main.cpp | 41 +++++++++++----------- src/page.h | 72 +++++++++++++++------------------------ src/templates/footer.html | 8 +---- src/templates/header.html | 2 +- src/templates/index.html | 15 ++++++-- 5 files changed, 64 insertions(+), 74 deletions(-) diff --git a/main.cpp b/main.cpp index 1a73613..f847d59 100644 --- a/main.cpp +++ b/main.cpp @@ -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("port"); auto bc_path_opt = opts.get_option("bc-path"); - + //cast port number in string to uint16 uint16_t app_port = boost::lexical_cast(*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(tz.c_str())); - tzset(); // Initialize timezone data + // // set new timezone + // std::string tz = "TZ=Coordinated Universal Time"; + // putenv(const_cast(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; } \ No newline at end of file diff --git a/src/page.h b/src/page.h index c1ba6e2..38c903e 100644 --- a/src/page.h +++ b/src/page.h @@ -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(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 delta_time = timestamp_difference( -// prev_blk_timestamp, blk.timestamp); - - array 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 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 coinbase_tx = sum_money_in_tx(blk.miner_tx); @@ -182,8 +166,6 @@ namespace xmreg { {"blksize" , fmt::format("{:0.2f}", static_cast(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(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 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 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 get_mixin_no_in_txs(const string& json_str) { diff --git a/src/templates/footer.html b/src/templates/footer.html index 5bda3ad..ca7ad58 100644 --- a/src/templates/footer.html +++ b/src/templates/footer.html @@ -1,12 +1,6 @@
- Server time {{server_timestamp}} | - {{#refresh}} - Autorefresh is ON (10 s) - {{/refresh}} - {{^refresh}} - Autorefresh is OFF - {{/refresh}} +
diff --git a/src/templates/header.html b/src/templates/header.html index 6459cd2..3e8fdda 100644 --- a/src/templates/header.html +++ b/src/templates/header.html @@ -5,7 +5,7 @@ {{#refresh}} {{/refresh}} - Hidden Monero Explorer + Onion Monero Explorer diff --git a/src/templates/index.html b/src/templates/index.html index 282b558..1ce60d0 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -1,7 +1,18 @@
-

Hidden Monero Blockchain Explorer

-

(no javascript - no web analytics trackers - no images - open sourced)

+

Onion Monero Blockchain Explorer

+

(no javascript - no web analytics trackers - no images - open sourced)

+

+ + Server time: {{server_timestamp}} | + + {{#refresh}} + Autorefresh is ON (10 s) + {{/refresh}} + {{^refresh}} + Autorefresh is OFF + {{/refresh}} +