Browse Source

- add more network summary info to homepage

- playing with layout/styling on homepage
fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
cdeb566a27
  1. 14
      app/api/coreApi.js
  2. 12
      app/api/rpcApi.js
  3. 25
      routes/baseActionsRouter.js
  4. 69
      views/index.pug

14
app/api/coreApi.js

@ -66,10 +66,20 @@ function getMempoolInfo() {
return tryCacheThenRpcApi(miscCache, "getMempoolInfo", 1000, rpcApi.getMempoolInfo); return tryCacheThenRpcApi(miscCache, "getMempoolInfo", 1000, rpcApi.getMempoolInfo);
} }
function getMiningInfo() {
return tryCacheThenRpcApi(miscCache, "getMiningInfo", 1000, rpcApi.getMiningInfo);
}
function getUptimeSeconds() { function getUptimeSeconds() {
return tryCacheThenRpcApi(miscCache, "getUptimeSeconds", 1000, rpcApi.getUptimeSeconds); return tryCacheThenRpcApi(miscCache, "getUptimeSeconds", 1000, rpcApi.getUptimeSeconds);
} }
function getChainTxStats(blockCount) {
return tryCacheThenRpcApi(miscCache, "getChainTxStats-" + blockCount, 120000, function() {
return rpcApi.getChainTxStats(blockCount);
});
}
function getPeerSummary() { function getPeerSummary() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
tryCacheThenRpcApi(miscCache, "getpeerinfo", 1000, rpcApi.getPeerInfo).then(function(getpeerinfo) { tryCacheThenRpcApi(miscCache, "getpeerinfo", 1000, rpcApi.getPeerInfo).then(function(getpeerinfo) {
@ -576,6 +586,7 @@ module.exports = {
getNetworkInfo: getNetworkInfo, getNetworkInfo: getNetworkInfo,
getNetTotals: getNetTotals, getNetTotals: getNetTotals,
getMempoolInfo: getMempoolInfo, getMempoolInfo: getMempoolInfo,
getMiningInfo: getMiningInfo,
getBlockByHeight: getBlockByHeight, getBlockByHeight: getBlockByHeight,
getBlocksByHeight: getBlocksByHeight, getBlocksByHeight: getBlocksByHeight,
getBlockByHash: getBlockByHash, getBlockByHash: getBlockByHash,
@ -588,5 +599,6 @@ module.exports = {
getRpcMethodHelp: getRpcMethodHelp, getRpcMethodHelp: getRpcMethodHelp,
getAddress: getAddress, getAddress: getAddress,
logCacheSizes: logCacheSizes, logCacheSizes: logCacheSizes,
getPeerSummary: getPeerSummary getPeerSummary: getPeerSummary,
getChainTxStats: getChainTxStats
}; };

12
app/api/rpcApi.js

@ -19,6 +19,10 @@ function getMempoolInfo() {
return getRpcData("getmempoolinfo"); return getRpcData("getmempoolinfo");
} }
function getMiningInfo() {
return getRpcData("getmininginfo");
}
function getUptimeSeconds() { function getUptimeSeconds() {
return getRpcData("uptime"); return getRpcData("uptime");
} }
@ -31,6 +35,10 @@ function getRawMempool() {
return getRpcDataWithParams("getrawmempool", true); return getRpcDataWithParams("getrawmempool", true);
} }
function getChainTxStats(blockCount) {
return getRpcDataWithParams("getchaintxstats", blockCount);
}
function getBlockByHeight(blockHeight) { function getBlockByHeight(blockHeight) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
getBlocksByHeight([blockHeight]).then(function(results) { getBlocksByHeight([blockHeight]).then(function(results) {
@ -399,6 +407,7 @@ module.exports = {
getNetworkInfo: getNetworkInfo, getNetworkInfo: getNetworkInfo,
getNetTotals: getNetTotals, getNetTotals: getNetTotals,
getMempoolInfo: getMempoolInfo, getMempoolInfo: getMempoolInfo,
getMiningInfo: getMiningInfo,
getBlockByHeight: getBlockByHeight, getBlockByHeight: getBlockByHeight,
getBlocksByHeight: getBlocksByHeight, getBlocksByHeight: getBlocksByHeight,
getBlockByHash: getBlockByHash, getBlockByHash: getBlockByHash,
@ -409,5 +418,6 @@ module.exports = {
getHelp: getHelp, getHelp: getHelp,
getRpcMethodHelp: getRpcMethodHelp, getRpcMethodHelp: getRpcMethodHelp,
getAddress: getAddress, getAddress: getAddress,
getPeerInfo: getPeerInfo getPeerInfo: getPeerInfo,
getChainTxStats: getChainTxStats
}; };

25
routes/baseActionsRouter.js

@ -31,6 +31,17 @@ router.get("/", function(req, res) {
return; return;
} }
var promises = [];
promises.push(coreApi.getMempoolInfo());
promises.push(coreApi.getMiningInfo());
var chainTxStatsIntervals = [ 144, 144 * 7, 144 * 30, 144 * 265 ];
res.locals.chainTxStatsLabels = [ "24 hours", "1 week", "1 month", "1 year", "All time" ];
for (var i = 0; i < chainTxStatsIntervals.length; i++) {
promises.push(coreApi.getChainTxStats(chainTxStatsIntervals[i]));
}
coreApi.getBlockchainInfo().then(function(getblockchaininfo) { coreApi.getBlockchainInfo().then(function(getblockchaininfo) {
res.locals.getblockchaininfo = getblockchaininfo; res.locals.getblockchaininfo = getblockchaininfo;
@ -41,11 +52,25 @@ router.get("/", function(req, res) {
} }
} }
promises.push(coreApi.getChainTxStats(getblockchaininfo.blocks - 1));
coreApi.getBlocksByHeight(blockHeights).then(function(latestBlocks) { coreApi.getBlocksByHeight(blockHeights).then(function(latestBlocks) {
res.locals.latestBlocks = latestBlocks; res.locals.latestBlocks = latestBlocks;
Promise.all(promises).then(function(promiseResults) {
res.locals.mempoolInfo = promiseResults[0];
res.locals.miningInfo = promiseResults[1];
var chainTxStats = [];
for (var i = 0; i < res.locals.chainTxStatsLabels.length; i++) {
chainTxStats.push(promiseResults[i + 2]);
}
res.locals.chainTxStats = chainTxStats;
res.render("index"); res.render("index");
}); });
});
}).catch(function(err) { }).catch(function(err) {
res.locals.userMessage = "Error loading recent blocks: " + err; res.locals.userMessage = "Error loading recent blocks: " + err;

69
views/index.pug

@ -4,7 +4,7 @@ block headContent
title Home title Home
block content block content
h1(class="h2") #{coinConfig.siteTitle} h1(class="h3") #{coinConfig.siteTitle}
hr hr
if (config.demoSite && session.hideHomepageBanner != "true") if (config.demoSite && session.hideHomepageBanner != "true")
@ -28,24 +28,83 @@ block content
a(href="/changeSetting?name=hideHomepageBanner&value=true", class="close", aria-label="Close", style="text-decoration: none;") a(href="/changeSetting?name=hideHomepageBanner&value=true", class="close", aria-label="Close", style="text-decoration: none;")
span(aria-hidden="true") &times; span(aria-hidden="true") &times;
div(class="card mb-3")
div(class="card-header")
h2(class="h6 mb-0") Network Summary
div(class="card-body")
table(class="table table-responsive-sm")
thead
tr
th Hashrate
if (getblockchaininfo.size_on_disk)
th Blockchain Size
th Difficulty
th Mempool Size
tbody(class="monospace")
tr
td #{miningInfo.networkhashps}
td #{utils.formatBytes(getblockchaininfo.size_on_disk)}
span(class="text-muted") (pruned: #{getblockchaininfo.pruned})
td
- var scales = [ {val:1000000000000000, name:"e15"}, {val:1000000000000, name:"e12"}, {val:1000000000, name:"e9"}, {val:1000000, name:"e6"} ];
- var scaleDone = false;
span #{parseFloat(getblockchaininfo.difficulty).toLocaleString()}
each item in scales
if (!scaleDone)
- var fraction = Math.floor(getblockchaininfo.difficulty / item.val);
if (fraction >= 1)
- scaleDone = true;
span(class="text-muted") (#{fraction}#{item.name})
td #{mempoolInfo.size.toLocaleString()} tx
span(class="text-muted") (#{mempoolInfo.usage.toLocaleString()} bytes)
if (latestBlocks) if (latestBlocks)
div(class="row mt-4") div(class="card mb-3")
div(class="card-header")
div(class="row")
div(class="col") div(class="col")
h2(class="h3") Latest Blocks h2(class="h6 mb-0") Latest Blocks
if (getblockchaininfo.initialblockdownload) if (getblockchaininfo.initialblockdownload)
small (#{(getblockchaininfo.headers - getblockchaininfo.blocks).toLocaleString()} behind) small (#{(getblockchaininfo.headers - getblockchaininfo.blocks).toLocaleString()} behind)
div(class="col") div(class="col")
span(style="float: right;") span(style="float: right;")
a(href="/blocks", class="btn btn-primary") Browse Blocks &raquo; a(href="/blocks") Browse Blocks &raquo;
hr div(class="card-body")
- var blocks = latestBlocks; - var blocks = latestBlocks;
- var blockOffset = 0; - var blockOffset = 0;
include includes/blocks-list.pug include includes/blocks-list.pug
if (chainTxStats)
div(class="card mb-3")
div(class="card-header")
h2(class="h6 mb-0") Transaction Stats
div(class="card-body")
table(class="table table-responsive-sm text-right")
thead
tr
th
each item, index in chainTxStatsLabels
th #{item}
tbody
tr
th(class="text-left") Count
each item, index in chainTxStats
td(class="monospace") #{item.window_tx_count.toLocaleString()}
tr
th(class="text-left") Rate
each item, index in chainTxStats
td(class="monospace") #{new Decimal(item.txrate).toDecimalPlaces(4)}
block endOfBody block endOfBody
script(async, defer, src="https://buttons.github.io/buttons.js") script(async, defer, src="https://buttons.github.io/buttons.js")
Loading…
Cancel
Save