diff --git a/src/MempoolStatus.cpp b/src/MempoolStatus.cpp index 75d9a54..9aeca58 100644 --- a/src/MempoolStatus.cpp +++ b/src/MempoolStatus.cpp @@ -265,6 +265,15 @@ MempoolStatus::get_mempool_txs() return mempool_txs; } +vector +MempoolStatus::get_mempool_txs(uint64_t no_of_tx) +{ + Guard lck (mempool_mutx); + + no_of_tx = std::min(no_of_tx, mempool_txs.size()); + + return vector(mempool_txs.begin(), mempool_txs.begin() + no_of_tx); +} bool MempoolStatus::is_thread_running() diff --git a/src/MempoolStatus.h b/src/MempoolStatus.h index 25b9db6..04248a7 100644 --- a/src/MempoolStatus.h +++ b/src/MempoolStatus.h @@ -113,10 +113,13 @@ struct MempoolStatus static bool read_network_info(); - static vector get_mempool_txs(); + // get first no_of_tx from the vector + static vector + get_mempool_txs(uint64_t no_of_tx); + static bool is_thread_running(); }; diff --git a/src/page.h b/src/page.h index 60d559e..4f580fc 100644 --- a/src/page.h +++ b/src/page.h @@ -804,15 +804,29 @@ namespace xmreg string mempool(bool add_header_and_footer = false, uint64_t no_of_mempool_tx = 25) { - std::vector mempool_txs - = MempoolStatus::get_mempool_txs(); + std::vector mempool_txs; - // size of mempool in bytes + if (add_header_and_footer) + { + // get all memmpool txs + mempool_txs = MempoolStatus::get_mempool_txs(); + } + else + { + // get only first no_of_mempool_tx txs + mempool_txs = MempoolStatus::get_mempool_txs(no_of_mempool_tx); + } + + // total size of mempool in bytes uint64_t mempool_size_bytes = MempoolStatus::mempool_size; + // reasign this number, in case no of txs in mempool is smaller + // than what we requested or we want all txs. + no_of_mempool_tx = mempool_txs.size(); + // initalise page tempate map with basic info about mempool mstch::map context { - {"mempool_size" , mempool_txs.size()}, + {"mempool_size" , MempoolStatus::mempool_no}, // total no of mempool txs {"show_cache_times" , show_cache_times} }; @@ -821,27 +835,6 @@ namespace xmreg // get reference to blocks template map to be field below mstch::array& txs = boost::get(context["mempooltxs"]); - // process only up to no_of_mempool_tx txs of mempool. - // this is useful from the front page were we show by default - // only 25 mempool txs. this way, we just parse 25 txs, rather - // than potentially hundrets just to ditch most of them later. - - if (add_header_and_footer == false) - { - // this is to show limited number of txs in mempool - // for example, in the front page - no_of_mempool_tx = mempool_txs.size() > no_of_mempool_tx - ? no_of_mempool_tx - : mempool_txs.size(); - } - else - { - // if we are adding footers and headers, means we - // disply mempool on its own page, thus show all mempoool txs. - no_of_mempool_tx = mempool_txs.size(); - } - - double duration_cached {0.0}; double duration_non_cached {0.0}; uint64_t cache_hits {0};