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. 27
      routes/baseActionsRouter.js
  4. 85
      views/index.pug

14
app/api/coreApi.js

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

12
app/api/rpcApi.js

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

27
routes/baseActionsRouter.js

@ -31,6 +31,17 @@ router.get("/", function(req, res) {
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) {
res.locals.getblockchaininfo = getblockchaininfo;
@ -41,10 +52,24 @@ router.get("/", function(req, res) {
}
}
promises.push(coreApi.getChainTxStats(getblockchaininfo.blocks - 1));
coreApi.getBlocksByHeight(blockHeights).then(function(latestBlocks) {
res.locals.latestBlocks = latestBlocks;
res.render("index");
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");
});
});
}).catch(function(err) {
res.locals.userMessage = "Error loading recent blocks: " + err;

85
views/index.pug

@ -4,7 +4,7 @@ block headContent
title Home
block content
h1(class="h2") #{coinConfig.siteTitle}
h1(class="h3") #{coinConfig.siteTitle}
hr
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;")
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)
div(class="row mt-4")
div(class="col")
h2(class="h3") Latest Blocks
if (getblockchaininfo.initialblockdownload)
small (#{(getblockchaininfo.headers - getblockchaininfo.blocks).toLocaleString()} behind)
div(class="card mb-3")
div(class="card-header")
div(class="row")
div(class="col")
h2(class="h6 mb-0") Latest Blocks
if (getblockchaininfo.initialblockdownload)
small (#{(getblockchaininfo.headers - getblockchaininfo.blocks).toLocaleString()} behind)
div(class="col")
span(style="float: right;")
a(href="/blocks") Browse Blocks &raquo;
div(class="card-body")
- var blocks = latestBlocks;
- var blockOffset = 0;
div(class="col")
span(style="float: right;")
a(href="/blocks", class="btn btn-primary") Browse Blocks &raquo;
include includes/blocks-list.pug
hr
- var blocks = latestBlocks;
- var blockOffset = 0;
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()}
include includes/blocks-list.pug
tr
th(class="text-left") Rate
each item, index in chainTxStats
td(class="monospace") #{new Decimal(item.txrate).toDecimalPlaces(4)}
block endOfBody
script(async, defer, src="https://buttons.github.io/buttons.js")
Loading…
Cancel
Save