Browse Source

Merge r4sas commits

pull/3/head
xcps 3 years ago
parent
commit
30458beaea
  1. 20
      routes/index.js
  2. 2
      scripts/blocknotify.sh
  3. 4
      views/index.pug
  4. 1
      views/transaction.pug

20
routes/index.js

@ -1,6 +1,24 @@ @@ -1,6 +1,24 @@
var models = require('../models');
var express = require('express');
var router = express.Router();
var HeightOffset = require('../config/config')['syncHeightOffset'] || 0;
function formatRate(hashrate, decimals = 2) {
if (hashrate === 0) return '0 H/s';
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(hashrate) / Math.log(k));
return parseFloat((hashrate / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
function shorterHash(hash) {
var parts = hash.match(/[\s\S]{1,14}/g) || [];
return parts[0] + '...' + parts[parts.length-1];
}
function formatRate(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
@ -26,8 +44,10 @@ router.get('/', async function(req, res, next) { @@ -26,8 +44,10 @@ router.get('/', async function(req, res, next) {
arrayItem.ago = arrayItem.time.toUTCString().substring(5);
arrayItem.difficulty = parseFloat(arrayItem.difficulty).toFixed(8);
arrayItem.hashrate = formatRate(arrayItem.hashrate, 4);
arrayItem.hash_short = shorterHash(arrayItem.hash);
});
res.render('index', {
HeightOffset,
blocks,
});
});

2
scripts/blocknotify.sh

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
#!/bin/sh
cd $(dirname "$0")/..
npm run syncBlockchain >/dev/null 2>&1
npm run sync >/dev/null 2>&1

4
views/index.pug

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
extends layout
block content
h3 Last 50 blocks
h3 Last 50 blocks (with delay for #{HeightOffset} blocks)
table
tr
@ -22,4 +22,4 @@ block content @@ -22,4 +22,4 @@ block content
td #{block.difficulty}
td #{block.hashrate}
td
a(href='/block/' + block.hash + '/') #{block.hash}
a(href='/block/' + block.hash + '/') #{block.hash_short}

1
views/transaction.pug

@ -56,3 +56,4 @@ block content @@ -56,3 +56,4 @@ block content
td
each transaction in vout.Transactions
a(href=`/transaction/${transaction.txid}/`) #{transaction.txid}
br

Loading…
Cancel
Save