From 7f235c831d622fd25f39fe6dc6c7a40466d16de7 Mon Sep 17 00:00:00 2001 From: Nadav Ivgi Date: Fri, 15 Feb 2019 04:21:51 +0200 Subject: [PATCH] Limit stats intervals to the history we have available --- routes/baseActionsRouter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/routes/baseActionsRouter.js b/routes/baseActionsRouter.js index f1cf51c..b7a2a30 100644 --- a/routes/baseActionsRouter.js +++ b/routes/baseActionsRouter.js @@ -48,8 +48,12 @@ router.get("/", function(req, res) { res.locals.getblockchaininfo = getblockchaininfo; if (getblockchaininfo.chain !== 'regtest') { - var chainTxStatsIntervals = [ 144, 144 * 7, 144 * 30, 144 * 365 ]; - res.locals.chainTxStatsLabels = [ "24 hours", "1 week", "1 month", "1 year", "All time" ]; + var chainTxStatsIntervals = [ 144, 144 * 7, 144 * 30, 144 * 365] + .filter(numBlocks => numBlocks < getblockchaininfo.blocks); + res.locals.chainTxStatsLabels = [ "24 hours", "1 week", "1 month", "1 year" ] + .slice(0, chainTxStatsIntervals.length) + .concat("All time"); + for (var i = 0; i < chainTxStatsIntervals.length; i++) { promises.push(coreApi.getChainTxStats(chainTxStatsIntervals[i])); }