Merge pull request #30 from moneroexamples/limit_mempool_tx_on_front_page
Limit mempool tx on front page
This commit is contained in:
commit
02091a64f9
|
@ -1,10 +1,5 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
#list(INSERT
|
||||
# CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake)
|
||||
set(CMAKE_MODULE_PATH
|
||||
${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
set(PROJECT_NAME
|
||||
xmrblocks)
|
||||
|
||||
|
@ -191,7 +186,7 @@ set(LIBRARIES
|
|||
crypto
|
||||
ssl)
|
||||
|
||||
if (!APPLE)
|
||||
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set(LIBRARIES ${LIBRARIES} unwind)
|
||||
endif()
|
||||
|
||||
|
|
5
main.cpp
5
main.cpp
|
@ -304,6 +304,11 @@ int main(int ac, const char* av[]) {
|
|||
return xmrblocks.search(string(req.url_params.get("value")));
|
||||
});
|
||||
|
||||
CROW_ROUTE(app, "/mempool")
|
||||
([&](const crow::request& req) {
|
||||
return xmrblocks.mempool(true);
|
||||
});
|
||||
|
||||
CROW_ROUTE(app, "/robots.txt")
|
||||
([&]() {
|
||||
string text = "User-agent: *\n"
|
||||
|
|
36
src/page.h
36
src/page.h
|
@ -258,6 +258,9 @@ class page {
|
|||
bool enable_pusher;
|
||||
|
||||
|
||||
uint64_t no_of_mempool_tx_of_frontpage;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
page(MicroCore* _mcore, Blockchain* _core_storage,
|
||||
|
@ -272,6 +275,7 @@ public:
|
|||
enable_pusher {_enable_pusher}
|
||||
{
|
||||
css_styles = xmreg::read(TMPL_CSS_STYLES);
|
||||
no_of_mempool_tx_of_frontpage = 25;
|
||||
}
|
||||
|
||||
|
||||
|
@ -651,7 +655,7 @@ public:
|
|||
* Render mempool data
|
||||
*/
|
||||
string
|
||||
mempool()
|
||||
mempool(bool add_header_and_footer = false)
|
||||
{
|
||||
std::vector<tx_info> mempool_txs;
|
||||
|
||||
|
@ -774,9 +778,37 @@ public:
|
|||
return t1 > t2;
|
||||
});
|
||||
|
||||
// read index.html
|
||||
// read mempool.html
|
||||
string mempool_html = xmreg::read(TMPL_MEMPOOL);
|
||||
|
||||
if (add_header_and_footer)
|
||||
{
|
||||
// this is when mempool is on its own page, /mempool
|
||||
add_css_style(context);
|
||||
|
||||
context["partial_mempool_shown"] = false;
|
||||
|
||||
// add header and footer
|
||||
string full_page = get_full_page(mempool_html);
|
||||
|
||||
// render the page
|
||||
return mstch::render(full_page, context);
|
||||
}
|
||||
|
||||
// this is for partial disply on front page.
|
||||
|
||||
context["mempool_fits_on_front_page"] = (txs.size() <= no_of_mempool_tx_of_frontpage);
|
||||
context["no_of_mempool_tx_of_frontpage"] = no_of_mempool_tx_of_frontpage;
|
||||
|
||||
if (txs.size() > no_of_mempool_tx_of_frontpage)
|
||||
{
|
||||
// dont show more than the specific number mempool txs on
|
||||
// the front page
|
||||
txs.resize(no_of_mempool_tx_of_frontpage);
|
||||
}
|
||||
|
||||
context["partial_mempool_shown"] = true;
|
||||
|
||||
// render the page
|
||||
return mstch::render(mempool_html, context);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
<h2>
|
||||
Memory pool (no of txs: {{mempool_size}}, size: {{mempool_size_kB}} kB)
|
||||
<h2 style="margin-bottom: 0px">
|
||||
Memory pool
|
||||
</h2>
|
||||
<h4 style="font-size: 14px; margin-top: 0px">(no of txs: {{mempool_size}}, size: {{mempool_size_kB}} kB)</h4>
|
||||
<div class="center">
|
||||
|
||||
<table class="center">
|
||||
<tr>
|
||||
<td>height</td>
|
||||
<td>age [h:m:s]</td>
|
||||
<td>size [kB]<!--(Δm)--></td>
|
||||
<td>transaction hash</td>
|
||||
<td>fee</td>
|
||||
<td>outputs</td>
|
||||
|
@ -19,6 +21,7 @@
|
|||
<tr>
|
||||
<td>N/A</td>
|
||||
<td>{{age}}</td>
|
||||
<td>N/A</td>
|
||||
<td><a href="/tx/{{hash}}">{{hash}}</a></td>
|
||||
<td>{{fee}}</td>
|
||||
<td>{{xmr_outputs}}</td>
|
||||
|
@ -30,5 +33,14 @@
|
|||
{{/mempooltxs}}
|
||||
</table>
|
||||
|
||||
{{^mempool_fits_on_front_page}}
|
||||
{{#partial_mempool_shown}}
|
||||
<div class="center" style="text-align: center">
|
||||
<a href="/mempool">Only {{no_of_mempool_tx_of_frontpage}} txs shown. Click here to see all off them</a>
|
||||
</div>
|
||||
{{/partial_mempool_shown}}
|
||||
|
||||
{{/mempool_fits_on_front_page}}
|
||||
|
||||
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue