mirror of
https://github.com/GOSTSec/gostexplr
synced 2025-03-13 05:51:26 +00:00
prettify diff and hashrate output
This commit is contained in:
parent
6108749fdd
commit
1ffcafe061
@ -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,
|
||||||
});
|
});
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user