no_of_last_blocks option added and default set to 10

master
moneroexamples 8 years ago
parent 89ec634422
commit 87ec3934f0

@ -39,20 +39,24 @@ int main(int ac, const char* av[]) {
bool enable_autorefresh_option {*enable_autorefresh_option_opt}; bool enable_autorefresh_option {*enable_autorefresh_option_opt};
bool enable_output_key_checker {*enable_output_key_checker_opt}; bool enable_output_key_checker {*enable_output_key_checker_opt};
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");
auto custom_db_path_opt = opts.get_option<string>("custom-db-path"); auto custom_db_path_opt = opts.get_option<string>("custom-db-path");
auto deamon_url_opt = opts.get_option<string>("deamon-url"); auto deamon_url_opt = opts.get_option<string>("deamon-url");
auto ssl_crt_file_opt = opts.get_option<string>("ssl-crt-file"); auto ssl_crt_file_opt = opts.get_option<string>("ssl-crt-file");
auto ssl_key_file_opt = opts.get_option<string>("ssl-key-file"); auto ssl_key_file_opt = opts.get_option<string>("ssl-key-file");
auto no_blocks_on_index_opt = opts.get_option<string>("no-blocks-on-index");
// set monero log output level // set monero log output level
uint32_t log_level = 0; uint32_t log_level = 0;
mlog_configure("", true); mlog_configure("", true);
//cast port number in string to uint16 //cast port number in string to uint
uint16_t app_port = boost::lexical_cast<uint16_t>(*port_opt); uint16_t app_port = boost::lexical_cast<uint16_t>(*port_opt);
// cast no_blocks_on_index_opt to uint
uint64_t no_blocks_on_index = boost::lexical_cast<uint64_t>(*no_blocks_on_index_opt);
bool use_ssl {false}; bool use_ssl {false};
string ssl_crt_file; string ssl_crt_file;
@ -155,7 +159,8 @@ int main(int ac, const char* av[]) {
enable_pusher, enable_pusher,
enable_key_image_checker, enable_key_image_checker,
enable_output_key_checker, enable_output_key_checker,
enable_autorefresh_option); enable_autorefresh_option,
no_blocks_on_index);
// crow instance // crow instance
crow::SimpleApp app; crow::SimpleApp app;

@ -35,6 +35,8 @@ namespace xmreg
"enable users to have the index page on autorefresh") "enable users to have the index page on autorefresh")
("port,p", value<string>()->default_value("8081"), ("port,p", value<string>()->default_value("8081"),
"default port") "default port")
("no-blocks-on-index", value<string>()->default_value("10"),
"number of last blocks to be shown on index page")
("bc-path,b", value<string>(), ("bc-path,b", value<string>(),
"path to lmdb blockchain") "path to lmdb blockchain")
("ssl-crt-file", value<string>(), ("ssl-crt-file", value<string>(),

@ -268,6 +268,7 @@ class page {
uint64_t no_of_mempool_tx_of_frontpage; uint64_t no_of_mempool_tx_of_frontpage;
uint64_t no_blocks_on_index;
public: public:
@ -277,7 +278,8 @@ public:
bool _testnet, bool _enable_pusher, bool _testnet, bool _enable_pusher,
bool _enable_key_image_checker, bool _enable_key_image_checker,
bool _enable_output_key_checker, bool _enable_output_key_checker,
bool _enable_autorefresh_option) bool _enable_autorefresh_option,
uint64_t _no_blocks_on_index)
: mcore {_mcore}, : mcore {_mcore},
core_storage {_core_storage}, core_storage {_core_storage},
rpc {_deamon_url}, rpc {_deamon_url},
@ -288,7 +290,8 @@ public:
have_custom_lmdb {false}, have_custom_lmdb {false},
enable_key_image_checker {_enable_key_image_checker}, enable_key_image_checker {_enable_key_image_checker},
enable_output_key_checker {_enable_output_key_checker}, enable_output_key_checker {_enable_output_key_checker},
enable_autorefresh_option {_enable_autorefresh_option} enable_autorefresh_option {_enable_autorefresh_option},
no_blocks_on_index {_no_blocks_on_index}
{ {
css_styles = xmreg::read(TMPL_CSS_STYLES); css_styles = xmreg::read(TMPL_CSS_STYLES);
no_of_mempool_tx_of_frontpage = 25; no_of_mempool_tx_of_frontpage = 25;
@ -336,24 +339,25 @@ public:
server_timestamp = std::time(nullptr); server_timestamp = std::time(nullptr);
// number of last blocks to show // number of last blocks to show
uint64_t no_of_last_blocks {25 + 1}; uint64_t no_of_last_blocks {no_blocks_on_index + 1};
// get the current blockchain height. Just to check // get the current blockchain height. Just to check
uint64_t height = core_storage->get_current_blockchain_height(); uint64_t height = core_storage->get_current_blockchain_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 {
{"testnet" , testnet}, {"testnet" , testnet},
{"have_custom_lmdb", have_custom_lmdb}, {"have_custom_lmdb" , have_custom_lmdb},
{"refresh" , refresh_page}, {"refresh" , refresh_page},
{"height" , std::to_string(height)}, {"height" , std::to_string(height)},
{"server_timestamp", xmreg::timestamp_to_str(server_timestamp)}, {"server_timestamp" , xmreg::timestamp_to_str(server_timestamp)},
{"age_format" , string("[h:m:d]")}, {"age_format" , string("[h:m:d]")},
{"page_no" , std::to_string(page_no)}, {"page_no" , std::to_string(page_no)},
{"total_page_no" , std::to_string(height / (no_of_last_blocks))}, {"total_page_no" , std::to_string(height / (no_of_last_blocks))},
{"is_page_zero" , !bool(page_no)}, {"is_page_zero" , !bool(page_no)},
{"next_page" , std::to_string(page_no + 1)}, {"no_of_last_blocks", no_of_last_blocks},
{"prev_page" , std::to_string((page_no > 0 ? page_no - 1 : 0))}, {"next_page" , std::to_string(page_no + 1)},
{"prev_page" , std::to_string((page_no > 0 ? page_no - 1 : 0))},
{"enable_pusher" , enable_pusher}, {"enable_pusher" , enable_pusher},
{"enable_key_image_checker" , enable_key_image_checker}, {"enable_key_image_checker" , enable_key_image_checker},
{"enable_output_key_checker", enable_output_key_checker}, {"enable_output_key_checker", enable_output_key_checker},

@ -31,7 +31,7 @@
{{{mempool_info}}} {{{mempool_info}}}
{{#is_page_zero}} {{#is_page_zero}}
<h2 style="margin-bottom: 0px">Transactions in the last 25 blocks</h2> <h2 style="margin-bottom: 0px">Transactions in the last {{no_of_last_blocks}} blocks</h2>
{{/is_page_zero}} {{/is_page_zero}}
{{^is_page_zero}} {{^is_page_zero}}
<h2 style="margin-bottom: 0px">Transactions in older blocks<!--(height: {{height}})--></h2> <h2 style="margin-bottom: 0px">Transactions in older blocks<!--(height: {{height}})--></h2>

Loading…
Cancel
Save