From c9956cf2955f27d2f197748b6e9519926c51168d Mon Sep 17 00:00:00 2001 From: joeuhren <46763106+joeuhren@users.noreply.github.com> Date: Wed, 30 Dec 2020 18:51:39 -0700 Subject: [PATCH] Improved /ext/getbasicstats api -Masternode count is only included in the results if the getmasternodecount api is available and enabled --- app.js | 21 ++++++++++++++++----- views/info.pug | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 5e0d09b..ae245c0 100644 --- a/app.js +++ b/app.js @@ -207,13 +207,24 @@ app.use('/ext/getcurrentprice', function(req, res) { app.use('/ext/getbasicstats', function(req, res) { // check if the getbasicstats api is enabled if (settings.public_api.ext['getbasicstats']) { - lib.get_blockcount(function(blockcount) { + // lookup stats + db.get_stats(settings.coin, function (stats) { + // lookup coin supply lib.get_supply(function(supply) { - db.get_stats(settings.coin, function (stats) { - lib.get_masternodecount(function(masternodestotal) { - eval('var p_ext = { "block_count": (blockcount ? blockcount : 0), "money_supply": (supply ? supply : 0), "last_price_'+settings.markets.exchange.toLowerCase()+'": stats.last_price, "last_price_usd": stats.last_usd_price, "masternode_count": masternodestotal.total }'); + // lookup block count + lib.get_blockcount(function(blockcount) { + // check if the masternode count api is enabled + if (settings.public_api.rpc['getmasternodecount'] == true && settings.api_cmds['getmasternodecount'] != null && settings.api_cmds['getmasternodecount'] != '') { + // masternode count api is available + lib.get_masternodecount(function(masternodestotal) { + eval('var p_ext = { "block_count": (blockcount ? blockcount : 0), "money_supply": (supply ? supply : 0), "last_price_'+settings.markets.exchange.toLowerCase()+'": stats.last_price, "last_price_usd": stats.last_usd_price, "masternode_count": masternodestotal.total }'); + res.send(p_ext); + }); + } else { + // masternode count api is not available + eval('var p_ext = { "block_count": (blockcount ? blockcount : 0), "money_supply": (supply ? supply : 0), "last_price_'+settings.markets.exchange.toLowerCase()+'": stats.last_price, "last_price_usd": stats.last_usd_price }'); res.send(p_ext); - }); + } }); }); }); diff --git a/views/info.pug b/views/info.pug index bc19a75..a301193 100644 --- a/views/info.pug +++ b/views/info.pug @@ -203,7 +203,7 @@ block content p div.font-weight-bold getbasicstats div - em Returns basic statistics about the coin including: block count, circulating supply, USD price, BTC price and # of masternodes + em="Returns basic statistics about the coin including: block count, circulating supply, USD price, BTC price" + (settings.public_api.rpc['getmasternodecount'] == true && settings.api_cmds['getmasternodecount'] != null && settings.api_cmds['getmasternodecount'] != '' ? ', ' + '# of masternodes' : '') a(href='/ext/getbasicstats') #{address}/ext/getbasicstats if settings.public_api.ext['getmasternodelist'] == true && settings.api_cmds['getmasternodelist'] != null && settings.api_cmds['getmasternodelist'] != '' li