Browse Source

prettify diff and hashrate output

master
R4SAS 6 years ago committed by R4SAS
parent
commit
1ffcafe061
  1. 2
      routes/block.js
  2. 13
      routes/index.js

2
routes/block.js

@ -28,6 +28,8 @@ router.get('/:hash', async function(req, res, next) {
const block = blockInstance.toJSON(); const block = blockInstance.toJSON();
block.confirmations = lastBlock.maxheight - block.height + 1; block.confirmations = lastBlock.maxheight - block.height + 1;
block.time = block.time.toUTCString(); block.time = block.time.toUTCString();
block.difficulty = block.difficulty.toFixed(8);
block.hashrate = block.hashrate.toLocaleString() + " H/s";
res.render('block', { res.render('block', {
block, block,
}); });

13
routes/index.js

@ -2,6 +2,18 @@ var models = require('../models');
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
function formatRate(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1000;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['H/s', 'KH/s', 'MH/s', 'GH/s', 'TH/s', 'PH/s', 'EH/s', 'ZH/s', 'YH/s'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
/* GET home page. */ /* GET home page. */
router.get('/', async function(req, res, next) { router.get('/', async function(req, res, next) {
@ -13,6 +25,7 @@ router.get('/', async function(req, res, next) {
blocks.forEach(function(arrayItem) { blocks.forEach(function(arrayItem) {
arrayItem.ago = arrayItem.time.toUTCString().substring(5); arrayItem.ago = arrayItem.time.toUTCString().substring(5);
arrayItem.difficulty = arrayItem.difficulty.toFixed(8); arrayItem.difficulty = arrayItem.difficulty.toFixed(8);
arrayItem.hashrate = formatRate(arrayItem.hashrate, 4);
}); });
res.render('index', { res.render('index', {
blocks, blocks,

Loading…
Cancel
Save